3 /* vim: set encoding=utf-8: */
5 * Nagios plugin to check Elvis DAM server-status json
6 * Copyright (C) 2012 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/>.
24 define('PROGNAME', basename(array_shift($argv)));
25 define('LABEL', strtoupper(str_replace('check_', '', PROGNAME)));
27 // loads from same dir as program
28 require_once 'utils.php';
33 echo "Usage: ", PROGNAME, " [OPTION]...
35 Check Elvis DAM server-status data
36 Example: ", PROGNAME ,"
38 Plugin action specific options:
39 -u URL to Elvis DAM /server-status. Sample: http://USERNAME:PASSWORD@HOSTNAME/dam/controller/admin/server-status
40 -m Message what you are querying
41 -e Expression what to retrieve from json data. this must be valid PHP Expression
42 -w The warning range. default '{$opt['w']}'
43 -c The critical range. default '{$opt['c']}'
55 $opt = array_merge($default_opt, getopt("u:e:m:w:c:"));
57 if (empty($opt['u']) || !isset($opt['e'])) {
61 $data = file_get_contents($opt['u']);
62 if ($data === false) {
63 echo "ERROR: Can't fetch '{$opt['u']}'\n";
67 $json = json_decode($data);
69 echo "ERROR: Can't parse json\n";
73 $eval = 'return $json' . $opt['e'] .';';
77 echo LABEL, ": ERROR: {$opt['m']}: Unexpected null\n";
79 } elseif ($res === false) {
80 echo LABEL, ": ERROR: {$opt['m']}: parse error: {$opt['e']}\n";
82 } elseif ($res > $opt['c']) {
83 echo LABEL, ": CRITICAL: {$opt['m']}: $res\n";
85 } elseif ($res > $opt['w']) {
86 echo LABEL, ": WARNING: {$opt['m']}: $res\n";
89 echo LABEL, ": OK: {$opt['m']}: $res\n";