#!/usr/bin/env php
<?php
$retcode=array('RC_OK'=>0,'RC_WARNING'=>1,'RC_CRITICAL'=>2,'RC_UNKNOWN'=>3);
$retstatus=array(0=>'OK',1=>'WARNING',2=>'CRITICAL',3=>'UNKNOWN');
require ("../IPS_JSON.php");
if ( !class_exists("IPS_JSON"))
{
print "This requires PHP JSON and IPS_JSON class\n";
exit($retcode['RC_UNKNOWN']) ;
}
$host="";
$port="3777";
$user='lizenz@email.ips';
$password='fernsteuer-password';
$age=3600;
$config='IPS_JSON_config.cfg';
$options=getopt("H:P:u:p:i:c:w:a:f:h");
if (isset($options['h'])) {
exit($retcode['RC_UNKNOWN']);
}
if (isset($options['f'])) {$config=$options['f'];}
if (file_exists($config)) {
$config_data=file_get_contents($config);
$res=eval($config_data);
if ($res===false) {
echo "UNKNOWN eval of $config failed. Hint:Use code only, no leading php tags\n";
exit($retcode['RC_UNKNOWN']);
}
}
if (isset($options['P'])) $port=$options['P'];
if (isset($options['H'])) {$host=$options['H'];}
if (isset($options['u'])) {$user=$options['u'];}
if (isset($options['p'])) {$password=$options['p'];}
if (isset($options['i'])) {$id=$options['i'];}
if (isset($options['a'])) {$age=$options['a'];}
if (isset($options['c'])) {$critical=$options['c'];}
if (isset($options['w'])) {$warning=$options['w'];}
if (empty($host) || empty($id)) {
echo "UNKNOWN Host or ID missed\n";
exit($retcode['RC_UNKNOWN']);
}
if (empty($user) || empty($password)) {
echo "UNKNOWN API username or Password\n";
exit($retcode['RC_UNKNOWN']);
}
$url="http://".$host.":".$port."/api/";
$id=(integer)$id;
$age=(integer)$age;
try {
$version=
$rpc->IPS_GetKernelVersion();
if (!$version) {
echo "UNKNOWN IPS Request failed:".$rpc->getErrorMessage()."\n";
exit ($retcode['RC_UNKNOWN']);
}
if (!$var) {
echo "UNKNOWN ".$rpc->getErrorMessage()."\n";
exit ($retcode['RC_UNKNOWN']);
}
}catch (Exception $e) {
echo "UNKNOWN IPS Call failed->".$e->getMessage()."\n";
exit ($retcode['RC_UNKNOWN']);
}
$name=$var["name"];
$value=$var["value"];
$digits=$var["digits"];
$last=$var["last"];
$type=$var["type"];
$suffix=$var["suffix"];
if (is_null($last)) {
echo "WARNING - $name:$value, but has no timestamp\n";
exit($retcode['RC_WARNING']);
}
$diff=time()-$last;
if ($diff>$age) {
echo "WARNING - $name:$value, but to old (actual ".$diff."s > max ". $age."s)\n";
exit ($retcode['RC_WARNING']);
}
if (is_integer($digits)) {
$value=sprintf("%0.".$digits."f",$value);
}
$perf='';
$res="$name:".$value.$suffix.", Age=".$diff."s";
#only integer and float values are qualified as performance data
if ($type == 1 ||$type==2) {
$perf=" |$name=$value;;;;";
}
#check level
if (isset($value) && (isset($critical) || isset($warning))) {
#extract absolute value
if (preg_match('/-([\d\.]+)/',$value,$v)) {
$data=$v[1];
if (isset($critical) && ($data >= $critical)) {
print "CRITICAL - $name : Value $data above critical level ($critical) !".$perf."\n";
exit($retcode['RC_CRITICAL']);
}
if (defined($warning) && ($data >= $warning)) {
print "WARNING - $name: Value $data above warning level ($warning) !".$perf."\n";
exit($retcode['RC_WARNING']);
}
}
}
#output
$res="$name:".$value.$suffix.", Age=".$diff."s";
echo "OK - ".$res.$perf."\n";
exit ($retcode['RC_OK']);
echo "Usage: check_ips_json.php [-h]|-i <VariableID> [-c <critical level>(absolute)] [-w <warning level>(absolute)] [-f <config_file>] | [-H <IPSHOST> -P <IPSAPIPORT> [-a <maxage> in sec ] [-u <apiuser>] [-p <apipassword>]\n";
exit (3);
}
usage()
print usage information
Definition check_ips_json.php:169
Symcon JSON API wrapper class.
Definition IPS_JSON.php:41
$rpc
IPS_JSON object.
Definition ips_wrapper.php:69