From 4bfe32c665a2e0a83243a9879cd609279b2613ea Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Fri, 17 Jun 2016 14:50:59 +0200 Subject: [PATCH] Add ICMP (system call to ping) in the Glances port plugin --- conf/glances.conf | 27 +++++++++++++++------------ glances/amps/glances_amp.py | 2 +- glances/ports_list.py | 15 ++++++++++----- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/conf/glances.conf b/conf/glances.conf index a85f606f..68e71c70 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -180,25 +180,28 @@ mem_warning=70 mem_critical=90 [ports] -# TCP Ports scanner plugin configuration +# Ports scanner plugin configuration # Interval in second between scan refresh=30 -# Set the timeout for a scan +# Set the default timeout for a scan (can be overwrite in the scan list) timeout=3 # Define the scan list -# host (name or IP) and port (TCP) are mandatory -# description is optinal (set to host:port) +# host (name or IP) is mandatory +# port is optional (set to 0 = ICMP check by default) +# description is optional (set to host:port) port_1_host=www.google.com port_1_port=443 -port_1_description=Internet -port_2_host=www.free.fr -port_2_port=80 -port_2_description=ISP -port_3_host=192.168.0.1 -port_3_port=80 -port_3_description=Home Box -port_4_host=192.168.5.1 +port_1_description=Internet Web +port_2_host=www.google.com +port_2_description=Internet Ping +port_3_host=www.free.fr +port_3_description=Free ISP +port_4_host=192.168.0.1 port_4_port=80 +port_5_description=Home Box +port_5_host=192.168.5.1 +port_5_port=80 +port_5_timeout=2 ############################################################################## # Client/server diff --git a/glances/amps/glances_amp.py b/glances/amps/glances_amp.py index b59789b2..2c6c4031 100644 --- a/glances/amps/glances_amp.py +++ b/glances/amps/glances_amp.py @@ -107,7 +107,7 @@ class GlancesAmp(object): logger.warning("{}: Can not find configuration key {} in section {}".format(self.NAME, k, self.amp_name)) self.configs['enable'] = 'false' else: - logger.warning("{} is disabled".format(self.NAME)) + logger.debug("{} is disabled".format(self.NAME)) # Init the count to 0 self.configs['count'] = 0 diff --git a/glances/ports_list.py b/glances/ports_list.py index 172743c1..c5783105 100644 --- a/glances/ports_list.py +++ b/glances/ports_list.py @@ -53,14 +53,17 @@ class GlancesPortsList(object): new_port = {} postfix = 'port_%s_' % str(i) - # Read mandatories configuration keys: host and port - for s in ['host', 'port']: - new_port[s] = config.get_value(self._section, '%s%s' % (postfix, s)) + # Read mandatories configuration key: host + new_port['host'] = config.get_value(self._section, '%s%s' % (postfix, 'host')) - if new_port['host'] is None or new_port['port'] is None: + if new_port['host'] is None: continue # Read optionals configuration keys + # Port is set to 0 by default. 0 mean ICMP check instead of TCP check + new_port['port'] = config.get_value(self._section, + '%s%s' % (postfix, 'port'), + 0) new_port['description'] = config.get_value(self._section, '%sdescription' % postfix, default="%s:%s" % (new_port['host'], new_port['port'])) @@ -72,7 +75,9 @@ class GlancesPortsList(object): new_port['refresh'] = refresh # Timeout in second - new_port['timeout'] = timeout + new_port['timeout'] = config.get_value(self._section, + '%stimeout' % postfix, + default=timeout) # Add the server to the list logger.debug("Add port %s:%s to the static list" % (new_port['host'], new_port['port'])) -- GitLab