def initialize(config): singleton = HttpInventoryProxySingleton() singleton.initialise(config) f = http.HTTPFactory() f.protocol = MyProxy # Listen to incoming connection reactor.listenTCP(config.port, f) # Run the periodic inventory if configured if config.polling: r = RunInventory() r.setup(config) r.run()
class RunInventory(Singleton): """ Little helper class that runs the inventory agent """ def setup(self, config): self.config = config self.logger = logging.getLogger() from pulse2.proxyssl.http_inventory_proxy import HttpInventoryProxySingleton self.singleton = HttpInventoryProxySingleton() def maybeStartLoop(self): if self.config.polling: self.logger.debug("Scheduling inventory in %s seconds" % self.config.polling_time) reactor.callLater(self.config.polling_time, self.run) def run(self): """ Start an OCS inventory, and loop according to the configuration """ if self.singleton.check_flag(): self.logger.debug("Starting an inventory") d = utils.getProcessOutputAndValue(self.config.command_name, self.config.command_attr) d.addCallbacks(self.onSuccess, self.onError) else: self.logger.debug("Flag not set, not starting an inventory") self.maybeStartLoop() def onSuccess(self, result): self.logger.debug("Inventory done") def onError(self, reason): self.logger.error("Error while doing inventory: %s" % str(reason))
def setup(self, config): self.config = config self.logger = logging.getLogger() from pulse2.proxyssl.http_inventory_proxy import HttpInventoryProxySingleton self.singleton = HttpInventoryProxySingleton()