function query_livestatus($host, $port, $query) { $buf = trim(query_socket($host, $port, $query)); if ($buf == '') { return array(); } $lines = explode("\n", $buf); if (preg_match('/^Invalid GET/', $lines[0])) { echo 'CRITICAL: Invalid request. Check filters' . PHP_EOL; exit(2); } return $lines; }
#!/usr/bin/env php <?php require 'lib.php'; $options = getopt("hH:p:m:r:"); if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options) || !array_key_exists('m', $options) || !array_key_exists('r', $options)) { usage(); exit(3); } $host = $options['H']; $port = $options['p']; $msg = $options['m']; $wantedResp = $options['r']; $resp = query_socket($host, $port, $msg); if ($wantedResp[0] == '/' && preg_match($wantedResp, $resp) || $wantedResp == $resp) { echo 'OK: Service replies correctly' . PHP_EOL; exit(0); } else { echo 'CRITICAL: Service replies incorrectly' . PHP_EOL; exit(2); } function usage() { echo 'Usage: ./' . basename(__FILE__) . ' -h help -H <host> -p <port> -m <msg> -r <response>' . PHP_EOL; }
#!/usr/bin/env php <?php require 'lib.php'; $options = getopt("hH:p:f:r:w:c:S"); if (array_key_exists('h', $options) || !array_key_exists('H', $options) || !array_key_exists('p', $options) || !array_key_exists('f', $options)) { usage(); exit(3); } if (!(array_key_exists('w', $options) && array_key_exists('c', $options)) && !array_key_exists('r', $options)) { usage(); exit(3); } $host = $options['H']; $port = $options['p']; $field = $options['f']; $resp = query_socket($host, $port, 'stat'); $lines = explode("\n", $resp); $val = false; foreach ($lines as $line) { if (!(stripos($line, $field . ': ') === false)) { $val = intval(substr($line, strlen($field . ': '))); } } $out_msg = $field . ' = ' . $val . '|' . $field . '=' . $val; if (array_key_exists('r', $options)) { $wantedResp = $options['r']; if ($val != $wantedResp) { echo 'CRITICAL: ' . $out_msg . PHP_EOL; exit(2); } } else {