3 /* vim: set encoding=utf-8: */
5 * Nagios plugin to check Elvis DAM server-status json
6 * Copyright (C) 2013 Elan Ruusamäe <glen@delfi.ee>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 define('PROGNAME', basename(array_shift($argv), '.php'));
23 define('LABEL', strtoupper(str_replace('check_', '', PROGNAME)));
25 // loads from same dir as program
26 require_once 'utils.php';
31 echo "Usage: ", PROGNAME, " [OPTION]...
33 Check Elvis DAM server-status data
34 Example: ", PROGNAME ,"
36 Plugin action specific options:
37 -u URL to Elvis DAM /server-status. Sample: http://USERNAME:PASSWORD@HOSTNAME/dam/controller/admin/server-status
38 -m Message what you are querying
39 -e Expression what to retrieve from json data. this must be valid PHP Expression
40 -i Invert expression, critical and warning must be below the tresholds
41 -w The warning range. default '{$opt['w']}'
42 -c The critical range. default '{$opt['c']}'
43 -v Enable verbose mode.
56 $opt = array_merge($default_opt, getopt("u:e:m:w:c:vi"));
57 $invert = isset($opt['i']);
59 if (empty($opt['u']) || !isset($opt['e'])) {
63 $data = file_get_contents($opt['u']);
64 if ($data === false) {
65 echo "ERROR: Can't fetch '{$opt['u']}'\n";
69 $json = json_decode($data);
71 echo "ERROR: Can't parse json\n";
75 $eval = 'return $json' . $opt['e'] .';';
76 if (isset($opt['v'])) {
82 echo LABEL, ": ERROR: {$opt['m']}: Unexpected null\n";
84 } elseif ($res === false) {
85 echo LABEL, ": ERROR: {$opt['m']}: parse error: {$opt['e']}\n";
87 } elseif ((!$invert && $res > $opt['c']) || ($invert && $res < $opt['c'])) {
88 echo LABEL, ": CRITICAL: {$opt['m']}: $res\n";
90 } elseif ((!$invert && $res > $opt['w']) || ($invert && $res < $opt['w'])) {
91 echo LABEL, ": WARNING: {$opt['m']}: $res\n";
94 echo LABEL, ": OK: {$opt['m']}: $res\n";