Skip to content

Commit

Permalink
Merge pull request #4 from awlx/new_stuff
Browse files Browse the repository at this point in the history
Iterate over all OIDs
  • Loading branch information
awlx committed Sep 28, 2021
2 parents 80a5d20 + 87fe404 commit 3705f1b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ class Device:

@classmethod
def from_dict(cls, device_cfg: Dict[str, str]) -> "Device":
oids = []
for entry in device_cfg["extra_oids"]:
oids.append(entry)
return cls(
hostname=device_cfg["hostname"],
community=device_cfg["community"],
username=device_cfg["username"],
password=device_cfg["password"],
ip=ip_address(device_cfg["ip"]),
extra_oids=device_cfg["extra_oids"],
extra_oids=oids,
)


Expand Down Expand Up @@ -261,14 +264,18 @@ def pollExtraOIDs(session: Session, hostname: str, extra_oids: List[str]) -> boo
"host": hostname,
"oid": oid_name,
},
"time": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"time": datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
"fields": {
},
}
]
for output in oid_output:
dbpayload[0]["fields"][output.oid] = (int(output.value) if is_integer(output.value) else 0)
return upload_to_influx(dbpayload)
try:
upload_to_influx(dbpayload)
except:
return False
return True

def pollDevice(session: Session, hostname: str) -> bool:

Expand All @@ -293,7 +300,7 @@ def pollDevice(session: Session, hostname: str) -> bool:
"interface": name,
"interface_description": values["_ifDescr"],
},
"time": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"time": datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
"fields": {
"ifin": int(values["_ifHCInOctets"]),
"ifout": int(values["_ifHCOutOctets"]),
Expand Down

0 comments on commit 3705f1b

Please sign in to comment.