Skip to content

Commit 72e92ff

Browse files
committed
add support for zabbix as alternative to nagios
1 parent e772ce7 commit 72e92ff

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

lib/vsc/utils/script_tools.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from vsc.utils.generaloption import SimpleOption
4343
from vsc.utils.lock import lock_or_bork, release_or_bork, LOCKFILE_DIR, LOCKFILE_FILENAME_TEMPLATE
4444
from vsc.utils.nagios import (
45-
SimpleNagios, NAGIOS_CACHE_DIR, NAGIOS_CACHE_FILENAME_TEMPLATE, exit_from_errorcode,
45+
SimpleZabbix, SimpleNagios, NAGIOS_CACHE_DIR, NAGIOS_CACHE_FILENAME_TEMPLATE, exit_from_errorcode,
4646
NAGIOS_EXIT_OK, NAGIOS_EXIT_WARNING, NAGIOS_EXIT_CRITICAL, NAGIOS_EXIT_UNKNOWN,
4747
)
4848
from vsc.utils.timestamp import (
@@ -140,18 +140,18 @@ def __init__(self, options, run_prologue=True, excepthook=None, **kwargs):
140140

141141
self.log = fancylogger.getLogger()
142142

143-
def prologue(self):
143+
def prologue(self, MonitorClass=SimpleNagios):
144144
"""Checks the options given for settings and takes appropriate action.
145145
146146
See _merge_options for the format.
147-
148-
- if nagios_report is set, creates a SimpleNagios instance and prints the report.
147+
- MonitorClass: the class to use for interaction with the monitoring software
148+
- if nagios_report is set, creates a MonitorClass instance and prints the report.
149149
- if ha is set, checks if running on the correct host, set the appropriate nagios message and bail if not.
150150
- if locking_filename is set, take a lock. If the lock fails, bork and set the nagios exit accordingly.
151151
"""
152152

153153
# bail if nagios report is requested
154-
self.nagios_reporter = SimpleNagios(_cache=self.options.nagios_check_filename,
154+
self.nagios_reporter = MonitorClass(_cache=self.options.nagios_check_filename,
155155
_report_and_exit=self.options.nagios_report,
156156
_threshold=self.options.nagios_check_interval_threshold,
157157
_cache_user=self.options.nagios_user,

lib/vsc/utils/zabbix.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
# -*- encoding: utf-8 -*-
3+
#
4+
# Copyright 2012-2021 Ghent University
5+
#
6+
# This file is part of vsc-utils,
7+
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
8+
# with support of Ghent University (http://ugent.be/hpc),
9+
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
10+
# the Flemish Research Foundation (FWO) (http://www.fwo.be/en)
11+
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
12+
#
13+
# https://github.com/hpcugent/vsc-utils
14+
#
15+
# vsc-utils is free software: you can redistribute it and/or modify
16+
# it under the terms of the GNU Library General Public License as
17+
# published by the Free Software Foundation, either version 2 of
18+
# the License, or (at your option) any later version.
19+
#
20+
# vsc-utils is distributed in the hope that it will be useful,
21+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
# GNU Library General Public License for more details.
24+
#
25+
# You should have received a copy of the GNU Library General Public License
26+
# along with vsc-utils. If not, see <http://www.gnu.org/licenses/>.
27+
#
28+
"""
29+
This module adapts the nagios module so its output can be interpreted by Zabbix.
30+
31+
@author: Samuel Moors (Vrije Universiteit Brussel)
32+
"""
33+
34+
import json
35+
36+
from vsc.utils.nagios import SimpleNagios
37+
38+
39+
class SimpleZabbix(SimpleNagios):
40+
def __str__(self):
41+
"""__str__ determines how the data is written to the cache"""
42+
processed_dict = {key: value for (key, value) in self.__dict__.items() if not key.startswith('_')}
43+
return json.dumps(processed_dict)
44+

0 commit comments

Comments
 (0)