43 lines
994 B
Python
43 lines
994 B
Python
from os import environ
|
|
import pythonping
|
|
from influxdb import InfluxDBClient
|
|
import json
|
|
import os
|
|
|
|
IPs = import os.environ['hosts']
|
|
IPs = IPs.replace(' ', '').split(",")
|
|
|
|
|
|
def senddataInflux(data, host='192.168.0.13', port=8086):
|
|
for ip in data:
|
|
json_body = [
|
|
{
|
|
"measurement": "data",
|
|
"tags": {
|
|
'pingresult': ip,
|
|
},
|
|
|
|
"fields": {
|
|
"average_rtt": data[ip],
|
|
}
|
|
}
|
|
]
|
|
|
|
client = InfluxDBClient(host, port, database = "telegraf") # Init connection to Influx Server
|
|
client.write_points(json_body) # Write Speedtest results
|
|
|
|
|
|
|
|
def ping(IPs):
|
|
results = {}
|
|
for IP in IPs:
|
|
pingRES = pythonping.ping(IP, count=5)
|
|
results[IP] = pingRES.rtt_avg_ms
|
|
return results
|
|
|
|
|
|
def main():
|
|
## Pull a list from the env variable - Max ~ 2000 IP addresses
|
|
senddataInflux(ping(IPs))
|
|
|
|
main() |