Skip to content

Commit 0a3380b

Browse files
author
Anze
committed
Extract OIDs and other relevant data from parameters
1 parent a0f3206 commit 0a3380b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

collector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ def fetch_job_configs(self, protocol):
241241
del entity_info["protocols"]
242242

243243
entity_info["account_id"] = account_id
244+
entity_info["entity_id"] = entity_info["id"]
245+
del entity_info["id"]
244246

245247
yield entity_info
246248

grafolean-worker-snmp.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from apscheduler.schedulers.blocking import BlockingScheduler
21
import os
32
import dotenv
43
import logging
@@ -25,7 +24,7 @@ class SNMPCollector(Collector):
2524
def do_snmp(*args, **entity_info):
2625
"""
2726
{
28-
"id": 1348300224,
27+
"entity_id": 1348300224,
2928
"name": "localhost",
3029
"entity_type": "device",
3130
"details": {
@@ -66,13 +65,20 @@ def do_snmp(*args, **entity_info):
6665
"account_id": 1
6766
}
6867
"""
69-
# log.info("Running job for account [{account_id}], IP [{ipv4}], OIDS: {oids}".format(
70-
# account_id=account_id,
71-
# ipv4=entity["ipv4"],
72-
# oids=["SNMP{} {}".format(o["fetch_method"].upper(), o["oid"]) for o in sensor["oids"]],
73-
# ))
68+
# filter out only those sensors that are supposed to run at this interval:
7469
affecting_intervals, = args
75-
log.info("Running: {} {}".format(affecting_intervals, json.dumps(entity_info)))
70+
sensors = [s for s in entity_info["sensors"] if s["interval"] in affecting_intervals]
71+
oids = []
72+
for sensor in sensors:
73+
oids.extend(sensor["sensor_details"]["oids"])
74+
log.info("Running job for account [{account_id}], IP [{ipv4}], nsensors: {n_sensors}, oids: {oids}".format(
75+
account_id=entity_info["account_id"],
76+
ipv4=entity_info["details"]["ipv4"],
77+
n_sensors=len(sensors),
78+
oids=["SNMP{} {}".format(o["fetch_method"].upper(), o["oid"]) for o in oids],
79+
))
80+
81+
7682

7783
def jobs(self):
7884
"""

0 commit comments

Comments
 (0)