2015-07-21 23:01:57 +01:00
|
|
|
<?php
|
|
|
|
|
2016-01-21 12:51:49 -07:00
|
|
|
require_once $config['install_dir'].'/includes/device-groups.inc.php';
|
|
|
|
|
2016-01-20 15:23:09 -07:00
|
|
|
/* FIXME: is there a central place we can put this? */
|
|
|
|
|
|
|
|
$alert_states = array(
|
|
|
|
// divined from librenms/alerts.php
|
|
|
|
'recovered' => 0,
|
|
|
|
'alerted' => 1,
|
|
|
|
'acknowledged' => 2,
|
|
|
|
'worse' => 3,
|
|
|
|
'better' => 4
|
|
|
|
);
|
|
|
|
|
|
|
|
$alert_severities = array(
|
|
|
|
// alert_rules.status is enum('ok','warning','critical')
|
|
|
|
'ok' => 1,
|
|
|
|
'warning' => 2,
|
|
|
|
'critical' => 3
|
|
|
|
);
|
|
|
|
|
|
|
|
//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'] : '';
|
2016-01-21 12:51:49 -07:00
|
|
|
$current_group = isset($widget_settings['group']) ? $widget_settings['group'] : '';
|
2016-05-27 16:13:51 +02:00
|
|
|
$current_proc = isset($widget_settings['proc']) ? $widget_settings['proc'] : '';
|
2016-01-20 15:23:09 -07:00
|
|
|
|
|
|
|
$common_output[] = '
|
|
|
|
<form class="form" onsubmit="widget_settings(this); return false;">
|
|
|
|
<div class="form-group row">
|
|
|
|
<div class="col-sm-4">
|
|
|
|
<label for="acknowledged" class="control-label">Show acknowledged alerts: </label>
|
|
|
|
</div>
|
|
|
|
<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[] = '
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
|
|
<div class="col-sm-4">
|
|
|
|
<label for="min_severity" class="control-label">Minimum displayed severity:</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-sm-8">
|
|
|
|
<select class="form-control" name="min_severity">
|
|
|
|
<option value="">any severity</option>';
|
|
|
|
|
|
|
|
foreach ($alert_severities as $name => $val) {
|
|
|
|
$common_output[] = "<option value=\"$val\"".($current_severity == $name || $current_severity == $val ? ' selected' : '').">$name or higher</option>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$common_output[] = '
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group row">
|
|
|
|
<div class="col-sm-4">
|
|
|
|
<label for="state" class="control-label">State:</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-sm-8">
|
|
|
|
<select class="form-control" name="state">';
|
|
|
|
$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[] = '
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-01-21 12:51:49 -07:00
|
|
|
<div class="form-group row">
|
|
|
|
<div class="col-sm-4">
|
|
|
|
<label for="group" class="control-label">Device Group:</label>
|
|
|
|
</div>
|
|
|
|
<div class="col-sm-8">
|
|
|
|
<select class="form-control" name="group">';
|
|
|
|
$common_output[] = '<option value=""'.($current_group == '' ? ' selected' : '').'>any group</option>';
|
|
|
|
|
|
|
|
$device_groups = GetDeviceGroups();
|
|
|
|
$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[] = '
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-05-27 16:13:51 +02:00
|
|
|
<div class="form-group row">
|
|
|
|
<div class="col-sm-4">
|
2016-06-06 11:41:41 +02:00
|
|
|
<label for="proc" class="control-label">Show Procedure field: </label>
|
2016-05-27 16:13:51 +02:00
|
|
|
</div>
|
|
|
|
<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[] = '
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-01-21 12:51:49 -07:00
|
|
|
|
2016-01-20 15:23:09 -07:00
|
|
|
<div class="form-group">
|
|
|
|
<div class="col-sm-12">
|
|
|
|
<button type="submit" class="btn btn-default">Set</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$device_id = $device['device_id'];
|
|
|
|
$acknowledged = $widget_settings['acknowledged'];
|
|
|
|
$state = $widget_settings['state'];
|
|
|
|
$min_severity = $widget_settings['min_severity'];
|
2016-01-21 12:51:49 -07:00
|
|
|
$group = $widget_settings['group'];
|
2016-05-27 16:13:51 +02:00
|
|
|
$proc = $widget_settings['proc'];
|
2016-01-20 15:23:09 -07:00
|
|
|
|
2016-01-21 17:01:45 -07:00
|
|
|
$title = "Alerts";
|
2016-01-20 15:23:09 -07:00
|
|
|
|
2016-01-21 17:01:45 -07:00
|
|
|
// state can be 0 or '', be sure they are treated differently
|
|
|
|
if (is_numeric($state)) {
|
|
|
|
$state_name = array_search($state, $alert_states);
|
|
|
|
$title = "$title ($state_name)";
|
|
|
|
}
|
|
|
|
elseif ($state) {
|
|
|
|
$title = "$title ($state)";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_numeric($acknowledged)) {
|
|
|
|
if ($acknowledged == '0') {
|
|
|
|
$title = "Unacknowledged $title";
|
|
|
|
}
|
|
|
|
elseif ($acknowledged == '1') {
|
|
|
|
$title = "Acknowledged $title";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_numeric($group)) {
|
|
|
|
$group_row = dbFetchRow("SELECT * FROM device_groups WHERE id = ?", array($group));
|
|
|
|
if ($group_row) {
|
|
|
|
$title = "$title for ".$group_row['name'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($min_severity) {
|
|
|
|
$sev_name = $min_severity;
|
|
|
|
if (is_numeric($min_severity)) {
|
|
|
|
$sev_name = array_search($min_severity, $alert_severities);
|
|
|
|
$title = "$title >=$sev_name";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$widget_settings['title'] = $title;
|
|
|
|
|
|
|
|
$group = $widget_settings['group'];
|
2016-01-20 15:23:09 -07:00
|
|
|
|
|
|
|
$common_output[] = '
|
2015-07-21 23:01:57 +01:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-sm-12">
|
|
|
|
<span id="message"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
2016-02-18 17:18:30 -07:00
|
|
|
<table id="alerts_'.$unique_id.'" class="table table-hover table-condensed alerts">
|
2015-07-21 23:01:57 +01:00
|
|
|
<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="timestamp">Timestamp</th>
|
2016-06-20 14:45:10 +02:00
|
|
|
<th data-column-id="severity" data-formatter="severity">Severity</th>
|
2016-05-27 16:13:51 +02:00
|
|
|
<th data-column-id="ack" data-formatter="ack" data-sortable="false">Acknowledge</th>';
|
|
|
|
if (is_numeric($proc)) {
|
2016-06-06 11:49:50 +02:00
|
|
|
if ($proc) { $common_output[] = '<th data-column-id="proc" data-formatter="proc" data-sortable="false">Procedure</th>'; }
|
2016-05-27 16:13:51 +02:00
|
|
|
}
|
2016-06-09 15:07:02 +02:00
|
|
|
else { $common_output[] = '<th data-column-id="proc" data-formatter="proc" data-sortable="false">Procedure</th>'; }
|
2016-05-27 16:13:51 +02:00
|
|
|
$common_output[] = '
|
2015-07-21 23:01:57 +01:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
<script>
|
2016-02-18 17:18:30 -07:00
|
|
|
var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({
|
2015-07-21 23:01:57 +01:00
|
|
|
ajax: true,
|
|
|
|
post: function ()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
id: "alerts",
|
2016-01-20 15:23:09 -07:00
|
|
|
';
|
|
|
|
|
|
|
|
if (is_numeric($acknowledged)) {
|
|
|
|
$common_output[]="acknowledged: '$acknowledged',\n";
|
|
|
|
}
|
|
|
|
if (isset($state) && $state != '') {
|
|
|
|
$common_output[]="state: '$state',\n";
|
|
|
|
}
|
|
|
|
if (isset($min_severity) && $min_severity != '') {
|
|
|
|
$common_output[]="min_severity: '$min_severity',\n";
|
|
|
|
}
|
|
|
|
|
2016-01-21 12:51:49 -07:00
|
|
|
if (is_numeric($group)) {
|
|
|
|
$common_output[]="group: '$group',\n";
|
|
|
|
}
|
2016-05-27 16:13:51 +02:00
|
|
|
if (is_numeric($proc)) {
|
|
|
|
$common_output[]="proc: '$proc',\n";
|
|
|
|
}
|
2016-01-21 12:51:49 -07:00
|
|
|
|
2016-01-20 15:23:09 -07:00
|
|
|
$common_output[]='
|
2015-07-21 23:01:57 +01:00
|
|
|
device_id: \'' . $device['device_id'] .'\'
|
2016-01-20 15:23:09 -07:00
|
|
|
}
|
2015-07-21 23:01:57 +01:00
|
|
|
},
|
2015-08-11 14:54:05 -07:00
|
|
|
url: "ajax_table.php",
|
2015-07-21 23:01:57 +01:00
|
|
|
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+"\'><span class=\'glyphicon glyphicon-"+row.ack_ico+"\'aria-hidden=\'true\'></span></button>";
|
2016-05-27 16:13:51 +02:00
|
|
|
},
|
2016-06-06 11:49:50 +02:00
|
|
|
"proc": function(column,row) {
|
|
|
|
return "<button type=\'button\' class=\'btn command-open-proc\' data-alert_id=\'"+row.alert_id+"\' name=\'open-proc\' id=\'open-proc\'>Open</button>";
|
2016-06-20 14:45:10 +02:00
|
|
|
},
|
|
|
|
"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>";
|
2016-06-06 11:49:50 +02:00
|
|
|
}
|
2015-07-21 23:01:57 +01:00
|
|
|
},
|
|
|
|
templates: {
|
|
|
|
}
|
|
|
|
}).on("loaded.rs.jquery.bootgrid", function() {
|
2015-08-08 09:43:28 +00:00
|
|
|
alerts_grid.find(".incident-toggle").each( function() {
|
2015-07-21 23:01:57 +01:00
|
|
|
$(this).parent().addClass(\'incident-toggle-td\');
|
|
|
|
}).on("click", function(e) {
|
|
|
|
var target = $(this).data("target");
|
|
|
|
$(target).collapse(\'toggle\');
|
|
|
|
$(this).toggleClass(\'glyphicon-plus glyphicon-minus\');
|
|
|
|
});
|
2015-08-08 09:43:28 +00:00
|
|
|
alerts_grid.find(".incident").each( function() {
|
2015-07-21 23:01:57 +01:00
|
|
|
$(this).parent().addClass(\'col-lg-4 col-md-4 col-sm-4 col-xs-4\');
|
|
|
|
$(this).parent().parent().on("mouseenter", function() {
|
2016-05-27 16:15:59 +02:00
|
|
|
$(this).find(".incident-toggle").fadeIn(200);
|
2015-07-21 23:01:57 +01:00
|
|
|
}).on("mouseleave", function() {
|
2016-05-27 16:15:59 +02:00
|
|
|
$(this).find(".incident-toggle").fadeOut(200);
|
2015-07-21 23:01:57 +01:00
|
|
|
}).on("click", "td:not(.incident-toggle-td)", function() {
|
|
|
|
var target = $(this).parent().find(".incident-toggle").data("target");
|
|
|
|
if( $(this).parent().find(".incident-toggle").hasClass(\'glyphicon-plus\') ) {
|
|
|
|
$(this).parent().find(".incident-toggle").toggleClass(\'glyphicon-plus glyphicon-minus\');
|
|
|
|
$(target).collapse(\'toggle\');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2016-05-27 16:13:51 +02:00
|
|
|
alerts_grid.find(".command-open-proc").on("click", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var alert_id = $(this).data("alert_id");
|
2016-06-06 11:49:50 +02:00
|
|
|
$.ajax({
|
2016-05-27 16:13:51 +02:00
|
|
|
type: "POST",
|
|
|
|
url: "ajax_form.php",
|
|
|
|
data: { type: "open-proc", alert_id: alert_id },
|
|
|
|
success: function(msg){
|
2016-06-06 11:49:50 +02:00
|
|
|
if (msg != "ERROR") { window.open(msg); }
|
|
|
|
else { $("#message").html(\'<div class="alert alert-info">Procedure link does not seem to be valid, please check the rule.</div>\'); }
|
2016-05-27 16:13:51 +02:00
|
|
|
},
|
|
|
|
error: function(){
|
2016-06-06 11:41:41 +02:00
|
|
|
$("#message").html(\'<div class="alert alert-info">An error occurred opening procedure for this alert. Does the procedure link was configured ?</div>\');
|
2016-05-27 16:13:51 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-08-08 09:43:28 +00:00
|
|
|
alerts_grid.find(".command-ack-alert").on("click", function(e) {
|
2015-07-21 23:01:57 +01:00
|
|
|
e.preventDefault();
|
|
|
|
var alert_id = $(this).data("alert_id");
|
|
|
|
var state = $(this).data("state");
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2015-08-11 14:54:05 -07:00
|
|
|
url: "ajax_form.php",
|
2015-07-21 23:01:57 +01:00
|
|
|
data: { type: "ack-alert", alert_id: alert_id, state: state },
|
|
|
|
success: function(msg){
|
|
|
|
$("#message").html(\'<div class="alert alert-info">\'+msg+\'</div>\');
|
|
|
|
if(msg.indexOf("ERROR:") <= -1) {
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(){
|
|
|
|
$("#message").html(\'<div class="alert alert-info">An error occurred acking this alert.</div>\');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>';
|
2016-01-20 15:23:09 -07:00
|
|
|
}
|
2015-07-21 23:01:57 +01:00
|
|
|
|