示例#1
0
        def _runrunrunr(dname=""):
            response.content_type = "application/json"
            res = {}
            for (gname, gen) in self.clust.detectors.iteritems():
                if dname and dname != gname:
                    continue
                res[gname] = {"matched": False, "tags": [], "new_tags": []}
                print "LAUNCHING DETECTOR", gen
                res[gname]["matched"] = evaluater.eval_expr(gen["apply_if"])
                if res[gname]["matched"]:
                    res[gname]["tags"] = gen["tags"]
                    for tag in res[gname]["tags"]:
                        if tag not in self.clust.tags:
                            res[gname]["new_tags"].append(tag)
                            print "ADDING NEW TAGS", tag

            return json.dumps(res)
示例#2
0
 def do_detector_thread(self):
     logger.log("DETECTOR thread launched", part="detector")
     while not self.clust.interrupted:
         for (gname, gen) in self.clust.detectors.iteritems():
             logger.debug("LOOK AT DETECTOR", gen)
             interval = int(gen["interval"].split("s")[0])  # todo manage like it should
             should_be_launch = gen["last_launch"] < int(time.time()) - interval
             if should_be_launch:
                 print "LAUNCHING DETECTOR", gen
                 gen["last_launch"] = int(time.time())
                 do_apply = evaluater.eval_expr(gen["apply_if"])
                 print "DO APPLY?", do_apply
                 if do_apply:
                     tags = gen["tags"]
                     for tag in tags:
                         if tag not in self.clust.tags:
                             print "ADDING NEW TAGS", tag
         time.sleep(1)