import time
from congressclient.v1 import client
-from keystoneclient import session as ksc_session
-from keystoneclient.auth.identity import v2
+
+import identity_auth
# NOTE: icmp message with all zero data (checksum = 0xf7ff)
# see https://tools.ietf.org/html/rfc792
LOG = doctor_log.Logger('doctor_monitor').getLogger()
+
class DoctorMonitorSample(object):
interval = 0.1 # second
raise Exception("Inspector type '%s' not supported", args.inspector_type)
self.hostname = args.hostname
- self.inspector_url = args.inspector_url
self.inspector_type = args.inspector_type
self.ip_addr = args.ip or socket.gethostbyname(self.hostname)
- if self.inspector_type == 'congress':
- auth = v2.Password(auth_url=os.environ['OS_AUTH_URL'],
- username=os.environ['OS_USERNAME'],
- password=os.environ['OS_PASSWORD'],
- tenant_name=os.environ['OS_TENANT_NAME'])
- self.session = ksc_session.Session(auth=auth)
-
- congress = client.Client(session=self.session, service_type='policy')
+ if self.inspector_type == 'sample':
+ self.inspector_url = 'http://127.0.0.1:12345/events'
+ elif self.inspector_type == 'congress':
+ auth=identity_auth.get_identity_auth()
+ sess=session.Session(auth=auth)
+ congress = client.Client(session=sess, service_type='policy')
ds = congress.list_datasources()['results']
doctor_ds = next((item for item in ds if item['driver'] == 'doctor'),
None)
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():
parser.add_argument('inspector_type', metavar='INSPECTOR_TYPE', type=str, nargs='?',
help='inspector to report',
default='sample')
- parser.add_argument('inspector_url', metavar='INSPECTOR_URL', type=str, nargs='?',
- help='inspector url to report error',
- default='http://127.0.0.1:12345/events')
return parser.parse_args()