mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
webui: Alerts table refresh (#7765)
* initial release * changed layout, matching pr 7628 * style changes usage of short hostname * alerts page cleanup * reduced css class, added js function * initial release * added min-height, also apply min-height via js if parrent is smaller * remove status column
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage graphs
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 LibreNMS
|
||||
* @author LibreNMS Contributors
|
||||
*/
|
||||
|
||||
require_once $config['install_dir'].'/includes/device-groups.inc.php';
|
||||
require_once $config['install_dir'] . '/includes/device-groups.inc.php';
|
||||
|
||||
/* FIXME: is there a central place we can put this? */
|
||||
|
||||
@@ -26,10 +39,10 @@ $alert_severities = array(
|
||||
//if( defined('SHOW_SETTINGS') || empty($widget_settings) ) {
|
||||
if (defined('SHOW_SETTINGS')) {
|
||||
$current_acknowledged = isset($widget_settings['acknowledged']) ? $widget_settings['acknowledged'] : '';
|
||||
$current_severity = isset($widget_settings['severity']) ? $widget_settings['severity'] : '';
|
||||
$current_state = isset($widget_settings['state']) ? $widget_settings['state'] : '';
|
||||
$current_group = isset($widget_settings['group']) ? $widget_settings['group'] : '';
|
||||
$current_proc = isset($widget_settings['proc']) ? $widget_settings['proc'] : '';
|
||||
$current_severity = isset($widget_settings['severity']) ? $widget_settings['severity'] : '';
|
||||
$current_state = isset($widget_settings['state']) ? $widget_settings['state'] : '';
|
||||
$current_group = isset($widget_settings['group']) ? $widget_settings['group'] : '';
|
||||
$current_proc = isset($widget_settings['proc']) ? $widget_settings['proc'] : '';
|
||||
|
||||
$common_output[] = '
|
||||
<form class="form" onsubmit="widget_settings(this); return false;">
|
||||
@@ -40,9 +53,9 @@ if (defined('SHOW_SETTINGS')) {
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control" name="acknowledged">';
|
||||
|
||||
$common_output[] = '<option value=""'.($current_acknowledged == '' ? ' selected' : ' ').'>not filtered</option>';
|
||||
$common_output[] = '<option value="1"'.($current_acknowledged == '1' ? ' selected' : ' ').'>show only acknowledged</option>';
|
||||
$common_output[] = '<option value="0"'.($current_acknowledged == '0' ? ' selected' : ' ').'>hide acknowledged</option>';
|
||||
$common_output[] = '<option value=""' . ($current_acknowledged == '' ? ' selected' : ' ') . '>not filtered</option>';
|
||||
$common_output[] = '<option value="1"' . ($current_acknowledged == '1' ? ' selected' : ' ') . '>show only acknowledged</option>';
|
||||
$common_output[] = '<option value="0"' . ($current_acknowledged == '0' ? ' selected' : ' ') . '>hide acknowledged</option>';
|
||||
|
||||
$common_output[] = '
|
||||
</select>
|
||||
@@ -57,7 +70,7 @@ if (defined('SHOW_SETTINGS')) {
|
||||
<option value="">any severity</option>';
|
||||
|
||||
foreach ($alert_severities as $name => $val) {
|
||||
$common_output[] = "<option value=\"$val\"".($current_severity == $name || $current_severity == $val ? ' selected' : '').">$name".($val > 3 ? "" : " or higher")."</option>";
|
||||
$common_output[] = "<option value=\"$val\"" . ($current_severity == $name || $current_severity == $val ? ' selected' : '') . ">$name" . ($val > 3 ? "" : " or higher") . "</option>";
|
||||
}
|
||||
|
||||
$common_output[] = '
|
||||
@@ -70,10 +83,10 @@ if (defined('SHOW_SETTINGS')) {
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control" name="state">';
|
||||
$common_output[] = '<option value=""'.($current_state == '' ? ' selected' : '').'>any state</option>';
|
||||
$common_output[] = '<option value=""' . ($current_state == '' ? ' selected' : '') . '>any state</option>';
|
||||
|
||||
foreach ($alert_states as $name => $val) {
|
||||
$common_output[] = "<option value=\"$val\"".($current_state == $name || (is_numeric($current_state) && $current_state == $val) ? ' selected' : '').">$name</option>";
|
||||
$common_output[] = "<option value=\"$val\"" . ($current_state == $name || (is_numeric($current_state) && $current_state == $val) ? ' selected' : '') . ">$name</option>";
|
||||
}
|
||||
|
||||
$common_output[] = '
|
||||
@@ -86,13 +99,13 @@ if (defined('SHOW_SETTINGS')) {
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control" name="group">';
|
||||
$common_output[] = '<option value=""'.($current_group == '' ? ' selected' : '').'>any group</option>';
|
||||
$common_output[] = '<option value=""' . ($current_group == '' ? ' selected' : '') . '>any group</option>';
|
||||
|
||||
$device_groups = GetDeviceGroups();
|
||||
$common_output[] = "<!-- ".print_r($device_groups, true)." -->";
|
||||
$common_output[] = "<!-- " . print_r($device_groups, true) . " -->";
|
||||
foreach ($device_groups as $group) {
|
||||
$group_id = $group['id'];
|
||||
$common_output[] = "<option value=\"$group_id\"".(is_numeric($current_group) && $current_group == $group_id ? ' selected' : '').">".$group['name']." - ".$group['description']."</option>";
|
||||
$common_output[] = "<option value=\"$group_id\"" . (is_numeric($current_group) && $current_group == $group_id ? ' selected' : '') . ">" . $group['name'] . " - " . $group['description'] . "</option>";
|
||||
}
|
||||
$common_output[] = '
|
||||
</select>
|
||||
@@ -105,8 +118,8 @@ if (defined('SHOW_SETTINGS')) {
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control" name="proc">';
|
||||
|
||||
$common_output[] = '<option value="1"'.($current_proc == '1' ? ' selected' : ' ').'>show</option>';
|
||||
$common_output[] = '<option value="0"'.($current_proc == '0' ? ' selected' : ' ').'>hide</option>';
|
||||
$common_output[] = '<option value="1"' . ($current_proc == '1' ? ' selected' : ' ') . '>show</option>';
|
||||
$common_output[] = '<option value="0"' . ($current_proc == '0' ? ' selected' : ' ') . '>hide</option>';
|
||||
|
||||
$common_output[] = '
|
||||
</select>
|
||||
@@ -121,12 +134,12 @@ if (defined('SHOW_SETTINGS')) {
|
||||
</form>
|
||||
';
|
||||
} else {
|
||||
$device_id = $device['device_id'];
|
||||
$device_id = $device['device_id'];
|
||||
$acknowledged = $widget_settings['acknowledged'];
|
||||
$state = $widget_settings['state'];
|
||||
$state = $widget_settings['state'];
|
||||
$min_severity = $widget_settings['min_severity'];
|
||||
$group = $widget_settings['group'];
|
||||
$proc = $widget_settings['proc'];
|
||||
$group = $widget_settings['group'];
|
||||
$proc = $widget_settings['proc'];
|
||||
|
||||
$title = "Alerts";
|
||||
|
||||
@@ -149,7 +162,7 @@ if (defined('SHOW_SETTINGS')) {
|
||||
if (is_numeric($group)) {
|
||||
$group_row = dbFetchRow("SELECT * FROM device_groups WHERE id = ?", array($group));
|
||||
if ($group_row) {
|
||||
$title = "$title for ".$group_row['name'];
|
||||
$title = "$title for " . $group_row['name'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,13 +170,13 @@ if (defined('SHOW_SETTINGS')) {
|
||||
$sev_name = $min_severity;
|
||||
if (is_numeric($min_severity)) {
|
||||
$sev_name = array_search($min_severity, $alert_severities);
|
||||
$title = "$title ".($min_severity > 3 ? "" :">")."=$sev_name";
|
||||
$title = "$title " . ($min_severity > 3 ? "" : ">") . "=$sev_name";
|
||||
}
|
||||
}
|
||||
|
||||
$widget_settings['title'] = $title;
|
||||
|
||||
$group = $widget_settings['group'];
|
||||
$group = $widget_settings['group'];
|
||||
|
||||
$common_output[] = '
|
||||
<div class="row">
|
||||
@@ -172,30 +185,27 @@ if (defined('SHOW_SETTINGS')) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table id="alerts_'.$unique_id.'" class="table table-hover table-condensed alerts">
|
||||
<table id="alerts_' . $unique_id . '" class="table table-hover table-condensed alerts">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="status" data-formatter="status" data-sortable="false">Status</th>
|
||||
<th data-column-id="rule">Rule</th>
|
||||
<th data-column-id="details" data-sortable="false"> </th>
|
||||
<th data-column-id="hostname">Hostname</th>
|
||||
<th data-column-id="severity"></th>
|
||||
<th data-column-id="timestamp">Timestamp</th>
|
||||
<th data-column-id="severity" data-formatter="severity">Severity</th>
|
||||
<th data-column-id="ack" data-formatter="ack" data-sortable="false">Acknowledge</th>';
|
||||
if (is_numeric($proc)) {
|
||||
if ($proc) {
|
||||
$common_output[] = '<th data-column-id="proc" data-formatter="proc" data-sortable="false">Procedure</th>';
|
||||
}
|
||||
} else {
|
||||
$common_output[] = '<th data-column-id="proc" data-formatter="proc" data-sortable="false">Procedure</th>';
|
||||
<th data-column-id="rule">Rule</th>
|
||||
<th data-column-id="details" data-sortable="false"></th>
|
||||
<th data-column-id="hostname">Hostname</th>
|
||||
<th data-column-id="ack_ico" data-sortable="false">ACK</th>';
|
||||
|
||||
if ($proc == '1') {
|
||||
$common_output[] = '<th data-column-id="proc" data-sortable="false">URL</th>';
|
||||
}
|
||||
|
||||
$common_output[] = '
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
<script>
|
||||
var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({
|
||||
var alerts_grid = $("#alerts_' . $unique_id . '").bootgrid({
|
||||
ajax: true,
|
||||
post: function ()
|
||||
{
|
||||
@@ -204,48 +214,29 @@ var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({
|
||||
';
|
||||
|
||||
if (is_numeric($acknowledged)) {
|
||||
$common_output[]="acknowledged: '$acknowledged',\n";
|
||||
$common_output[] = "acknowledged: '$acknowledged',\n";
|
||||
}
|
||||
if (isset($state) && $state != '') {
|
||||
$common_output[]="state: '$state',\n";
|
||||
$common_output[] = "state: '$state',\n";
|
||||
}
|
||||
if (isset($min_severity) && $min_severity != '') {
|
||||
$common_output[]="min_severity: '$min_severity',\n";
|
||||
$common_output[] = "min_severity: '$min_severity',\n";
|
||||
}
|
||||
|
||||
if (is_numeric($group)) {
|
||||
$common_output[]="group: '$group',\n";
|
||||
$common_output[] = "group: '$group',\n";
|
||||
}
|
||||
if (is_numeric($proc)) {
|
||||
$common_output[]="proc: '$proc',\n";
|
||||
$common_output[] = "proc: '$proc',\n";
|
||||
}
|
||||
|
||||
$common_output[]='
|
||||
device_id: \'' . $device['device_id'] .'\'
|
||||
$common_output[] = '
|
||||
device_id: \'' . $device['device_id'] . '\'
|
||||
}
|
||||
},
|
||||
url: "ajax_table.php",
|
||||
rowCount: [50, 100, 250, -1],
|
||||
formatters: {
|
||||
"status": function(column,row) {
|
||||
return "<h4><span class=\'label label-"+row.extra+" threeqtr-width\'>" + row.msg + "</span></h4>";
|
||||
},
|
||||
"ack": function(column,row) {
|
||||
return "<button type=\'button\' class=\'btn btn-"+row.ack_col+" btn-sm command-ack-alert\' data-target=\'#ack-alert\' data-state=\'"+row.state+"\' data-alert_id=\'"+row.alert_id+"\' name=\'ack-alert\' id=\'ack-alert\' data-extra=\'"+row.extra+"\'><i class=\'fa fa-"+row.ack_ico+"\'aria-hidden=\'true\'></i></button>";
|
||||
},
|
||||
"proc": function(column,row) {
|
||||
return "<button type=\'button\' class=\'btn btn-sm command-open-proc\' data-alert_id=\'"+row.alert_id+"\' name=\'open-proc\' id=\'open-proc\'>Open</button>";
|
||||
},
|
||||
"severity": function(column,row) {
|
||||
var eventColor = "info";
|
||||
if (row.severity.match (/critical/)) { eventColor = "danger"; }
|
||||
else if (row.severity.match (/warning/)) { eventColor = "warning"; }
|
||||
else if (row.severity.match (/ok/)) { eventColor = "success"; }
|
||||
return "<h4><span class=\'label label-" + eventColor + " threeqtr-width\'>" + row.severity + "</span></h4>";
|
||||
}
|
||||
},
|
||||
templates: {
|
||||
}
|
||||
|
||||
}).on("loaded.rs.jquery.bootgrid", function() {
|
||||
alerts_grid = $(this);
|
||||
alerts_grid.find(".incident-toggle").each( function() {
|
||||
@@ -269,24 +260,6 @@ var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({
|
||||
}
|
||||
});
|
||||
});
|
||||
alerts_grid.find(".command-open-proc").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
var alert_id = $(this).data("alert_id");
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ajax_form.php",
|
||||
data: { type: "open-proc", alert_id: alert_id },
|
||||
success: function(msg){
|
||||
if (msg != "ERROR") { window.open(msg); }
|
||||
else {
|
||||
toastr.error("Procedure link does not seem to be valid, please check the rule");
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
toastr.error("An error occurred opening procedure for this alert. Was the procedure link configured?");
|
||||
}
|
||||
});
|
||||
});
|
||||
alerts_grid.find(".command-ack-alert").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
var alert_id = $(this).data("alert_id");
|
||||
|
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
header('Content-type: text/plain');
|
||||
|
||||
$alert_id = $_POST['alert_id'];
|
||||
if (!is_numeric($alert_id)) {
|
||||
echo 'ERROR: No alert selected';
|
||||
exit;
|
||||
} else {
|
||||
$proc = dbFetchCell('SELECT proc FROM alerts,alert_rules WHERE alert_rules.id = alerts.rule_id AND alerts.id = ?', array($alert_id));
|
||||
if (($proc == "") || ($proc == "NULL")) {
|
||||
echo header("HTTP/1.0 404 Not Found");
|
||||
} elseif (! preg_match('/^http[s]*:\/\//', $proc)) {
|
||||
echo "ERROR";
|
||||
} else {
|
||||
echo $proc;
|
||||
}
|
||||
exit;
|
||||
}
|
@@ -1,9 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage graphs
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 LibreNMS
|
||||
* @author LibreNMS Contributors
|
||||
*/
|
||||
|
||||
$where = 1;
|
||||
|
||||
if (is_numeric($_POST['device_id'])) {
|
||||
$where .= ' AND E.device_id = ?';
|
||||
$where .= ' AND E.device_id = ?';
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
|
||||
@@ -15,7 +28,7 @@ if ($_POST['state'] >= 0) {
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where";
|
||||
} else {
|
||||
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?";
|
||||
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?";
|
||||
$param[] = array($_SESSION['user_id']);
|
||||
}
|
||||
|
||||
@@ -24,7 +37,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`E`.`id`) $sql";
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -36,7 +49,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -44,53 +57,45 @@ if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
|
||||
$sql = "SELECT D.device_id,name AS alert,rule_id, state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate,details $sql";
|
||||
$sql = "SELECT D.device_id,name AS alert,rule_id, state,time_logged,DATE_FORMAT(time_logged, '" . $config['dateformat']['mysql']['compact'] . "') as humandate,details $sql";
|
||||
|
||||
$rulei = 0;
|
||||
foreach (dbFetchRows($sql, $param) as $alertlog) {
|
||||
$dev = device_by_id_cache($alertlog['device_id']);
|
||||
$dev = device_by_id_cache($alertlog['device_id']);
|
||||
logfile($alertlog['rule_id']);
|
||||
$log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? AND `state` = 1 ORDER BY id DESC LIMIT 1', array($alertlog['rule_id'], $alertlog['device_id']));
|
||||
$log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? AND `state` = 1 ORDER BY id DESC LIMIT 1', array($alertlog['rule_id'], $alertlog['device_id']));
|
||||
$fault_detail = alert_details($log);
|
||||
if (empty($fault_detail)) {
|
||||
$fault_detail = 'Rule created, no faults found';
|
||||
}
|
||||
$alert_state = $alertlog['state'];
|
||||
$alert_state = $alertlog['state'];
|
||||
if ($alert_state == '0') {
|
||||
$fa_icon = 'check';
|
||||
$fa_color = 'success';
|
||||
$text = 'Ok';
|
||||
$status = 'label-success';
|
||||
} elseif ($alert_state == '1') {
|
||||
$fa_icon = 'times';
|
||||
$fa_color = 'danger';
|
||||
$text = 'Alert';
|
||||
$status = 'label-danger';
|
||||
} elseif ($alert_state == '2') {
|
||||
$fa_icon = 'info-circle';
|
||||
$fa_color = 'muted';
|
||||
$text = 'Ack';
|
||||
$status = 'label-info';
|
||||
} elseif ($alert_state == '3') {
|
||||
$fa_icon = 'arrow-down';
|
||||
$fa_color = 'warning';
|
||||
$text = 'Worse';
|
||||
$status = 'label-warning';
|
||||
} elseif ($alert_state == '4') {
|
||||
$fa_icon = 'arrow-up';
|
||||
$fa_color = 'info';
|
||||
$text = 'Better';
|
||||
$status = 'label-primary';
|
||||
}//end if
|
||||
|
||||
|
||||
$response[] = array(
|
||||
'id' => $rulei++,
|
||||
'id' => $rulei++,
|
||||
'time_logged' => $alertlog['humandate'],
|
||||
'details' => '<a class="fa fa-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident'.($rulei).'" data-parent="#alerts"></a>',
|
||||
'hostname' => '<div class="incident">'.generate_device_link($dev, shorthost($dev['hostname'])).'<div id="incident'.($rulei).'" class="collapse">'.$fault_detail.'</div></div>',
|
||||
'alert' => htmlspecialchars($alertlog['alert']),
|
||||
'status' => "<b><i class='fa fa-".$fa_icon." text-".$fa_color."'></i> $text</b>",
|
||||
'details' => '<a class="fa fa-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident' . ($rulei) . '" data-parent="#alerts"></a>',
|
||||
'hostname' => '<div class="incident">' . generate_device_link($dev, shorthost($dev['hostname'])) . '<div id="incident' . ($rulei) . '" class="collapse">' . $fault_detail . '</div></div>',
|
||||
'alert' => htmlspecialchars($alertlog['alert']),
|
||||
'status' => "<i class='alert-status " . $status . "'></i>"
|
||||
);
|
||||
}//end foreach
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
@@ -1,6 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage graphs
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 LibreNMS
|
||||
* @author LibreNMS Contributors
|
||||
*/
|
||||
|
||||
require_once $config['install_dir'].'/includes/device-groups.inc.php';
|
||||
require_once $config['install_dir'] . '/includes/device-groups.inc.php';
|
||||
|
||||
$where = ' `devices`.`disabled` = 0';
|
||||
|
||||
@@ -26,16 +39,16 @@ $alert_severities = array(
|
||||
$show_recovered = false;
|
||||
|
||||
if (is_numeric($_POST['device_id']) && $_POST['device_id'] > 0) {
|
||||
$where .= ' AND `alerts`.`device_id`='.$_POST['device_id'];
|
||||
$where .= ' AND `alerts`.`device_id`=' . $_POST['device_id'];
|
||||
}
|
||||
|
||||
if (is_numeric($_POST['acknowledged'])) {
|
||||
// I assume that if we are searching for acknowleged/not, we aren't interested in recovered
|
||||
$where .= " AND `alerts`.`state`".($_POST['acknowledged'] ? "=" : "!=").$alert_states['acknowledged'];
|
||||
$where .= " AND `alerts`.`state`" . ($_POST['acknowledged'] ? "=" : "!=") . $alert_states['acknowledged'];
|
||||
}
|
||||
|
||||
if (is_numeric($_POST['state'])) {
|
||||
$where .= " AND `alerts`.`state`=".$_POST['state'];
|
||||
$where .= " AND `alerts`.`state`=" . $_POST['state'];
|
||||
if ($_POST['state'] == $alert_states['recovered']) {
|
||||
$show_recovered = true;
|
||||
}
|
||||
@@ -48,7 +61,7 @@ if (isset($_POST['min_severity'])) {
|
||||
$min_severity_id = $alert_severities[$_POST['min_severity']];
|
||||
}
|
||||
if (isset($min_severity_id)) {
|
||||
$where .= " AND `alert_rules`.`severity` ".($min_severity_id > 3 ? "" :">")."= ".($min_severity_id > 3 ? $min_severity_id - 3 : $min_severity_id);
|
||||
$where .= " AND `alert_rules`.`severity` " . ($min_severity_id > 3 ? "" : ">") . "= " . ($min_severity_id > 3 ? $min_severity_id - 3 : $min_severity_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +71,7 @@ if (is_numeric($_POST['group'])) {
|
||||
}
|
||||
|
||||
if (!$show_recovered) {
|
||||
$where .= " AND `alerts`.`state`!=".$alert_states['recovered'];
|
||||
$where .= " AND `alerts`.`state`!=" . $alert_states['recovered'];
|
||||
}
|
||||
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
@@ -68,15 +81,15 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql = ' FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`';
|
||||
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
$sql .= " RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE $where";
|
||||
|
||||
$count_sql = "SELECT COUNT(`alerts`.`id`) $sql";
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -88,7 +101,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -98,41 +111,28 @@ if ($rowCount != -1) {
|
||||
|
||||
$sql = "SELECT `alerts`.*, `devices`.`hostname`, `devices`.`sysName`, `devices`.`hardware`, `devices`.`location`, `alert_rules`.`rule`, `alert_rules`.`name`, `alert_rules`.`severity` $sql";
|
||||
|
||||
$rulei = 0;
|
||||
$rulei = 0;
|
||||
$format = $_POST['format'];
|
||||
foreach (dbFetchRows($sql, $param) as $alert) {
|
||||
$log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', array($alert['rule_id'], $alert['device_id']));
|
||||
$log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', array($alert['rule_id'], $alert['device_id']));
|
||||
$fault_detail = alert_details($log);
|
||||
|
||||
$ico = 'check';
|
||||
$col = 'green';
|
||||
$extra = '';
|
||||
$msg = '';
|
||||
if ((int) $alert['state'] === 0) {
|
||||
$ico = 'check';
|
||||
$col = 'green';
|
||||
$extra = 'success';
|
||||
$msg = 'ok';
|
||||
} elseif ((int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) {
|
||||
$ico = 'volume-up';
|
||||
$col = 'red';
|
||||
$extra = 'danger';
|
||||
$msg = 'alert';
|
||||
if ((int) $alert['state'] === 3) {
|
||||
$msg = 'worse';
|
||||
} elseif ((int) $alert['state'] === 4) {
|
||||
$msg = 'better';
|
||||
$alert_to_ack = '<button type="button" class="btn btn-success command-ack-alert fa fa-eye" aria-hidden="true" title="Mark as acknowledged" data-target="ack-alert" data-state="' . $alert['state'] . '" data-alert_id="' . $alert['id'] . '" name="ack-alert"></button>';
|
||||
$alert_to_nack = '<button type="button" class="btn btn-danger command-ack-alert fa fa-eye-slash" aria-hidden="true" title="Mark as not acknowledged" data-target="ack-alert" data-state="' . $alert['state'] . '" data-alert_id="' . $alert['id'] . '" name="ack-alert"></button>';
|
||||
|
||||
if ((int)$alert['state'] === 0) {
|
||||
$ico = '';
|
||||
$msg = '';
|
||||
} elseif ((int)$alert['state'] === 1 || (int)$alert['state'] === 3 || (int)$alert['state'] === 4) {
|
||||
$ico = $alert_to_ack;
|
||||
if ((int)$alert['state'] === 3) {
|
||||
$msg = '<i class="fa fa-angle-double-down" style="font-size:20px;" aria-hidden="true" title="Status got worse"></i>';
|
||||
} elseif ((int)$alert['state'] === 4) {
|
||||
$msg = '<i class="fa fa-angle-double-up" style="font-size:20px;" aria-hidden="true" title="Status got better"></i>';
|
||||
}
|
||||
} elseif ((int) $alert['state'] === 2) {
|
||||
$ico = 'volume-off';
|
||||
$col = '#800080';
|
||||
$extra = 'warning';
|
||||
$msg = 'muted';
|
||||
}//end if
|
||||
$alert_checked = '';
|
||||
$orig_ico = $ico;
|
||||
$orig_col = $col;
|
||||
$orig_class = $extra;
|
||||
} elseif ((int)$alert['state'] === 2) {
|
||||
$ico = $alert_to_nack;
|
||||
}
|
||||
|
||||
$severity = $alert['severity'];
|
||||
if ($alert['state'] == 3) {
|
||||
@@ -141,39 +141,58 @@ foreach (dbFetchRows($sql, $param) as $alert) {
|
||||
$severity .= ' <strong>-</strong>';
|
||||
}
|
||||
|
||||
$ack_ico = 'volume-up';
|
||||
$ack_col = 'success';
|
||||
$ack_ico = $alert_to_ack;
|
||||
|
||||
if ($alert['state'] == 2) {
|
||||
$ack_ico = 'volume-off';
|
||||
$ack_col = 'danger';
|
||||
$ack_ico = $alert_to_nack;
|
||||
}
|
||||
|
||||
$hostname = '
|
||||
<div class="incident">
|
||||
'.generate_device_link($alert).'
|
||||
<div id="incident'.($rulei + 1).'" class="collapse">'.$fault_detail.'</div>
|
||||
</div>';
|
||||
$hostname = '<div class="incident">' . generate_device_link($alert, shorthost($alert['hostname'])) . '<div id="incident' . ($rulei + 1) . '" class="collapse">' . $fault_detail . '</div></div>';
|
||||
|
||||
switch ($severity) {
|
||||
case 'critical':
|
||||
$severity_ico = '<span class="alert-status label-danger"> </span>';
|
||||
break;
|
||||
case 'warning':
|
||||
$severity_ico = '<span class="alert-status label-warning"> </span>';
|
||||
break;
|
||||
case 'ok':
|
||||
$severity_ico = '<span class="alert-status label-success"> </span>';
|
||||
break;
|
||||
default:
|
||||
$severity_ico = '<span class="alert-status label-info"> </span>';
|
||||
break;
|
||||
}
|
||||
|
||||
$proc = dbFetchCell('SELECT proc FROM alerts,alert_rules WHERE alert_rules.id = alerts.rule_id AND alerts.id = ?', array($alert['id']));
|
||||
if (($proc == "") || ($proc == "NULL")) {
|
||||
$has_proc = '';
|
||||
} else {
|
||||
if (!preg_match('/^http[s]*:\/\//', $proc)) {
|
||||
$has_proc = '';
|
||||
} else {
|
||||
$has_proc = '<a href="' . $proc . '" target="_blank"><button type="button" class="btn btn-info fa fa-external-link" aria-hidden="true"></button></a>';
|
||||
}
|
||||
}
|
||||
|
||||
$response[] = array(
|
||||
'id' => $rulei++,
|
||||
'rule' => '<i title="'.htmlentities($alert['rule']).'"><a href="'.generate_url(array('page'=>'alert-rules')).'">'.htmlentities($alert['name']).'</a></i>',
|
||||
'details' => '<a class="fa fa-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident'.($rulei).'" data-parent="#alerts"></a>',
|
||||
'hostname' => $hostname,
|
||||
'id' => $rulei++,
|
||||
'rule' => '<i title="' . htmlentities($alert['rule']) . '"><a href="' . generate_url(array('page' => 'alert-rules')) . '">' . htmlentities($alert['name']) . '</a></i>',
|
||||
'details' => '<a class="fa fa-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident' . ($rulei) . '" data-parent="#alerts"></a>',
|
||||
'hostname' => $hostname,
|
||||
'timestamp' => ($alert['timestamp'] ? $alert['timestamp'] : 'N/A'),
|
||||
'severity' => $severity,
|
||||
'ack_col' => $ack_col,
|
||||
'state' => $alert['state'],
|
||||
'alert_id' => $alert['id'],
|
||||
'ack_ico' => $ack_ico,
|
||||
'extra' => $extra,
|
||||
'msg' => $msg,
|
||||
'severity' => $severity_ico,
|
||||
'state' => $alert['state'],
|
||||
'alert_id' => $alert['id'],
|
||||
'ack_ico' => $ack_ico,
|
||||
'proc' => $has_proc,
|
||||
);
|
||||
}//end foreach
|
||||
}
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
Reference in New Issue
Block a user