def main(): """Main controller""" parser = create_parser() (options, _) = parser.parse_args() verify_options(options, parser) if options.list_services: print_services() sys.exit() try: netbox = Netbox.objects.get(sysname__icontains=options.netbox) except Netbox.DoesNotExist: parser.error("No netbox found") sys.exit() source = Subsystem.objects.get(pk='serviceping') target = Subsystem.objects.get(pk='eventEngine') eventtype = EventType.objects.get(pk='serviceState') state = 's' if options.state.startswith('d') else 'e' event = Event(source=source, target=target, subid=options.subid, netbox=netbox, event_type=eventtype, device=netbox.device, state=state) event.save()
def main(): """Main controller""" parser = create_parser() (options, _) = parser.parse_args() verify_options(options, parser) if options.list_services: print_services() sys.exit() try: netbox = Netbox.objects.get(sysname__icontains=options.netbox) except Netbox.DoesNotExist: parser.error("No netbox found") sys.exit() source = Subsystem.objects.get(pk='serviceping') target = Subsystem.objects.get(pk='eventEngine') eventtype = EventType.objects.get(pk='serviceState') state = 's' if options.state.startswith('d') else 'e' event = Event(source=source, target=target, subid=options.subid, netbox=netbox, event_type=eventtype, device=netbox.device, state=state) event.save()
def main(): """Main controller""" if len(sys.argv) <= 2: print "Need netbox and eventstate" sys.exit() netboxarg = sys.argv[1] eventstate = sys.argv[2] try: subid = sys.argv[3] except IndexError: subid = "" try: netbox = Netbox.objects.get(sysname__icontains=netboxarg) except Netbox.DoesNotExist: print "No netbox found" sys.exit() if eventstate[0] not in ['u', 'd']: print "Specify [u]p or [d]own event" sys.exit() source = Subsystem.objects.get(pk='thresholdMon') target = Subsystem.objects.get(pk='eventEngine') eventtype = EventType.objects.get(pk='thresholdState') state = 's' if eventstate.startswith('d') else 'e' # oid = 'cpu1min' # value = '90' event = Event(source=source, target=target, subid=subid, netbox=netbox, event_type=eventtype, state=state) event.save()
def _make_snmpagentstate_event(self): event = Event() event.source_id = 'ipdevpoll' event.target_id = 'eventEngine' event.netbox_id = self.netbox.id event.event_type_id = 'snmpAgentState' return event
def simple_event(): event = EventQueue(source_id='ipdevpoll', target_id='eventEngine', event_type_id='info') yield event if event.pk: event.delete()
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 post_fake_boxdown(netbox): event = Event( source_id="pping", target_id="eventEngine", event_type_id="boxState", netbox=netbox, state=Event.STATE_START, ) event.save()
def main(): """Main controller""" (options, args) = parse_options() source = Subsystem.objects.get(name='ipdevpoll') target = Subsystem.objects.get(name='eventEngine') netbox = Netbox.objects.get(sysname__icontains=options.sysname) device = netbox.device eventtype = EventType.objects.get(pk__icontains=options.eventtype) event = Event(source=source, target=target, netbox=netbox, device=device, event_type=eventtype, state=get_state(args)) event.varmap = {'alerttype': options.alerttype} event.save()
def main(): """Main controller""" (options, args) = parse_options() source = Subsystem.objects.get(name='ipdevpoll') target = Subsystem.objects.get(name='eventEngine') netbox = Netbox.objects.get(sysname__icontains=options.sysname) device = netbox.device eventtype = EventType.objects.get(pk__icontains=options.eventtype) event = Event(source=source, target=target, netbox=netbox, device=device, event_type=eventtype, state=get_state(args)) event.varmap = {'alerttype': options.alerttype} 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 _make_modulestate_event(cls, django_module): event = Event() event.source_id = 'ipdevpoll' event.target_id = 'eventEngine' event.device = django_module.device event.netbox = django_module.netbox event.subid = unicode(django_module.id) event.event_type_id = 'moduleState' return event
def _make_modulestate_event(cls, django_module): event = Event() event.source_id = 'ipdevpoll' event.target_id = 'eventEngine' event.device = django_module.device event.netbox = django_module.netbox event.subid = unicode(django_module.id) event.event_type_id = 'moduleState' return event
def main(): """Main controller""" if len(sys.argv) <= 2: print("Need netbox and eventstate") sys.exit() netboxarg = sys.argv[1] eventstate = sys.argv[2] try: subid = sys.argv[3] except IndexError: subid = "" try: netbox = Netbox.objects.get(sysname__icontains=netboxarg) except Netbox.DoesNotExist: print("No netbox found") sys.exit() if eventstate[0] not in ['u', 'd']: print("Specify [u]p or [d]own event") sys.exit() source = Subsystem.objects.get(pk='thresholdMon') target = Subsystem.objects.get(pk='eventEngine') eventtype = EventType.objects.get(pk='thresholdState') state = 's' if eventstate.startswith('d') else 'e' # oid = 'cpu1min' # value = '90' event = Event( source=source, target=target, subid=subid, netbox=netbox, event_type=eventtype, state=state, ) 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 _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()
def _event_template(): event = Event() event.source_id = 'thresholdMon' event.target_id = 'eventEngine' event.event_type_id = 'thresholdState' return event
def create_event(subject, state, value, taskid=None): """ Adds events to the EventQueue that starts or ends maintenance tasks based on a given subject and state. """ target = 'eventEngine' subsystem = 'maintenance' source = subsystem severity = 50 eventtype = 'maintenanceState' event = Event(state=state, value=value, severity=severity) varmap = {} event.event_type_id = eventtype event.target_id = target event.source_id = source if isinstance(subject, manage.Netbox): event.netbox = subject event.device = subject.device varmap['netbox'] = subject.sysname elif isinstance(subject, service.Service): event.subid = subject.id event.netbox = subject.netbox event.device = subject.netbox.device varmap['service'] = subject.handler varmap['servicename'] = subject.handler if taskid: varmap['maint_taskid'] = taskid event.save() event.varmap = varmap _logger.debug("Event posted: %r", event)
def _event_template(): event = Event() event.source_id = 'thresholdMon' event.target_id = 'eventEngine' event.event_type_id = 'thresholdState' return event
def test_setting_varmap_on_new_event_should_not_raise(): event = Event() varmap = dict(foo='bar') event.varmap = varmap assert event.varmap == varmap
def base(self, device=None, netbox=None, subid='', varmap=None, alert_type=None): """Creates and returns an event base template :param device: A nav.models.manage.Device object or primary key. :param netbox: A nav.models.manage.Netbox object or primary key. :param subid: A subid string, if applicable. :param varmap: A dictionary of arbitrary event variables to attach. :param alert_type: An option alert type hint for eventEngine; useful for cases where eventEngine has no specific plugin. :return: """ event = EventQueue() event.source_id = self.source event.target_id = self.target event.event_type_id = self.event_type if isinstance(device, int): event.device_id = device else: event.device = device if isinstance(netbox, int): event.netbox_id = netbox else: event.netbox = netbox event.subid = six.text_type(subid) var = dict(varmap or {}) if alert_type: var['alerttype'] = alert_type event.varmap = var return event
def test_setting_varmap_on_new_event_should_not_raise(): event = Event() varmap = dict(foo='bar') event.varmap = varmap assert event.varmap == varmap