Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bda69e2

Browse files
committed
Connect to HTTPD
1 parent 2ae4fbd commit bda69e2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

monit.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@
33
class Monit:
44
def __init__(self, host='localhost', port=2812, username=None, password='', https=False):
55
self.services = {}
6+
self.baseurl = (https and 'https://%s:%i' or 'http://%s:%i') % (host, port)
7+
self.auth = None
8+
if username:
9+
self.auth = requests.auth.HTTPBasicAuth(username, password)
10+
self.update()
611

712
def update(self):
8-
pass
13+
url = self.baseurl + '/_status?format=xml'
14+
response = requests.get(url, auth=self.auth)
15+
from xml.etree.ElementTree import XML
16+
root = XML(response.text)
17+
for serv_el in root.iter('service'):
18+
serv = Monit.Service(self, serv_el)
19+
self.services[serv.name] = serv
920

1021
class Service:
1122
def __init__(self, parent, xml):
23+
self.name = xml.find('name').text
1224
self.running = None
1325
self.monitored = None
1426

@@ -18,5 +30,5 @@ def start(self):
1830
def stop(self):
1931
pass
2032

21-
def monitor(self, monitor)
22-
pass
33+
def monitor(self, monitor):
34+
pass

0 commit comments

Comments
 (0)