Skip to content

Commit 3bbcebd

Browse files
authored
Merge pull request #1 from smoors/zabbix
Zabbix
2 parents e772ce7 + a316993 commit 3bbcebd

23 files changed

+197
-30
lines changed

lib/vsc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2015-2021 Ghent University
2+
# Copyright 2015-2022 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2015-2021 Ghent University
2+
# Copyright 2015-2022 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/availability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2022 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2022 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/fs_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2022 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2022 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/nagios.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# -*- encoding: utf-8 -*-
33
#
4-
# Copyright 2012-2021 Ghent University
4+
# Copyright 2012-2022 Ghent University
55
#
66
# This file is part of vsc-utils,
77
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
@@ -277,7 +277,10 @@ def report_and_exit(self):
277277
unknown_exit("%s nagios gzipped JSON file unavailable (%s)" % (self.header, self.filename))
278278

279279
(timestamp, ((nagios_exit_code, nagios_exit_string), nagios_message)) = nagios_cache.load('nagios')
280+
self.print_report_and_exit(timestamp, nagios_exit_code, nagios_exit_string, nagios_message)
280281

282+
def print_report_and_exit(self, timestamp, nagios_exit_code, nagios_exit_string, nagios_message):
283+
"""Print the nagios report (if the data is not too old) and exit"""
281284
if self.threshold <= 0 or time.time() - timestamp < self.threshold:
282285
self.log.info("Nagios check cache file %s contents delivered: %s", self.filename, nagios_message)
283286
print("%s %s" % (nagios_exit_string, nagios_message))
@@ -431,6 +434,8 @@ class SimpleNagios(NagiosResult):
431434
USE_HEADER = True
432435
RESERVED_WORDS = set(['message', 'ok', 'warning', 'critical', 'unknown',
433436
'_exit', '_cache', '_cache_user', '_final', '_final_state', '_report', '_threshold'])
437+
REPORTERCLASS = NagiosReporter
438+
DEFAULT_CACHE_USER = 'nrpe'
434439

435440
def __init__(self, **kwargs):
436441
"""Initialise message and perfdata"""
@@ -453,10 +458,11 @@ def __init__(self, **kwargs):
453458
if self._cache:
454459
# make a NagiosReporter instance that can be used for caching
455460
if self._cache_user:
456-
cache = NagiosReporter('no header', self._cache, self._threshold, nagios_username=self._cache_user,
461+
cache = self.REPORTERCLASS('no header', self._cache, self._threshold, nagios_username=self._cache_user,
457462
world_readable=self._world_readable)
458463
else:
459-
cache = NagiosReporter('no header', self._cache, self._threshold, world_readable=self._world_readable)
464+
cache = self.REPORTERCLASS(
465+
'no header', self._cache, self._threshold, world_readable=self._world_readable)
460466
if self._report_and_exit:
461467
cache.report_and_exit()
462468
else:

lib/vsc/utils/pickle_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2022 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/rest_oauth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2022 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/script_tools.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2022 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
@@ -80,7 +80,7 @@ def _script_name(full_name):
8080
os.path.join(NAGIOS_CACHE_DIR,
8181
NAGIOS_CACHE_FILENAME_TEMPLATE % (_script_name(sys.argv[0]),))),
8282
'nagios-check-interval-threshold': ('threshold of nagios checks timing out', 'int', 'store', 0),
83-
'nagios-user': ('user nagios runs as', 'string', 'store', 'nrpe'),
83+
'nagios-user': ('user nagios runs as', 'string', 'store', None),
8484
'nagios-world-readable-check': ('make the nagios check data file world readable', None, 'store_true', False),
8585
}
8686

@@ -114,6 +114,7 @@ class ExtendedSimpleOption(SimpleOption):
114114
115115
The prologue should be called at the start of the script; the epilogue at the end.
116116
"""
117+
MONITORCLASS = SimpleNagios
117118

118119
def __init__(self, options, run_prologue=True, excepthook=None, **kwargs):
119120
"""Initialise.
@@ -127,6 +128,9 @@ def __init__(self, options, run_prologue=True, excepthook=None, **kwargs):
127128
options_ = _merge_options(options)
128129
super(ExtendedSimpleOption, self).__init__(options_, **kwargs)
129130

131+
if not self.options.nagios_user:
132+
self.options.nagios_user = self.MONITORCLASS.DEFAULT_CACHE_USER
133+
130134
self.nagios_reporter = None
131135
self.lockfile = None
132136

@@ -151,12 +155,12 @@ def prologue(self):
151155
"""
152156

153157
# bail if nagios report is requested
154-
self.nagios_reporter = SimpleNagios(_cache=self.options.nagios_check_filename,
155-
_report_and_exit=self.options.nagios_report,
156-
_threshold=self.options.nagios_check_interval_threshold,
157-
_cache_user=self.options.nagios_user,
158-
_world_readable=self.options.nagios_world_readable_check,
159-
)
158+
self.nagios_reporter = self.MONITORCLASS(_cache=self.options.nagios_check_filename,
159+
_report_and_exit=self.options.nagios_report,
160+
_threshold=self.options.nagios_check_interval_threshold,
161+
_cache_user=self.options.nagios_user,
162+
_world_readable=self.options.nagios_world_readable_check,
163+
)
160164

161165
# check for HA host
162166
if self.options.ha and not proceed_on_ha_service(self.options.ha):

0 commit comments

Comments
 (0)