summaryrefslogtreecommitdiffstats
path: root/tests/monitor.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/monitor.py')
-rw-r--r--tests/monitor.py45
1 files changed, 23 insertions, 22 deletions
diff --git a/tests/monitor.py b/tests/monitor.py
index caf4c321..75d82392 100644
--- a/tests/monitor.py
+++ b/tests/monitor.py
@@ -10,6 +10,7 @@
import argparse
from datetime import datetime
import json
+import logger as doctor_log
import os
import requests
import socket
@@ -26,6 +27,8 @@ ICMP_ECHO_MESSAGE = '\x08\x00\xf7\xff\x00\x00\x00\x00'
SUPPORTED_INSPECTOR_TYPES = ['sample', 'congress']
+LOG = doctor_log.Logger('doctor_monitor').getLogger()
+
class DoctorMonitorSample(object):
interval = 0.1 # second
@@ -58,8 +61,8 @@ class DoctorMonitorSample(object):
(congress_endpoint, doctor_ds['id']))
def start_loop(self):
- print "start ping to host %(h)s (ip=%(i)s)" % {'h': self.hostname,
- 'i': self.ip_addr}
+ LOG.debug("start ping to host %(h)s (ip=%(i)s)" % {'h': self.hostname,
+ 'i': self.ip_addr})
sock = socket.socket(socket.AF_INET, socket.SOCK_RAW,
socket.IPPROTO_ICMP)
sock.settimeout(self.timeout)
@@ -68,40 +71,38 @@ class DoctorMonitorSample(object):
sock.sendto(ICMP_ECHO_MESSAGE, (self.ip_addr, 0))
data = sock.recv(4096)
except socket.timeout:
- print "doctor monitor detected at %s" % time.time()
+ LOG.info("doctor monitor detected at %s" % time.time())
self.report_error()
- print "ping timeout, quit monitoring..."
+ LOG.info("ping timeout, quit monitoring...")
return
time.sleep(self.interval)
def report_error(self):
+ payload = [
+ {
+ 'id': 'monitor_sample_id1',
+ 'time': datetime.now().isoformat(),
+ 'type': self.event_type,
+ 'details': {
+ 'hostname': self.hostname,
+ 'status': 'down',
+ 'monitor': 'monitor_sample',
+ 'monitor_event_id': 'monitor_sample_event1'
+ },
+ },
+ ]
+ data = json.dumps(payload)
+
if self.inspector_type == 'sample':
- payload = {"type": self.event_type, "hostname": self.hostname}
- data = json.dumps(payload)
headers = {'content-type': 'application/json'}
requests.post(self.inspector_url, data=data, headers=headers)
elif self.inspector_type == 'congress':
- data = [
- {
- 'id': 'monitor_sample_id1',
- 'time': datetime.now().isoformat(),
- 'type': self.event_type,
- 'details': {
- 'hostname': self.hostname,
- 'status': 'down',
- 'monitor': 'monitor_sample',
- 'monitor_event_id': 'monitor_sample_event1'
- },
- },
- ]
-
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-Auth-Token':self.session.get_token(),
}
-
- requests.put(self.inspector_url, data=json.dumps(data), headers=headers)
+ requests.put(self.inspector_url, data=data, headers=headers)
def get_args():