Exemplo n.º 1
0
    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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
    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()