initial commit
commit
acb6c91ccd
@ -0,0 +1,175 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(dirname(__FILE__) . "/../../common.inc.php");
|
||||||
|
|
||||||
|
pre_init();
|
||||||
|
init_session();
|
||||||
|
grab_request_vars();
|
||||||
|
check_prereqs();
|
||||||
|
check_authentication(false);
|
||||||
|
|
||||||
|
generate_report();
|
||||||
|
|
||||||
|
|
||||||
|
function generate_report()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
The second report would list all services that have a status of “CRITICAL - Plugin timed out while executing system call”. They want to be able to select how many days such that they enter 5 days, the report will show the services that have been in the status of Plugin Timed Out for five days or greater. The report would show the same as the first:
|
||||||
|
|
||||||
|
Host Name, Host Address, Service Description, Status Information, Duration (Days)
|
||||||
|
*/
|
||||||
|
$default_statuses = "
|
||||||
|
CRITICAL - Plugin timed out while executing system call
|
||||||
|
";
|
||||||
|
$default_days = 5;
|
||||||
|
$statuses = grab_request_var("statuses", $default_statuses);
|
||||||
|
$days = floatval(grab_request_var("days", $default_days));
|
||||||
|
if ($days <= 0) {
|
||||||
|
$days = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$status_array = explode("\n", $statuses);
|
||||||
|
$status_array = array_map(function($el) { return trim($el); }, $status_array);
|
||||||
|
$status_array = array_filter($status_array, function($el) { return !empty($el); });
|
||||||
|
|
||||||
|
do_page_start(array("page_title" => "Non-OK Services Report"), true);
|
||||||
|
echo '
|
||||||
|
<form method="get">
|
||||||
|
<div class="well report-options form-inline">
|
||||||
|
<div class="reportoptionpicker">
|
||||||
|
<div class="subtext">Leave blank for all statuses</div>
|
||||||
|
<div class="input-group" style="margin-right: 10px;">
|
||||||
|
<label class="input-group-addon">Statuses to check for</label>
|
||||||
|
<textarea class="form-control" name="statuses">'. implode("\n", $status_array) .'</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="input-group" style="margin-right: 10px;">
|
||||||
|
<label class="input-group-addon">Days</label>
|
||||||
|
<input type="text" class="form-control" name="days" value="' . $days . '" style="width: 50px;">
|
||||||
|
</div>
|
||||||
|
<button type="submit" id="run" class="btn btn-sm btn-primary" name="reportbtn">Run</button>
|
||||||
|
<div style="clear: both;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<style>
|
||||||
|
th,td {
|
||||||
|
padding: 2px 10px;
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
width: 400px !important;
|
||||||
|
height: 4em !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
';
|
||||||
|
|
||||||
|
$services = get_objects_services($status_array, $days);
|
||||||
|
if ($services != false) {
|
||||||
|
|
||||||
|
echo "<table>";
|
||||||
|
|
||||||
|
foreach ($services as $i => $service) {
|
||||||
|
$d = "d";
|
||||||
|
if ($i == 0) {
|
||||||
|
$d = "h";
|
||||||
|
}
|
||||||
|
echo "<tr><t$d>${service['host_name']}</t$d><t$d>${service['host_address']}</t$d><t$d>${service['svc_desc']}</t$d><t$d>${service['svc_status']}</t$d><t$d>${service['duration']}</t$d></tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</table>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo "<p>No services that match listed statuses whose status has been that for $days days found!</p>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function replace_characters($str)
|
||||||
|
{
|
||||||
|
$str = html_entity_decode($str, ENT_QUOTES);
|
||||||
|
$str = str_replace("'", "'", $str);
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function get_objects_services($statuses, $days, $return_headers = true)
|
||||||
|
{
|
||||||
|
$arr = array();
|
||||||
|
|
||||||
|
if (!is_array($statuses)) {
|
||||||
|
echo "passed variable to get_objects_services() must be an array of service names\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$services_xml = get_xml_service_status(array());
|
||||||
|
|
||||||
|
if (!$services_xml) {
|
||||||
|
echo "Something went wrong getting service status!\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($return_headers == true) {
|
||||||
|
$arr[] = array(
|
||||||
|
"host_name" => "Host Name",
|
||||||
|
"host_address" => "Host Address",
|
||||||
|
"svc_desc" => "Service Description",
|
||||||
|
"svc_status" => "Status Information",
|
||||||
|
"duration" => "Duration (days)",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$count = 0;
|
||||||
|
foreach ($services_xml->servicestatus as $svc) {
|
||||||
|
|
||||||
|
$svc_arr = array();
|
||||||
|
|
||||||
|
if (!empty($statuses)) {
|
||||||
|
$found = false;
|
||||||
|
foreach ($statuses as $status) {
|
||||||
|
$status = replace_characters($status);
|
||||||
|
$svc_status = replace_characters((string) $svc->status_text);
|
||||||
|
if ($status == $svc_status) {
|
||||||
|
$found = true;
|
||||||
|
}
|
||||||
|
// echo "<pre>";
|
||||||
|
// var_dump($status);
|
||||||
|
// var_dump($svc_status);
|
||||||
|
// echo "</pre>";
|
||||||
|
}
|
||||||
|
if ($found != true) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$svc_arr['host_name'] = (string) $svc->host_name;
|
||||||
|
$svc_arr['host_address'] = (string) $svc->host_address;
|
||||||
|
$svc_arr['svc_desc'] = (string) $svc->name;
|
||||||
|
$svc_arr['svc_status'] = (string) $svc->status_text;
|
||||||
|
|
||||||
|
$state_change_time = strtotime($svc->last_state_change);
|
||||||
|
|
||||||
|
// something went wrong with strtotime..
|
||||||
|
// likely means it's just always been down i suspect
|
||||||
|
if ($state_change_time == false || $state_change_time == -1) {
|
||||||
|
$state_change_time = strtotime($svc->status_update_time);
|
||||||
|
|
||||||
|
// something seriously wrong at this point..
|
||||||
|
if ($state_change_time == false || $state_change_time == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$svc_arr['duration'] = time() - $state_change_time;
|
||||||
|
|
||||||
|
if ($svc_arr['duration'] < (floatval($days) * 24 * 60 * 60)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$svc_arr['duration'] = round(floatval((float) $svc_arr['duration'] / (float)(24 * 60 * 60)), 2);
|
||||||
|
$count++;
|
||||||
|
$arr[] = $svc_arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($count == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(dirname(__FILE__) . '/../componenthelper.inc.php');
|
||||||
|
|
||||||
|
report_svc_status_lookup_init();
|
||||||
|
|
||||||
|
|
||||||
|
function report_svc_status_lookup_init()
|
||||||
|
{
|
||||||
|
$desc = "Report on specified services in non-OK state";
|
||||||
|
if (!report_svc_status_lookup_check_version()) {
|
||||||
|
$desc .= " <strong>Error: This component requires Nagios XI 5.6.0 or later.</strong>";
|
||||||
|
}
|
||||||
|
|
||||||
|
register_component("report_svc_status_lookup", array(
|
||||||
|
COMPONENT_NAME => "report_svc_status_lookup",
|
||||||
|
COMPONENT_AUTHOR => "hedenface",
|
||||||
|
COMPONENT_DESCRIPTION => $desc,
|
||||||
|
COMPONENT_TITLE => "Services Non-OK Report",
|
||||||
|
COMPONENT_VERSION => "0.0.0",
|
||||||
|
COMPONENT_DATE => "31/07/2021",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!report_svc_status_lookup_check_version()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
register_callback(CALLBACK_MENUS_INITIALIZED, 'report_svc_status_lookup_component_addmenu');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function report_svc_status_lookup_check_version()
|
||||||
|
{
|
||||||
|
if (function_exists('get_product_release')) {
|
||||||
|
if (get_product_release() >= 5600) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function report_svc_status_lookup_component_addmenu()
|
||||||
|
{
|
||||||
|
$component_url = get_component_url_base("report_svc_status_lookup");
|
||||||
|
|
||||||
|
$menu_section = find_menu_item(MENU_REPORTS, "menu-reports-nagiosxi", "id");
|
||||||
|
if ($menu_section == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$order = grab_array_var($menu_section, "order", "");
|
||||||
|
$new_order = $order + 0.1;
|
||||||
|
if ($new_order < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_menu_item(MENU_REPORTS, array(
|
||||||
|
"type" => "link",
|
||||||
|
"title" => "Service Status Lookup",
|
||||||
|
"id" => "menu-report-svc-lookup",
|
||||||
|
"order" => $new_order,
|
||||||
|
"opts" => array(
|
||||||
|
"href" => $component_url . "/index.php",
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue