Change exit message when export plugin init failed

pull/2096/head
nicolargo 2022-07-15 11:16:07 +02:00
parent 2ffb54a291
commit 9aaf620e2f
12 changed files with 15 additions and 12 deletions

View File

@ -546,7 +546,7 @@ queue=glances_queue
[mqtt]
# Configuration for the --export mqtt option
host=localhost
port=8883
port=1883
tls=true
user=guest
password=guest

View File

@ -42,7 +42,7 @@ class Export(GlancesExport):
'influxdb', mandatories=['host', 'port', 'user', 'password', 'db'], options=['protocol', 'prefix', 'tags']
)
if not self.export_enable:
sys.exit(2)
exit('Missing INFLUXDB version 1 config')
# The hostname is always add as a tag
self.hostname = node().split('.')[0]

View File

@ -43,7 +43,7 @@ class Export(GlancesExport):
options=['protocol', 'prefix', 'tags'],
)
if not self.export_enable:
sys.exit(2)
exit('Missing INFLUXDB version 1 config')
# The hostname is always add as a tag
self.hostname = node().split('.')[0]

View File

@ -40,7 +40,7 @@ class Export(GlancesExport):
'kafka', mandatories=['host', 'port', 'topic'], options=['compression', 'tags']
)
if not self.export_enable:
sys.exit(2)
exit('Missing KAFKA config')
# Init the kafka client
self.client = self.init()

View File

@ -12,6 +12,7 @@
import socket
import string
import json
import sys
from glances.logger import logger
from glances.exports.glances_export import GlancesExport
@ -53,10 +54,12 @@ class Export(GlancesExport):
self.topic_structure = (self.topic_structure or 'per-metric').lower()
if self.topic_structure not in ['per-metric', 'per-plugin']:
logger.critical("topic_structure must be either 'per-metric' or 'per-plugin'.")
return None
sys.exit(2)
# Init the MQTT client
self.client = self.init()
if not self.client:
exit('MQTT client initialization failed')
def init(self):
"""Init the connection to the MQTT server."""

View File

@ -37,7 +37,7 @@ class Export(GlancesExport):
# Load the configuration file
self.export_enable = self.load_conf('opentsdb', mandatories=['host', 'port'], options=['prefix', 'tags'])
if not self.export_enable:
sys.exit(2)
exit('Missing OPENTSDB config')
# Default prefix for stats is 'glances'
if self.prefix is None:

View File

@ -32,7 +32,7 @@ class Export(GlancesExport):
# Load the Prometheus configuration file section
self.export_enable = self.load_conf('prometheus', mandatories=['host', 'port', 'labels'], options=['prefix'])
if not self.export_enable:
sys.exit(2)
exit('Missing PROMETHEUS config')
# Optionals configuration keys
if self.prefix is None:

View File

@ -44,7 +44,7 @@ class Export(GlancesExport):
'rabbitmq', mandatories=['host', 'port', 'user', 'password', 'queue'], options=['protocol']
)
if not self.export_enable:
sys.exit(2)
exit('Missing RABBITMQ config')
# Get the current hostname
self.hostname = socket.gethostname()

View File

@ -34,7 +34,7 @@ class Export(GlancesExport):
# Load the RESTful section in the configuration file
self.export_enable = self.load_conf('restful', mandatories=['host', 'port', 'protocol', 'path'])
if not self.export_enable:
sys.exit(2)
exit('Missing RESTFUL config')
# Init the stats buffer
# It's a dict of stats

View File

@ -38,7 +38,7 @@ class Export(GlancesExport):
# Load the Riemann configuration
self.export_enable = self.load_conf('riemann', mandatories=['host', 'port'], options=[])
if not self.export_enable:
sys.exit(2)
exit('Missing RIEMANN config')
# Get the current hostname
self.hostname = socket.gethostname()

View File

@ -36,7 +36,7 @@ class Export(GlancesExport):
# Load the configuration file
self.export_enable = self.load_conf('statsd', mandatories=['host', 'port'], options=['prefix'])
if not self.export_enable:
sys.exit(2)
exit('Missing STATSD config')
# Default prefix for stats is 'glances'
if self.prefix is None:

View File

@ -37,7 +37,7 @@ class Export(GlancesExport):
# Load the ZeroMQ configuration file section ([export_zeromq])
self.export_enable = self.load_conf('zeromq', mandatories=['host', 'port', 'prefix'], options=[])
if not self.export_enable:
sys.exit(2)
exit('Missing ZEROMQ config')
# Init the ZeroMQ context
self.context = None