-
Notifications
You must be signed in to change notification settings - Fork 9
/
antminer-zbx-chk
42 lines (34 loc) · 1.16 KB
/
antminer-zbx-chk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
import sys
import logging
import requests
from requests.auth import HTTPDigestAuth
def get_value(host, port, username, password, item):
keys = item.split('.')
try:
response = requests.get('http://{host}:{port}/cgi-bin/get_miner_status.cgi'.format(host=host, port=port),
auth=HTTPDigestAuth(username, password))
data = response.json()
except Exception as p:
return 0
if len(keys) == 2:
return data[keys[0]][keys[1]]
elif len(keys) == 3:
return data[keys[0]][int(keys[1])][keys[2]]
elif len(keys) == 4:
values = {}
for i in data[keys[0]][int(keys[1])][keys[2]].split(','):
j = i.split('=')
if len(j) != 2:
continue
values[j[0]] = j[1]
return values[keys[3]]
else:
return 0
if __name__ == '__main__':
logging.basicConfig(level=logging.ERROR)
try:
name, host, port, username, password, item = sys.argv
except:
raise ValueError("Usage: script <host> <port> <username> <password> <item>")
print(get_value(host, port, username, password, item))