Added functionality that returns the status of the gateways in addtion to loss/rtt/rttsd
This commit is contained in:
@@ -4,7 +4,10 @@ IP Address and subnet for IPv4 and IPv6 are collected. I don't have an ipv6 on
|
||||
# telegraf_gateways
|
||||
Depending on how recent your pfSense install is, you may need to use the python 3.7 version of the plugin. If you are running 2.4.5, you probably want telegraf_gateways-3.7.py. They both output he same data in the same format.
|
||||
|
||||
All I did was copy telegraf_gateways-3.7.py to /usr/local/bin and rename it to telegraf_gateways.py
|
||||
There is also now a "telegraf_gateways_status-3.7.py" which calls the "return_gateways_status_text" function from "/etc/inc/gwlb.inc". In addition to the loss, rtt, and rttsd included in the original plugin, this plugin will also return the gateway IP, monitored IP, status, and substatus of the gateway. This eliminates the guess work of whether or not pfSense has marked this gateway as down.
|
||||
|
||||
To use this plugin, simply choose your preferred version and save it as "/usr/local/bin/telegraf_gateways.py" on your pfSense box.
|
||||
|
||||
## Python 2.7
|
||||
|
||||
Does /usr/local/bin/python2.7 exist on your pfSense system? If so, use this telegraf_gateways-2.7.py
|
||||
|
||||
46
plugins/telegraf_gateways_status-3.7.py
Normal file
46
plugins/telegraf_gateways_status-3.7.py
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/usr/local/bin/python3.7
|
||||
|
||||
from datetime import datetime
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
php_str = """php -r "require_once('/etc/inc/gwlb.inc'); print(return_gateways_status_text());" """
|
||||
|
||||
try:
|
||||
|
||||
proc = subprocess.Popen(php_str, shell=True, stdout=subprocess.PIPE)
|
||||
output = proc.stdout.read().decode('utf-8')
|
||||
|
||||
fields_output, gw_output = output.split("\n",1)
|
||||
gateways_text = gw_output.split("\n")
|
||||
fields = fields_output.split()
|
||||
|
||||
for gw in gateways_text:
|
||||
if len(gw) > 0:
|
||||
gw_str="gateways,gateway_name="
|
||||
values = gw.split()
|
||||
for i,val in enumerate(values):
|
||||
field = fields[i].lower()
|
||||
if field in ['monitor','source','status','substatus']:
|
||||
if field == 'monitor':
|
||||
field = 'monitor_ip'
|
||||
elif field == 'source':
|
||||
field = 'gateway_ip'
|
||||
val = f'"{val}"'
|
||||
elif field == 'delay':
|
||||
field = 'rtt'
|
||||
val = val.replace('ms','')
|
||||
elif field == 'stddev':
|
||||
field = 'rttsd'
|
||||
val = val.replace('ms','')
|
||||
elif field == 'loss':
|
||||
val = str(int(float(val.replace('%','')))) + "i"
|
||||
if i == 0:
|
||||
gw_str+=str(val) + " "
|
||||
else:
|
||||
gw_str+=str(field)+"="+str(val)+","
|
||||
gw_str=gw_str[:-1]
|
||||
print(gw_str)
|
||||
|
||||
except Exception as e:
|
||||
print(e, file=sys.stderr)
|
||||
Reference in New Issue
Block a user