work #1

Merged
paradizelost merged 8 commits from work into main 2024-11-26 12:59:22 -06:00
3 changed files with 21 additions and 13 deletions

View File

@ -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 /

View File

@ -8,3 +8,4 @@ services:
- 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"
#

View File

@ -1,4 +1,4 @@
#/usr/bin/python3
#!/usr/bin/python3
import os
import subprocess as sp
import requests
@ -19,8 +19,12 @@ infdbpass = os.environ["INFLUX_PASSWORD"]
influxuri = os.environ["INFLUX_URI"]
pingaddresses = os.environ["PING_HOSTS"].split(",")
while(True):
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:
@ -29,3 +33,6 @@ while(True):
result = addinfluxrecord(ip,myresp)
print(result)
time.sleep(5)
else:
print("No Hosts Defined")
exit