Пример #1
0
 def test_list_agents(self):
     for i in range(10):
         agent = AgentStore()
         agent.put()
     agent = AgentStore.query().get()
     agent.is_active = False
     agent.put()
     agents = AgentStore.all()
     self.assertEqual(len(agents), 9)
Пример #2
0
    def test_agent_due(self):
        in_two_hours = datetime.datetime.now() + datetime.timedelta(hours=2)

        agent1 = TestAgent.new('Agent 1', cron_entry='*/10 * * * *')
        agent2 = TestAgent.new('Agent 2', cron_entry='%s %s * * *' % (in_two_hours.minute, in_two_hours.hour))
        d1 = datetime.datetime.now() + datetime.timedelta(seconds=601)
        d2 = datetime.datetime.now() + datetime.timedelta(hours=3)
        d3 = datetime.datetime.now() - datetime.timedelta(seconds=10)
        a1 = AgentStore.due(d1)
        a2 = AgentStore.due(d2)
        a3 = AgentStore.due(d3)
        self.assertEqual(len(a1), 1)
        self.assertEqual(len(a2), 2)
        self.assertEqual(len(a3), 0)
Пример #3
0
 def new(cls, name, cron_entry=None, config=None, source_agents=None, deduplicate_output_events=False):
     if config is None:
         config = {}
     return AgentStore.new(
         name, cls, cron_entry,
         source_agents=source_agents,
         config=config, deduplicate_output_events=deduplicate_output_events)
Пример #4
0
    def test_agent_due(self):
        in_two_hours = datetime.datetime.now() + datetime.timedelta(hours=2)

        agent1 = TestAgent.new('Agent 1', cron_entry='*/10 * * * *')
        agent2 = TestAgent.new('Agent 2',
                               cron_entry='%s %s * * *' %
                               (in_two_hours.minute, in_two_hours.hour))
        d1 = datetime.datetime.now() + datetime.timedelta(seconds=601)
        d2 = datetime.datetime.now() + datetime.timedelta(hours=3)
        d3 = datetime.datetime.now() - datetime.timedelta(seconds=10)
        a1 = AgentStore.due(d1)
        a2 = AgentStore.due(d2)
        a3 = AgentStore.due(d3)
        self.assertEqual(len(a1), 1)
        self.assertEqual(len(a2), 2)
        self.assertEqual(len(a3), 0)
Пример #5
0
 def test_list_agents(self):
     for i in range(10):
         agent = AgentStore()
         agent.put()
     agent = AgentStore.query().get()
     agent.is_active = False
     agent.put()
     agents = AgentStore.all()
     self.assertEqual(len(agents), 9)
Пример #6
0
 def get(self):
     agents = AgentStore.all()
     template = templates.get_template('list_all_agents.html')
     return self.response.out.write(
         template.render({
             'agents': agents,
             'page_title': 'All Agents'
         }))
Пример #7
0
    def post(self, agent_id, secret):

        store = AgentStore.get_by_id(int(agent_id))
        try:
            if 'secret' in store.config and store.config['secret'] != secret:
                self.response.set_status(403)
                return

            store.receive_webhook(self.request, self.response)
        except Exception, e:
            logging.exception(e)
            raise e
Пример #8
0
 def get(self):
     agents = AgentStore.all()
     self.response.content_type = 'text/plain'
     for agent in agents:
         try:
             logging.info('Running %s (%s) ...' % (agent.name, agent.key.id()))
             self.response.out.write('Running ' + agent.name + '...')
             agent.run()
         except Exception, e:
             logging.exception(e)
             self.response.out.write('Failed. See logs.\n')
         else:
             self.response.out.write('Done.\n')
Пример #9
0
 def get(self):
     agents = AgentStore.all()
     self.response.content_type = 'text/plain'
     for agent in agents:
         try:
             logging.info('Running %s (%s) ...' % (agent.name, agent.key.id()))
             self.response.out.write('Running ' + agent.name + '...')
             agent.run()
         except Exception, e:
             logging.exception(e)
             self.response.out.write('Failed. See logs.\n')
         else:
             self.response.out.write('Done.\n')
Пример #10
0
 def new(cls,
         name,
         cron_entry=None,
         config=None,
         source_agents=None,
         deduplicate_output_events=False):
     if config is None:
         config = {}
     return AgentStore.new(
         name,
         cls,
         cron_entry,
         source_agents=source_agents,
         config=config,
         deduplicate_output_events=deduplicate_output_events)
Пример #11
0
 def get(self):
     # TODO: don't hard code this dict
     registered_agents = {
         'URL Fetch': URLFetchAgent,
         'Print Events console': PrintEventsAgent,
         'Mail': EmailAgent,
         'Webhook': WebhookAgent,
         "Google Spreadsheet": GoogleSpreadsheetAgent,
         "Hipchat": HipchatAgent
     }
     agents = AgentStore.all()
     template = templates.get_template('add_agent.html')
     return self.response.out.write(template.render({
         'registered_agents': registered_agents,
         'agents': agents,
         'page_title': 'Add Agent'
     }))
Пример #12
0
 def get(self):
     # TODO: don't hard code this dict
     registered_agents = {
         'URL Fetch': URLFetchAgent,
         'Print Events console': PrintEventsAgent,
         'Mail': EmailAgent,
         'Webhook': WebhookAgent,
         "Google Spreadsheet": GoogleSpreadsheetAgent,
         "Hipchat": HipchatAgent
     }
     agents = AgentStore.all()
     template = templates.get_template('add_agent.html')
     return self.response.out.write(
         template.render({
             'registered_agents': registered_agents,
             'agents': agents,
             'page_title': 'Add Agent'
         }))
Пример #13
0
 def get(self):
     agents = AgentStore.all()
     for agent in agents:
         if agent.dedup_hashs is not None:
             agent.dedup_hashs = []
             agent.put()
Пример #14
0
 def get(self):
     agents = AgentStore.all()
     template = templates.get_template('list_all_agents.html')
     return self.response.out.write(template.render({'agents': agents, 'page_title': 'All Agents'}))
Пример #15
0
 def get(self):
     now = datetime.datetime.now()
     agents = AgentStore.due(now)
     for agent in agents:
         if not agent.cron_entry == models.ON_NEW_EVENT:
             agent.run_taskqueue()
Пример #16
0
 def get(self):
     now = datetime.datetime.now()
     agents = AgentStore.due(now)
     for agent in agents:
         agent.run_taskqueue()
Пример #17
0
 def get(self):
     now = datetime.datetime.now()
     agents = AgentStore.due(now)
     for agent in agents:
         agent.run_taskqueue()
Пример #18
0
 def get(self):
     agents = AgentStore.all()
     for agent in agents:
         if agent.dedup_hashs is not None:
             agent.dedup_hashs = []
             agent.put()
Пример #19
0
 def get(self):
     now = datetime.datetime.now()
     agents = AgentStore.due(now)
     for agent in agents:
         if not agent.cron_entry == models.ON_NEW_EVENT:
             agent.run_taskqueue()