def process_result(self, result): meta = {} data = {} # Organize data and metadata in different dicts for tmp in result.data: if isinstance(tmp, Metadata): meta[tmp.object_id] = tmp elif isinstance(tmp, Data): if tmp.ref_id in data: data[tmp.ref_id].append(tmp) else: data[tmp.ref_id] = [tmp] for key, m in meta.iteritems(): if key not in data: data[key] = None datums = [] continue datums = data[key] event_types = [] for d in datums: if d.data.event_types is not None: if isinstance(d.data.event_types, list): for event in d.data.event_types: event_types.append(event) else: event_types.append(d.data.event_types) # to remove duplicates event_types = list(set(event_types)) logger.info('event types: %s' % event_types) if isinstance(m.subject.contents, PsService): s = m.subject.contents service = create_psservice(s.serviceName, s.accessPoint, s.serviceType, s.serviceDescription, event_types) for d in datums: if isinstance(d.data, Metadata): if isinstance(d.data.subject, NetUtilSubject): self.process_NetUtilSubject(service, d.data) elif isinstance(d.data.subject, PingerSubject) or isinstance( d.data.subject, OWAMPSubject): self.process_EndpointpairSubject(service, d.data) else: logger.error( "Undefined data type '%s' at service '%s'" % (type(d.data.subject), get_service_accesspoint(service))) else: logger.error( "Undefined data type '%s' at service '%s'" % (type(d.data), get_service_accesspoint(service)))
def query(self, hLSService): """ Sends query to Service of type hLS returns XML string response. """ hls_accessPoint = get_service_accesspoint(hLSService) result = query_hls(hls_accessPoint) return result
def populate_hlses(self, gLSService): gls = get_service_accesspoint(gLSService) logger.info("Populating hLSes from gLS: '%s'" % gls) result = look_for_hlses(gls) hlses = [] for meta in result.data: service = meta.subject.contents if meta.event_types is None: events = [] elif isinstance(meta.event_types, str): events = [meta.event_types] else: events = list(set(meta.event_types)) # hLSes are also able to handle discovery events events.append(psevents.SUMMARY) hlses.append({'service':service, 'events':events}) if len(hlses) == 0: raise Exception("No hLSes is found at %s" % gls) for h in hlses: try: serviceName = h['service'].serviceName accessPoint = h['service'].accessPoint serviceDescription = h['service'].serviceDescription service = create_psservice(serviceName, accessPoint, 'hLS', serviceDescription, h['events']) except Exception, ex: logger.error("Found error in '%s': %s" % (serviceName, ex))
def populate_hlses(self, gLSService): gls = get_service_accesspoint(gLSService) logger.info("Populating hLSes from gLS: '%s'" % gls) result = look_for_hlses(gls) hlses = [] for meta in result.data: service = meta.subject.contents if meta.event_types is None: events = [] elif isinstance(meta.event_types, str): events = [meta.event_types] else: events = list(set(meta.event_types)) # hLSes are also able to handle discovery events events.append(psevents.SUMMARY) hlses.append({'service': service, 'events': events}) if len(hlses) == 0: raise Exception("No hLSes is found at %s" % gls) for h in hlses: try: serviceName = h['service'].serviceName accessPoint = h['service'].accessPoint serviceDescription = h['service'].serviceDescription service = create_psservice(serviceName, accessPoint, 'hLS', serviceDescription, h['events']) except Exception, ex: logger.error("Found error in '%s': %s" % (serviceName, ex))
def process_EndpointpairSubject(self, service, meta): etype = ContentType.objects.get_for_model(Port) endpointpair = meta.subject.contents try: endpoint = create_endpoint(endpointpair.src, \ get_address_type(endpointpair.src), \ endpointpair.dst, get_address_type(endpointpair.dst)) if isinstance(meta.event_types, str): event_types = [meta.event_types] else: event_types = meta.event_types for event in event_types: w = psServiceWatchList.objects.get_or_create(service=service, eventType=EventType.objects.get(value=event), objectType=etype, objectID=endpoint.id) if w[1] == 1: w[0].watchedObject = endpoint w[0].save() except Exception, ex: logger.error("Couldn't add endpoint '%s', from service '%s'" % (ex, get_service_accesspoint(service)))
def process_EndpointpairSubject(self, service, meta): etype = ContentType.objects.get_for_model(Port) endpointpair = meta.subject.contents try: endpoint = create_endpoint(endpointpair.src, \ get_address_type(endpointpair.src), \ endpointpair.dst, get_address_type(endpointpair.dst)) if isinstance(meta.event_types, str): event_types = [meta.event_types] else: event_types = meta.event_types for event in event_types: w = psServiceWatchList.objects.get_or_create( service=service, eventType=EventType.objects.get(value=event), objectType=etype, objectID=endpoint.id) if w[1] == 1: w[0].watchedObject = endpoint w[0].save() except Exception, ex: logger.error("Couldn't add endpoint '%s', from service '%s'" % (ex, get_service_accesspoint(service)))
def process_result(self, result): meta = {} data = {} # Organize data and metadata in different dicts for tmp in result.data: if isinstance(tmp, Metadata): meta[tmp.object_id] = tmp elif isinstance(tmp, Data): if tmp.ref_id in data: data[tmp.ref_id].append(tmp) else: data[tmp.ref_id] = [tmp] for key, m in meta.iteritems(): if key not in data: data[key] = None datums = [] continue datums = data[key] event_types = [] for d in datums: if d.data.event_types is not None: if isinstance(d.data.event_types, list): for event in d.data.event_types: event_types.append(event) else: event_types.append(d.data.event_types) # to remove duplicates event_types = list(set(event_types)) logger.info('event types: %s' % event_types) if isinstance(m.subject.contents, PsService): s = m.subject.contents service = create_psservice(s.serviceName, s.accessPoint, s.serviceType, s.serviceDescription, event_types) for d in datums: if isinstance(d.data, Metadata): if isinstance(d.data.subject, NetUtilSubject): self.process_NetUtilSubject(service, d.data) elif isinstance(d.data.subject, PingerSubject) or isinstance(d.data.subject, OWAMPSubject): self.process_EndpointpairSubject(service, d.data) else: logger.error("Undefined data type '%s' at service '%s'" % (type(d.data.subject), get_service_accesspoint(service))) else: logger.error("Undefined data type '%s' at service '%s'" % (type(d.data), get_service_accesspoint(service)))