Added functionality that returns the status of the gateways in addtion to loss/rtt/rttsd

This commit is contained in:
Will Blanton 2021-04-22 14:58:05 -04:00
parent 158a63b51e
commit 01fac80a2e
4 changed files with 20987 additions and 116 deletions

View File

@ -229,6 +229,7 @@ What I updated:
- Created dashboard wide variables to make the dashboard more portable and easily configurable. You shouldn't need to update any of the queries. - Created dashboard wide variables to make the dashboard more portable and easily configurable. You shouldn't need to update any of the queries.
- Took some inspiration and panels [from this dashboard](https://grafana.com/grafana/dashboards/9806 "from this dashboard") - Took some inspiration and panels [from this dashboard](https://grafana.com/grafana/dashboards/9806 "from this dashboard")
- Included gateway RTT from dpinger thanks to [this integration](https://forum.netgate.com/topic/142093/can-telegraf-package-gather-latency-packet-loss-information/3 "this integration") - Included gateway RTT from dpinger thanks to [this integration](https://forum.netgate.com/topic/142093/can-telegraf-package-gather-latency-packet-loss-information/3 "this integration")
- Pulled information from the "return_gateways_status_text" function in "/etc/inc/gwlb.inc" to return the actual status of the gateway, as well as the current loss/rtt and IP values.
- Used[ telegraf configs](https://www.reddit.com/r/pfBlockerNG/comments/bu0ms0/pfblockerngtelegrafinfluxdb_ip_block_list/ " telegraf configs") from this post by [/u/PeskyWarrior](https://www.reddit.com/u/PeskyWarrior "/u/PeskyWarrior") - Used[ telegraf configs](https://www.reddit.com/r/pfBlockerNG/comments/bu0ms0/pfblockerngtelegrafinfluxdb_ip_block_list/ " telegraf configs") from this post by [/u/PeskyWarrior](https://www.reddit.com/u/PeskyWarrior "/u/PeskyWarrior")
- Tag, templating - No need to specify all cpus or interfaces in the graph queries. These values are pulled in with queries. - Tag, templating - No need to specify all cpus or interfaces in the graph queries. These values are pulled in with queries.
- Added chart to show all adapters, IP, MAC and Status[ from here](https://github.com/influxdata/telegraf/issues/3756#issuecomment-485606025 " from here") - Added chart to show all adapters, IP, MAC and Status[ from here](https://github.com/influxdata/telegraf/issues/3756#issuecomment-485606025 " from here")

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,10 @@ IP Address and subnet for IPv4 and IPv6 are collected. I don't have an ipv6 on
# telegraf_gateways # 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. 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 ## Python 2.7
Does /usr/local/bin/python2.7 exist on your pfSense system? If so, use this telegraf_gateways-2.7.py Does /usr/local/bin/python2.7 exist on your pfSense system? If so, use this telegraf_gateways-2.7.py

View 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)