コード例 #1
0
ファイル: __init__.py プロジェクト: bradleyjones/apiary
class AgentMonitor(Base):

    def __init__(self):
        super(AgentMonitor, self).__init__('agentmanager')
        self.publisher = SimplePublisher(
            'apiary',
            self.config['Rabbit']['host'],
            self.config['Rabbit']['username'],
            self.config['Rabbit']['password'])

    def start(self):
        try:
            self.agentmodel = Agent(self.config)

            while(True):
                self.logger.debug("Scanning agents...")
                agents = self.agentmodel.findAll()
                for agent in agents:
                    # Scan for Dead Agents
                    if ((agent.HEARTBEAT + 300) < time.time()) and (not agent.DEAD):
                        agent.DEAD = True
                        self.logger.info("Agent %s is Dead!", agent.UUID)
                        event = {}
                        event[agent.UUID] = agent.to_hash()

                        doc = {
                            'action': 'EVENT',
                            "to": "hive",
                            "from": "hive",
                            "data": {'agents': event},
                            "machineid": "boop"}
                        self.publisher.publish_msg(
                            json.dumps(doc),
                            'events.agentmanager.agent.dead')
                        self.agentmodel.save(agent)

                # Added sleep for the CPU's sake
                time.sleep(1)

        except Exception as e:
            self.logger.error("Errors Occured: %s", str(e))
        except KeyboardInterrupt:
            self.stop()
        finally:
            self.logger.info("Exiting...")
            sys.exit(0)

    def stop(self):
        pass
コード例 #2
0
ファイル: __init__.py プロジェクト: bradleyjones/apiary
 def __init__(self):
     super(AgentMonitor, self).__init__('agentmanager')
     self.publisher = SimplePublisher(
         'apiary',
         self.config['Rabbit']['host'],
         self.config['Rabbit']['username'],
         self.config['Rabbit']['password'])