bundlewrap/bundles/icinga2/files/check_usv_snmp

71 lines
1.9 KiB
Text
Raw Permalink Normal View History

2021-04-25 06:02:04 +00:00
#!/usr/bin/env python3
from sys import argv, exit
from easysnmp import Session
try:
hostname = argv[1]
community = argv[2]
except IndexError:
print('Usage: {} <hostname> <snmp_community>'.format(argv[0]))
exit(3)
try:
session = Session(hostname=hostname, community=community, version=2)
items = session.walk('iso.3.6.1.2.1.33')
result = {}
for item in items:
result[item.oid[len('iso.3.6.1.2.1.33')+1:]] = item.value
warn = set()
crit = set()
if int(result['1.2.2.0']):
warn.add('USV is on battery!')
# Estimated runtime in minutes
if int(result['1.2.3.0']) < 15:
crit.add('Remaining runtime is less than 15 minutes!')
2021-04-25 06:02:04 +00:00
elif int(result['1.2.3.0']) < 25:
warn.add('Remaining runtime is less than 25 minutes!')
2021-04-25 06:02:04 +00:00
# Battery status in percent
if int(result['1.2.4.0']) < 10:
crit.add('Remaining runtime is less than 10%!')
2021-04-25 06:02:04 +00:00
elif int(result['1.2.4.0']) < 25:
warn.add('Remaining runtime is less than 25%!')
2021-04-25 06:02:04 +00:00
# Output load in percent
if int(result['1.4.4.1.5.1']) > 90:
crit.add('Output Power is more than 90% of rated capacity!')
2021-04-25 06:02:04 +00:00
elif int(result['1.4.4.1.5.1']) > 80:
warn.add('Output Power is more than 80% of rated capacity!')
print('{model} running{from_bat} at {out_pct}% load ({out_w} W), battery at {bat_pct}% ({bat_min} min)'.format(
model=result['1.1.2.0'],
out_pct=result['1.4.4.1.5.1'],
out_w=result['1.4.4.1.4.1'],
bat_pct=result['1.2.4.0'],
bat_min=result['1.2.3.0'],
from_bat=' from battery' if int(result['1.2.2.0']) else '',
))
2021-04-25 06:02:04 +00:00
for line in sorted(crit):
print('CRIT: ' + line)
2021-04-25 06:02:04 +00:00
for line in sorted(warn):
print('WARN: ' + line)
2021-04-25 06:02:04 +00:00
if crit:
exit(2)
elif warn:
exit(1)
else:
exit(0)
except Exception as e:
print(repr(e))
exit(3)