From ed0b51f7a4f2bfe7de213e9da654eaa868b709b0 Mon Sep 17 00:00:00 2001 From: Victor Robellini Date: Sun, 12 Apr 2020 01:42:28 -0400 Subject: [PATCH] Added updated python script Luckily this person knows more python than me: https://gist.github.com/fastjack/a0feb792a9655da7aa3e2a7a1d9f812f --- plugins/telegraf_gateways-3.7.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 plugins/telegraf_gateways-3.7.py diff --git a/plugins/telegraf_gateways-3.7.py b/plugins/telegraf_gateways-3.7.py new file mode 100755 index 0000000..293e450 --- /dev/null +++ b/plugins/telegraf_gateways-3.7.py @@ -0,0 +1,21 @@ +#!/usr/local/bin/python3.7 + +# telegraf_gateways-3.7.py +# https://gist.github.com/fastjack/a0feb792a9655da7aa3e2a7a1d9f812f#file-gateways-py-for-pfsense-2-4-5 +# Special thanks to fashjack - https://gist.github.com/fastjack + +import glob, os, socket + +DPINGER_SOCK_PATH = "/var/run/" + +os.chdir(DPINGER_SOCK_PATH) + +for sock_name in glob.glob("dpinger*.sock"): + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock_path = DPINGER_SOCK_PATH+sock_name + s = sock.connect(sock_path) + line = sock.recv(1024).decode().split('\n', 1)[0] + values = line.split() + print("gateways,gateway_name="+values[0]+" rtt="+str(int(values[1])/100.0)+ \ + ",rttsd="+str(int(values[2])/100.0)+",loss="+str(int(values[3]))+"i") + sock.close()