Last active
August 7, 2021 09:32
-
-
Save turingmachine/a8dcfc414002a4be36fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
from datetime import datetime, timedelta | |
import Globals | |
from Products.ZenUtils.ZCmdBase import ZCmdBase | |
from Availability import Report | |
replace_args = {'day':1,'hour':0,'minute':0,'second':0,'microsecond':0} | |
last_day = datetime.now().replace(**replace_args) - timedelta(microseconds=1) | |
first_day = last_day.replace(**replace_args) | |
last_day = time.mktime(last_day.timetuple()) | |
first_day = time.mktime(first_day.timetuple()) | |
zcmdbase = ZCmdBase() | |
report = Report(startDate=first_day, endDate=last_day, severity=3) | |
def format_seconds(seconds): | |
m, s = divmod(seconds, 60) | |
h, m = divmod(m, 60) | |
return "%d:%02d:%02d" % (h, m, s) | |
def parse_timestamp(timestamp): | |
return datetime.fromtimestamp(float(timestamp)/1000) | |
print "Device Name, IP Address, Downtime %, Uptime %, Downtime, Last Failure, MTBF" | |
for device in report.run(zcmdbase.dmd): | |
print "{}, {}, {}, {}, {}, {}, {}".format( | |
device.device, | |
device.getDevice(zcmdbase.dmd).manageIp, | |
'{:.2%}'.format(1 - device.availability), | |
'{:.2%}'.format(device.availability), | |
format_seconds(device.downtime/1000), | |
parse_timestamp(sorted(device.events)[-1]).strftime("%Y-%m-%d %H:%M"), | |
format_seconds((last_day - first_day - (device.downtime/1000)) / len(device.events)), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment