Exemplo n.º 1
0
    def _deleteDevices(self, uids, deleteEvents=False, deletePerf=True):
        @transact
        def dbDeleteDevices(uids):
            devs = imap(self._getObject, uids)
            deletedIds = []
            for dev in devs:
                devid = dev.getId()
                deletedIds.append(devid)
                parent = dev.getPrimaryParent()
                dev.deleteDevice(deleteStatus=deleteEvents,
                                 deletePerf=deletePerf)
            return deletedIds

        def uidChunks(uids, chunksize=10):
            i = 0
            maxi = len(uids)
            while i < maxi:
                nexti = i + chunksize
                yield uids[i:nexti]
                i = nexti

        deletedIds = sum(map(dbDeleteDevices, uidChunks(uids)), [])
        for devid in deletedIds:
            self._dmd.ZenEventManager.sendEvent(
                Event(
                    summary='Deleted device: ' + devid,
                    severity=2,  #info
                    eventClass='/Change/Remove',  #zEventAction=history
                    device=devid))
Exemplo n.º 2
0
    def _deleteDevices(self, uids, deleteEvents=False, deletePerf=True):
        @transact
        def dbDeleteDevices(uids):
            devs = imap(self._getObject, uids)
            deletedIds = []
            for dev in devs:
                devid = dev.getId()
                deletedIds.append(devid)
                parent = dev.getPrimaryParent()
                dev.deleteDevice(deleteStatus=deleteEvents,
                                 deletePerf=deletePerf)
                # Make absolutely sure that the count gets updated
                # when we delete a device.
                parent = self._dmd.unrestrictedTraverse("/".join(
                    parent.getPhysicalPath()))
                parent.setCount()
            return deletedIds

        def uidChunks(uids, chunksize=10):
            i = 0
            maxi = len(uids)
            while i < maxi:
                nexti = i + chunksize
                yield uids[i:nexti]
                i = nexti

        deletedIds = sum(map(dbDeleteDevices, uidChunks(uids)), [])
        for devid in deletedIds:
            self._dmd.ZenEventManager.sendEvent(
                Event(
                    summary='Deleted device: ' + devid,
                    severity=2,  #info
                    eventClass='/Change/Remove',  #zEventAction=history
                    device=devid))
Exemplo n.º 3
0
 def sendEvent(self, reason, summary, message, severity):
     eventKey = '_'.join([self.notification.action, self.notification.id])
     event = Event(device="localhost",
                   eventClass="/Cmd/Failed",
                   summary="%s %s" % (self.notification.id, summary),
                   message=message,
                   eventKey=eventKey,
                   notification=self.notification.titleOrId(),
                   stdout=self.out,
                   stderr=self.err,
                   severity=severity,
                   component="zenactiond")
     self.notification.dmd.ZenEventManager.sendEvent(event)
Exemplo n.º 4
0
    def sendEvent(self, **kwargs):
        evt = Event()
        defaults = dict(device='localhost',
                        eventClass="/TestEvent",
                        summary='Test event generated by %s' %
                        self.__class__.__name__,
                        severity=4)
        defaults.update(kwargs)
        for k, v in defaults.items():
            setattr(evt, k, v)

        evid = self.layer.zem.sendEvent(evt)
        self.layer._evids.append(evid)
        return evid
 def teartrapevent(self):
     '''teartrapevent'''
     evt = Event()
     evt.device = "/Service/Huawei/BMC"
     evt.eventClass = 'hwOEMEvent'
     evt.summary = "Huawei OEM event"
     evt.severity = 2
     zem.sendEvent(evt)
     self.assertTrue(True)
Exemplo n.º 6
0
    def sendEvent(self, **kw):
        """Post events to the EventManager.

        @type kw: keywords (dict)
        @param kw: the values for an event: device, summary, etc.
        @return: None
        """
        if 'device' not in kw:
            kw['device'] = self.options.monitor
        if 'component' not in kw:
            kw['component'] = self.name
        try:
            self.zem.sendEvent(Event(**kw))
        except Exception:
            self.log.exception("Unable to send an event")
Exemplo n.º 7
0
 def handleExecuteError(self, exception, notification, target):
     # If there is an error executing this action on a target,
     # we need to handle it, but we don't want to prevent other
     # actions from executing on any other targets that may be
     # about to be acted on.
     msg = 'Error executing action {notification} on {target}'.format(
         notification=notification.id,
         target=target,
     )
     log.error(exception)
     log.error(msg)
     traceback = format_exc()
     event = Event(device="localhost",
                   eventClass="/App/Failed",
                   summary=msg,
                   message=traceback,
                   severity=SEVERITY_WARNING, component="zenactiond")
     notification.dmd.ZenEventManager.sendEvent(event)
Exemplo n.º 8
0
                log.error('Error executing action: {action} on notification {notification}'.format(
                    action = notification.action,
                    notification = notification.id,
                ))
                audit_msg =  "%s Action:%s Status:%s Target:%s Info:%s" % (
                                    audit_event_trigger_info, notification.action, "FAIL", target, aee)
            except Exception, e:
                msg = 'Error executing action {notification}'.format(
                    notification = notification.id,
                )
                log.exception(e)
                log.error(msg)
                traceback = format_exc()
                event = Event(device="localhost",
                              eventClass="/App/Failed",
                              summary=msg,
                              message=traceback,
                              severity=SEV_WARNING, component="zenactiond")
                self.dmd.ZenEventManager.sendEvent(event)
                audit_msg =  "%s Action:%s Status:%s Target:%s Info:%s" % (
                                    audit_event_trigger_info, notification.action, "FAIL", target, action.getInfo(notification))
            else:
                # audit trail of performed actions
                audit_msg =  "%s Action:%s Status:%s Target:%s Info:%s" % (
                                    audit_event_trigger_info, notification.action, "SUCCESS", target, action.getInfo(notification))
                self.recordNotification(notification, signal, trigger.id)

            log.info(audit_msg)
        log.debug('Done processing signal. (%s)' % signal.message)

    def shouldSuppress(self, notification, signal, triggerId):
Exemplo n.º 9
0
    def processSignal(self, signal):
        matches = self.notificationDao.getSignalNotifications(signal)
        log.debug('Found these matching notifications: %s' % matches)

        trigger = self.notificationDao.guidManager.getObject(
            signal.trigger_uuid)
        audit_event_trigger_info = "Event:'%s' Trigger:%s" % (
            signal.event.occurrence[0].fingerprint, trigger.id)
        for notification in matches:
            if signal.clear and not notification.send_clear:
                log.debug(
                    'Ignoring clearing signal since send_clear is set to False on this subscription %s'
                    % notification.id)
                continue

            if self.shouldSuppress(notification, signal, trigger.id):
                log.debug('Suppressing notification %s', notification.id)
                continue

            try:
                target = signal.subscriber_uuid or '<none>'
                action = self.getAction(notification.action)
                action.setupAction(notification.dmd)
                if isinstance(action, TargetableAction):
                    target = ','.join(action.getTargets(notification, signal))
                with self.notification_timer:
                    action.execute(notification, signal)
            except ActionMissingException as e:
                log.error('Error finding action: {action}'.format(
                    action=notification.action))
                audit_msg = "%s Action:%s Status:%s Target:%s Info:%s" % (
                    audit_event_trigger_info, notification.action, "FAIL",
                    target, "<action not found>")
            except ActionExecutionException as aee:
                log.error(
                    'Error executing action: {action} on notification {notification}'
                    .format(
                        action=notification.action,
                        notification=notification.id,
                    ))
                audit_msg = "%s Action:%s Status:%s Target:%s Info:%s" % (
                    audit_event_trigger_info, notification.action, "FAIL",
                    target, aee)
            except Exception as e:
                msg = 'Error executing action {notification}'.format(
                    notification=notification.id, )
                log.exception(e)
                log.error(msg)
                traceback = format_exc()
                event = Event(device="localhost",
                              eventClass="/App/Failed",
                              summary=msg,
                              message=traceback,
                              severity=SEV_WARNING,
                              component="zenactiond")
                self.dmd.ZenEventManager.sendEvent(event)
                audit_msg = "%s Action:%s Status:%s Target:%s Info:%s" % (
                    audit_event_trigger_info, notification.action, "FAIL",
                    target, action.getInfo(notification))
            else:
                # audit trail of performed actions
                audit_msg = "%s Action:%s Status:%s Target:%s Info:%s" % (
                    audit_event_trigger_info, notification.action, "SUCCESS",
                    target, action.getInfo(notification))
                self.recordNotification(notification, signal, trigger.id)

            log.info(audit_msg)
        log.debug('Done processing signal. (%s)' % signal.message)
Exemplo n.º 10
0
# Copyright (C) Zenoss, Inc. 2007, all rights reserved.
#
# This content is made available according to terms specified in
# License.zenoss under the directory where your Zenoss product is installed.
#
##############################################################################

import Globals
from Products.ZenUtils.ZCmdBase import ZCmdBase
zodb = ZCmdBase(noopts=True)
zem = zodb.dmd.ZenEventManager

from Products.ZenEvents.Event import Event
from Products.ZenEvents.ZenEventClasses import Status_Ping

evt = Event()
evt.device = "gate.confmon.loc"
evt.eventClass = Status_Ping
evt.summary = "device is down"
evt.severity = 5
zem.sendEvent(evt)

evt = Event()
evt.device = "gate.confmon.loc"
evt.eventClass = "TestEvent"
evt.summary = "this is a test event"
evt.severity = 3
evt.ntseverity = "info"
evt.ntsource = "Zope"
zem.sendEvent(evt)
Exemplo n.º 11
0
# 
# This content is made available according to terms specified in
# License.zenoss under the directory where your Zenoss product is installed.
# 
##############################################################################


import Globals
from Products.ZenUtils.ZCmdBase import ZCmdBase
zodb = ZCmdBase(noopts=True)
zem = zodb.dmd.ZenEventManager

from Products.ZenEvents.Event import Event
from Products.ZenEvents.ZenEventClasses import Status_Ping

evt = Event()
evt.device = "gate.confmon.loc"
evt.eventClass = Status_Ping
evt.summary = "device is down"
evt.severity = 5
zem.sendEvent(evt)

evt = Event()
evt.device = "gate.confmon.loc"
evt.eventClass = "TestEvent"
evt.summary = "this is a test event"
evt.severity = 3
evt.ntseverity = "info"
evt.ntsource = "Zope"
zem.sendEvent(evt)