mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
Plugin snmp__synology: fix code style issues reported by flake8
This commit is contained in:
parent
8b69c8a1fe
commit
dacb55010a
2 changed files with 76 additions and 74 deletions
|
@ -29,8 +29,8 @@ has been configured correctly.
|
||||||
|
|
||||||
=head1 MAGIC MARKERS
|
=head1 MAGIC MARKERS
|
||||||
|
|
||||||
#%# family=snmpauto
|
#%# family=snmpauto
|
||||||
#%# capabilities=snmpconf
|
#%# capabilities=snmpconf
|
||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
|
@ -63,60 +63,63 @@ disktable_model = '1.3.6.1.4.1.6574.2.1.1.3'
|
||||||
disktable_temp = '1.3.6.1.4.1.6574.2.1.1.6'
|
disktable_temp = '1.3.6.1.4.1.6574.2.1.1.6'
|
||||||
sys_temperature = '1.3.6.1.4.1.6574.1.2.0'
|
sys_temperature = '1.3.6.1.4.1.6574.1.2.0'
|
||||||
|
|
||||||
|
|
||||||
class SynologySNMPClient(object):
|
class SynologySNMPClient(object):
|
||||||
def __init__(self, host, port, community):
|
def __init__(self, host, port, community):
|
||||||
self.hostname = host
|
self.hostname = host
|
||||||
self.transport = cmdgen.UdpTransportTarget((host, int(port)))
|
self.transport = cmdgen.UdpTransportTarget((host, int(port)))
|
||||||
self.auth = cmdgen.CommunityData('test-agent', community)
|
self.auth = cmdgen.CommunityData('test-agent', community)
|
||||||
self.gen = cmdgen.CommandGenerator()
|
self.gen = cmdgen.CommandGenerator()
|
||||||
|
|
||||||
def _get_disks(self):
|
def _get_disks(self):
|
||||||
disk_table = '1.3.6.1.4.1.6574.2.1'
|
disk_table = '1.3.6.1.4.1.6574.2.1'
|
||||||
errorIndication, errorStatus, errorIndex, varBindTable = self.gen.bulkCmd(
|
errorIndication, errorStatus, errorIndex, varBindTable = self.gen.bulkCmd(
|
||||||
self.auth,
|
self.auth,
|
||||||
self.transport,
|
self.transport,
|
||||||
0, 24,
|
0, 24,
|
||||||
disk_table)
|
disk_table)
|
||||||
|
|
||||||
if errorIndication:
|
if errorIndication:
|
||||||
logging.error("SNMP bulkCmd for devices failed: %s, %s, %s" % (errorIndication, errorStatus, errorIndex))
|
logging.error("SNMP bulkCmd for devices failed: %s, %s, %s",
|
||||||
return
|
errorIndication, errorStatus, errorIndex)
|
||||||
|
return
|
||||||
|
|
||||||
devices = {}
|
devices = {}
|
||||||
for row in varBindTable:
|
for row in varBindTable:
|
||||||
for oid, value in row:
|
for oid, value in row:
|
||||||
oid = str(oid)
|
oid = str(oid)
|
||||||
if not oid.startswith(disk_table):
|
if not oid.startswith(disk_table):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
disk_id = oid[oid.rindex('.')+1:]
|
disk_id = oid[oid.rindex('.')+1:]
|
||||||
|
|
||||||
values = devices.get(disk_id, [None, None, None])
|
values = devices.get(disk_id, [None, None, None])
|
||||||
if oid.startswith(disktable_id):
|
if oid.startswith(disktable_id):
|
||||||
values[0] = str(value).strip()
|
values[0] = str(value).strip()
|
||||||
if oid.startswith(disktable_model):
|
if oid.startswith(disktable_model):
|
||||||
values[1] = str(value).strip()
|
values[1] = str(value).strip()
|
||||||
if oid.startswith(disktable_temp):
|
if oid.startswith(disktable_temp):
|
||||||
values[2] = int(value)
|
values[2] = int(value)
|
||||||
devices[disk_id] = values
|
devices[disk_id] = values
|
||||||
|
|
||||||
for x in sorted(devices.keys()):
|
for x in sorted(devices.keys()):
|
||||||
yield tuple([x] + devices[x])
|
yield tuple([x] + devices[x])
|
||||||
|
|
||||||
def _get_sys_temperature(self):
|
def _get_sys_temperature(self):
|
||||||
errorIndication, errorStatus, errorIndex, varBindTable = self.gen.getCmd(
|
errorIndication, errorStatus, errorIndex, varBindTable = self.gen.getCmd(
|
||||||
self.auth,
|
self.auth,
|
||||||
self.transport,
|
self.transport,
|
||||||
sys_temperature)
|
sys_temperature)
|
||||||
|
|
||||||
if errorIndication:
|
if errorIndication:
|
||||||
logging.error("SNMP getCmd for %s failed: %s, %s, %s" % (sys_temperature, errorIndication, errorStatus, errorIndex))
|
logging.error("SNMP getCmd for %s failed: %s, %s, %s",
|
||||||
return None
|
sys_temperature, errorIndication, errorStatus, errorIndex)
|
||||||
|
return None
|
||||||
|
|
||||||
return int(varBindTable[0][1])
|
return int(varBindTable[0][1])
|
||||||
|
|
||||||
def print_config(self):
|
def print_config(self):
|
||||||
print """multigraph synology_hdd_temperatures
|
print """multigraph synology_hdd_temperatures
|
||||||
host_name {hostname}
|
host_name {hostname}
|
||||||
graph_title HDD temperatures on {hostname}
|
graph_title HDD temperatures on {hostname}
|
||||||
graph_vlabel Temperature in °C
|
graph_vlabel Temperature in °C
|
||||||
|
@ -124,14 +127,13 @@ graph_args --base 1000
|
||||||
graph_category sensors
|
graph_category sensors
|
||||||
graph_info HDD temperatures on {hostname}""".format(hostname=self.hostname)
|
graph_info HDD temperatures on {hostname}""".format(hostname=self.hostname)
|
||||||
|
|
||||||
for id, name, model, temp in self._get_disks():
|
for id, name, model, temp in self._get_disks():
|
||||||
print """disk{disk_id}.info Temperature of {name} ({model})
|
print """disk{disk_id}.info Temperature of {name} ({model})
|
||||||
disk{disk_id}.label {name} ({model})
|
disk{disk_id}.label {name} ({model})
|
||||||
disk{disk_id}.type GAUGE
|
disk{disk_id}.type GAUGE
|
||||||
disk{disk_id}.min 0""".format(disk_id=id, name=name, model=model)
|
disk{disk_id}.min 0""".format(disk_id=id, name=name, model=model)
|
||||||
|
|
||||||
|
print """multigraph synology_sys_temperature
|
||||||
print """multigraph synology_sys_temperature
|
|
||||||
host_name {hostname}
|
host_name {hostname}
|
||||||
graph_title System temperatures of {hostname}
|
graph_title System temperatures of {hostname}
|
||||||
graph_vlabel Temperature in °C
|
graph_vlabel Temperature in °C
|
||||||
|
@ -144,13 +146,13 @@ sys_temp.type GAUGE
|
||||||
sys_temp.min 0
|
sys_temp.min 0
|
||||||
""".format(hostname=self.hostname)
|
""".format(hostname=self.hostname)
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
print """multigraph synology_hdd_temperatures"""
|
print """multigraph synology_hdd_temperatures"""
|
||||||
for id, name, model, temp in self._get_disks():
|
for id, name, model, temp in self._get_disks():
|
||||||
print """disk{disk_id}.value {temp}""".format(disk_id=id, temp=temp)
|
print """disk{disk_id}.value {temp}""".format(disk_id=id, temp=temp)
|
||||||
|
|
||||||
print """multigraph synology_sys_temperature"""
|
print """multigraph synology_sys_temperature"""
|
||||||
print "sys_temp.value {temp}".format(temp=self._get_sys_temperature())
|
print "sys_temp.value {temp}".format(temp=self._get_sys_temperature())
|
||||||
|
|
||||||
|
|
||||||
host = None
|
host = None
|
||||||
|
@ -159,30 +161,31 @@ community = os.getenv('community', None)
|
||||||
debug = bool(os.getenv('MUNIN_DEBUG', os.getenv('DEBUG', 0)))
|
debug = bool(os.getenv('MUNIN_DEBUG', os.getenv('DEBUG', 0)))
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-7s %(message)s')
|
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-7s %(message)s')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
match = re.search("^(?:|.*\/)snmp_([^_]+)_synology$", sys.argv[0])
|
match = re.search(r"^(?:|.*\/)snmp_([^_]+)_synology$", sys.argv[0])
|
||||||
host = match.group(1)
|
host = match.group(1)
|
||||||
match = re.search("^([^:]+):(\d+)$", host)
|
match = re.search(r"^([^:]+):(\d+)$", host)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
host = match.group(1)
|
host = match.group(1)
|
||||||
port = match.group(2)
|
port = match.group(2)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.error("Caught exception: %s" % ex)
|
logging.error("Caught exception: %s" % ex)
|
||||||
|
|
||||||
|
|
||||||
if "snmpconf" in sys.argv[1:]:
|
if "snmpconf" in sys.argv[1:]:
|
||||||
print "require 1.3.6.1.4.1.6574.2.1.1"
|
print "require 1.3.6.1.4.1.6574.2.1.1"
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
if not (host and port and community):
|
if not (host and port and community):
|
||||||
print "# Bad configuration. Cannot run with Host=%s, port=%s and community=%s" % (host, port, community)
|
print("# Bad configuration. Cannot run with Host=%s, port=%s and community=%s"
|
||||||
sys.exit(1)
|
% (host, port, community))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
c = SynologySNMPClient(host, port, community)
|
c = SynologySNMPClient(host, port, community)
|
||||||
|
|
||||||
if "config" in sys.argv[1:]:
|
if "config" in sys.argv[1:]:
|
||||||
c.print_config()
|
c.print_config()
|
||||||
else:
|
else:
|
||||||
c.execute()
|
c.execute()
|
||||||
|
|
|
@ -431,7 +431,6 @@ plugins/streaming/packetship_
|
||||||
plugins/swift/swift-async_
|
plugins/swift/swift-async_
|
||||||
plugins/swift/swift-quarantined_
|
plugins/swift/swift-quarantined_
|
||||||
plugins/swift/swift-replication-time_
|
plugins/swift/swift-replication-time_
|
||||||
plugins/synology/snmp__synology
|
|
||||||
plugins/system/auth
|
plugins/system/auth
|
||||||
plugins/system/blockhosts
|
plugins/system/blockhosts
|
||||||
plugins/systemd/systemd_units
|
plugins/systemd/systemd_units
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue