changes structure

This commit is contained in:
Github GPG acces 2024-03-15 21:45:20 +01:00
parent ff5b181d6c
commit ad44273645
No known key found for this signature in database
GPG Key ID: 384AAACE61391474
2 changed files with 5 additions and 10 deletions

View File

@ -595,7 +595,6 @@ queue=glances_queue
# Configuration for the --export mqtt option
host=localhost
port=8883
hostname=NONE
tls=false
user=guest
password=guest

View File

@ -38,17 +38,13 @@ class Export(GlancesExport):
# Load the MQTT configuration file
self.export_enable = self.load_conf(
'mqtt', mandatories=['host', 'password'], options=['port', 'user', 'hostname', 'topic', 'tls', 'topic_structure']
'mqtt', mandatories=['host', 'password'], options=['port', 'user', 'devicename', 'topic', 'tls', 'topic_structure']
)
if not self.export_enable:
exit('Missing MQTT config')
# Get the current hostname
self.hostname = (self.hostname or socket.gethostname())
if self.hostname in ['NONE']:
self.hostname = socket.gethostname()
else:
self.hostname = self.hostname
self.devicename = self.devicename or socket.gethostname()
self.port = int(self.port) or 8883
self.topic = self.topic or 'glances'
self.user = self.user or 'glances'
@ -69,7 +65,7 @@ class Export(GlancesExport):
if not self.export_enable:
return None
try:
client = paho.Client(client_id='glances_' + self.hostname, clean_session=False)
client = paho.Client(client_id='glances_' + self.devicename, clean_session=False)
client.username_pw_set(username=self.user, password=self.password)
if self.tls:
client.tls_set(certifi.where())
@ -93,7 +89,7 @@ class Export(GlancesExport):
for sensor, value in zip(columns, points):
try:
sensor = [whitelisted(name) for name in sensor.split('.')]
to_export = [self.topic, self.hostname, name]
to_export = [self.topic, self.devicename, name]
to_export.extend(sensor)
topic = '/'.join(to_export)
@ -102,7 +98,7 @@ class Export(GlancesExport):
logger.error("Can not export stats to MQTT server (%s)" % e)
elif self.topic_structure == 'per-plugin':
try:
topic = '/'.join([self.topic, self.hostname, name])
topic = '/'.join([self.topic, self.devicename, name])
sensor_values = dict(zip(columns, points))
# Build the value to output