mirror of
https://github.com/nicolargo/glances.git
synced 2024-09-22 18:18:16 +03:00
Add args visibility to the plugins to handle with the SNMP server properties (address, community...)
This commit is contained in:
parent
2fec33adf3
commit
c3ba3f64e6
@ -90,7 +90,7 @@ class GlancesClient():
|
|||||||
client_version = self.client.init()
|
client_version = self.client.init()
|
||||||
self.set_mode('glances')
|
self.set_mode('glances')
|
||||||
except socket.error as err:
|
except socket.error as err:
|
||||||
print(_("Error: Connection to {0} server failed").format(self.get_mode()))
|
# print(_("Error: Connection to {0} server failed").format(self.get_mode()))
|
||||||
# Fallback to SNMP
|
# Fallback to SNMP
|
||||||
self.set_mode('snmp')
|
self.set_mode('snmp')
|
||||||
except ProtocolError as err:
|
except ProtocolError as err:
|
||||||
@ -106,23 +106,16 @@ class GlancesClient():
|
|||||||
self.stats = GlancesStatsClient()
|
self.stats = GlancesStatsClient()
|
||||||
self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
|
self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
|
||||||
elif self.get_mode() == 'snmp':
|
elif self.get_mode() == 'snmp':
|
||||||
|
print (_("Info: Connection to Glances server failed. Trying fallback to SNMP..."))
|
||||||
# Then fallback to SNMP if needed
|
# Then fallback to SNMP if needed
|
||||||
from glances.core.glances_snmp import GlancesSNMPClient
|
|
||||||
|
|
||||||
# Test if SNMP is available on the server side
|
|
||||||
clientsnmp = GlancesSNMPClient()
|
|
||||||
|
|
||||||
# !!! Simple request with system name
|
|
||||||
# !!! Had to have a standard method to check SNMP server
|
|
||||||
print(_("Trying {0}...").format(self.get_mode()))
|
|
||||||
if (clientsnmp.get_by_oid("1.3.6.1.2.1.1.5.0") == {}):
|
|
||||||
print(_("Error: Connection to {0} server failed").format(self.get_mode()))
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
from glances.core.glances_stats import GlancesStatsClientSNMP
|
from glances.core.glances_stats import GlancesStatsClientSNMP
|
||||||
|
|
||||||
# Init stats
|
# Init stats
|
||||||
self.stats = GlancesStatsClientSNMP()
|
self.stats = GlancesStatsClientSNMP(args=self.args)
|
||||||
|
|
||||||
|
if not self.stats.check_snmp():
|
||||||
|
print(_("Error: Connection to SNMP server failed"))
|
||||||
|
sys.exit(2)
|
||||||
else:
|
else:
|
||||||
ret = False
|
ret = False
|
||||||
|
|
||||||
|
@ -30,10 +30,10 @@ except ImportError, e:
|
|||||||
class GlancesSNMPClient(object):
|
class GlancesSNMPClient(object):
|
||||||
""" SNMP client class (based on PySNMP) """
|
""" SNMP client class (based on PySNMP) """
|
||||||
|
|
||||||
def __init__(self, host = "localhost",
|
def __init__(self, host="localhost",
|
||||||
port = 161,
|
port=161,
|
||||||
community = "public",
|
community="public",
|
||||||
version = "SNMPv2-MIB"):
|
version="SNMPv2-MIB"):
|
||||||
super(GlancesSNMPClient, self).__init__()
|
super(GlancesSNMPClient, self).__init__()
|
||||||
self.cmdGen = cmdgen.CommandGenerator()
|
self.cmdGen = cmdgen.CommandGenerator()
|
||||||
self.host = host
|
self.host = host
|
||||||
|
@ -64,7 +64,7 @@ class GlancesStats(object):
|
|||||||
# Default behavior
|
# Default behavior
|
||||||
raise AttributeError(item)
|
raise AttributeError(item)
|
||||||
|
|
||||||
def load_plugins(self):
|
def load_plugins(self, args=None):
|
||||||
"""
|
"""
|
||||||
Load all plugins in the "plugins" folder
|
Load all plugins in the "plugins" folder
|
||||||
"""
|
"""
|
||||||
@ -85,7 +85,7 @@ class GlancesStats(object):
|
|||||||
# for example, the file glances_xxx.py
|
# for example, the file glances_xxx.py
|
||||||
# generate self._plugins_list["xxx"] = ...
|
# generate self._plugins_list["xxx"] = ...
|
||||||
plugname = os.path.basename(plug)[len(header):-3].lower()
|
plugname = os.path.basename(plug)[len(header):-3].lower()
|
||||||
self._plugins[plugname] = m.Plugin()
|
self._plugins[plugname] = m.Plugin(args=args)
|
||||||
|
|
||||||
def getAllPlugins(self):
|
def getAllPlugins(self):
|
||||||
"""
|
"""
|
||||||
@ -221,15 +221,31 @@ class GlancesStatsClientSNMP(GlancesStats):
|
|||||||
This class store, update and give stats for the SNMP client
|
This class store, update and give stats for the SNMP client
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config=None):
|
def __init__(self, config=None, args=None):
|
||||||
# Init the plugin list dict
|
# Init the plugin list dict
|
||||||
self._plugins = collections.defaultdict(dict)
|
self._plugins = collections.defaultdict(dict)
|
||||||
|
|
||||||
# Init the configuration
|
# Init the configuration
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
|
# Init the arguments
|
||||||
|
self.args = args
|
||||||
|
|
||||||
# Load plugins
|
# Load plugins
|
||||||
self.load_plugins()
|
self.load_plugins(args=self.args)
|
||||||
|
|
||||||
|
def check_snmp(self):
|
||||||
|
"""
|
||||||
|
Chek if SNMP is available on the server
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Import the SNMP client class
|
||||||
|
from glances.core.glances_snmp import GlancesSNMPClient
|
||||||
|
|
||||||
|
# Create an instance of the SNMP client
|
||||||
|
clientsnmp = GlancesSNMPClient(host=self.args.client)
|
||||||
|
|
||||||
|
return clientsnmp.get_by_oid("1.3.6.1.2.1.1.5.0") != {}
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""
|
"""
|
||||||
|
@ -32,8 +32,8 @@ class Plugin(GlancesPlugin):
|
|||||||
Only for display
|
Only for display
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -37,8 +37,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a list
|
stats is a list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
#!!! TODO: display plugin...
|
#!!! TODO: display plugin...
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is integer (number of core)
|
stats is integer (number of core)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We dot not want to display the stat in the curse interface
|
# We dot not want to display the stat in the curse interface
|
||||||
# The core number is displayed by the load plugin
|
# The core number is displayed by the load plugin
|
||||||
|
@ -39,8 +39,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a dict
|
stats is a dict
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -34,8 +34,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a list
|
stats is a list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -50,8 +50,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a list
|
stats is a list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -30,8 +30,9 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
stats is a list
|
stats is a list
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
|
||||||
GlancesPlugin.__init__(self)
|
def __init__(self, args=None):
|
||||||
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# Init the sensor class
|
# Init the sensor class
|
||||||
self.glancesgrabhddtemp = glancesGrabHDDTemp()
|
self.glancesgrabhddtemp = glancesGrabHDDTemp()
|
||||||
|
@ -35,8 +35,8 @@ class Plugin(GlancesPlugin):
|
|||||||
Glances' Help Plugin
|
Glances' Help Plugin
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -43,8 +43,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a dict
|
stats is a dict
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -46,8 +46,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a dict
|
stats is a dict
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -38,8 +38,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a dict
|
stats is a dict
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -27,8 +27,8 @@ class Plugin(GlancesPlugin):
|
|||||||
Glances's monitor Plugin
|
Glances's monitor Plugin
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -42,8 +42,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a list
|
stats is a list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -32,8 +32,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is (string)
|
stats is (string)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -34,8 +34,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a list
|
stats is a list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -33,10 +33,13 @@ class GlancesPlugin(object):
|
|||||||
Main class for Glances' plugin
|
Main class for Glances' plugin
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
# Plugin name (= module name without glances_)
|
# Plugin name (= module name without glances_)
|
||||||
self.plugin_name = self.__class__.__module__[len('glances_'):]
|
self.plugin_name = self.__class__.__module__[len('glances_'):]
|
||||||
|
|
||||||
|
# Init the args
|
||||||
|
self.args = args
|
||||||
|
|
||||||
# Init the stats list
|
# Init the stats list
|
||||||
self.stats = None
|
self.stats = None
|
||||||
|
|
||||||
@ -61,7 +64,7 @@ class GlancesPlugin(object):
|
|||||||
from glances.core.glances_snmp import GlancesSNMPClient
|
from glances.core.glances_snmp import GlancesSNMPClient
|
||||||
|
|
||||||
# Init the SNMP request
|
# Init the SNMP request
|
||||||
clientsnmp = GlancesSNMPClient()
|
clientsnmp = GlancesSNMPClient(host=self.args.client)
|
||||||
|
|
||||||
# Process the SNMP request
|
# Process the SNMP request
|
||||||
snmpresult = clientsnmp.get_by_oid(*snmp_oid.values())
|
snmpresult = clientsnmp.get_by_oid(*snmp_oid.values())
|
||||||
|
@ -29,8 +29,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a list
|
stats is a list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -32,8 +32,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a list
|
stats is a list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -29,8 +29,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a tuple
|
stats is a tuple
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
|
@ -30,59 +30,6 @@ from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin
|
|||||||
from glances.plugins.glances_plugin import GlancesPlugin
|
from glances.plugins.glances_plugin import GlancesPlugin
|
||||||
|
|
||||||
|
|
||||||
class glancesGrabSensors:
|
|
||||||
"""
|
|
||||||
Get sensors stats using the PySensors library
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""
|
|
||||||
Init sensors stats
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
sensors.init()
|
|
||||||
except Exception:
|
|
||||||
self.initok = False
|
|
||||||
else:
|
|
||||||
self.initok = True
|
|
||||||
|
|
||||||
# Init the stats
|
|
||||||
self.reset()
|
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
"""
|
|
||||||
Reset/init the stats
|
|
||||||
"""
|
|
||||||
self.sensors_list = []
|
|
||||||
|
|
||||||
def __update__(self):
|
|
||||||
"""
|
|
||||||
Update the stats
|
|
||||||
"""
|
|
||||||
# Reset the list
|
|
||||||
self.reset()
|
|
||||||
|
|
||||||
# grab only temperature stats
|
|
||||||
if self.initok:
|
|
||||||
for chip in sensors.iter_detected_chips():
|
|
||||||
for feature in chip:
|
|
||||||
sensors_current = {}
|
|
||||||
if feature.name.startswith(b'temp'):
|
|
||||||
sensors_current['label'] = feature.label
|
|
||||||
sensors_current['value'] = int(feature.get_value())
|
|
||||||
self.sensors_list.append(sensors_current)
|
|
||||||
|
|
||||||
return self.sensors_list
|
|
||||||
|
|
||||||
def get(self):
|
|
||||||
self.__update__()
|
|
||||||
return self.sensors_list
|
|
||||||
|
|
||||||
def quit(self):
|
|
||||||
if self.initok:
|
|
||||||
sensors.cleanup()
|
|
||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
"""
|
"""
|
||||||
Glances' sensors plugin
|
Glances' sensors plugin
|
||||||
@ -92,8 +39,8 @@ class Plugin(GlancesPlugin):
|
|||||||
The hard disks are already sorted by name
|
The hard disks are already sorted by name
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# Init the sensor class
|
# Init the sensor class
|
||||||
self.glancesgrabsensors = glancesGrabSensors()
|
self.glancesgrabsensors = glancesGrabSensors()
|
||||||
@ -170,3 +117,56 @@ class Plugin(GlancesPlugin):
|
|||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
class glancesGrabSensors:
|
||||||
|
"""
|
||||||
|
Get sensors stats using the PySensors library
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Init sensors stats
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sensors.init()
|
||||||
|
except Exception:
|
||||||
|
self.initok = False
|
||||||
|
else:
|
||||||
|
self.initok = True
|
||||||
|
|
||||||
|
# Init the stats
|
||||||
|
self.reset()
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
"""
|
||||||
|
Reset/init the stats
|
||||||
|
"""
|
||||||
|
self.sensors_list = []
|
||||||
|
|
||||||
|
def __update__(self):
|
||||||
|
"""
|
||||||
|
Update the stats
|
||||||
|
"""
|
||||||
|
# Reset the list
|
||||||
|
self.reset()
|
||||||
|
|
||||||
|
# grab only temperature stats
|
||||||
|
if self.initok:
|
||||||
|
for chip in sensors.iter_detected_chips():
|
||||||
|
for feature in chip:
|
||||||
|
sensors_current = {}
|
||||||
|
if feature.name.startswith(b'temp'):
|
||||||
|
sensors_current['label'] = feature.label
|
||||||
|
sensors_current['value'] = int(feature.get_value())
|
||||||
|
self.sensors_list.append(sensors_current)
|
||||||
|
|
||||||
|
return self.sensors_list
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
self.__update__()
|
||||||
|
return self.sensors_list
|
||||||
|
|
||||||
|
def quit(self):
|
||||||
|
if self.initok:
|
||||||
|
sensors.cleanup()
|
||||||
|
@ -38,8 +38,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a dict
|
stats is a dict
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -37,8 +37,8 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is date (string)
|
stats is date (string)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, args=None):
|
||||||
GlancesPlugin.__init__(self)
|
GlancesPlugin.__init__(self, args=args)
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
Loading…
Reference in New Issue
Block a user