Exemplo n.º 1
0
    def mainLoop(self, driver):
        """
        Main collection loop, a Python iterable

        @param driver: driver object
        @type driver: driver object
        @return: Twisted deferred object
        @rtype: Twisted deferred object
        """
        if self.options.cycle:
            driveLater(self.cycleTime(), self.mainLoop)

        if self.clients:
            self.log.error("Modeling cycle taking too long")
            return

        self.start = time.time()

        self.log.debug("Starting collector loop...")
        yield self.getDeviceList()
        self.devicegen = iter(driver.next())
        d = drive(self.fillCollectionSlots)
        d.addErrback(self.fillError)
        yield d
        driver.next()
        self.log.debug("Collection slots filled")
Exemplo n.º 2
0
    def mainLoop(self, driver):
        """
        Main collection loop, a Python iterable

        @param driver: driver object
        @type driver: driver object
        @return: Twisted deferred object
        @rtype: Twisted deferred object
        """
        if self.options.cycle:
            driveLater(self.cycleTime(), self.mainLoop)

        if self.clients:
            self.log.error("Modeling cycle taking too long")
            return

        self.start = time.time()

        self.log.debug("Starting collector loop...")
        yield self.getDeviceList()
        self.devicegen = iter(driver.next())
        d = drive(self.fillCollectionSlots)
        d.addErrback(self.fillError)
        yield d
        driver.next()
        self.log.debug("Collection slots filled")
Exemplo n.º 3
0
        def inner(driver):
            try:
                now = time.time()
                yield self.service().callRemote('getThresholdClasses')
                self.remote_updateThresholdClasses(driver.next())

                yield self.service().callRemote('getDefaultRRDCreateCommand')
                createCommand = driver.next()

                yield self.service().callRemote('getCollectorThresholds')
                self.rrdStats.config(self.options.monitor,
                                     self.name,
                                     driver.next(),
                                     createCommand)


                if self.options.singleInstance:
                    self.log.info('connected():retrieving for single instance %s',
                                  self.options.singleInstance)
                    yield self.service().callRemote('getAppEngineInstanceConfiguration',
                                                    self.options.singleInstance)
                    instanceConfig = driver.next()
                    self.instanceInventory=[instanceConfig]
                else:
                    self.log.info('connected():retrieving all instances')
                    yield self.service().callRemote('getAllAppEngineInstanceConfigurations')
                    instanceConfigs = driver.next()
                    self.instanceInventory=instanceConfigs

                infrastructureMap = self.discoverInfrastructures()
                self.log.debug('connected():adding infrastructure remotely')
                for instance, infrastructure in infrastructureMap.iteritems():
                    if instance and infrastructure:
                        self.log.debug('instance class %s', instance.__class__)
                        self.log.debug('infrastructure %s', infrastructure)
                        yield self.service().callRemote('addInfrastructure',
                                                        instance,
                                                        infrastructure)
                        driver.next()
                        self.log.info('connected():finished added infrastructure')

                cycle = self.options.configCycleInterval * 60
                driveLater(cycle, inner).addCallbacks(success, err)
                self.sendEvents(
                    self.rrdStats.gauge('cycleTime', cycle, time.time() - now) +
                    self.rrdStats.gauge('endPoints', cycle, len(self.instanceInventory))
                    )
                self.heartbeatTimeout = cycle * 3
                self.log.debug('connected():FINISHED')
            except Exception, ex:
                self.log.debug('connected():Logging exception')
                self.log.exception(ex)
                raise ex
Exemplo n.º 4
0
    def start(self, driver):
        """
        Read the basic config needed to do anything, and to reread
        the configuration information on a periodic basis.
        """
        log.debug("Fetching configuration from zenhub")
        devices = self._devices.keys()
        yield self.fetchConfig()
        self.updateDevices(driver.next(), devices)

        yield self.model().callRemote('getSnmpStatus', self.options.device)
        self.updateSnmpStatus(driver.next())

        yield self.model().callRemote('getProcessStatus', self.options.device)
        self.updateProcessStatus(driver.next())

        driveLater(self.configCycleInterval * 60, self.start)
Exemplo n.º 5
0
    def mainLoop(self, driver):
        """
        Main collection loop, a Python iterable

        @param driver: driver object
        @type driver: driver object
        @return: Twisted deferred object
        @rtype: Twisted deferred object
        """
        if self.options.cycle:
            self.isMainScheduled = True
            driveLater(self.cycleTime(), self.mainLoop)

        if self.clients:
            self.log.error("Modeling cycle taking too long")
            return

        # ZEN-26637 - did we collect during collector loop?
        self.didCollect = False
        self.mainLoopGotDeviceList = False
        self.start = time.time()
        self.collectorLoopIteration = self.collectorLoopIteration + 1

        self.log.info("Starting collector loop #{:03d}...".format(
            self.collectorLoopIteration))
        yield self.getDeviceList()
        deviceList = driver.next()
        self.log.debug("getDeviceList returned %s devices", len(deviceList))
        self.log.debug("getDeviceList returned %s devices", deviceList)
        self.devicegen = iter(deviceList)
        self.iterationDeviceCount = len(deviceList)
        self.processedDevicesCount = 0
        self.log.info(
            "Got %d devices to be scanned during collector loop #%03d",
            self.iterationDeviceCount, self.collectorLoopIteration)
        d = drive(self.fillCollectionSlots)
        d.addErrback(self.fillError)
        self.mainLoopGotDeviceList = True
        yield d
        driver.next()
        self.log.debug("Collection slots filled")
Exemplo n.º 6
0
    def mainLoop(self, driver):
        """
        Main collection loop, a Python iterable

        @param driver: driver object
        @type driver: driver object
        @return: Twisted deferred object
        @rtype: Twisted deferred object
        """
        if self.options.cycle:
            driveLater(self.cycleTime(), self.mainLoop)

        if self.clients:
            self.log.error("Modeling cycle taking too long")
            return

        # ZEN-26637 - did we collect during collector loop?
        self.didCollect = False
        self.mainLoopGotDeviceList = False
        self.start = time.time()
        self.collectorLoopIteration = self.collectorLoopIteration + 1

        self.log.info("Starting collector loop #{:03d}...".format(self.collectorLoopIteration))
        yield self.getDeviceList()
        deviceList = driver.next()
        self.log.debug("getDeviceList returned %s devices", len(deviceList))
        self.log.debug("getDeviceList returned %s devices", deviceList)
        self.devicegen = iter(deviceList)
        self.iterationDeviceCount = len(deviceList)
        self.processedDevicesCount = 0
        self.log.info("Got %d devices to be scanned during collector loop #%03d", self.iterationDeviceCount, self.collectorLoopIteration)
        d = drive(self.fillCollectionSlots)
        d.addErrback(self.fillError)
        self.mainLoopGotDeviceList = True
        yield d
        driver.next()
        self.log.debug("Collection slots filled")
Exemplo n.º 7
0
 def configTask(driver):
     self.log.debug("configTask(): fetching config")
     yield self.fetchConfig()
     driver.next()
     driveLater(self.configCycleInterval * 60, configTask)
Exemplo n.º 8
0
            class_name = ''
            while 1:
                yield result.fetchSome()
                if not driver.next(): break
                for obj in driver.next():
                    props = [p for p in obj.__dict__.keys()
                             if not p.startswith('_')]
                    if obj._class_name != class_name:
                        class_name = obj._class_name
                        print obj._class_name
                        print repr(props)
                    print repr([getattr(obj, p) for p in props])
            q.close()
        except Exception, ex:
            log.exception(ex)
    return driveLater(0.25, inner)

        
def main():
    logging.basicConfig()
    log = logging.getLogger()
    log.setLevel(10)
    DEBUGLEVEL.value = 99

    creds, query = sys.argv[1:3]
    hosts = sys.argv[3:]

    def stop(result):
        print result
        reactor.stop()
    def later():
Exemplo n.º 9
0
                yield result.fetchSome()
                if not driver.next(): break
                for obj in driver.next():
                    props = [
                        p for p in obj.__dict__.keys() if not p.startswith('_')
                    ]
                    if obj._class_name != class_name:
                        class_name = obj._class_name
                        print obj._class_name
                        print repr(props)
                    print repr([getattr(obj, p) for p in props])
            q.close()
        except Exception, ex:
            log.exception(ex)

    return driveLater(0.25, inner)


def main():
    logging.basicConfig()
    log = logging.getLogger()
    log.setLevel(10)
    DEBUGLEVEL.value = 99

    creds, query = sys.argv[1:3]
    hosts = sys.argv[3:]

    def stop(result):
        print result
        reactor.stop()
Exemplo n.º 10
0
 def configTask(driver):
     self.log.debug("configTask(): fetching config")
     yield self.fetchConfig()
     driver.next()
     driveLater(self.configCycleInterval*60, configTask)
Exemplo n.º 11
0
 def emailCycle( self, driver ):
     
     """
     Main function of this daemon. 
     
     Step 1: Retrieve emails from POP mailbox
     Step 2: Send new mail
     Step 3: Record performance data
     """
     
     self.heartbeat()
     
     startTime = time.time()
     
     if self.options.cycle:
         deferred = driveLater( self.options.emailcycleinterval, 
                                self.emailCycle )
         deferred.addErrback( self.logError )
     
     # How many emails have been sent but not retrieved?
     yield defer.succeed( self.getEmailsInFlight() )
     sentMail = driver.next()
     
     # if one or more, try and get them
     if sentMail:
         yield defer.succeed( self.openPopConnection() )
         connection = driver.next()
         
         # continue if successfully connected to POP server
         if not connection is None:
             yield defer.succeed( self.getNewMailCount( connection ) )
             newMailCount = driver.next()
             
             # if there are new messages in the inbox, process 
             # MAX_EMAIL_CHUNK at a time, yielding in between
             retrievedEmailCount = 0
             if newMailCount:
                 generator = self.retrieveEmail( connection, newMailCount )
                 try:
                     while True:
                         yield defer.succeed( generator.next() )
                         retrievedEmailCount = driver.next()
                 except StopIteration:
                     self.closePopConnection( connection )
                     
             # analyze the mail that was received and determine
             # if we need to send any events
             yield defer.succeed( self.sendRetrievedEvents( retrievedEmailCount ) )
             driver.next()
     
     # send new email messages
     yield defer.succeed( self.sendEmail() )
     driver.next()
     
     # update performance data
     self.lastCycleTime = time.time() - startTime
     if self.isFirstCycle:
         self.isFirstCycle = False
     else:
         if self.recordPerformanceData:
             self.updatePerformanceData()
         
     yield defer.succeed( 0 )
     driver.next()