function check_prot($host, $port, $key, $dns_solve, $ping) { global $red, $green; //ping以外の確認 foreach ($port as $prot => $num) { //pingが失敗した場合は各プロトコルを赤にする if ($ping != 0) { $value[$prot] = $red; } else { //pingが成功したからDNSとその他のチェック if ($prot == "dns") { $value[$prot] = check_dns($host, $dns_solve, $ping); } else { $value[$prot] = check_tcp($host, $num); } //dns以外の閉じる } //ping成功時の閉じる } //foreachの閉じる return $value; }
return $ret; } /* Get the json document */ $object = get_info($protocol, $host, $port, $cert, $key, $cluster); if (empty($object)) { echo 'CRITICAL: Data inaccessible' . PHP_EOL; exit(2); } //print_r($object); //echo PHP_EOL."---------------------".PHP_EOL; $ret_code = 0; $strings = array(); foreach ($object as $k => $container) { foreach ($container as $cnx) { if (!empty($cnx["IP"]) && !empty($cnx["PublicPort"])) { if (!check_tcp($cnx["IP"], $cnx["PublicPort"])) { $ret_code = 2; array_push($strings, $k . ':' . $cnx["PublicPort"]); } } } } if ($ret_code == 0) { echo "OK: All tests successful" . PHP_EOL; } else { echo "CRITICAL: " . join(',', $strings) . PHP_EOL; } exit($ret_code); /* print usage */ function usage() {