Example #1
0
 def load_events(self, obj, path):
     """
     Load events from JSON file
     """
     # Decode JSON
     with open(path) as f:
         try:
             data = json.load(f)
         except ValueError as e:
             self.die('Failed to decode JSON file "%s": %s' % (path, str(e)))
     # Load events
     topic = "events.%s" % obj.pool.name
     for e in data:
         if e["profile"] != obj.profile.name:
             self.stdout.write(
                 "Profile mismatch in %s: %s != %s %s"
                 % (path, obj.profile.name, e["profile"], e)
             )
             continue
         msg = {
             "id": str(bson.ObjectId()),
             "ts": time.time(),
             "object": obj.id,
             "data": e["raw_vars"],
         }
         nsq_pub(topic, msg)
         self.stdout.write(msg["id"])
Example #2
0
 def mark_as_new(self, message=None):
     """
     Move to unclassified queue
     """
     from noc.core.nsq.pub import nsq_pub
     data = {"source": self.source}
     data.update(self.raw_vars)
     msg = {
         "id": str(self.id),
         "ts": time.mktime(self.timestamp.timetuple()),
         "object": self.managed_object.id,
         "data": data
     }
     nsq_pub("events.%s" % self.managed_object.pool.name, msg)
     self.delete()
Example #3
0
 def syslog_message(self, obj, msg):
     topic = "events.%s" % obj.pool.name
     raw_vars = {
         "source": "syslog",
         "facility": "23",
         "severity": "6",
         "message": msg
     }
     msg = {
         "id": str(bson.ObjectId()),
         "ts": time.time(),
         "object": obj.id,
         "data": raw_vars
     }
     nsq_pub(topic, msg)
     self.stdout.write(msg["id"])
Example #4
0
    def mark_as_new(self, message=None):
        """
        Move to new queue for reclassification
        @todo: Rename method to *reclassify*
        """
        from noc.core.nsq.pub import nsq_pub

        # if message is None:
        #    message = "Reclassification requested"
        # log = self.log + [EventLog(timestamp=datetime.datetime.now(),
        #                            from_status="A", to_status="N",
        #                            message=message)]
        data = {"source": self.source}
        data.update(self.raw_vars)
        msg = {
            "id": str(self.id),
            "ts": time.mktime(self.timestamp.timetuple()),
            "object": self.managed_object.id,
            "data": data
        }
        nsq_pub("events.%s" % self.managed_object.pool.name, msg)
        self.delete()
Example #5
0
 def raise_event(self, mo_id, pool_name, raw_vars):
     d = datetime.datetime.strptime(raw_vars["ts"], "%Y-%m-%dT%H:%M:%S")
     ts = time.mktime(d.timetuple())
     msg = {"ts": ts, "object": mo_id, "source": "other", "data": raw_vars}
     self.logger.info("Pub Event: %s", msg)
     nsq_pub("events.%s" % pool_name, msg)