mirror of https://github.com/nicolargo/glances.git
Add default gateway option
This commit is contained in:
parent
bd8e36cfd3
commit
73b383155b
|
|
@ -185,23 +185,19 @@ mem_critical=90
|
|||
refresh=30
|
||||
# Set the default timeout for a scan (can be overwrite in the scan list)
|
||||
timeout=3
|
||||
# If True, add the default gateway on top of the port list
|
||||
port_default_gateway=True
|
||||
# Define the scan list
|
||||
# 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 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
|
||||
# port (TCP port number) is optional (if not set, use ICMP)
|
||||
# description is optional (if not set, define to host:port)
|
||||
port_1_host=192.168.0.1
|
||||
port_1_port=80
|
||||
port_1_description=Home Box
|
||||
port_2_host=www.free.fr
|
||||
port_2_description=My ISP
|
||||
port_3_host=www.google.com
|
||||
port_3_description=Internet
|
||||
|
||||
##############################################################################
|
||||
# Client/server
|
||||
|
|
|
|||
|
|
@ -141,12 +141,17 @@ class Plugin(GlancesPlugin):
|
|||
fnull = open(os.devnull, 'w')
|
||||
|
||||
counter = Counter()
|
||||
ret = subprocess.check_call(cmd, stdout=fnull, stderr=fnull, close_fds=True)
|
||||
if ret == 0:
|
||||
# Ping return RTT.
|
||||
port['status'] = counter.get() / 2.0
|
||||
try:
|
||||
ret = subprocess.check_call(cmd, stdout=fnull, stderr=fnull, close_fds=True)
|
||||
except Exception as e:
|
||||
logger.debug("{0}: Error while pinging host ({2})".format(self.plugin_name, port['host'], e))
|
||||
return 1
|
||||
else:
|
||||
port['status'] = False
|
||||
if ret == 0:
|
||||
# Ping return RTT.
|
||||
port['status'] = counter.get() / 2.0
|
||||
else:
|
||||
port['status'] = False
|
||||
|
||||
return ret
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,18 @@
|
|||
|
||||
from glances.compat import range
|
||||
from glances.logger import logger
|
||||
from glances.globals import BSD
|
||||
|
||||
# XXX *BSDs: Segmentation fault (core dumped)
|
||||
# -- https://bitbucket.org/al45tair/netifaces/issues/15
|
||||
if not BSD:
|
||||
try:
|
||||
import netifaces
|
||||
netifaces_tag = True
|
||||
except ImportError:
|
||||
netifaces_tag = False
|
||||
else:
|
||||
netifaces_tag = False
|
||||
|
||||
|
||||
class GlancesPortsList(object):
|
||||
|
|
@ -47,8 +59,25 @@ class GlancesPortsList(object):
|
|||
logger.warning("No [%s] section in the configuration file. Cannot load ports list." % self._section)
|
||||
else:
|
||||
logger.debug("Start reading the [%s] section in the configuration file" % self._section)
|
||||
|
||||
refresh = config.get_value(self._section, 'refresh', default=self._default_refresh)
|
||||
timeout = config.get_value(self._section, 'timeout', default=self._default_timeout)
|
||||
|
||||
# Add default gateway on top of the ports_list lits
|
||||
default_gateway = config.get_value(self._section, 'port_default_gateway', default='False')
|
||||
if default_gateway.lower().startswith('true') and netifaces_tag:
|
||||
new_port = {}
|
||||
new_port['host'] = netifaces.gateways()['default'][netifaces.AF_INET][0]
|
||||
# ICMP
|
||||
new_port['port'] = 0
|
||||
new_port['description'] = 'DefaultGateway'
|
||||
new_port['refresh'] = refresh
|
||||
new_port['timeout'] = timeout
|
||||
new_port['status'] = None
|
||||
logger.debug("Add default gateway %s to the static list" % (new_port['host']))
|
||||
ports_list.append(new_port)
|
||||
|
||||
# Read the scan list
|
||||
for i in range(1, 256):
|
||||
new_port = {}
|
||||
postfix = 'port_%s_' % str(i)
|
||||
|
|
|
|||
Loading…
Reference in New Issue