Пример #1
0
 def get_events(self, options):
     """
     Generator returning active events
     """
     c = ActiveEvent.objects.all()
     trap_oid = None
     syslog_re = None
     profile = options["profile"]
     if options["event"]:
         c = c.filter(id=ObjectId(options["event"]))
     if options["object"]:
         try:
             o = ManagedObject.objects.get(name=options["object"])
         except ManagedObject.DoesNotExist:
             self.die("Object not found: %s" % options["object"])
         c = c.filter(managed_object=o.id)
     if options["selector"]:
         try:
             s = ManagedObjectSelector.objects.get(name=options["selector"])
         except ManagedObjectSelector.DoesNotExist:
             self.die("Selector not found: %s" % options["selector"])
         c = c.filter(
             managed_object__in=[mo.id for mo in s.managed_objects])
     if options["class"]:
         o = EventClass.objects.filter(name=options["class"]).first()
         if not o:
             self.die("Event class not found: %s" % options["class"])
         c = c.filter(event_class=o.id)
     if options["trap"]:
         if is_oid(options["trap"]):
             trap_oid = options["trap"]
         else:
             trap_oid = MIB.get_oid(options["trap"])
             if trap_oid is None:
                 self.die("Cannot find OID for %s" % options["trap"])
         c = c.filter(raw_vars__source="SNMP Trap")
     if options["syslog"]:
         try:
             syslog_re = re.compile(options["syslog"], re.IGNORECASE)
         except Exception as e:
             self.die("Invalid RE: %s" % str(e))
         c = c.filter(raw_vars__source="syslog")
     for e in c:
         if profile:
             if not e.managed_object.profile == Profile[profile]:
                 continue
         if trap_oid:
             if ("source" in e.raw_vars
                     and e.raw_vars["source"] == "SNMP Trap"
                     and "1.3.6.1.6.3.1.1.4.1.0" in e.raw_vars
                     and e.raw_vars["1.3.6.1.6.3.1.1.4.1.0"] == trap_oid):
                 yield e
         elif syslog_re:
             if ("source" in e.raw_vars and e.raw_vars["source"] == "syslog"
                     and "message" in e.raw_vars
                     and syslog_re.search(e.raw_vars["message"])):
                 yield e
         else:
             yield e
Пример #2
0
 def lookup(self, oid):
     """
     Convert oid to symbolic name and vise versa
     :param oid:
     :return:
     """
     if self.rx_oid.match(oid):
         # oid -> name
         name = MIB.get_name(oid)
         oid = oid
     else:
         name = oid
         oid = MIB.get_oid(name)
     if oid and name:
         return {"status": True, "oid": oid, "name": name}
     return {"status": False}