def doTask(self):
        log.debug("Scanning device %s [%s]", self._devId, self._manageIp)

        self._eventsFetched = 0

        # see if we need to connect first before doing any collection
        if not self._watcher:
            d = self._connect()
            d.addCallbacks(self._connectCallback, self._failure)
        else:
            # since we don't need to bother connecting, we'll just create an 
            # empty deferred and have it run immediately so the collect callback
            # will be fired off
            d = defer.Deferred()
            reactor.callLater(0, d.callback, None)

        # try collecting events after a successful connect, or if we're already
        # connected
        d.addCallback(self._collectCallback)

        # Add the _finished callback to be called in both success and error
        # scenarios. While we don't need final error processing in this task,
        # it is good practice to catch any final errors for diagnostic purposes.
        d.addBoth(self._finished)

        # returning a Deferred will keep the framework from assuming the task
        # is done until the Deferred actually completes
        return d
    def _collectSuccessful(self, result):
        """
        Callback for a successful fetch of events from the remote device.
        """
        self.state = ZenEventLogTask.STATE_PROCESSING

        log.debug("Successful collection from %s [%s], result=%s",
                  self._devId, self._manageIp, result)

        events = result
        if events:
            # process all of the fetched events
            for logRecord in events:
                self._eventsFetched += 1
                # TODO: figure out how to post this state on the cycle interval
                self._eventService.sendEvent(self._makeEvent(logRecord))

            # schedule another immediate collection so that we'll keep eating
            # events as long as they are ready for us; using callLater ensures
            # it goes to the end of the immediate work-queue so that other 
            # events get processing time
            log.debug("Queuing another fetch for %s [%s]",
                      self._devId, self._manageIp)
            d = defer.Deferred()
            reactor.callLater(0, d.callback, None)
            d.addCallback(self._collectCallback)
            return d
Exemplo n.º 3
0
 def connected(self):
     """
     Called after connected to the zenhub service
     """
     reactor.callLater(_CONFIG_PULLING_TIMEOUT, self._checkConfigLoad)
     d = self.configure()
     d.addCallback(self.heartbeat)
     d.addErrback(self.reportError)
Exemplo n.º 4
0
 def _checkConfigLoad(self):
     """
     Looping call to check whether zenmodeler got configuration
     from ZenHub.
     """
     if not self.configLoaded:
         self.log.info(
             "Modeling has not started pending configuration "
             "pull from ZenHub. Is ZenHub overloaded?"
         )
         reactor.callLater(_CONFIG_PULLING_TIMEOUT, self._checkConfigLoad)
Exemplo n.º 5
0
    def timeoutClients(self, unused=None):
        """
        Check to see which clients have timed out and which ones haven't.
        Stop processing anything that's timed out.

        @param unused: unused (unused)
        @type unused: string
        """
        reactor.callLater(1, self.timeoutClients)
        self._timeoutClients()
        d = drive(self.fillCollectionSlots)
        d.addCallback(self.checkStop)
        d.addErrback(self.fillError)
Exemplo n.º 6
0
    def heartbeat(self, ignored=None):
        """
        Twisted keep-alive mechanism to ensure that
        we're still connected to zenhub

        @param ignored: object (unused)
        @type ignored: object
        """
        ARBITRARY_BEAT = 30
        reactor.callLater(ARBITRARY_BEAT, self.heartbeat)
        if self.options.cycle:
            evt = dict(eventClass=Heartbeat,
                       component='zenmodeler',
                       device=self.options.monitor,
                       timeout=self.options.heartbeatTimeout)
            self.sendEvent(evt)
            self.niceDoggie(self.cycleTime())

        # We start modeling from here to accomodate the startup delay.

        if not self.started:
            if self.immediate == 0 and self.startat:
                # This stuff relies on ARBITRARY_BEAT being < 60s
                if self.timeMatches():
                    self.started = True
                    self.log.info("Starting modeling...")
                    reactor.callLater(1, self.main)
            else:
                self.started = True
                self.log.info("Starting modeling in %s seconds.",
                              self.startDelay)
                reactor.callLater(self.startDelay, self.main)
Exemplo n.º 7
0
    def heartbeat(self, ignored=None):
        """
        Twisted keep-alive mechanism to ensure that
        we're still connected to zenhub

        @param ignored: object (unused)
        @type ignored: object
        """
        ARBITRARY_BEAT = 30
        reactor.callLater(ARBITRARY_BEAT, self.heartbeat)
        if self.options.cycle:
            evt = dict(eventClass=Heartbeat,
                       component='zenmodeler',
                       device=self.options.monitor,
                       timeout=self.options.heartbeatTimeout)
            self.sendEvent(evt)
            self.niceDoggie(self.cycleTime())

        # We start modeling from here to accomodate the startup delay.

        if not self.started:
            if self.immediate == 0 and self.startat:
                # This stuff relies on ARBITRARY_BEAT being < 60s
                if self.timeMatches():
                    self.started = True
                    self.log.info("Starting modeling...")
                    reactor.callLater(1, self.main)
            else:
                self.started = True
                self.log.info("Starting modeling in %s seconds.", self.startDelay)
                reactor.callLater(self.startDelay, self.main)
Exemplo n.º 8
0
        def inner(driver):
            """
            Generator function to gather our configuration

            @param driver: driver object
            @type driver: driver object
            """
            self.log.debug('fetching monitor properties')
            yield self.config().callRemote('propertyItems')
            items = dict(driver.next())
            # If the cycletime option is not specified or zero, then use the
            # modelerCycleInterval value in the database.
            if not self.options.cycletime:
                self.modelerCycleInterval = items.get('modelerCycleInterval',
                                                      _DEFAULT_CYCLE_INTERVAL)
            self.configCycleInterval = items.get('configCycleInterval',
                                                 self.configCycleInterval)
            reactor.callLater(self.configCycleInterval * 60, self.configure)

            self.log.debug("Getting threshold classes...")
            yield self.config().callRemote('getThresholdClasses')
            self.remote_updateThresholdClasses(driver.next())

            self.log.debug("Getting collector thresholds...")
            yield self.config().callRemote('getCollectorThresholds')
            thresholds = driver.next()
            threshold_notifier = ThresholdNotifier(self.sendEvent, thresholds)

            self.rrdStats.config(self.name,
                                 self.options.monitor,
                                 self.metricWriter(),
                                 threshold_notifier,
                                 self.derivativeTracker())

            self.log.debug("Getting collector plugins for each DeviceClass")
            yield self.config().callRemote('getClassCollectorPlugins')
            self.classCollectorPlugins = driver.next()

            self.configLoaded = True
Exemplo n.º 9
0
        def inner(driver):
            """
            Generator function to gather our configuration

            @param driver: driver object
            @type driver: driver object
            """
            self.log.debug('fetching monitor properties')
            yield self.config().callRemote('propertyItems')
            items = dict(driver.next())
            # If the cycletime option is not specified or zero, then use the
            # modelerCycleInterval value in the database.
            if not self.options.cycletime:
                self.modelerCycleInterval = items.get('modelerCycleInterval',
                                                      _DEFAULT_CYCLE_INTERVAL)
            self.configCycleInterval = items.get('configCycleInterval',
                                                 self.configCycleInterval)
            reactor.callLater(self.configCycleInterval * 60, self.configure)

            self.log.debug("Getting threshold classes...")
            yield self.config().callRemote('getThresholdClasses')
            self.remote_updateThresholdClasses(driver.next())

            self.log.debug("Getting collector thresholds...")
            yield self.config().callRemote('getCollectorThresholds')
            thresholds = driver.next()
            threshold_notifier = ThresholdNotifier(self.sendEvent, thresholds)

            self.rrdStats.config(self.name, self.options.monitor,
                                 self.metricWriter(), threshold_notifier,
                                 self.derivativeTracker())

            self.log.debug("Getting collector plugins for each DeviceClass")
            yield self.config().callRemote('getClassCollectorPlugins')
            self.classCollectorPlugins = driver.next()

            self.configLoaded = True
Exemplo n.º 10
0
    def heartbeat(self, ignored=None):
        """
        Twisted keep-alive mechanism to ensure that
        we're still connected to zenhub

        @param ignored: object (unused)
        @type ignored: object
        """
        ARBITRARY_BEAT = 30
        reactor.callLater(ARBITRARY_BEAT, self.heartbeat)
        if self.options.cycle:
            evt = dict(eventClass=Heartbeat,
                       component='zenmodeler',
                       device=self.options.monitor,
                       timeout=3 * ARBITRARY_BEAT)
            self.sendEvent(evt)
            self.niceDoggie(self.cycleTime())

        # We start modeling from here to accomodate the startup delay.
        if not self.started:
            if self.immediate == 0 and self.startat:
                # This stuff relies on ARBITRARY_BEAT being < 60s
                if self.timeMatches():
                    self.started = True
                    reactor.callLater(1, self.main)
            else:
                self.started = True
                reactor.callLater(self.startDelay, self.main)

        # save modeled device rate
        self.rrdStats.derive('modeledDevices', ARBITRARY_BEAT,
                             self.counters['modeledDevicesCount'])

        # save running count
        self.rrdStats.gauge('modeledDevicesCount', ARBITRARY_BEAT,
                            self.counters['modeledDevicesCount'])

        # persist counters values
        self.saveCounters()
Exemplo n.º 11
0
    def heartbeat(self, ignored=None):
        """
        Twisted keep-alive mechanism to ensure that
        we're still connected to zenhub

        @param ignored: object (unused)
        @type ignored: object
        """
        ARBITRARY_BEAT = 30
        reactor.callLater(ARBITRARY_BEAT, self.heartbeat)
        if self.options.cycle:
            evt = dict(eventClass=Heartbeat,
                       component='zenmodeler',
                       device=self.options.monitor,
                       timeout=3*ARBITRARY_BEAT)
            self.sendEvent(evt)
            self.niceDoggie(self.cycleTime())

        # We start modeling from here to accomodate the startup delay.
        if not self.started:
            if self.immediate == 0 and self.startat:
                # This stuff relies on ARBITRARY_BEAT being < 60s
                if self.timeMatches():
                    self.started = True
                    reactor.callLater(1, self.main)
            else:
                self.started = True
                reactor.callLater(self.startDelay, self.main)

        # save modeled device rate
        self.rrdStats.derive('modeledDevices', self.counters['modeledDevicesCount'])

        # save running count
        self.rrdStats.gauge('modeledDevicesCount', self.counters['modeledDevicesCount'])

        # persist counters values
        self.saveCounters()