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