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 = str(subid) var = dict(varmap or {}) if alert_type: var['alerttype'] = alert_type event.varmap = var return event
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 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 test_setting_varmap_on_new_event_should_not_raise(): event = Event() varmap = dict(foo='bar') event.varmap = varmap assert event.varmap == varmap