Skip to content
Open
10 changes: 5 additions & 5 deletions lib/vsc/utils/script_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from vsc.utils.generaloption import SimpleOption
from vsc.utils.lock import lock_or_bork, release_or_bork, LOCKFILE_DIR, LOCKFILE_FILENAME_TEMPLATE
from vsc.utils.nagios import (
SimpleNagios, NAGIOS_CACHE_DIR, NAGIOS_CACHE_FILENAME_TEMPLATE, exit_from_errorcode,
SimpleZabbix, SimpleNagios, NAGIOS_CACHE_DIR, NAGIOS_CACHE_FILENAME_TEMPLATE, exit_from_errorcode,
NAGIOS_EXIT_OK, NAGIOS_EXIT_WARNING, NAGIOS_EXIT_CRITICAL, NAGIOS_EXIT_UNKNOWN,
)
from vsc.utils.timestamp import (
Expand Down Expand Up @@ -140,18 +140,18 @@ def __init__(self, options, run_prologue=True, excepthook=None, **kwargs):

self.log = fancylogger.getLogger()

def prologue(self):
def prologue(self, MonitorClass=SimpleNagios):
"""Checks the options given for settings and takes appropriate action.

See _merge_options for the format.

- if nagios_report is set, creates a SimpleNagios instance and prints the report.
- MonitorClass: the class to use for interaction with the monitoring software
- if nagios_report is set, creates a MonitorClass instance and prints the report.
- if ha is set, checks if running on the correct host, set the appropriate nagios message and bail if not.
- if locking_filename is set, take a lock. If the lock fails, bork and set the nagios exit accordingly.
"""

# bail if nagios report is requested
self.nagios_reporter = SimpleNagios(_cache=self.options.nagios_check_filename,
self.nagios_reporter = MonitorClass(_cache=self.options.nagios_check_filename,
_report_and_exit=self.options.nagios_report,
_threshold=self.options.nagios_check_interval_threshold,
_cache_user=self.options.nagios_user,
Expand Down
44 changes: 44 additions & 0 deletions lib/vsc/utils/zabbix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# -*- encoding: utf-8 -*-
#
# Copyright 2012-2021 Ghent University
#
# This file is part of vsc-utils,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# the Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/hpcugent/vsc-utils
#
# vsc-utils is free software: you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# vsc-utils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with vsc-utils. If not, see <http://www.gnu.org/licenses/>.
#
"""
This module adapts the nagios module so its output can be interpreted by Zabbix.

@author: Samuel Moors (Vrije Universiteit Brussel)
"""

import json

from vsc.utils.nagios import SimpleNagios


class SimpleZabbix(SimpleNagios):
def __str__(self):
"""__str__ determines how the data is written to the cache"""
processed_dict = {key: value for (key, value) in self.__dict__.items() if not key.startswith('_')}
return json.dumps(processed_dict)