Merge branch 'develop' into issue1446

This commit is contained in:
nicolargo 2019-03-31 16:59:31 +02:00
commit 20ca58d5a4
4 changed files with 46 additions and 51 deletions

2
NEWS
View File

@ -15,6 +15,8 @@ Bugs corrected:
* Fix Cassandra table name export #1402
* 500 Internal Server Error /api/3/network/interface_name #1401
* Connection to MQTT server failed : getaddrinfo() argument 2 must be integer or string #1450
* `l` keypress (hide alert log) not working after some time #1449
Others:

View File

@ -413,6 +413,7 @@ port=8883
user=guest
password=guest
topic=glances
tls=true
[couchdb]
# Configuration for the --export couchdb option

View File

@ -42,20 +42,22 @@ class Export(GlancesExport):
self.user = None
self.password = None
self.topic = None
self.tls = 'true'
# Load the MQTT configuration file
self.export_enable = self.load_conf('mqtt',
mandatories=['host', 'password'],
options=['port', 'user', 'topic'])
options=['port', 'user', 'topic', 'tls'])
if not self.export_enable:
exit('Missing MQTT config')
# Get the current hostname
self.hostname = socket.gethostname()
self.port = self.port or 8883
self.port = int(self.port) or 8883
self.topic = self.topic or 'glances'
self.user = self.user or 'glances'
self.tls = (self.tls.lower() == 'true')
# Init the MQTT client
self.client = self.init()
@ -69,7 +71,8 @@ class Export(GlancesExport):
clean_session=False)
client.username_pw_set(username=self.user,
password=self.password)
client.tls_set(certs.where())
if self.tls:
client.tls_set(certs.where())
client.connect(host=self.host,
port=self.port)
client.loop_start()
@ -81,8 +84,8 @@ class Export(GlancesExport):
def export(self, name, columns, points):
"""Write the points in MQTT."""
WHITELIST='_-' + string.ascii_letters + string.digits
SUBSTITUTE='_'
WHITELIST = '_-' + string.ascii_letters + string.digits
SUBSTITUTE = '_'
def whitelisted(s,
whitelist=WHITELIST,

View File

@ -114,59 +114,48 @@ class Plugin(GlancesPlugin):
ret = []
# Only process if display plugin enable...
if not self.stats and self.is_disable():
if not self.stats or self.is_disable():
return ret
# Build the string message
# Header
ret.append(self.curse_add_line(global_message(), "TITLE"))
if self.stats:
# Header
# msg = 'Warning or critical alerts'
# ret.append(self.curse_add_line(msg, "TITLE"))
# logs_len = glances_events.len()
# if logs_len > 1:
# msg = ' (last {} entries)'.format(logs_len)
# else:
# msg = ' (one entry)'
# ret.append(self.curse_add_line(msg, "TITLE"))
# Loop over alerts
for alert in self.stats:
# New line
ret.append(self.curse_new_line())
# Start
msg = str(datetime.fromtimestamp(alert[0]))
# Loop over alerts
for alert in self.stats:
# New line
ret.append(self.curse_new_line())
# Start
msg = str(datetime.fromtimestamp(alert[0]))
ret.append(self.curse_add_line(msg))
# Duration
if alert[1] > 0:
# If finished display duration
msg = ' ({})'.format(datetime.fromtimestamp(alert[1]) -
datetime.fromtimestamp(alert[0]))
else:
msg = ' (ongoing)'
ret.append(self.curse_add_line(msg))
ret.append(self.curse_add_line(" - "))
# Infos
if alert[1] > 0:
# If finished do not display status
msg = '{} on {}'.format(alert[2], alert[3])
ret.append(self.curse_add_line(msg))
# Duration
if alert[1] > 0:
# If finished display duration
msg = ' ({})'.format(datetime.fromtimestamp(alert[1]) -
datetime.fromtimestamp(alert[0]))
else:
msg = ' (ongoing)'
else:
msg = str(alert[3])
ret.append(self.curse_add_line(msg, decoration=alert[2]))
# Min / Mean / Max
if self.approx_equal(alert[6], alert[4], tolerance=0.1):
msg = ' ({:.1f})'.format(alert[5])
else:
msg = ' (Min:{:.1f} Mean:{:.1f} Max:{:.1f})'.format(
alert[6], alert[5], alert[4])
ret.append(self.curse_add_line(msg))
# Top processes
top_process = ', '.join([p['name'] for p in alert[9]])
if top_process != '':
msg = ': {}'.format(top_process)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_add_line(" - "))
# Infos
if alert[1] > 0:
# If finished do not display status
msg = '{} on {}'.format(alert[2], alert[3])
ret.append(self.curse_add_line(msg))
else:
msg = str(alert[3])
ret.append(self.curse_add_line(msg, decoration=alert[2]))
# Min / Mean / Max
if self.approx_equal(alert[6], alert[4], tolerance=0.1):
msg = ' ({:.1f})'.format(alert[5])
else:
msg = ' (Min:{:.1f} Mean:{:.1f} Max:{:.1f})'.format(
alert[6], alert[5], alert[4])
ret.append(self.curse_add_line(msg))
# Top processes
top_process = ', '.join([p['name'] for p in alert[9]])
if top_process != '':
msg = ': {}'.format(top_process)
ret.append(self.curse_add_line(msg))
# logger.info(alert)
return ret