initial release

master
Bryan Heden 3 years ago
parent 9811477c1a
commit 7d001b7164

@ -0,0 +1,3 @@
# 1.0.0
* Initial release

@ -1,2 +1,17 @@
# report_notifications_disabled # report_notifications_disabled
> A simple report that prints tables with Hosts and Services with their notifications disabled.
## Information
You can find a link to the report under "Available Reports" section on the "Reports" tab.
There is a configurable option to ignore specific hosts and services. By default, it ignores the following services:
* Night Mode
* Day Mode
* Light Mode - Day
* Light Mode - Night
* Light Mode - Twilight
But, you can add hosts and services to the list if you'd like to ignore additional resources. The configuration option is under the "Admin" tab, in the "System Extensions" link section, under "Manage Components".

@ -0,0 +1,75 @@
<?php
require_once(dirname(__FILE__) . "/../../common.inc.php");
pre_init();
init_session();
grab_request_vars();
check_prereqs();
check_authentication(true);
report_notifications_disabled_generate_report();
function report_notifications_disabled_generate_report()
{
$hosts = report_notifications_disabled_get_hosts();
$services = report_notifications_disabled_get_services();
do_page_start(array("page_title" => "Notifications Disabled Report"), true);
echo "<h5>Disabled Hosts</h5>";
echo report_notifications_disabled_get_host_table($hosts);
echo "<br>";
echo "<h5>Disabled Services</h5>";
echo report_notifications_disabled_get_service_table($services);
}
function report_notifications_disabled_get_host_table($data)
{
$header_row = "<tr>";
$header_row .= "<th>Host</th>";
$header_row .= "<th>User</th>";
$header_row .= "<th>When</th>";
$header_row .= "</tr>";
return "<table class=\"table table-condensed table-striped table-bordered\">" . $header_row . report_notifications_disabled_get_rows($data) . "</table>";
}
function report_notifications_disabled_get_service_table($data)
{
$header_row = "<tr>";
$header_row .= "<th>Host</th>";
$header_row .= "<th>Service</th>";
$header_row .= "<th>User</th>";
$header_row .= "<th>When</th>";
$header_row .= "</tr>";
return "<table class=\"table table-condensed table-striped table-bordered\">" . $header_row . report_notifications_disabled_get_rows($data) . "</table>";
}
function report_notifications_disabled_get_rows($data)
{
$rows = "";
foreach ($data as $row_data) {
$rows .= report_notifications_disabled_get_row($row_data);
}
return $rows;
}
function report_notifications_disabled_get_row($row_data)
{
$row = "<tr>";
$row .= "<td>" . $row_data["host_name"] . "</td>";
if (!empty($row_data["service_description"])) {
$row .= "<td>" . $row_data["service_description"] . "</td>";
}
$row .= "<td>" . $row_data["user"] . "</td>";
$row .= "<td>" . $row_data["when"] . "</td>";
return $row;
}

@ -0,0 +1,425 @@
<?php
/*
A list of Hosts and their Services that have Notifications Disabled
* Include Host Name, Service Description, Date Notifications were disabled, and the user who disabled it
* Exclude the following notifications disabled services:
Night Mode
Day Mode
Light Mode - Day
Light Mode - Night
Light Mode - Twilight
*/
require_once(dirname(__FILE__) . '/../componenthelper.inc.php');
report_notifications_disabled_init();
/****
Defaults
****/
// by default, how far back to look in the audit log for entries
define("REPORT_NOTIFICATIONS_DISABLED_HOW_FAR_BACK_IN_DAYS", 30);
function report_notifications_disabled_default_hosts_to_ignore()
{
return "";
}
function report_notifications_disabled_default_services_to_ignore()
{
return "Night Mode,Day Mode,Light Mode - Day,Light Mode - Night,Light Mode - Twilight";
}
/****
Component Functions
****/
function report_notifications_disabled_init()
{
$desc = "Report on objects (hosts/services) with notifications disabled.";
if (!report_notifications_disabled_check_version()) {
$desc = $desc . " <strong>Error: This component requires Nagios XI 5.6.0 or later.</strong>";
}
register_component("report_notifications_disabled", array(
COMPONENT_NAME => "report_notifications_disabled",
COMPONENT_AUTHOR => "hedenface",
COMPONENT_DESCRIPTION => $desc,
COMPONENT_TITLE => "Notifications Disabled Report",
COMPONENT_VERSION => "1.0.0",
COMPONENT_DATE => "05/22/2023",
COMPONENT_CONFIGFUNCTION => "report_notifications_disabled_config",
)
);
if (!report_notifications_disabled_check_version()) {
return;
}
register_callback(CALLBACK_MENUS_INITIALIZED, 'report_notifications_disabled_component_addmenu');
}
function report_notifications_disabled_check_version()
{
if (function_exists('get_product_release')) {
if (get_product_release() >= 5600) {
return true;
}
}
return false;
}
function report_notifications_disabled_component_addmenu()
{
$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" => "Notifications Disabled",
"id" => "menu-reports-nagiosxi",
"order" => $new_order,
"opts" => array(
"href" => get_component_url_base("report_notifications_disabled") . "/index.php",
)
));
add_menu_item(MENU_REPORTS, array(
"type" => "linkspacer",
"id" => "menu-reports-notifications-disabled-report-spacer",
"order" => $new_order + 0.1
));
}
/****
Component Configuration Functions
****/
function report_notifications_disabled_config($mode = "", $inargs, &$outargs, &$result)
{
$result = 0;
$output = "";
switch ($mode) {
case COMPONENT_CONFIGMODE_GETSETTINGSHTML:
$settings_raw = get_option("report_notifications_disabled_options");
if ($settings_raw == "") {
$settings = array();
}
else {
$settings = unserialize($settings_raw);
}
// initial values
$ignore_host_list = grab_array_var($settings, "ignore_host_list", report_notifications_disabled_default_hosts_to_ignore());
$ignore_service_list = grab_array_var($settings, "ignore_service_list", report_notifications_disabled_default_services_to_ignore());
// just to make sure..
if (empty($ignore_host_list)) {
$ignore_host_list = report_notifications_disabled_default_hosts_to_ignore();
}
if (empty($ignore_service_list)) {
$ignore_service_list = report_notifications_disabled_default_services_to_ignore();
}
// values passed to us
$ignore_host_list = grab_array_var($inargs, "ignore_host_list", $ignore_host_list);
$ignore_service_list = grab_array_var($inargs, "ignore_service_list", $ignore_service_list);
$output = '
<p>Use the Notifications Disabled Report configuration to adjust specific Services to ignore</p>
<h5 class="ul">Notifications Disabled Report</h5>
<table class="table table-condensed table-no-border table-auto-width">
<tr>
<td class="vt">
<label>Hosts to ignore (a comma separated list):</label>
</td>
<td>
<textarea name="ignore_host_list" class="form-control fullsize">' . htmlentities($ignore_host_list) . '</textarea>
</td>
</tr>
<tr>
<td class="vt">
<label>Services to ignore (a comma separated list):</label>
</td>
<td>
<textarea name="ignore_service_list" class="form-control fullsize">' . htmlentities($ignore_service_list) . '</textarea>
</td>
</tr>
</table>';
break;
case COMPONENT_CONFIGMODE_SAVESETTINGS:
// get variables
$ignore_host_list = grab_array_var($inargs, "ignore_host_list", report_notifications_disabled_default_hosts_to_ignore());
$ignore_service_list = grab_array_var($inargs, "ignore_service_list", report_notifications_disabled_default_services_to_ignore());
// just to make sure..
if (empty($ignore_host_list)) {
$ignore_host_list = report_notifications_disabled_default_hosts_to_ignore();
}
if (empty($ignore_service_list)) {
$ignore_service_list = report_notifications_disabled_default_services_to_ignore();
}
// save settings
$settings = array(
"ignore_host_list" => $ignore_host_list,
"ignore_service_list" => $ignore_service_list,
);
set_option("report_notifications_disabled_options", serialize($settings));
break;
default:
break;
}
return $output;
}
function report_notifications_ignore_host_list()
{
$settings_raw = get_option("report_notifications_disabled_options");
if ($settings_raw == "") {
$settings = array();
}
else {
$settings = unserialize($settings_raw);
}
$ignore_host_list = grab_array_var($settings, "ignore_host_list", report_notifications_disabled_default_hosts_to_ignore());
if (empty($ignore_host_list)) {
$ignore_host_list = report_notifications_disabled_default_hosts_to_ignore();
}
return $ignore_host_list;
}
function report_notifications_ignore_service_list()
{
$settings_raw = get_option("report_notifications_disabled_options");
if ($settings_raw == "") {
$settings = array();
}
else {
$settings = unserialize($settings_raw);
}
$ignore_service_list = grab_array_var($settings, "ignore_service_list", report_notifications_disabled_default_services_to_ignore());
if (empty($ignore_service_list)) {
$ignore_service_list = report_notifications_disabled_default_services_to_ignore();
}
return $ignore_service_list;
}
/****
Report Functions
****/
function report_notifications_disabled_get_hosts()
{
$all_hosts = get_data_host_status(array("notifications_enabled" => 0));
$hosts = array();
foreach ($all_hosts as $host) {
if (in_array($host["host_name"], split(",", report_notifications_ignore_host_list()))) {
continue;
}
$audit = report_notifications_disabled_search_audit_logs(REPORT_NOTIFICATIONS_DISABLED_HOW_FAR_BACK_IN_DAYS, $host["host_name"]);
if ($audit === false || count($audit) == 0) {
$user = "No user found";
$when = "";
} else {
$user = $audit["user"];
$when = $audit["log_time"];
}
$hosts[] = array(
"host_name" => $host["host_name"],
"user" => $user,
"when" => $when,
);
}
return $hosts;
}
function report_notifications_disabled_get_services()
{
$all_services = get_data_service_status(array("notifications_enabled" => 0));
$services = array();
foreach ($all_services as $service) {
if (in_array($service["host_name"], split(",", report_notifications_ignore_host_list()))) {
continue;
}
if (in_array($service["service_description"], split(",", report_notifications_ignore_service_list()))) {
continue;
}
$audit = report_notifications_disabled_search_audit_logs(REPORT_NOTIFICATIONS_DISABLED_HOW_FAR_BACK_IN_DAYS, $service["host_name"], $service["service_description"]);
if ($audit === false || count($audit) == 0) {
$user = "No user found";
$when = "";
} else {
$user = $audit["user"];
$when = $audit["log_time"];
}
$services[] = array(
"host_name" => $service["host_name"],
"service_description" => $service["service_description"],
"user" => $user,
"when" => $when,
);
}
return $services;
}
function report_notifications_disabled_search_audit_logs($how_far_back_in_days, $host_name, $service_description = null)
{
// we start with the last 24 hours, then go back as far as specified in the function call
$starttime = time() - (24 * 60 * 60);
$endtime = time();
for ($i = 0; $i < $how_far_back_in_days; $i++) {
if (empty($service_description) == true) {
$audit_logs = report_notifications_disabled_get_auditlog(array(
"starttime" => $starttime,
"endtime" => $endtime,
"type" => AUDITLOGTYPE_INFO,
"message" => "lk:Submitted a command to Nagios Core: DISABLE_HOST_NOTIFICATIONS;$host_name",
));
} else {
$audit_logs = report_notifications_disabled_get_auditlog(array(
"starttime" => $starttime,
"endtime" => $endtime,
"type" => AUDITLOGTYPE_INFO,
"message" => "lk:Submitted a command to Nagios Core: DISABLE_SVC_NOTIFICATIONS;$host_name;$service_description",
));
}
// we want the latest
if (count($audit_logs) >= 1) {
return $audit_logs[0];
}
// otherwise, we adjust starttime and endtime
$starttime -= (24 * 60 * 60);
$endtime -= (24 * 60 * 60);
}
// if we have nothing, return false
return false;
}
// taken from get_auditlog_xml_output (without the xml part, along with some adjustments)
// no functionality exists natively for returning auditlog as an array
function report_notifications_disabled_get_auditlog($request_args)
{
global $sqlquery;
global $db_tables;
global $request;
// WE HAVE TO MUNGE THINGS HERE BECAUSE THE TIMESTAMPS CONTAINS COLONS AND WILL GET MESSED UP BY THE NORMAL SQL LIMITING LOGIC...
$sqlmods = "";
// by default, only show last 24 hours worth of logs
$starttime = grab_array_var($request_args, "starttime", time() - (24 * 60 * 60));
unset($request_args["starttime"]);
$sqlmods .= " AND " . $db_tables[DB_NAGIOSXI]["auditlog"] . ".log_time >= '" . get_datetime_string($starttime, DT_SQL_DATE_TIME) . "'";
// optional end time
$endtime = grab_array_var($request_args, "endtime", "");
if ($endtime != "") {
$sqlmods .= " AND " . $db_tables[DB_NAGIOSXI]["auditlog"] . ".log_time <= '" . get_datetime_string($endtime, DT_SQL_DATE_TIME) . "'";
}
$audit_log = array();
// generate query
$fieldmap = array(
"auditlog_id" => $db_tables[DB_NAGIOSXI]["auditlog"] . ".auditlog_id",
"log_time" => $db_tables[DB_NAGIOSXI]["auditlog"] . ".log_time",
"source" => $db_tables[DB_NAGIOSXI]["auditlog"] . ".source",
"user" => $db_tables[DB_NAGIOSXI]["auditlog"] . ".user",
"type" => $db_tables[DB_NAGIOSXI]["auditlog"] . ".type",
"message" => $db_tables[DB_NAGIOSXI]["auditlog"] . ".message",
"ip_address" => $db_tables[DB_NAGIOSXI]["auditlog"] . ".ip_address",
"details" => $db_tables[DB_NAGIOSXI]["auditlog"] . ".details",
);
$args = array(
"sql" => $sqlquery['GetAuditLog'] . $sqlmods,
"fieldmap" => $fieldmap,
"useropts" => $request_args, // FOR NON-BACKEND-CALLS
);
$sql = generate_sql_query(DB_NAGIOSXI, $args);
if (!($rs = exec_sql_query(DB_NAGIOSXI, $sql))) {
handle_backend_db_error(DB_NAGIOSXI);
} else {
while (!$rs->EOF) {
$typestr = intval($rs->fields["type"]);
switch ($typestr) {
case AUDITLOGTYPE_ADD:
$typestr = "ADD";
break;
case AUDITLOGTYPE_DELETE:
$typestr = "DELETE";
break;
case AUDITLOGTYPE_MODIFY:
$typestr = "MODIFY";
break;
case AUDITLOGTYPE_CHANGE:
$typestr = "CHANGE";
break;
case AUDITLOGTYPE_SECURITY:
$typestr = "SECURITY";
break;
case AUDITLOGTYPE_INFO:
$typestr = "INFO";
break;
case AUDITLOGTYPE_OTHER:
$typestr = "OTHER";
break;
default:
break;
}
$audit_log[] = array(
"id" => get_xml_db_field_val($rs, "auditlog_id"),
"log_time" => get_xml_db_field_val($rs, "log_time"),
"source" => get_xml_db_field_val($rs, "source"),
"user" => get_xml_db_field_val($rs, "user"),
"type" => get_xml_db_field_val($rs, "type"),
"typestr" => $typestr,
"message" => get_xml_db_field_val($rs, "message"),
"details" => get_xml_db_field_val($rs, "details"),
"ip_address" => get_xml_db_field_val($rs, "ip_address"),
);
$rs->MoveNext();
}
}
return $audit_log;
}
Loading…
Cancel
Save