Skip to content

Commit 75732bf

Browse files
committed
dont print nagios exit string for zabbix
1 parent c7595ad commit 75732bf

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lib/vsc/utils/nagios.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,15 @@ def report_and_exit(self):
280280

281281
if self.threshold <= 0 or time.time() - timestamp < self.threshold:
282282
self.log.info("Nagios check cache file %s contents delivered: %s", self.filename, nagios_message)
283-
print("%s %s" % (nagios_exit_string, nagios_message))
283+
self.print_report(nagios_exit_string, nagios_message)
284284
sys.exit(nagios_exit_code)
285285
else:
286286
unknown_exit("%s gzipped JSON file too old (timestamp = %s)" % (self.header, time.ctime(timestamp)))
287287

288+
def print_report(self, nagios_exit_string, nagios_message):
289+
"""Print the nagios report"""
290+
print("%s %s" % (nagios_exit_string, nagios_message))
291+
288292
def cache(self, nagios_exit, nagios_message):
289293
"""Store the result in the cache file with a timestamp.
290294
@@ -434,6 +438,11 @@ class SimpleNagios(NagiosResult):
434438

435439
def __init__(self, **kwargs):
436440
"""Initialise message and perfdata"""
441+
self._init(**kwargs)
442+
443+
def _init(self, reporterclass=NagiosReporter, **kwargs):
444+
"""The real init method"""
445+
437446
self.__dict__ = {}
438447
self.message = None # the message
439448

@@ -453,10 +462,10 @@ def __init__(self, **kwargs):
453462
if self._cache:
454463
# make a NagiosReporter instance that can be used for caching
455464
if self._cache_user:
456-
cache = NagiosReporter('no header', self._cache, self._threshold, nagios_username=self._cache_user,
465+
cache = reporterclass('no header', self._cache, self._threshold, nagios_username=self._cache_user,
457466
world_readable=self._world_readable)
458467
else:
459-
cache = NagiosReporter('no header', self._cache, self._threshold, world_readable=self._world_readable)
468+
cache = reporterclass('no header', self._cache, self._threshold, world_readable=self._world_readable)
460469
if self._report_and_exit:
461470
cache.report_and_exit()
462471
else:

lib/vsc/utils/zabbix.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,29 @@
3030
3131
@author: Samuel Moors (Vrije Universiteit Brussel)
3232
"""
33+
from __future__ import print_function
3334

3435
import json
3536

36-
from vsc.utils.nagios import SimpleNagios
37+
38+
from vsc.utils.nagios import SimpleNagios, NagiosReporter
3739

3840

3941
class SimpleZabbix(SimpleNagios):
42+
def __init__(self, **kwargs):
43+
"""Initialise message and perfdata"""
44+
super(SimpleZabbix, self)._init(reporterclass=ZabbixReporter, **kwargs)
45+
4046
def __str__(self):
4147
"""__str__ determines how the data is written to the cache"""
4248
processed_dict = {key: value for (key, value) in self.__dict__.items() if not key.startswith('_')}
4349
return json.dumps(processed_dict)
4450

51+
52+
class ZabbixReporter(NagiosReporter):
53+
"""Reporting class for Zabbix reports"""
54+
55+
def print_report(self, nagios_exit_string, nagios_message):
56+
"""Print the nagios report"""
57+
print(nagios_message)
58+

0 commit comments

Comments
 (0)