Ready for testing
This commit is contained in:
parent
9e93b732ec
commit
2a1599a746
10
dockerfile
Normal file
10
dockerfile
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# set base image (host OS)
|
||||||
|
FROM python:3.8
|
||||||
|
# copy the dependencies file to the working directory
|
||||||
|
COPY require.txt .
|
||||||
|
# install dependencies
|
||||||
|
RUN pip install -r require.txt
|
||||||
|
# copy the content of the local src directory to the working directory
|
||||||
|
COPY main.py .
|
||||||
|
# command to run on container start
|
||||||
|
CMD [ "python", "./telegramMiddleman.py" ]
|
||||||
64
main.py
64
main.py
@ -9,17 +9,8 @@ from influxdb import InfluxDBClient
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
hostList = os.environ["hosts"]
|
||||||
|
hostList = hostList.split(",")
|
||||||
### telegram logging
|
|
||||||
# API Key
|
|
||||||
apikey = '1857016076:AAGVag6tEtEpJHNpPtLyHYU-JsnN7arwDRk'
|
|
||||||
# Key of your chat.
|
|
||||||
chatid = '840699197'
|
|
||||||
|
|
||||||
def logTelegram(message):
|
|
||||||
os.system("curl --silent -X POST https://api.telegram.org/bot" + apikey + "/sendMessage -d chat_id=" + chatid +" -d text=\""+ message +"\"")
|
|
||||||
### end telegram logging
|
|
||||||
|
|
||||||
|
|
||||||
def uploadInflux(data, host='192.168.0.13', port=8086): # Main upload
|
def uploadInflux(data, host='192.168.0.13', port=8086): # Main upload
|
||||||
@ -47,41 +38,28 @@ def uploadInflux(data, host='192.168.0.13', port=8086): # Main upload
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
upslist = {}
|
||||||
|
|
||||||
# try:
|
## pull all the UPSes froom each host into a nice dict
|
||||||
# hostList = os.environ["hosts"]
|
for host in hostList:
|
||||||
# hostList = hostList.replace(" ","").split(",")
|
upslist[host] = []
|
||||||
# except:
|
client = PyNUTClient(host, '3493')
|
||||||
# print("error with hosts entry, please make sure in format -> 10.x.x.1, 10.x.x.2")
|
for UPS in client.list_ups():
|
||||||
|
upslist[host].append(UPS)
|
||||||
|
|
||||||
# host
|
# print(upslist)
|
||||||
hostList = ['10.0.5.2', '10.0.5.181']
|
|
||||||
|
|
||||||
upslist = {}
|
data = {}
|
||||||
|
|
||||||
## pull all the UPSes froom each host into a nice dict
|
## Pull whatever data we would like into a dict of each ups
|
||||||
for host in hostList:
|
for host in upslist:
|
||||||
upslist[host] = []
|
client = PyNUTClient(host, '3493')
|
||||||
client = PyNUTClient(host, '3493')
|
for UPS in upslist[host]:
|
||||||
for UPS in client.list_ups():
|
data[UPS] = client.list_vars(UPS)
|
||||||
upslist[host].append(UPS)
|
|
||||||
|
|
||||||
# print(upslist)
|
uploadInflux(data)
|
||||||
|
|
||||||
data = {}
|
while True:
|
||||||
|
main()
|
||||||
## Pull whatever data we would like into a dict of each ups
|
sleep(15)
|
||||||
for host in upslist:
|
|
||||||
client = PyNUTClient(host, '3493')
|
|
||||||
for UPS in upslist[host]:
|
|
||||||
data[UPS] = client.list_vars(UPS)
|
|
||||||
|
|
||||||
uploadInflux(data)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# client = PyNUTClient('10.0.5.181', '3493')
|
|
||||||
|
|
||||||
# # print(client.list_ups())
|
|
||||||
# print(client.list_vars("Net-UPS1"))
|
|
||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
influxdb
|
||||||
|
nut2
|
||||||
Loading…
Reference in New Issue
Block a user