diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..21ac735 --- /dev/null +++ b/dockerfile @@ -0,0 +1,10 @@ +# set base image (host OS) +FROM python:3.8 +# copy the dependencies file to the working directory +COPY requirements.txt . +# install dependencies +RUN pip install -r requirements.txt +# copy the content of the local src directory to the working directory +COPY main.py . +# command to run on container start +CMD [ "python", "./main.py" ] diff --git a/main.py b/main.py new file mode 100644 index 0000000..7d757e7 --- /dev/null +++ b/main.py @@ -0,0 +1,43 @@ +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() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..142a68b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pythonping +influxdb \ No newline at end of file