示例#1
0
 def run(self):
     if "--worker" in sys.argv:
         executor = zope.component.getUtility(IWorkerExecutor)
         executor.setWorkerClass(self.workerClass)
         executor.run()
     else:
         myPreferences = self.prefsClass()
         myTaskFactory = zope.component.getUtility(IWorkerTaskFactory)
         myTaskFactory.setWorkerClass(self.workerClass)
         myTaskSplitter = SimpleTaskSplitter(myTaskFactory)
         daemon = CollectorDaemon(myPreferences, myTaskSplitter)
         myTaskFactory.postInitialization()
         self.log = daemon.log
         daemon.run()
示例#2
0
    def testName(self):
        configs = []
        c = DummyObject()
        c.id = 'host1'
        c.configCycleInterval = 30
        configs.append(c)

        c = DummyObject()
        c.id = 'host2'
        c.configCycleInterval = 100
        configs.append(c)

        taskFactory = SimpleTaskFactory(BasicTestTask)
        taskSplitter = SimpleTaskSplitter(taskFactory)
        tasks = taskSplitter.splitConfiguration(configs)
        self.assertEquals(len(tasks), 2)
示例#3
0
        # 1) super sets self._prefs.task with the call to postStartupTasks
        # 2) call remote createAllUsers
        # 3) service in turn walks DeviceClass tree and returns users
        CollectorDaemon.runPostConfigTasks(self, result)
        if not isinstance(result, Failure) and self._prefs.task is not None:
            service = self.getRemoteConfigServiceProxy()
            log.debug(
                'TrapDaemon.runPostConfigTasks callRemote createAllUsers')
            d = service.callRemote("createAllUsers")
            d.addCallback(self._createUsers)

    def remote_createUser(self, user):
        self._createUsers([user])

    def _createUsers(self, users):
        fmt = 'TrapDaemon._createUsers {0} users'
        count = len(users)
        log.debug(fmt.format(count))
        if self._prefs.task.session is None:
            log.debug("No session created, so unable to create users")
        else:
            self._prefs.task.session.create_users(users)


if __name__ == '__main__':
    myPreferences = SnmpTrapPreferences()
    myTaskFactory = SimpleTaskFactory(MibConfigTask)
    myTaskSplitter = SimpleTaskSplitter(myTaskFactory)
    daemon = TrapDaemon(myPreferences, myTaskSplitter)
    daemon.run()
示例#4
0
                            severity=Error,
                            agent=COLLECTOR_NAME))
        return result

    def cleanup(self):
        unused(self)
        pass

    def doTask(self):
        self.state = TaskStates.STATE_WAITING
        log.debug("Connecting to %s (%s)", self._devId, self._manageIp)

        spec = txamqp.spec.load(os.path.join(os.path.dirname(__file__), "lib/txamqp/specs/standard/amqp0-8.xml"))
        delegate = TwistedDelegate()
        d = ClientCreator(reactor,
                          AMQClient,
                          delegate=delegate,
                          spec=spec,
                          vhost=self._config.zAMQPVirtualHost).connectTCP(self._config.manageIp,
                                                                          self._config.zAMQPPort)
        d.addCallback(self._onConnSucc,
                      self._config.zAMQPQueue,
                      self._config.zAMQPUsername,
                      self._config.zAMQPPassword)
        d.addErrback(self._onConnFail)
        return d

if __name__ == '__main__':
    tf = SimpleTaskFactory(AMQPEventsTask)
    ts = SimpleTaskSplitter(tf)
    CollectorDaemon(AMQPEventPreferences(), ts).run()