Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# For each AMP scrip, call the load_config method
for s in self.config.sections():
if s.startswith("amp_"):
# An AMP section exists in the configuration file
# If an AMP script exist in the glances/amps folder, use it
amp_conf_name = s[4:]
amp_script = os.path.join(amps_path, header + s[4:] + ".py")
if not os.path.exists(amp_script):
# If not, use the default script
amp_script = os.path.join(amps_path, "glances_default.py")
try:
amp = __import__(os.path.basename(amp_script)[:-3])
except ImportError as e:
logger.warning("Missing Python Lib ({}), cannot load {} AMP".format(e, amp_conf_name))
except Exception as e:
logger.warning("Cannot load {} AMP ({})".format(amp_conf_name, e))
else:
# Add the AMP to the dictionary
# The key is the AMP name
# for example, the file glances_xxx.py
# generate self._amps_list["xxx"] = ...
self.__amps_dict[amp_conf_name] = amp.Amp(name=amp_conf_name, args=self.args)
# Load the AMP configuration
self.__amps_dict[amp_conf_name].load_config(self.config)
# Log AMPs list
logger.debug("AMPs list: {}".format(self.getList()))
return True
server['password'] = None
server['status'] = 'PROTECTED'
else:
server['status'] = 'OFFLINE'
logger.debug("Cannot grab stats from {} ({} {})".format(uri, e.errcode, e.errmsg))
else:
# Status
server['status'] = 'ONLINE'
# Optional stats (load is not available on Windows OS)
try:
# LOAD
load_min5 = json.loads(s.getLoad())['min5']
server['load_min5'] = '{:.2f}'.format(load_min5)
except Exception as e:
logger.warning(
"Error while grabbing stats form {}: {}".format(uri, e))
return server
"""IP plugin."""
import threading
from json import loads
from glances.compat import iterkeys, urlopen, queue
from glances.logger import logger
from glances.timer import Timer
from glances.plugins.glances_plugin import GlancesPlugin
# Import plugin specific dependency
try:
import netifaces
except ImportError as e:
import_error_tag = True
logger.warning("Missing Python Lib ({}), IP plugin is disabled".format(e))
else:
import_error_tag = False
# List of online services to retreive public IP address
# List of tuple (url, json, key)
# - url: URL of the Web site
# - json: service return a JSON (True) or string (False)
# - key: key of the IP addresse in the JSON structure
urls = [('https://ip.42.pl/raw', False, None),
('https://httpbin.org/ip', True, 'origin'),
('https://jsonip.com', True, 'ip'),
('https://api.ipify.org/?format=json', True, 'ip')]
class Plugin(GlancesPlugin):
"""Glances IP Plugin.
"""Quicklook plugin."""
from glances.cpu_percent import cpu_percent
from glances.logger import logger
from glances.outputs.glances_bars import Bar
from glances.outputs.glances_sparklines import Sparkline
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# Import plugin specific dependency
try:
from cpuinfo import cpuinfo
except ImportError as e:
cpuinfo_tag = False
logger.warning("Missing Python Lib ({}), Quicklook plugin will not display CPU info".format(e))
else:
cpuinfo_tag = True
# Define the history items list
# All items in this list will be historised if the --enable-history tag is set
items_history_list = [{'name': 'cpu',
'description': 'CPU percent usage',
'y_unit': '%'},
{'name': 'percpu',
'description': 'PERCPU percent usage',
'y_unit': '%'},
{'name': 'mem',
'description': 'MEM percent usage',
'y_unit': '%'},
{'name': 'swap',
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
"""RAID plugin."""
from glances.compat import iterkeys
from glances.logger import logger
from glances.plugins.glances_plugin import GlancesPlugin
# Import plugin specific dependency
try:
from pymdstat import MdStat
except ImportError as e:
import_error_tag = True
logger.warning("Missing Python Lib ({}), Raid plugin is disabled".format(e))
else:
import_error_tag = False
class Plugin(GlancesPlugin):
"""Glances RAID plugin.
stats is a dict (see pymdstat documentation)
"""
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args, config=config)
# We want to display the stat in the curse interface
self.display_curse = True
version=self.args.snmp_version,
community=self.args.snmp_community,
user=self.args.snmp_user,
auth=self.args.snmp_auth)
# If we cannot grab the hostname, then exit...
ret = clientsnmp.get_by_oid("1.3.6.1.2.1.1.5.0") != {}
if ret:
# Get the OS name (need to grab the good OID...)
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("Cannot detect SNMP system name")
return ret
def load(self, config):
"""Load the server list from the configuration file."""
server_list = []
if config is None:
logger.debug("No configuration file available. Cannot load server list.")
elif not config.has_section(self._section):
logger.warning("No [%s] section in the configuration file. Cannot load server list." % self._section)
else:
logger.info("Start reading the [%s] section in the configuration file" % self._section)
for i in range(1, 256):
new_server = {}
postfix = 'server_%s_' % str(i)
# Read the server name (mandatory)
for s in ['name', 'port', 'alias']:
new_server[s] = config.get_value(self._section, '%s%s' % (postfix, s))
if new_server['name'] is not None:
# Manage optionnal information
if new_server['port'] is None:
new_server['port'] = '61209'
new_server['username'] = 'glances'
# By default, try empty (aka no) password
new_server['password'] = ''
try:
server['status'] = 'PROTECTED'
else:
server['status'] = 'OFFLINE'
logger.debug("Cannot grab stats from {} ({} {})".format(uri, e.errcode, e.errmsg))
else:
# Status
server['status'] = 'ONLINE'
# Optional stats (load is not available on Windows OS)
try:
# LOAD
load_min5 = json.loads(s.getLoad())['min5']
server['load_min5'] = '{:.2f}'.format(load_min5)
server['load_percent_views'] = json.loads(s.getViewsLoad())['min5']['decoration']
except Exception as e:
logger.warning(
"Error while grabbing stats form {}: {}".format(uri, e))
return server