mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-26 10:42:29 +03:00
Ok for Web and Port
This commit is contained in:
parent
c3d6b1b10f
commit
c6ddc13acb
@ -530,6 +530,13 @@ class GlancesPlugin(object):
|
||||
"""
|
||||
return self.stats
|
||||
|
||||
def get_stat_name(self, header=""):
|
||||
""""Return the stat name with an optional header"""
|
||||
ret = self.plugin_name
|
||||
if header != "":
|
||||
ret += '_' + header
|
||||
return ret
|
||||
|
||||
def get_alert(self,
|
||||
current=0,
|
||||
minimum=0,
|
||||
@ -572,11 +579,8 @@ class GlancesPlugin(object):
|
||||
except TypeError:
|
||||
return 'DEFAULT'
|
||||
|
||||
# Build the stat_name = plugin_name + header
|
||||
if header == "":
|
||||
stat_name = self.plugin_name
|
||||
else:
|
||||
stat_name = self.plugin_name + '_' + header
|
||||
# Build the stat_name
|
||||
stat_name = self.get_stat_name(header=header)
|
||||
|
||||
# Manage limits
|
||||
# If is_max is set then display the value in MAX
|
||||
@ -616,7 +620,6 @@ class GlancesPlugin(object):
|
||||
trigger):
|
||||
"""Manage the threshold for the current stat."""
|
||||
glances_thresholds.add(stat_name, trigger)
|
||||
# logger.info(glances_thresholds.get())
|
||||
|
||||
def manage_action(self,
|
||||
stat_name,
|
||||
@ -681,7 +684,7 @@ class GlancesPlugin(object):
|
||||
|
||||
# logger.debug("{} {} value is {}".format(stat_name, criticity, limit))
|
||||
|
||||
# Return the limit
|
||||
# Return the limiter
|
||||
return limit
|
||||
|
||||
def get_limit_action(self, criticity, stat_name=""):
|
||||
|
@ -97,29 +97,52 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
return self.stats
|
||||
|
||||
def get_key(self):
|
||||
return 'indice'
|
||||
|
||||
def get_ports_alert(self, port, header="", log=False):
|
||||
"""Return the alert status relative to the port scan return value."""
|
||||
ret = 'OK'
|
||||
if port['status'] is None:
|
||||
return 'CAREFUL'
|
||||
ret = 'CAREFUL'
|
||||
elif port['status'] == 0:
|
||||
return 'CRITICAL'
|
||||
ret = 'CRITICAL'
|
||||
elif (isinstance(port['status'], (float, int)) and
|
||||
port['rtt_warning'] is not None and
|
||||
port['status'] > port['rtt_warning']):
|
||||
return 'WARNING'
|
||||
ret = 'WARNING'
|
||||
|
||||
return 'OK'
|
||||
# Get stat name
|
||||
stat_name = self.get_stat_name(header=header)
|
||||
|
||||
# Manage threshold
|
||||
self.manage_threshold(stat_name, ret)
|
||||
|
||||
# Manage action
|
||||
self.manage_action(stat_name, ret.lower(), header, port['indice'])
|
||||
|
||||
return ret
|
||||
|
||||
def get_web_alert(self, web, header="", log=False):
|
||||
"""Return the alert status relative to the web/url scan return value."""
|
||||
ret = 'OK'
|
||||
if web['status'] is None:
|
||||
return 'CAREFUL'
|
||||
ret = 'CAREFUL'
|
||||
elif web['status'] not in [200, 301, 302]:
|
||||
return 'CRITICAL'
|
||||
ret = 'CRITICAL'
|
||||
elif web['rtt_warning'] is not None and web['elapsed'] > web['rtt_warning']:
|
||||
return 'WARNING'
|
||||
ret = 'WARNING'
|
||||
|
||||
return 'OK'
|
||||
# Get stat name
|
||||
stat_name = self.get_stat_name(header=header)
|
||||
|
||||
# Manage threshold
|
||||
self.manage_threshold(stat_name, ret)
|
||||
|
||||
# Manage action
|
||||
self.manage_action(stat_name, ret.lower(), header, web['indice'])
|
||||
|
||||
return ret
|
||||
|
||||
def msg_curse(self, args=None, max_width=None):
|
||||
"""Return the dict to display in the curse interface."""
|
||||
@ -152,7 +175,9 @@ class Plugin(GlancesPlugin):
|
||||
width=name_max_width)
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = '{:>9}'.format(status)
|
||||
ret.append(self.curse_add_line(msg, self.get_ports_alert(p)))
|
||||
ret.append(self.curse_add_line(msg,
|
||||
self.get_ports_alert(p,
|
||||
header=p['indice'] + '_rtt')))
|
||||
ret.append(self.curse_new_line())
|
||||
elif 'url' in p:
|
||||
msg = '{:{width}}'.format(p['description'][0:name_max_width],
|
||||
@ -165,7 +190,9 @@ class Plugin(GlancesPlugin):
|
||||
else:
|
||||
status = p['status']
|
||||
msg = '{:>9}'.format(status)
|
||||
ret.append(self.curse_add_line(msg, self.get_web_alert(p)))
|
||||
ret.append(self.curse_add_line(msg,
|
||||
self.get_web_alert(p,
|
||||
header=p['indice'] + '_rtt')))
|
||||
ret.append(self.curse_new_line())
|
||||
|
||||
# Delete the last empty line
|
||||
|
@ -79,6 +79,7 @@ class GlancesPortsList(object):
|
||||
new_port['timeout'] = timeout
|
||||
new_port['status'] = None
|
||||
new_port['rtt_warning'] = None
|
||||
new_port['indice'] = str('port_0')
|
||||
logger.debug("Add default gateway %s to the static list" % (new_port['host']))
|
||||
ports_list.append(new_port)
|
||||
|
||||
@ -121,6 +122,9 @@ class GlancesPortsList(object):
|
||||
# Convert to second
|
||||
new_port['rtt_warning'] = int(new_port['rtt_warning']) / 1000.0
|
||||
|
||||
# Indice
|
||||
new_port['indice'] = 'port_' + str(i)
|
||||
|
||||
# Add the server to the list
|
||||
logger.debug("Add port %s:%s to the static list" % (new_port['host'], new_port['port']))
|
||||
ports_list.append(new_port)
|
||||
|
@ -95,6 +95,9 @@ class GlancesWebList(object):
|
||||
# Convert to second
|
||||
new_web['rtt_warning'] = int(new_web['rtt_warning']) / 1000.0
|
||||
|
||||
# Indice
|
||||
new_web['indice'] = 'web_' + str(i)
|
||||
|
||||
# Add the server to the list
|
||||
logger.debug("Add Web URL %s to the static list" % new_web['url'])
|
||||
web_list.append(new_web)
|
||||
|
Loading…
Reference in New Issue
Block a user