コード例 #1
0
ファイル: __init__.py プロジェクト: hdeweirdt/imp
 def fact_timeout_check(self):
     """
         Check if a fact is about to timeout
     """
     LOGGER.debug("Query for expired facts")
     expired_resources = Fact.renew_facts(timeout = 60)
 
     for res_id in expired_resources:
         LOGGER.debug("Facts of resource %s expired, poll new facts" % res_id)
         self.poll_facts(str(res_id))
         return
コード例 #2
0
ファイル: __init__.py プロジェクト: hdeweirdt/imp
    def get(self, fact_name):
        resource_id = self.get_argument("id", None, True)
        
        fact, timeout = Fact.get(resource_id, fact_name)
        
        if fact is not None and not timeout:
            
            self.write(fact.value)

        if timeout:
            self._server._logger.info("Fact %s about %s has timed out, an update is requested" % (resource_id, fact_name))
        
        if fact is None or timeout:
            self._server.poll_facts(resource_id)
            self.set_status(404)
コード例 #3
0
ファイル: __init__.py プロジェクト: hdeweirdt/imp
 def on_message(self, msg):
     """
         Receive a new file
     """
     message = json.loads(msg.body)
     if "operation" in message:
         operation = message["operation"]
     else:
         return
     
     if operation == "FACTS_REPLY":
         if "code" in message and message["code"] != 200:
             self._logger.error("Received a 404 message on a facts reply. " + str(message))
             return
         
         if "facts" in message:
             facts = message['facts']
             
             for subject,facts in message['facts'].items():
                 self._logger.info("Received facts from %s" % subject)
                 for fact in facts:
                     value = facts[fact]
                     if not isinstance(value, str):
                         value = json.dumps(value)
                     
                     fact_obj = Fact()
                     fact_obj.value_time = time.time()
                     fact_obj.resource_id = Id.parse_id(subject)
                     fact_obj.name = fact
                     fact_obj.value = value
                     fact_obj.entity_type = fact_obj.resource_id.entity_type
                     
                     fact_obj.save()
                 
         else:
             self._logger.error("No facts in message: " + str(message))
             
     elif operation == "PONG":
         if "hostname" not in message:
             self._logger.error("Invalid PONG heartbeat received")
             return
             
         for host in message["hostname"]:
             h = Agent(host)
             h.save()
             
         
     elif operation == "UPDATED":
         if "id" not in message or "version" not in message:
             self._logger.error("Invalid UPDATED operation")
             return
         
         version = DataStore.instance().get(Version, message['id'])
         if version is not None:
             version.mark_updated()
             version.save()
         
     elif operation == "UPDATE":
         # ignore
         pass
     
     elif operation == "FACTS":
         pass
         
     else:
         self._logger.debug("Received message with unknown operation. operation = %s" % str(operation))