From fbb9c2357bbde0f7c1169dd41405a6863a24dd06 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Fri, 14 Jan 2022 22:23:53 +0100 Subject: [PATCH] Add Nagios compatible script to export data from the monitor page Migrated from https://git.ispconfig.org/ispconfig/ispconfig3/-/merge_requests/1432 Added README, moved suggested location to /usr/local/ispconfig/server/scripts/ and add Licence text. --- check_ispconfig/README | 20 +++++++ check_ispconfig/check_ispconfig.php | 92 +++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 check_ispconfig/README create mode 100755 check_ispconfig/check_ispconfig.php diff --git a/check_ispconfig/README b/check_ispconfig/README new file mode 100644 index 0000000..24e0f6e --- /dev/null +++ b/check_ispconfig/README @@ -0,0 +1,20 @@ +# check_ispconfig + +Nagios compatible script to export data from the monitor page. + +Outputs a single line like: `WARNING: (ok: 12, info: system_update, warning: sys_log)` + + +## Installation + +- In an NRPE compatibe config file, such as /etc/nagios/nrpe.cfg: +`command[check_ispconfig]=/usr/bin/sudo /usr/local/ispconfig/server/scripts/check_ispconfig.php` + +- To allow an nrpe user to run this, add /etc/sudoers.d/ispconfig: +``` +Cmnd_Alias CHECK_ISPCONFIG = /usr/local/ispconfig/server/scripts/check_ispconfig.php + +nagios ALL = NOPASSWD : CHECK_ISPCONFIG +``` + +- Setup your monitoring tool of choice to call this script. diff --git a/check_ispconfig/check_ispconfig.php b/check_ispconfig/check_ispconfig.php new file mode 100755 index 0000000..6d3bd91 --- /dev/null +++ b/check_ispconfig/check_ispconfig.php @@ -0,0 +1,92 @@ +#!/usr/bin/env php +dbmaster->queryAllRecords("SELECT DISTINCT type, state FROM monitor_data + WHERE server_id = ? AND state != 'no_state'", $conf['server_id']); + +foreach($records as $record) { + $server_states[$record['state']][] = $record['type']; +} + +foreach ($server_states as $state => $data) { + if ($state == 'ok') { + $state_list[] = "$state: " . count($data); + } + else { + $state_list[] = "$state: " . join(', ', $data); + } +} +if (empty($server_states)) { + $server_state = 'unknown'; + $retval = 3; +} +elseif (is_array($server_states['critical']) && count($server_states['critical']) > 0 || is_array($server_states['error']) && count($server_states['error']) > 0) { + $server_state = 'critical'; + $retval = 2; +} +elseif ($server_states['warning'] > 0) { + $server_state = 'warning'; + $retval = 1; +} + +$status_line = strtoupper($server_state) . ': (' . join(', ', $state_list) . ')'; + +echo $status_line . PHP_EOL; +exit($retval); -- GitLab