diff --git a/Dockerfile b/Dockerfile index 811c0f3..6f4828c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM debian:bullseye-slim # -RUN apt update && apt install python3 python3-pip -y +RUN apt update && apt install python3 python3-pip iputils-ping -y COPY logpingresult.py /usr/local/bin/ COPY requirements.txt / COPY init.sh / diff --git a/docker-compose.yml b/docker-compose.yml index 4cd5e50..8eb5541 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,4 +7,5 @@ services: - INFLUX_USER=${INFLUX_USER} - INFLUX_PASSWORD=${INFLUX_PASSWORD} - INFLUX_URI=${INFLUX_URI} - - PING_HOSTS="8.8.8.8,10.0.2.1,24.220.0.10,10.2.0.1,192.168.1.25" \ No newline at end of file + - PING_HOSTS="8.8.8.8,10.0.2.1,24.220.0.10,10.2.0.1,192.168.1.25" + # \ No newline at end of file diff --git a/logpingresult.py b/logpingresult.py index 08492b1..b2eb914 100644 --- a/logpingresult.py +++ b/logpingresult.py @@ -1,4 +1,4 @@ -#/usr/bin/python3 +#!/usr/bin/python3 import os import subprocess as sp import requests @@ -19,13 +19,20 @@ infdbpass = os.environ["INFLUX_PASSWORD"] influxuri = os.environ["INFLUX_URI"] pingaddresses = os.environ["PING_HOSTS"].split(",") while(True): - for ip in pingaddresses: - response = sp.getstatusoutput(f"ping -c 1 {ip}") - if(response[0]!=0): - time=2000 - else: - myresp = response[1].split("\n")[1].split(' ')[6].split('=')[1] - - result = addinfluxrecord(ip,myresp) - print(result) - time.sleep(5) \ No newline at end of file + if len(pingaddresses) > 0: + print(pingaddresses) + for ip in pingaddresses: + print(ip) + response = sp.getstatusoutput(f"ping -c 1 {ip}") + print(response) + if(response[0]!=0): + time=2000 + else: + myresp = response[1].split("\n")[1].split(' ')[6].split('=')[1] + + result = addinfluxrecord(ip,myresp) + print(result) + time.sleep(5) + else: + print("No Hosts Defined") + exit \ No newline at end of file