def get_data(self, **kwargs): c = EventClass.objects.filter(name="Unknown | SNMP Trap").first() pipeline = [{ "$match": { "event_class": c.id } }, { "$project": { "vars": 1 } }, { "$group": { "_id": "$vars.trap_oid", "count": { "$sum": 1 } } }] oids = ActiveEvent._get_collection().aggregate(pipeline) data = [(e["_id"], MIB.get_name(e["_id"]), e["count"]) for e in oids] data = sorted(data, key=lambda x: -x[2]) return self.from_dataset(title=self.title, columns=[ "OID", "Name", TableColumn("Count", format="integer", align="right", total="sum") ], data=data)
def get_data(self, **kwargs): c = EventClass.objects.filter(name="Unknown | SNMP Trap").first() # Переделать на agregate Функция считает число OID'ов в переменных аварий # и проверяет их на опознанность pipeline = [{ "$match": { "event_class": c.id } }, { "$project": { "vars": 1 } }, { "$group": { "_id": "$vars.trap_oid", "count": { "$sum": 1 } } }] oids = ActiveEvent._get_collection().aggregate(pipeline) d = [(e["_id"], MIB.get_name(e["_id"]), e["count"]) for e in oids] print d data = [(o, n, c) for o, n, c in d if self.rx_unclassified.search(n)] return self.from_dataset(title=self.title, columns=[ "OID", "Name", TableColumn("Count", format="integer", align="right", total="sum") ], data=data)
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}