$crit = preg_replace('/%$/', '', $crit); if ($type == "service" && !array_key_exists('n', $options)) { echo "Service description not provided -n option\n"; exit(3); } if ($type == "service") { $service_name = $options['n']; /* echo "DESC: " . $service_name . "\n"; */ } $result = array(); $status_file_content = file_get_contents($status_file); $counts; if ($type == "service") { $counts = query_alert_count($status_file_content, $service_name, $status_code); } else { $counts = query_host_count($status_file_content, $status_code); } if ($counts['total'] == 0) { $percent = 0; } else { $percent = $counts['actual'] / $counts['total'] * 100; } if ($percent >= $crit) { echo "CRITICAL: total:<" . $counts['total'] . ">, affected:<" . $counts['actual'] . ">\n"; exit(2); } if ($percent >= $warn) { echo "WARNING: total:<" . $counts['total'] . ">, affected:<" . $counts['actual'] . ">\n"; exit(1); } echo "OK: total:<" . $counts['total'] . ">, affected:<" . $counts['actual'] . ">\n";
$indent = ""; if (array_key_exists('indent', $_GET)) { $indent = $_GET["indent"]; } $result = array(); $status_file_content = file_get_contents($status_file); if ($q1 == "alerts") { /* Add the service status object to result array */ $result['alerts'] = query_alerts($status_file_content, $alert_type, $host); } if ($q2 == "hosts") { /* Add the service status object to result array */ $result['hosts'] = query_hosts($status_file_content, $alert_type, $host); } /* Add host count object to the results */ $result['hostcounts'] = query_host_count($status_file_content); /* Add services runtime states */ $result['servicestates'] = query_service_states($status_file_content); /* Return results */ if ($indent == "true") { hdp_mon_generate_response(indent(json_encode($result))); } else { hdp_mon_generate_response(json_encode($result)); } # Functions /* Query service states */ function query_service_states($status_file_content) { $num_matches = preg_match_all("/servicestatus \\{([\\S\\s]*?)\\}/", $status_file_content, $matches, PREG_PATTERN_ORDER); $services_object = array(); $services_object["PUPPET"] = 0;