-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnfd.py
More file actions
executable file
·27 lines (23 loc) · 873 Bytes
/
nfd.py
File metadata and controls
executable file
·27 lines (23 loc) · 873 Bytes
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
import urllib2
import json
def getServiceLists(uri, realm = None, user = None, passwd = None):
if realm is not None:
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm = realm, uri = uri, user = user, passwd = passwd)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
try:
icinga = json.loads(urllib2.urlopen(uri).read())
except urllib2.HTTPError:
return None, None, None
critical = list()
warning = list()
okay = list()
for service in icinga['status']['service_status']:
if service['status'] == 'WARNING':
warning.append(service)
elif service['status'] == 'CRITICAL':
critical.append(service)
elif service['status'] == 'OK':
okay.append(service)
return warning, critical, okay