add raid space usage
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
- https://easysnmp.readthedocs.io/en/latest/session_api.html
|
- https://easysnmp.readthedocs.io/en/latest/session_api.html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = '0.11.0'
|
__version__ = '0.12.0'
|
||||||
__author__ = 'anima'
|
__author__ = 'anima'
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
@@ -126,6 +126,42 @@ class SNMPSynologyDisk():
|
|||||||
return disks
|
return disks
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Synology [DSM & DSM UC] Checks raids (baseclass)
|
||||||
|
#
|
||||||
|
class SNMPSynologyRaid():
|
||||||
|
def __init__(self, session):
|
||||||
|
self.session = session
|
||||||
|
|
||||||
|
def get_raids(self):
|
||||||
|
raids = list()
|
||||||
|
baseoid = '.1.3.6.1.4.1.6574.3'
|
||||||
|
oids = dict()
|
||||||
|
oids['index'] = '1'
|
||||||
|
oids['name'] = '2'
|
||||||
|
oids['status'] = '3'
|
||||||
|
oids['free'] = '4'
|
||||||
|
oids['total'] = '5'
|
||||||
|
oids['hotspare'] = '6'
|
||||||
|
|
||||||
|
raid_ids = list()
|
||||||
|
results = self.session.walk(baseoid)
|
||||||
|
for result in results:
|
||||||
|
if '6574.3.1.1.1.' in result.oid:
|
||||||
|
raid_ids.append(result.value)
|
||||||
|
|
||||||
|
for raid in raid_ids:
|
||||||
|
tmp_raid = dict()
|
||||||
|
for result in results:
|
||||||
|
for name, oid in oids.items():
|
||||||
|
if '6574.3.1.1.' + oid + '.' + raid in result.oid:
|
||||||
|
tmp_raid[name] = result.value
|
||||||
|
break
|
||||||
|
raids.append(tmp_raid)
|
||||||
|
|
||||||
|
return raids
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Synology General Summary
|
# Synology General Summary
|
||||||
#
|
#
|
||||||
@@ -516,10 +552,36 @@ class SNMPSynologyDiskHealthResult(nagiosplugin.Result):
|
|||||||
return f'Health of {self.metric.name} is in status {status}!'
|
return f'Health of {self.metric.name} is in status {status}!'
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Synology [DSM & DSM UC] Checks RAID status
|
||||||
|
#
|
||||||
|
class SNMPSynologyRaidSpaceResource(nagiosplugin.Resource, SNMPSynologyRaid):
|
||||||
|
def __init__(self, session) -> None:
|
||||||
|
self.session = session
|
||||||
|
|
||||||
|
def probe(self) -> list:
|
||||||
|
"""check memory usage in %
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Generator[nagisplugin.Metric]: multiple metric elements (yield)
|
||||||
|
"""
|
||||||
|
raids = self.get_raids()
|
||||||
|
for raid in raids:
|
||||||
|
# skip storage pools because they already full of there volumes
|
||||||
|
# works only with default naming maybe as argument ?
|
||||||
|
if raid['name'].startswith('Storage Pool'):
|
||||||
|
continue
|
||||||
|
used_space_in_percent = 100 - int(int(raid['free']) / int(raid['total']) * 100)
|
||||||
|
yield nagiosplugin.Metric(name='raid_' + raid["name"].lower().replace(' ', '_'), value=used_space_in_percent, uom='%', context='raid_space_scalar_context')
|
||||||
|
|
||||||
|
def __init__(self, session) -> None:
|
||||||
|
self.session = session
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Arguments
|
# Arguments
|
||||||
#
|
#
|
||||||
def parse_args() -> argparse.Namespace:
|
def parse_args() -> argparse.Namespace:
|
||||||
"""evaluates given arguments
|
"""evaluates given arguments
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -548,6 +610,7 @@ def parse_args() -> argparse.Namespace:
|
|||||||
'disk_ident',
|
'disk_ident',
|
||||||
'disk_life',
|
'disk_life',
|
||||||
'disk_sectors',
|
'disk_sectors',
|
||||||
|
'raid',
|
||||||
],
|
],
|
||||||
help='check mode to run')
|
help='check mode to run')
|
||||||
|
|
||||||
@@ -654,6 +717,11 @@ def main():
|
|||||||
nagiosplugin.ScalarContext(name='disk_sectors_scalar_context', warning=args.warning, critical=args.critical),
|
nagiosplugin.ScalarContext(name='disk_sectors_scalar_context', warning=args.warning, critical=args.critical),
|
||||||
nagiosplugin.Summary())
|
nagiosplugin.Summary())
|
||||||
check.name = "Disk BadSectors"
|
check.name = "Disk BadSectors"
|
||||||
|
case 'raid':
|
||||||
|
check = nagiosplugin.Check(SNMPSynologyRaidSpaceResource(session=session),
|
||||||
|
nagiosplugin.ScalarContext(name='raid_space_scalar_context', warning=args.warning, critical=args.critical),
|
||||||
|
nagiosplugin.Summary())
|
||||||
|
check.name = "Raid space usage"
|
||||||
case _:
|
case _:
|
||||||
raise nagiosplugin.CheckError(f'Unknown check mode: {args.check_mode}')
|
raise nagiosplugin.CheckError(f'Unknown check mode: {args.check_mode}')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user