mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-29 04:04:03 +03:00
Correct issue with SNMP fallback mode in Python 3
This commit is contained in:
parent
9405479f13
commit
f9778982ce
@ -49,7 +49,7 @@ LOGGING_CFG = {
|
||||
'filename': os.path.join(tempfile.gettempdir(), 'glances.log')
|
||||
},
|
||||
'console':{
|
||||
'level':'ERROR',
|
||||
'level':'CRITICAL',
|
||||
'class':'logging.StreamHandler',
|
||||
'formatter': 'short'
|
||||
}
|
||||
|
@ -59,6 +59,9 @@ class GlancesSNMPClient(object):
|
||||
ret[name.prettyPrint()] = ''
|
||||
else:
|
||||
ret[name.prettyPrint()] = val.prettyPrint()
|
||||
# In Python 3, prettyPrint() return 'b'linux'' instead of 'linux'
|
||||
if ret[name.prettyPrint()].startswith('b\''):
|
||||
ret[name.prettyPrint()] = ret[name.prettyPrint()][2:-1]
|
||||
return ret
|
||||
|
||||
def get_by_oid(self, *oid):
|
||||
@ -93,6 +96,9 @@ class GlancesSNMPClient(object):
|
||||
item[name.prettyPrint()] = ''
|
||||
else:
|
||||
item[name.prettyPrint()] = val.prettyPrint()
|
||||
# In Python 3, prettyPrint() return 'b'linux'' instead of 'linux'
|
||||
if item[name.prettyPrint()].startswith('b\''):
|
||||
item[name.prettyPrint()] = item[name.prettyPrint()][2:-1]
|
||||
ret.append(item)
|
||||
return ret
|
||||
|
||||
|
@ -240,8 +240,10 @@ class GlancesStatsClientSNMP(GlancesStats):
|
||||
oid_os_name = clientsnmp.get_by_oid("1.3.6.1.2.1.1.1.0")
|
||||
try:
|
||||
self.system_name = self.get_system_name(oid_os_name['1.3.6.1.2.1.1.1.0'])
|
||||
logger.info(_('SNMP system name detected: {}').format(self.system_name))
|
||||
except KeyError:
|
||||
self.system_name = None
|
||||
logger.warning(_('Can not detect SNMP system name'))
|
||||
|
||||
return ret
|
||||
|
||||
@ -253,7 +255,12 @@ class GlancesStatsClientSNMP(GlancesStats):
|
||||
return short_system_name
|
||||
|
||||
# Find the short name in the oid_to_short_os_name dict
|
||||
for r,v in oid_to_short_system_name.iteritems():
|
||||
try:
|
||||
iteritems = oid_to_short_system_name.iteritems()
|
||||
except AttributeError:
|
||||
# Correct issue #386
|
||||
iteritems = oid_to_short_system_name.items()
|
||||
for r,v in iteritems:
|
||||
if re.search(r, oid_system_name):
|
||||
short_system_name = v
|
||||
break
|
||||
|
@ -120,7 +120,7 @@ class Plugin(GlancesPlugin):
|
||||
return self.stats
|
||||
|
||||
# Convert SNMP stats to float
|
||||
for key in self.stats.iterkeys():
|
||||
for key in list(self.stats.keys()):
|
||||
self.stats[key] = float(self.stats[key])
|
||||
|
||||
return self.stats
|
||||
|
@ -19,10 +19,14 @@
|
||||
|
||||
"""File system plugin."""
|
||||
|
||||
# System libs
|
||||
import base64
|
||||
|
||||
# Glances libs
|
||||
from glances.core.glances_globals import version, logger
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
# PSutil lib for local grab
|
||||
import psutil
|
||||
|
||||
# SNMP OID
|
||||
|
@ -23,6 +23,7 @@
|
||||
import os
|
||||
|
||||
# Import Glances libs
|
||||
from glances.core.glances_globals import logger
|
||||
from glances.plugins.glances_core import Plugin as CorePlugin
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
@ -84,14 +85,20 @@ class Plugin(GlancesPlugin):
|
||||
# Update stats using SNMP
|
||||
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid)
|
||||
|
||||
self.stats['cpucore'] = nb_log_core
|
||||
|
||||
if self.stats['min1'] == '':
|
||||
self.reset()
|
||||
return self.stats
|
||||
|
||||
for key in self.stats.iterkeys():
|
||||
self.stats[key] = float(self.stats[key])
|
||||
# Python 3 return a dict like:
|
||||
# {'min1': "b'0.08'", 'min5': "b'0.12'", 'min15': "b'0.15'"}
|
||||
try:
|
||||
iteritems = self.stats.iteritems()
|
||||
except AttributeError:
|
||||
iteritems = self.stats.items()
|
||||
for k,v in iteritems:
|
||||
self.stats[k] = float(v)
|
||||
|
||||
self.stats['cpucore'] = nb_log_core
|
||||
|
||||
return self.stats
|
||||
|
||||
|
@ -132,7 +132,7 @@ class Plugin(GlancesPlugin):
|
||||
self.reset()
|
||||
return self.stats
|
||||
|
||||
for key in self.stats.iterkeys():
|
||||
for key in list(self.stats.keys()):
|
||||
if self.stats[key] != '':
|
||||
self.stats[key] = float(self.stats[key]) * 1024
|
||||
|
||||
|
@ -102,7 +102,7 @@ class Plugin(GlancesPlugin):
|
||||
self.reset()
|
||||
return self.stats
|
||||
|
||||
for key in self.stats.iterkeys():
|
||||
for key in list(self.stats.keys()):
|
||||
if self.stats[key] != '':
|
||||
self.stats[key] = float(self.stats[key]) * 1024
|
||||
|
||||
|
@ -121,7 +121,7 @@ class GlancesPlugin(object):
|
||||
for item in snmpresult:
|
||||
item_stats = {}
|
||||
item_key = None
|
||||
for key in snmp_oid.iterkeys():
|
||||
for key in list(snmp_oid.keys()):
|
||||
oid = snmp_oid[key] + '.' + str(index)
|
||||
if oid in item:
|
||||
if item_key is None:
|
||||
@ -136,7 +136,7 @@ class GlancesPlugin(object):
|
||||
snmpresult = clientsnmp.get_by_oid(*snmp_oid.values())
|
||||
|
||||
# Build the internal dict with the SNMP result
|
||||
for key in snmp_oid.iterkeys():
|
||||
for key in list(snmp_oid.keys()):
|
||||
ret[key] = snmpresult[snmp_oid[key]]
|
||||
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user