forked from georgeherby/MADevice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnector.py
23 lines (19 loc) · 876 Bytes
/
connector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import logging
import requests
log = logging.getLogger('__name__')
def get_status(server):
try:
if 'username' in server and 'password' in server:
log.debug("MADmin auth used")
return requests.get(f'http://{server["ip"]}/get_status', auth=(server['username'], server['password'])).json()
else:
if 'username' in server or 'password' in server:
log.warning("Ensure both username and password are set to use authenticated MADmin")
log.debug("No MADmin auth used")
return requests.get(f'http://{server["ip"]}/get_status').json()
except requests.exceptions.Timeout:
log.error("Connection to get_status timed-out")
except requests.exceptions.RequestException as e:
log.error(str(e))
except Exception as e:
log.error("General error {0}".format(e))