Page 1 of 1
Service status summary MOD
Posted: Fri Apr 15, 2016 2:45 am
by smoulin
Hi,
i have modified Service status summary to see only Critical alerts(hard opr soft) that are not in scheduled downtime (fixed or flexible) or acknowledged.
It works perfectly except for the counter displayed... Displaying 4 alerts for 3 elements displayed..

I did not find a lot of informations about "$backendargs" collection.
Here the code part for the alert diaply, working nice, exactly what i want to display:
Code: Select all
// MOD BY S.MOULIN
$state_text[5] = "<div class='servicecritical";
if ($state_totals[5] > 0)
$state_text[5] .= " haveservicecritical";
$state_text[5] .= "'>";
$state_text[5] .= "<a href='" . $baseurl . "&show=" . $show . "&hoststatustypes=" . $hoststatustypes . "&servicestatustypes=" . SERVICESTATE_CRITICAL . "&serviceattr=10&hostattr=10'>" . $state_totals[5] . "</a>";
$state_text[5] .= "</div>";
// END
And now the code part for the "counter" that is often different than the list display by the code upper:
Code: Select all
// MOD BY S.MOULIN
// get critical wihtout acknowledged or downtime
unset($backendargs["has_been_checked"]);
$backendargs["limitrecords"] = false; // don't limit records
$backendargs["totals"] = 1; // only get recordcount
$backendargs["current_state"] = 2;
$backendargs["problem_acknowledged"] = 0;
$backendargs["scheduled_downtime_depth"] = 0;
$xml = get_xml_service_status($backendargs);
$state_totals[5] = 0;
if ($xml)
$state_totals[5] = intval($xml->recordcount);
// END MOD
And to be more explicit, here is the modification of the HTML table code:
Code: Select all
$output .= '
<table class="infotable table table-condensed table-striped table-bordered">
<thead>
<tr><th colspan="5" bgcolor="#ff531a">TOP ALERT' . $state_text[5] . '</th></tr>
</thead>
';
I know this settings can be modified by updates, and risk is accepted.
It would be great if you could help us on this !
Re: Service status summary MOD
Posted: Fri Apr 15, 2016 10:18 am
by tmcdonald
You're certainly free to make such mods, but we can't provide support for them. If you need assistance it will need to be on an unmodified codebase.
Re: Service status summary MOD
Posted: Mon Apr 18, 2016 4:51 am
by smoulin
Ok, i understand...
Is it possible to have documentation for "$backendargs" collection ?
I cannot find informations/definitions about :
$backendargs["limitrecords"]
$backendargs["totals"]
$backendargs["current_state"]
$backendargs["problem_acknowledged"]
$backendargs["scheduled_downtime_depth"]
etc ...
Re: Service status summary MOD
Posted: Mon Apr 18, 2016 9:25 am
by tmcdonald
We don't have external documentation available for our commercial source code, mostly because we don't want to encourage modification.
Re: Service status summary MOD
Posted: Mon Apr 18, 2016 11:15 am
by smoulin
It looks like you apply a personnal enterprise Policy...
I am referring to this thread:
https://support.nagios.com/forum/viewto ... =6&t=36457
Thread where your teammate effectively help somebody on
excatly same subject.
We pay a very expensive support and i will suspend it asap.
Maintenance Status: Current (Expires in 11 days on 2016-04-29)
Do you think we will pay:
Renewal - 1 Year Email Support and Maintenance --> 2 246 € for that ?
I don't think so.
And be sure that i will find information by myself.
Have a nice day, nothing personnal.
Re: Service status summary MOD
Posted: Mon Apr 18, 2016 12:04 pm
by tmcdonald
The thread you refer to contains code that was written by a Nagios employee, which is something we can support. Supporting code written by non-employees is out of scope, though I may not have made that distinction clear in this thread. To be clear, we are not able to support/guarantee code written by third-parties. We can assist in some cases like with plugins that are not directly modifying the codebase, but as a general rule we don't do code review for third-party modifications.
Re: Service status summary MOD
Posted: Wed Apr 20, 2016 3:01 am
by smoulin
I do not need a support on custom code.
I just need to have more informations about Backend API.
Existing documentation :
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
talk about this but not enough for what i want to do.
Re: Service status summary MOD
Posted: Wed Apr 20, 2016 6:07 am
by smoulin
I have found what i was looking for.
For those who needs the same informations:
1 -- just open http://.../nagiosxi/backend/?cmd=getserviceStatus in your browser.
2 -- Under each <servicestatus> entry, you will find someting like:
Code: Select all
<instance_id>1</instance_id>
<service_id>5959</service_id>
<host_id>4768</host_id>
<host_name>X-Prod-TFS</host_name>
<name>SQL DISK F</name>
<current_notification_number>0</current_notification_number>
....
3 -- All value can be used with $backendargs["value"]
Example:
if you want to apply filter on "current_notification_number" = 1
you have to use :
$backendargs["current_notification_number"] = 1;
That's all.
You can use ALL xml entries, that's pretty easy.
here my full code for those who need it:
file
/usr/local/nagiosxi/html/includes/components/xicore/ajaxhelpers-status.inc.php
Code: Select all
....
function xicore_ajax_get_service_status_summary_html($args = null)
{
global $lstr;
//BENCHMARKING
//$start = timer_start();
$output = '';
$host = grab_array_var($args, "host", "");
$hostgroup = grab_array_var($args, "hostgroup", "");
$servicegroup = grab_array_var($args, "servicegroup", "");
$hoststatustypes = grab_array_var($args, "hoststatustypes", HOSTSTATE_ANY);
// special "all" stuff
if ($hostgroup == "all")
$hostgroup = "";
if ($servicegroup == "all")
$servicegroup = "";
if ($host == "all")
$host = "";
// limit hosts by hostgroup or host
$host_ids = array();
$host_ids_str = "";
// limit by hostgroup
if ($hostgroup != "") {
$host_ids = get_hostgroup_member_ids($hostgroup);
} // limit by host
else if ($host != "") {
$host_ids[] = get_host_id($host);
}
$y = 0;
foreach ($host_ids as $hid) {
if ($y > 0)
$host_ids_str .= ",";
$host_ids_str .= $hid;
$y++;
}
// limit service by servicegroup
$service_ids = array();
$service_ids_str = "";
if ($servicegroup != "") {
$service_ids = get_servicegroup_member_ids($servicegroup);
}
$y = 0;
foreach ($service_ids as $sid) {
if ($y > 0)
$service_ids_str .= ",";
$service_ids_str .= $sid;
$y++;
}
// PREP TO GET TOTAL RECORD COUNTS FROM BACKEND...
$backendargs = array();
$backendargs["cmd"] = "getservicestatus";
$backendargs["limitrecords"] = false; // don't limit records
$backendargs["totals"] = 1; // only get recordcount
$backendargs["combinedhost"] = true; // get host status too
// host id limiters
if ($host_ids_str != "")
$backendargs["host_id"] = "in:" . $host_ids_str;
// service id limiters
if ($service_ids_str != "")
$backendargs["service_id"] = "in:" . $service_ids_str;
// get total services
//$timerinfo[]=get_timer();
//$xml=get_backend_xml_data($backendargs);
$xml = get_xml_service_status($backendargs);
$total_records = 0;
if ($xml)
$total_records = intval($xml->recordcount);
// get state totals (ok/pending checked later)
$state_totals = array();
for ($x = 1; $x <= 3; $x++) {
$backendargs["current_state"] = $x;
//$timerinfo[]=get_timer();
//$xml=get_backend_xml_data($backendargs);
$xml = get_xml_service_status($backendargs);
$state_totals[$x] = 0;
if ($xml)
$state_totals[$x] = intval($xml->recordcount);
}
// get ok (non-pending)
$backendargs["current_state"] = 0;
$backendargs["has_been_checked"] = 1;
//$timerinfo[]=get_timer();
//$xml=get_backend_xml_data($backendargs);
$xml = get_xml_service_status($backendargs);
$state_totals[0] = 0;
if ($xml)
$state_totals[0] = intval($xml->recordcount);
// get pending
$backendargs["current_state"] = 0;
$backendargs["has_been_checked"] = 0;
//$timerinfo[]=get_timer();
//$xml=get_backend_xml_data($backendargs);
$xml = get_xml_service_status($backendargs);
$state_totals[4] = 0;
if ($xml)
$state_totals[4] = intval($xml->recordcount);
// MOD BY S.MOULIN
// get critical wihtout acknowledged or downtime
unset($backendargs["brevity"]);
$backendargs["cmd"] = "getservicestatus";
$backendargs["has_been_checked"] = 1;
$backendargs["problem_acknowledged"] = 0;
$backendargs["is_flapping"] = 0;
$backendargs["acknowledgement_type"] = 0;
$backendargs["scheduled_downtime_depth"] = 0;
$backendargs["current_state"] = 2;
$backendargs["totals"] = 1; // only get recordcount
$backendargs["limitrecords"] = false; // don't limit records
$xml = get_xml_service_status($backendargs);
$state_totals[5] = 0;
if ($xml)
$state_totals[5] = intval($xml->recordcount);
// END MOD
// total problems
$total_problems = $state_totals[1] + $state_totals[2] + $state_totals[3];
// unhandled problems
$backendargs["current_state"] = "in:1,2,3";
unset($backendargs["has_been_checked"]);
//$backendargs["has_been_checked"]=1;
$backendargs["problem_acknowledged"] = 0;
$backendargs["scheduled_downtime_depth"] = 0;
//$backendargs["notifications_enabled"]=1;
// Commenting below so the unhandled services number actually reflects what is displayed in the table when clicking the link -SW
//$backendargs["host_current_state"]=0; // up state
//$timerinfo[]=get_timer();
//$xml=get_backend_xml_data($backendargs);
$xml = get_xml_service_status($backendargs);
$unhandled_problems = 0;
if ($xml)
$unhandled_problems = intval($xml->recordcount);
//$output.='ARGS: '.serialize($args);
//$timerinfo[]=get_timer();
/*
$last_ti=0;
$x=0;
foreach($timerinfo as $ti){
if($x==0){
$last_ti=$ti;
$x++;
continue;
}
echo "T".$x."-T".($x-1).": ".get_timer_diff($last_ti,$ti)."<BR>";
$last_ti=$ti;
$x++;
}
//print_r($timerinfo);
*/
$output .= '<div class="infotable_title">' . _('Service Status Summary') . '</div>';
$show = "services";
// urls
$baseurl = get_base_url() . "includes/components/xicore/status.php?";
if ($hostgroup != "")
$baseurl .= "&hostgroup=" . urlencode($hostgroup);
if ($servicegroup != "")
$baseurl .= "&servicegroup=" . urlencode($servicegroup);
if ($host != "")
$baseurl .= "&host=" . urlencode($host);
$state_text = array();
$state_text[0] = "<div class='serviceok";
if ($state_totals[0] > 0)
$state_text[0] .= " haveserviceok";
$state_text[0] .= "'>";
$state_text[0] .= "<a href='" . $baseurl . "&show=" . $show . "&hoststatustypes=" . $hoststatustypes . "&servicestatustypes=" . SERVICESTATE_OK . "'>" . $state_totals[0] . "</a>";
$state_text[0] .= "</div>";
$state_text[1] = "<div class='servicewarning";
if ($state_totals[1] > 0)
$state_text[1] .= " haveservicewarning";
$state_text[1] .= "'>";
$state_text[1] .= "<a href='" . $baseurl . "&show=" . $show . "&hoststatustypes=" . $hoststatustypes . "&servicestatustypes=" . SERVICESTATE_WARNING . "'>" . $state_totals[1] . "</a>";
$state_text[1] .= "</div>";
$state_text[3] = "<div class='serviceunknown";
if ($state_totals[3] > 0)
$state_text[3] .= " haveserviceunknown";
$state_text[3] .= "'>";
$state_text[3] .= "<a href='" . $baseurl . "&show=" . $show . "&hoststatustypes=" . $hoststatustypes . "&servicestatustypes=" . SERVICESTATE_UNKNOWN . "'>" . $state_totals[3] . "</a>";
$state_text[3] .= "</div>";
$state_text[2] = "<div class='servicecritical";
if ($state_totals[2] > 0)
$state_text[2] .= " haveservicecritical";
$state_text[2] .= "'>";
$state_text[2] .= "<a href='" . $baseurl . "&show=" . $show . "&hoststatustypes=" . $hoststatustypes . "&servicestatustypes=" . SERVICESTATE_CRITICAL . "'>" . $state_totals[2] . "</a>";
$state_text[2] .= "</div>";
$state_text[4] = "<div class='servicepending";
if ($state_totals[4] > 0)
$state_text[4] .= " haveservicepending";
$state_text[4] .= "'>";
$state_text[4] .= "<a href='" . $baseurl . "&show=" . $show . "&hoststatustypes=" . $hoststatustypes . "&servicestatustypes=" . SERVICESTATE_PENDING . "'>" . $state_totals[4] . "</a>";
$state_text[4] .= "</div>";
// MOD BY S.MOULIN
$state_text[5] = "<div class='servicecritical";
if ($state_totals[5] > 0)
$state_text[5] .= " haveservicecritical";
$state_text[5] .= "'>";
$state_text[5] .= "<a href='" . $baseurl . "&show=services&servicestatustypes=16&serviceattr=2058&hostattr=2058'>" . $state_totals[5] . "</a>";
$state_text[5] .= "</div>";
// END
$unhandled_problems_text = "<div class='unhandledserviceproblems";
if ($unhandled_problems > 0)
$unhandled_problems_text .= " haveunhandledserviceproblems";
$unhandled_problems_text .= "'>";
$unhandled_problems_text .= "<a href='" . $baseurl . "&show=" . $show . "&hoststatustypes=" . $hoststatustypes . "&servicestatustypes=" . (SERVICESTATE_WARNING | SERVICESTATE_UNKNOWN | SERVICESTATE_CRITICAL) . "&serviceattr=" . (SERVICESTATUSATTR_NOTACKNOWLEDGED | SERVICESTATUSATTR_NOTINDOWNTIME) . "'>" . $unhandled_problems . "</a>";
$unhandled_problems_text .= "</div>";
$total_problems_text = "<div class='serviceproblems";
if ($total_problems > 0)
$total_problems_text .= " haveserviceproblems";
$total_problems_text .= "'>";
$total_problems_text .= "<a href='" . $baseurl . "&show=" . $show . "&hoststatustypes=" . $hoststatustypes . "&servicestatustypes=" . (SERVICESTATE_WARNING | SERVICESTATE_UNKNOWN | SERVICESTATE_CRITICAL) . "'>" . $total_problems . "</a>";
$total_problems_text .= "</div>";
$total_records_text = "<div class='allservices";
if ($total_records > 0)
$total_records_text .= " haveallservices";
$total_records_text .= "'>";
$total_records_text .= "<a href='" . $baseurl . "&show=" . $show . "&hoststatustypes=" . $hoststatustypes . "'>" . $total_records . "</a>";
$total_records_text .= "</div>";
if (1) {
$output .= '
<table class="infotable table table-condensed table-striped table-bordered">
<thead>
<tr><th colspan="2" bgcolor="#ffcccc">Action needed' . $state_text[5] . '</th><th colspan="2">Critical' . $state_text[2] . '</th></tr>
</thead>
';
$output .= '
<thead>
<tr><th>' . $lstr['ServiceStateOkText'] . '</th><th>' . $lstr['ServiceStateWarningText'] . '</th><th>' . $lstr['ServiceStateUnknownText'] . '</th><th>' . $lstr['ServiceStatePendingText'] . '</th></tr>
</thead>
';
$output .= '
<tbody>
<tr><td>' . $state_text[0] . '</td><td>' . $state_text[1] . '</td><td>' . $state_text[3] . '</td><td>' . $state_text[4] . '</td></tr>
</tbody>
';
$output .= '
<thead>
<tr><th colspan="2">' . _('Unhandled') . '</th><th>' . _('Problems') . '</th><th>All</th></tr>
</thead>
';
$output .= '
<tbody>
<tr><td colspan="2">' . $unhandled_problems_text . '</td><td>' . $total_problems_text . '</td><td>' . $total_records_text . '</td></tr>
</tbody>
';
$output .= '
</table>';
}
$output .= '
<div class="ajax_date">' . _('Last Updated') . ': ' . get_datetime_string(time()) . '</div>
';
//echo "TOTAL: ".timer_stop($start)."<br />";
return $output;
}
....
Remember that this is NOT supported by NAGIOS and an update should break your modifications.
Re: Service status summary MOD
Posted: Wed Apr 20, 2016 12:27 pm
by tmcdonald
smoulin wrote:here my full code for those who need it
To clarify for future reference, this file was written by Nagios Enterprises, and this snippet being posted was modified by
@smoulin.
smoulin wrote:Remember that this is NOT supported by NAGIOS and an update should break your modifications.
This is correct, we will be unable to provide support for this modified code, and any damage that may result from its use is not something we can guarantee a fix for.
With all that having been said, is there anything else related or can I close this?
Update: It should also be mentioned that you can get basically the same functionality by using the "Open Service Problems" page without modifying any code.