def send_event(netbox, event_spec, send=True): """Send a boxstate event for a given netbox""" event = Event(**DEFAULT_KWARGS) event.netbox = netbox event.state = Event.STATE_END if event_spec == 'up' else Event.STATE_START print(event) if send: event.save()
def send_event(interface, event_spec, send=True): """Send a linkState event for a given interface""" event = Event(**DEFAULT_KWARGS) event.netbox = interface.netbox event.subid = interface.pk event.state = Event.STATE_END if event_spec == 'up' else Event.STATE_START print("{type} {state} event for {subject}".format( type=event.event_type_id, state="start" if event.state == Event.STATE_START else "end", subject=event.get_subject())) if send: event.save()
def _make_linkstate_event(self, start=True): django_ifc = self.get_existing_model() event = Event() event.source_id = 'ipdevpoll' event.target_id = 'eventEngine' event.netbox_id = self.netbox.id event.device = django_ifc.netbox.device event.subid = self.id event.event_type_id = 'linkState' event.state = event.STATE_START if start else event.STATE_END event.save() EventVar(event_queue=event, variable='alerttype', value='linkDown' if start else 'linkUp').save() EventVar(event_queue=event, variable='interface', value=self.ifname).save() EventVar(event_queue=event, variable='ifalias', value=django_ifc.ifalias or '').save()
def _get_aggregate_link_event(self, start): target = self.get_target() aggregator = target.get_aggregator() event = Event() event.source_id = event.target_id = 'eventEngine' event.netbox_id = aggregator.netbox_id event.subid = aggregator.id event.event_type_id = 'aggregateLinkState' event.state = event.STATE_START if start else event.STATE_END event.save() EventVar(event_queue=event, variable='alerttype', value='linkDegraded' if start else 'linkRestored').save() EventVar(event_queue=event, variable='aggregate', value=target.id).save() EventVar(event_queue=event, variable='aggregate_ifname', value=target.ifname).save() EventVar(event_queue=event, variable='aggregate_ifalias', value=target.ifalias or '').save()