mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Renovated Alert Rules (#11115)
* Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
This commit is contained in:
@@ -22,15 +22,23 @@ if (!is_numeric($vars['alert_id'])) {
|
|||||||
echo 'ERROR: No alert selected';
|
echo 'ERROR: No alert selected';
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
|
$alert_name = dbFetchCell('SELECT name FROM alert_rules WHERE id=?', [$vars['alert_id']]);
|
||||||
|
$alert_msg_prefix = 'Alert rule';
|
||||||
|
if ($alert_name) {
|
||||||
|
$alert_msg_prefix .= ' ' . $alert_name;
|
||||||
|
}
|
||||||
|
if (!$alert_name) {
|
||||||
|
$alert_msg_prefix .= ' id ' . $vars['alert_id'];
|
||||||
|
}
|
||||||
if (dbDelete('alert_rules', '`id` = ?', array($vars['alert_id']))) {
|
if (dbDelete('alert_rules', '`id` = ?', array($vars['alert_id']))) {
|
||||||
dbDelete('alert_device_map', 'rule_id=?', [$vars['alert_id']]);
|
dbDelete('alert_device_map', 'rule_id=?', [$vars['alert_id']]);
|
||||||
dbDelete('alert_group_map', 'rule_id=?', [$vars['alert_id']]);
|
dbDelete('alert_group_map', 'rule_id=?', [$vars['alert_id']]);
|
||||||
dbDelete('alert_transport_map', 'rule_id=?', [$vars['alert_id']]);
|
dbDelete('alert_transport_map', 'rule_id=?', [$vars['alert_id']]);
|
||||||
dbDelete('alert_template_map', 'alert_rule_id=?', [$vars['alert_id']]);
|
dbDelete('alert_template_map', 'alert_rule_id=?', [$vars['alert_id']]);
|
||||||
echo 'Alert rule has been deleted.';
|
echo $alert_msg_prefix . ' has been deleted.';
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
echo 'ERROR: Alert rule has not been deleted.';
|
echo 'ERROR: ' . $alert_msg_prefix . ' has not been deleted.';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ if (!Auth::user()->hasGlobalAdmin()) {
|
|||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||||
<button type="submit" class="btn btn-danger danger" id="alert-rule-removal" data-target="alert-rule-removal">Delete</button>
|
<button type="submit" class="btn btn-danger danger" id="alert-rule-removal" data-target="alert-rule-removal">Delete</button>
|
||||||
<input type="hidden" name="alert_id" id="alert_id" value="">
|
<input type="hidden" name="alert_id" id="alert_id" value="">
|
||||||
|
<input type="hidden" name="alert_name" id="alert_name" value="">
|
||||||
<input type="hidden" name="confirm" id="confirm" value="yes">
|
<input type="hidden" name="confirm" id="confirm" value="yes">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -43,12 +44,16 @@ if (!Auth::user()->hasGlobalAdmin()) {
|
|||||||
<script>
|
<script>
|
||||||
$('#confirm-delete').on('show.bs.modal', function(event) {
|
$('#confirm-delete').on('show.bs.modal', function(event) {
|
||||||
alert_id = $(event.relatedTarget).data('alert_id');
|
alert_id = $(event.relatedTarget).data('alert_id');
|
||||||
|
alert_name = $(event.relatedTarget).data('alert_name');
|
||||||
$("#alert_id").val(alert_id);
|
$("#alert_id").val(alert_id);
|
||||||
|
$("#alert_name").val(alert_name);
|
||||||
|
$( "p" ).first().text( 'If you would like to remove the alert rule named \''+alert_name+'\' then please click Delete.' );
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#alert-rule-removal').click('', function(event) {
|
$('#alert-rule-removal').click('', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var alert_id = $("#alert_id").val();
|
var alert_id = $("#alert_id").val();
|
||||||
|
var alert_name = $("#alert_name").val();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: 'ajax_form.php',
|
url: 'ajax_form.php',
|
||||||
@@ -56,13 +61,15 @@ $('#alert-rule-removal').click('', function(event) {
|
|||||||
dataType: "html",
|
dataType: "html",
|
||||||
success: function(msg) {
|
success: function(msg) {
|
||||||
if(msg.indexOf("ERROR:") <= -1) {
|
if(msg.indexOf("ERROR:") <= -1) {
|
||||||
$("#row_"+alert_id).remove();
|
$("#rule_id_"+alert_id).remove();
|
||||||
|
toastr.success(msg);
|
||||||
|
} else {
|
||||||
|
toastr.error(msg);
|
||||||
}
|
}
|
||||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
|
||||||
$("#confirm-delete").modal('hide');
|
$("#confirm-delete").modal('hide');
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
$("#message").html('<div class="alert alert-info">The alert rule could not be deleted.</div>');
|
toastr.error('ERROR: ajax post failed; unable to delete alert rule');
|
||||||
$("#confirm-delete").modal('hide');
|
$("#confirm-delete").modal('hide');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ if (Auth::user()->hasGlobalAdmin()) {
|
|||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div role="tabpanel" class="tab-pane active" id="main">
|
<div role="tabpanel" class="tab-pane active" id="main">
|
||||||
<div class='form-group' title="The description of this alert rule.">
|
<div class='form-group' title="The description of this alert rule.">
|
||||||
<label for='name' class='col-sm-3 col-md-2 control-label'>Rule name: </label>
|
<label for='rule_name' class='col-sm-3 col-md-2 control-label'>Rule name: </label>
|
||||||
<div class='col-sm-9 col-md-10'>
|
<div class='col-sm-9 col-md-10'>
|
||||||
<input type='text' id='name' name='name' class='form-control validation' maxlength='200' required>
|
<input type='text' id='rule_name' name='name' class='form-control validation' maxlength='200' required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -316,7 +316,7 @@ if (Auth::user()->hasGlobalAdmin()) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function loadRule(rule) {
|
function loadRule(rule) {
|
||||||
$('#name').val(rule.name);
|
$('#rule_name').val(rule.name);
|
||||||
$('#proc').val(rule.proc);
|
$('#proc').val(rule.proc);
|
||||||
$('#builder').queryBuilder("setRules", rule.builder);
|
$('#builder').queryBuilder("setRules", rule.builder);
|
||||||
$('#severity').val(rule.severity).trigger('change');
|
$('#severity').val(rule.severity).trigger('change');
|
||||||
|
|||||||
@@ -1,11 +1,38 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* print-alert-rules.inc.php
|
||||||
|
*
|
||||||
|
* LibreNMS print alert rules table
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* @package LibreNMS
|
||||||
|
* @link http://librenms.org
|
||||||
|
* @copyright 2020 The LibreNMS Community
|
||||||
|
* @author Original Author <unknown>
|
||||||
|
* @author Joseph Tingiris <joseph.tingiris@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!Auth::user()->hasGlobalAdmin()) {
|
||||||
|
die('ERROR: You need to be admin');
|
||||||
|
}
|
||||||
|
|
||||||
use LibreNMS\Alerting\QueryBuilderParser;
|
use LibreNMS\Alerting\QueryBuilderParser;
|
||||||
|
|
||||||
$no_refresh = true;
|
$no_refresh = true;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<span id="message"></span>
|
<span id="message"></span>
|
||||||
@@ -48,11 +75,13 @@ if (isset($_POST['create-default'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_once 'includes/html/modal/new_alert_rule.inc.php';
|
require_once 'includes/html/modal/new_alert_rule.inc.php';
|
||||||
require_once 'includes/html/modal/delete_alert_rule.inc.php';
|
require_once 'includes/html/modal/delete_alert_rule.inc.php'; // Also dies if !Auth::user()->hasGlobalAdmin()
|
||||||
require_once 'includes/html/modal/alert_rule_collection.inc.php';
|
require_once 'includes/html/modal/alert_rule_collection.inc.php'; // Also dies if !Auth::user()->hasGlobalAdmin()
|
||||||
?>
|
|
||||||
<form method="post" action="" id="result_form">
|
require_once 'includes/html/modal/edit_transport_group.inc.php';
|
||||||
<?php
|
require_once 'includes/html/modal/edit_alert_transport.inc.php';
|
||||||
|
|
||||||
|
echo '<form method="post" action="" id="result_form">';
|
||||||
echo csrf_field();
|
echo csrf_field();
|
||||||
if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
|
if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
|
||||||
$results = $_POST['results'];
|
$results = $_POST['results'];
|
||||||
@@ -60,27 +89,15 @@ if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
|
|||||||
$results = 50;
|
$results = 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '<div class="table-responsive">
|
echo '<div class="table-responsive">';
|
||||||
<table class="table table-hover table-condensed" width="100%">
|
echo '<div class="col pull-left">';
|
||||||
<tr>
|
|
||||||
<th>#</th>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Rule</th>
|
|
||||||
<th>Severity</th>
|
|
||||||
<th>Status</th>
|
|
||||||
<th>Extra</th>
|
|
||||||
<th>Enabled</th>
|
|
||||||
<th style="width:86px;">Action</th>
|
|
||||||
</tr>';
|
|
||||||
|
|
||||||
echo '<td colspan="7">';
|
|
||||||
if (Auth::user()->hasGlobalAdmin()) {
|
|
||||||
echo '<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#create-alert" data-device_id="'.$device['device_id'].'"><i class="fa fa-plus"></i> Create new alert rule</button>';
|
echo '<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#create-alert" data-device_id="'.$device['device_id'].'"><i class="fa fa-plus"></i> Create new alert rule</button>';
|
||||||
echo '<i> - OR - </i>';
|
echo '<i> - OR - </i>';
|
||||||
echo '<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#search_rule_modal" data-device_id="'.$device['device_id'].'"><i class="fa fa-plus"></i> Create rule from collection</button>';
|
echo '<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#search_rule_modal" data-device_id="'.$device['device_id'].'"><i class="fa fa-plus"></i> Create rule from collection</button>';
|
||||||
}
|
echo '</div>';
|
||||||
echo '</td>
|
|
||||||
<td><select name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">';
|
echo '<div class="col pull-right">';
|
||||||
|
echo '<select data-toggle="popover" data-placement="left" data-content="results per page" name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">';
|
||||||
$result_options = array(
|
$result_options = array(
|
||||||
'10',
|
'10',
|
||||||
'50',
|
'50',
|
||||||
@@ -95,11 +112,14 @@ foreach ($result_options as $option) {
|
|||||||
if ($results == $option) {
|
if ($results == $option) {
|
||||||
echo ' selected';
|
echo ' selected';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo ">$option</option>";
|
echo ">$option</option>";
|
||||||
}
|
}
|
||||||
|
echo '</select>';
|
||||||
|
echo '</div>';
|
||||||
|
|
||||||
echo '</select></td>';
|
echo '</div>';
|
||||||
|
|
||||||
|
echo '<br>';
|
||||||
|
|
||||||
$param = [];
|
$param = [];
|
||||||
if (isset($device['device_id']) && $device['device_id'] > 0) {
|
if (isset($device['device_id']) && $device['device_id'] > 0) {
|
||||||
@@ -119,7 +139,7 @@ if (isset($device['device_id']) && $device['device_id'] > 0) {
|
|||||||
$full_query = 'SELECT alert_rules.* FROM alert_rules';
|
$full_query = 'SELECT alert_rules.* FROM alert_rules';
|
||||||
}
|
}
|
||||||
|
|
||||||
$full_query .= ' ORDER BY id ASC';
|
$full_query .= ' ORDER BY name ASC';
|
||||||
|
|
||||||
$rule_list = dbFetchRows($full_query, $param);
|
$rule_list = dbFetchRows($full_query, $param);
|
||||||
$count = count($rule_list);
|
$count = count($rule_list);
|
||||||
@@ -132,6 +152,26 @@ if (isset($_POST['page_number']) && $_POST['page_number'] > 0 && $_POST['page_nu
|
|||||||
|
|
||||||
$start = (($page_number - 1) * $results);
|
$start = (($page_number - 1) * $results);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table id="alert-rules-table" class="table table-condensed table-hover table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-column-id="Type">Type<th>
|
||||||
|
<th data-column-id="Name">Name</th>
|
||||||
|
<th data-column-id="Devices">Devices<th>
|
||||||
|
<th data-column-id="Transports">Transports<th>
|
||||||
|
<th data-column-id="Extra">Extra</th>
|
||||||
|
<th data-column-id="Rule">Rule</th>
|
||||||
|
<th data-column-id="Severity">Severity</th>
|
||||||
|
<th data-column-id="Status">Status</th>
|
||||||
|
<th data-column-id="Enabled">Enabled</th>
|
||||||
|
<th data-column-id="Action" style="width:86px;">Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($rule_list as $rule) {
|
foreach ($rule_list as $rule) {
|
||||||
$index++;
|
$index++;
|
||||||
@@ -147,15 +187,19 @@ foreach ($rule_list as $rule) {
|
|||||||
$ico = 'check';
|
$ico = 'check';
|
||||||
$col = 'success';
|
$col = 'success';
|
||||||
$extra = '';
|
$extra = '';
|
||||||
|
$status_msg = '';
|
||||||
if (sizeof($sub) == 1) {
|
if (sizeof($sub) == 1) {
|
||||||
$sub = $sub[0];
|
$sub = $sub[0];
|
||||||
if ((int) $sub['state'] === 0) {
|
if ((int) $sub['state'] === 0) {
|
||||||
$ico = 'check';
|
$ico = 'check';
|
||||||
$col = 'success';
|
$col = 'success';
|
||||||
} elseif ((int) $sub['state'] === 1 || (int) $sub['state'] === 2) {
|
$status_msg = "All devices matching " . $rule['name'] . " are OK";
|
||||||
|
}
|
||||||
|
if ((int) $sub['state'] === 1 || (int) $sub['state'] === 2) {
|
||||||
$ico = 'exclamation';
|
$ico = 'exclamation';
|
||||||
$col = 'danger';
|
$col = 'danger';
|
||||||
$extra = 'danger';
|
$extra = 'danger';
|
||||||
|
$status_msg = "Some devices matching " . $rule['name'] . " are currently alerting";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +211,7 @@ foreach ($rule_list as $rule) {
|
|||||||
$ico = 'pause';
|
$ico = 'pause';
|
||||||
$col = '';
|
$col = '';
|
||||||
$extra = 'active';
|
$extra = 'active';
|
||||||
|
$status_msg = $rule['name'] . " is OFF";
|
||||||
} else {
|
} else {
|
||||||
$alert_checked = 'checked';
|
$alert_checked = 'checked';
|
||||||
}
|
}
|
||||||
@@ -175,23 +220,125 @@ foreach ($rule_list as $rule) {
|
|||||||
|
|
||||||
$device_count = dbFetchCell('SELECT COUNT(*) FROM alert_device_map WHERE rule_id=?', [$rule['id']]);
|
$device_count = dbFetchCell('SELECT COUNT(*) FROM alert_device_map WHERE rule_id=?', [$rule['id']]);
|
||||||
$group_count = dbFetchCell('SELECT COUNT(*) FROM alert_group_map WHERE rule_id=?', [$rule['id']]);
|
$group_count = dbFetchCell('SELECT COUNT(*) FROM alert_group_map WHERE rule_id=?', [$rule['id']]);
|
||||||
if ($device_count && $group_count) {
|
if ($device_count) {
|
||||||
$popover_msg = 'Restricted rule';
|
$popover_msg = 'Device restricted rule #' . $rule['id'];
|
||||||
$icon_indicator = 'fa fa-connectdevelop fa-fw text-primary';
|
|
||||||
} elseif ($device_count) {
|
|
||||||
$popover_msg = 'Device restricted rule';
|
|
||||||
$icon_indicator = 'fa fa-server fa-fw text-primary';
|
$icon_indicator = 'fa fa-server fa-fw text-primary';
|
||||||
} elseif ($group_count) {
|
}
|
||||||
$popover_msg = 'Group restricted rule';
|
if ($group_count) {
|
||||||
|
$popover_msg = 'Group restricted rule #' . $rule['id'];
|
||||||
$icon_indicator = 'fa fa-th fa-fw text-primary';
|
$icon_indicator = 'fa fa-th fa-fw text-primary';
|
||||||
} else {
|
}
|
||||||
$popover_msg = 'Global alert rule';
|
if ($device_count && $group_count) {
|
||||||
|
$popover_msg = 'Device and Group restricted rule #' . $rule['id'];
|
||||||
|
$icon_indicator = 'fa fa-connectdevelop fa-fw text-primary';
|
||||||
|
}
|
||||||
|
if (!$device_count && !$group_count) {
|
||||||
|
$popover_msg = 'Global alert rule #' . $rule['id'];
|
||||||
$icon_indicator = 'fa fa-globe fa-fw text-success';
|
$icon_indicator = 'fa fa-globe fa-fw text-success';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<tr class='".$extra."' id='row_".$rule['id']."'>";
|
echo "<tr class='".$extra."' id='rule_id_".$rule['id']."'>";
|
||||||
echo "<td><i>#".((int) $rule['id'])."</i><br /><i class=\"$icon_indicator\"></i></td>";
|
|
||||||
|
// Type
|
||||||
|
|
||||||
|
echo "<td colspan=\"2\"><div data-toggle='popover' data-placement='top' data-content=\"$popover_msg\" class=\"$icon_indicator\"></div></td>";
|
||||||
|
|
||||||
|
// Name
|
||||||
|
|
||||||
echo '<td>'.$rule['name'].'</td>';
|
echo '<td>'.$rule['name'].'</td>';
|
||||||
|
|
||||||
|
// Devices (and Groups)
|
||||||
|
|
||||||
|
if ($rule['invert_map'] == 0) {
|
||||||
|
$groups_msg = 'Only devices in this group.';
|
||||||
|
$devices_msg = 'Only this device.';
|
||||||
|
$except_device_or_group = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($rule['invert_map'] == 1) {
|
||||||
|
$devices_msg = 'All devices EXCEPT this device. ';
|
||||||
|
$groups_msg = 'All devices EXCEPT this group.';
|
||||||
|
$except_device_or_group = '<strong><em>EXCEPT</em></strong> ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$devices_and_groups_popover='right';
|
||||||
|
|
||||||
|
$groups=null;
|
||||||
|
if ($group_count) {
|
||||||
|
$group_query = 'SELECT device_groups.name, device_groups.id FROM alert_group_map, device_groups WHERE alert_group_map.rule_id=? and alert_group_map.group_id = device_groups.id ORDER BY name';
|
||||||
|
$group_maps = dbFetchRows($group_query, [$rule['id']]);
|
||||||
|
foreach ($group_maps as $group_map) {
|
||||||
|
$groups .= "$except_device_or_group<a href=\"/device-groups/" . $group_map['id'] . "/edit\" data-container='body' data-toggle='popover' data-placement='$devices_and_groups_popover' data-content='Edit device group " . $group_map['name'] . "' title='$groups_msg' target=\"_blank\">" . $group_map['name'] . "</a><br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$devices=null;
|
||||||
|
if ($device_count) {
|
||||||
|
$device_query = 'SELECT devices.device_id,devices.hostname FROM alert_device_map, devices WHERE alert_device_map.rule_id=? and alert_device_map.device_id = devices.device_id ORDER BY hostname';
|
||||||
|
$device_maps = dbFetchRows($device_query, [$rule['id']]);
|
||||||
|
foreach ($device_maps as $device_map) {
|
||||||
|
$devices .= "$except_device_or_group<a href=\"/device/device=" . $device_map['device_id'] . "/tab=edit/\" data-container='body' data-toggle='popover' data-placement='$devices_and_groups_popover' data-content='Edit device " . $device_map['hostname'] . "' title='$devices_msg' target=\"_blank\">" . $device_map['hostname'] . "</a><br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "<td colspan='2'>";
|
||||||
|
if ($groups) {
|
||||||
|
// Individual Groups first
|
||||||
|
echo $groups;
|
||||||
|
}
|
||||||
|
if ($devices) {
|
||||||
|
// Individual Devices last
|
||||||
|
echo $devices;
|
||||||
|
}
|
||||||
|
if (!$devices && !$groups) {
|
||||||
|
// All Devices
|
||||||
|
echo "<a href=\"/devices\" data-container='body' data-toggle='popover' data-placement='$devices_and_groups_popover' data-content='View All Devices' target=\"_blank\">All Devices</a><br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</td>";
|
||||||
|
|
||||||
|
// Transports
|
||||||
|
$transport_count=dbFetchCell('SELECT COUNT(*) FROM alert_transport_map WHERE rule_id=?', [$rule['id']]);
|
||||||
|
|
||||||
|
$transports_popover='right';
|
||||||
|
|
||||||
|
$transports=null;
|
||||||
|
if ($transport_count) {
|
||||||
|
$transport_maps = dbFetchRows('SELECT transport_or_group_id,target_type FROM alert_transport_map WHERE alert_transport_map.rule_id=? ORDER BY target_type', [$rule['id']]);
|
||||||
|
foreach ($transport_maps as $transport_map) {
|
||||||
|
$transport_name=null;
|
||||||
|
if ($transport_map['target_type'] == "group") {
|
||||||
|
$transport_name = dbFetchCell('SELECT transport_group_name FROM alert_transport_groups WHERE transport_group_id=?', [$transport_map['transport_or_group_id']]);
|
||||||
|
$transport_edit = "<a href='' data-toggle='modal' data-target='#edit-transport-group' data-group_id='" . $transport_map['transport_or_group_id'] . "' data-container='body' data-toggle='popover' data-placement='$transports_popover' data-content='Edit transport group $transport_name'>" . $transport_name . "</a>";
|
||||||
|
}
|
||||||
|
if ($transport_map['target_type'] == "single") {
|
||||||
|
$transport_name = dbFetchCell('SELECT transport_name FROM alert_transports WHERE transport_id=?', [$transport_map['transport_or_group_id']]);
|
||||||
|
$transport_edit = "<a href='' data-toggle='modal' data-target='#edit-alert-transport' data-transport_id='" . $transport_map['transport_or_group_id'] . "' data-container='body' data-toggle='popover' data-placement='$transports_popover' data-content='Edit transport $transport_name'>" . $transport_name . "</a>";
|
||||||
|
}
|
||||||
|
$transports .= $transport_edit . "<br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$transport_count || !$transports) {
|
||||||
|
$default_transports = dbFetchRows('SELECT transport_id, transport_name FROM alert_transports WHERE is_default=1 ORDER BY transport_name', []);
|
||||||
|
foreach ($default_transports as $default_transport) {
|
||||||
|
$transport_edit = "<a href='' data-toggle='modal' data-target='#edit-alert-transport' data-transport_id='" . $default_transport['transport_id'] . "' data-container='body' data-toggle='popover' data-placement='$transports_popover' data-content='Edit default transport " . $default_transport['transport_name'] . "'>" . $default_transport['transport_name'] . "</a>";
|
||||||
|
$transports .= $transport_edit . "<br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$transports) {
|
||||||
|
$transports = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "<td colspan='2'>$transports</td>";
|
||||||
|
|
||||||
|
// Extra
|
||||||
|
|
||||||
|
echo '<td><small>Max: '.$rule_extra['count'].'<br />Delay: '.$rule_extra['delay'].'<br />Interval: '.$rule_extra['interval'].'</small></td>';
|
||||||
|
|
||||||
|
// Rule
|
||||||
|
|
||||||
echo "<td class='col-sm-4'>";
|
echo "<td class='col-sm-4'>";
|
||||||
if ($rule_extra['invert'] === true) {
|
if ($rule_extra['invert'] === true) {
|
||||||
echo '<strong><em>Inverted</em></strong> ';
|
echo '<strong><em>Inverted</em></strong> ';
|
||||||
@@ -206,44 +353,76 @@ foreach ($rule_list as $rule) {
|
|||||||
}
|
}
|
||||||
echo '<i>'.htmlentities($rule_display).'</i></td>';
|
echo '<i>'.htmlentities($rule_display).'</i></td>';
|
||||||
|
|
||||||
echo '<td>'.$rule['severity'].'</td>';
|
// Severity
|
||||||
echo "<td><span id='alert-rule-".$rule['id']."' class='fa fa-fw fa-2x fa-".$ico.' text-'.$col."'></span> ";
|
echo '<td>'.($rule['severity'] == "ok" ? strtoupper($rule['severity']) : ucwords($rule['severity'])).'</td>';
|
||||||
|
|
||||||
|
// Status
|
||||||
|
|
||||||
|
$status_popover='top';
|
||||||
|
|
||||||
|
echo "<td><span data-toggle='popover' data-placement='$status_popover' data-content='$status_msg' id='alert-rule-".$rule['id']."' class='fa fa-fw fa-2x fa-".$ico.' text-'.$col."'></span> ";
|
||||||
if ($rule_extra['mute'] === true) {
|
if ($rule_extra['mute'] === true) {
|
||||||
echo "<i class='fa fa-fw fa-2x fa-volume-off text-primary' aria-hidden='true'></i></td>";
|
echo "<div data-toggle='popover' data-content='Alerts for " . $rule['name'] . " are muted' class='fa fa-fw fa-2x fa-volume-off text-primary' aria-hidden='true'></div></td>";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '<td><small>Max: '.$rule_extra['count'].'<br />Delay: '.$rule_extra['delay'].'<br />Interval: '.$rule_extra['interval'].'</small></td>';
|
// Enabled
|
||||||
|
|
||||||
|
$enabled_popover='top';
|
||||||
|
|
||||||
echo '<td>';
|
echo '<td>';
|
||||||
if (Auth::user()->hasGlobalAdmin()) {
|
if ($rule['disabled']) {
|
||||||
echo "<input id='".$rule['id']."' type='checkbox' name='alert-rule' data-orig_class='".$orig_class."' data-orig_colour='".$orig_col."' data-orig_state='".$orig_ico."' data-alert_id='".$rule['id']."' ".$alert_checked." data-size='small' data-content='".$popover_msg."' data-toggle='modal'>";
|
$enabled_msg = $rule['name'] . " is OFF";
|
||||||
|
}
|
||||||
|
if (!$rule['disabled']) {
|
||||||
|
$enabled_msg = $rule['name'] . " is ON";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo "<div id='on-off-checkbox-" .$rule['id']. "' data-toggle='popover' data-placement='$enabled_popover' data-content='" . $enabled_msg . "' class='btn-group btn-group-sm' role='group'>";
|
||||||
|
echo "<input id='".$rule['id']."' type='checkbox' name='alert-rule' data-orig_class='".$orig_class."' data-orig_colour='".$orig_col."' data-orig_state='".$orig_ico."' data-alert_id='".$rule['id']."' data-alert_name='".$rule['name']."' data-alert_status='". $status_msg. "' ".$alert_checked." data-size='small' data-toggle='modal'>";
|
||||||
|
echo "</div>";
|
||||||
echo '</td>';
|
echo '</td>';
|
||||||
|
|
||||||
|
// Action
|
||||||
|
|
||||||
|
$action_popover='left';
|
||||||
|
|
||||||
echo '<td>';
|
echo '<td>';
|
||||||
if (Auth::user()->hasGlobalAdmin()) {
|
|
||||||
echo "<div class='btn-group btn-group-sm' role='group'>";
|
echo "<div class='btn-group btn-group-sm' role='group'>";
|
||||||
echo "<button type='button' class='btn btn-primary' data-toggle='modal' data-target='#create-alert' data-rule_id='".$rule['id']."' name='edit-alert-rule' data-content='".$popover_msg."' data-container='body'><i class='fa fa-lg fa-pencil' aria-hidden='true'></i></button> ";
|
echo "<button type='button' class='btn btn-primary' data-toggle='modal' data-placement='$action_popover' data-target='#create-alert' data-rule_id='".$rule['id']."' name='edit-alert-rule' data-content='Edit alert rule " . $rule['name'] . "' data-container='body'><i class='fa fa-lg fa-pencil' aria-hidden='true'></i></button> ";
|
||||||
echo "<button type='button' class='btn btn-danger' aria-label='Delete' data-toggle='modal' data-target='#confirm-delete' data-alert_id='".$rule['id']."' name='delete-alert-rule' data-content='".$popover_msg."' data-container='body'><i class='fa fa-lg fa-trash' aria-hidden='true'></i></button>";
|
echo "<button type='button' class='btn btn-danger' aria-label='Delete' data-placement='$action_popover' data-toggle='modal' data-target='#confirm-delete' data-alert_id='".$rule['id']."' data-alert_name='".$rule['name']."' name='delete-alert-rule' data-content='Delete alert rule " . $rule['name'] . "' data-container='body'><i class='fa fa-lg fa-trash' aria-hidden='true'></i></button>";
|
||||||
}
|
|
||||||
|
|
||||||
echo '</td>';
|
echo '</td>';
|
||||||
|
|
||||||
echo "</tr>\r\n";
|
echo "</tr>\r\n";
|
||||||
}//end foreach
|
}//end foreach
|
||||||
|
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
// Pagination
|
||||||
|
|
||||||
if (($count % $results) > 0) {
|
if (($count % $results) > 0) {
|
||||||
echo ' <tr>
|
echo '<div class="table-responsive">';
|
||||||
<td colspan="8" align="center">'.generate_pagination($count, $results, $page_number).'</td>
|
echo '<div class="col pull-left">';
|
||||||
</tr>';
|
echo generate_pagination($count, $results, $page_number);
|
||||||
|
echo '</div>';
|
||||||
|
echo '<div class="col pull-right">';
|
||||||
|
$showing_start = ($page_number*$results)-$results+1;
|
||||||
|
$showing_end = $page_number*$results;
|
||||||
|
if ($showing_end > $count) {
|
||||||
|
$showing_end = $count;
|
||||||
|
}
|
||||||
|
echo "<p class=\"pagination\">Showing $showing_start to $showing_end of $count alert rules</p>";
|
||||||
|
echo '</div>';
|
||||||
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '</table>
|
echo '<input type="hidden" name="page_number" id="page_number" value="'.$page_number.'">
|
||||||
<input type="hidden" name="page_number" id="page_number" value="'.$page_number.'">
|
|
||||||
<input type="hidden" name="results_amount" id="results_amount" value="'.$results.'">
|
<input type="hidden" name="results_amount" id="results_amount" value="'.$results.'">
|
||||||
</form>
|
</form>';
|
||||||
</div>';
|
|
||||||
|
|
||||||
if ($count < 1) {
|
if ($count < 1) {
|
||||||
if (Auth::user()->hasGlobalAdmin()) {
|
|
||||||
echo '<div class="row">
|
echo '<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<form role="form" method="post">
|
<form role="form" method="post">
|
||||||
@@ -255,14 +434,10 @@ if ($count < 1) {
|
|||||||
</div>
|
</div>
|
||||||
</div>';
|
</div>';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
$("[data-toggle='modal'], [data-toggle='popover']").popover({
|
$("[data-toggle='modal'], [data-toggle='popover']").popover({
|
||||||
trigger: 'hover',
|
trigger: 'hover'
|
||||||
'placement': 'top'
|
|
||||||
});
|
});
|
||||||
$('#ack-alert').click('', function(e) {
|
$('#ack-alert').click('', function(e) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -290,6 +465,8 @@ $('input[name="alert-rule"]').on('switchChange.bootstrapSwitch', function(event
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var alert_id = $(this).data("alert_id");
|
var alert_id = $(this).data("alert_id");
|
||||||
|
var alert_name = $(this).data("alert_name");
|
||||||
|
var alert_status = $(this).data("alert_status");
|
||||||
var orig_state = $(this).data("orig_state");
|
var orig_state = $(this).data("orig_state");
|
||||||
var orig_colour = $(this).data("orig_colour");
|
var orig_colour = $(this).data("orig_colour");
|
||||||
var orig_class = $(this).data("orig_class");
|
var orig_class = $(this).data("orig_class");
|
||||||
@@ -305,15 +482,19 @@ $('input[name="alert-rule"]').on('switchChange.bootstrapSwitch', function(event
|
|||||||
$('#alert-rule-'+alert_id).addClass('fa-'+orig_state);
|
$('#alert-rule-'+alert_id).addClass('fa-'+orig_state);
|
||||||
$('#alert-rule-'+alert_id).removeClass('text-default');
|
$('#alert-rule-'+alert_id).removeClass('text-default');
|
||||||
$('#alert-rule-'+alert_id).addClass('text-'+orig_colour);
|
$('#alert-rule-'+alert_id).addClass('text-'+orig_colour);
|
||||||
$('#row_'+alert_id).removeClass('active');
|
$('#alert-rule-'+alert_id).attr('data-content', alert_status);
|
||||||
$('#row_'+alert_id).addClass(orig_class);
|
$('#on-off-checkbox-'+alert_id).attr('data-content', alert_name+' is ON');
|
||||||
|
$('#rule_id_'+alert_id).removeClass('active');
|
||||||
|
$('#rule_id_'+alert_id).addClass(orig_class);
|
||||||
} else {
|
} else {
|
||||||
$('#alert-rule-'+alert_id).removeClass('fa-'+orig_state);
|
$('#alert-rule-'+alert_id).removeClass('fa-'+orig_state);
|
||||||
$('#alert-rule-'+alert_id).addClass('fa-pause');
|
$('#alert-rule-'+alert_id).addClass('fa-pause');
|
||||||
$('#alert-rule-'+alert_id).removeClass('text-'+orig_colour);
|
$('#alert-rule-'+alert_id).removeClass('text-'+orig_colour);
|
||||||
$('#alert-rule-'+alert_id).addClass('text-default');
|
$('#alert-rule-'+alert_id).addClass('text-default');
|
||||||
$('#row_'+alert_id).removeClass('warning');
|
$('#alert-rule-'+alert_id).attr('data-content', alert_name+' is OFF');
|
||||||
$('#row_'+alert_id).addClass('active');
|
$('#on-off-checkbox-'+alert_id).attr('data-content', alert_name+' is OFF');
|
||||||
|
$('#rule_id_'+alert_id).removeClass('warning');
|
||||||
|
$('#rule_id_'+alert_id).addClass('active');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||||
@@ -338,5 +519,4 @@ function changePage(page,e) {
|
|||||||
$('#page_number').val(page);
|
$('#page_number').val(page);
|
||||||
$('#result_form').submit();
|
$('#result_form').submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -4,6 +4,16 @@
|
|||||||
"name": "Devices up/down",
|
"name": "Devices up/down",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"rule": "macros.device_down = \"1\" && devices.status_reason = \"icmp\"",
|
||||||
|
"name": "Device Down! Due to no ICMP response.",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rule": "macros.device_down = \"1\" && devices.status_reason = \"snmp\"",
|
||||||
|
"name": "SNMP not responding on Device - Check on SNMP Service - Device marked Down!",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"rule": "devices.uptime < \"300\" && macros.device = \"1\"",
|
"rule": "devices.uptime < \"300\" && macros.device = \"1\"",
|
||||||
"name": "Device rebooted",
|
"name": "Device rebooted",
|
||||||
|
|||||||
Reference in New Issue
Block a user