mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Alerts gui commit
This commit is contained in:
@@ -465,3 +465,33 @@ function get_port_graphs() {
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
echo _json_encode($output);
|
||||
}
|
||||
|
||||
function list_bills() {
|
||||
global $config;
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
$bill_id = $router['bill_id'];
|
||||
if(isset($_GET['custid'])) {
|
||||
$sql = "`bill_custid` = ?";
|
||||
$param = array($_GET['custid']);
|
||||
} elseif(isset($_GET['ref'])) {
|
||||
$sql = "`bill_ref` = ?";
|
||||
$param = array($_GET['ref']);
|
||||
} elseif(is_numeric($bill_id)) {
|
||||
$sql = "`bill_id` = ?";
|
||||
$param = array($bill_id);
|
||||
} else {
|
||||
$sql = "";
|
||||
$param = array();
|
||||
}
|
||||
if(count($param) >= 1) {
|
||||
$sql = "WHERE $sql";
|
||||
}
|
||||
$bills = dbFetchRows("SELECT * FROM `bills` $sql",$param);
|
||||
$total_bills = count($bills);
|
||||
$output = array("status" => "ok", "err-msg" => '', "count" => $total_bills, "bills" => $bills);
|
||||
$app->response->setStatus('200');
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
echo _json_encode($output);
|
||||
}
|
||||
|
||||
|
||||
@@ -709,4 +709,12 @@ function generate_pagination($count,$limit,$page,$links = 2) {
|
||||
return($return);
|
||||
}
|
||||
|
||||
function is_admin() {
|
||||
if ($_SESSION['userlevel'] == '10') {
|
||||
$allowed = true;
|
||||
} else {
|
||||
$allowed = false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
223
html/includes/modal/alert_template.inc.php
Normal file
223
html/includes/modal/alert_template.inc.php
Normal file
@@ -0,0 +1,223 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
if(is_admin() === false) {
|
||||
die('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal fade bs-example-modal-lg" id="alert-template" tabindex="-1" role="dialog" aria-labelledby="Create" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="Create">Alert Rules</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" role="form" id="rules" class="form alert-template-form">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<span id="response"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="template" class="control-label">Template:</label><br />
|
||||
<div class="alert alert-danger" role="alert">You can enter text for your template directly below if you're feeling brave enough :)</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="designer" class="control-label">Designer:</label><br />
|
||||
<div class="alert alert-warning" role="alert">The designer below will help you create a template - be warned, it's beta :)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" id="template" name="template" rows="15"></textarea><br /><br />
|
||||
<strong><em>Give your template a name: </em></strong><br />
|
||||
<input type="text" class="form-control input-sm" id="name" name="name"><br />
|
||||
<span id="error"></span><br />
|
||||
<button type="button" class="btn btn-primary btn-sm" name="create-template" id="create-template">Create template</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<span><strong>Controls:</strong><br />
|
||||
<?php
|
||||
$controls = array('if','endif','else','foreach', 'endforeach');
|
||||
foreach ($controls as $control) {
|
||||
echo ' <button type="button" class="btn btn-primary btn-sm" data-target="#control-add" id="control-add" name="control-add" data-type="control" data-value="'.$control.'">'.$control.'</button>';
|
||||
}
|
||||
?>
|
||||
</span><br /><br />
|
||||
<span><strong>Placeholders:</strong><br />
|
||||
<?php
|
||||
$placeholders = array('hostname','title','elapsed','id','uid','faults','state','severity','rule','timestamp','contacts','key','value','new line');
|
||||
foreach ($placeholders as $placeholder) {
|
||||
echo ' <button type="button" class="btn btn-success btn-sm" data-target="#placeholder-add" id="placeholder-add" name="placeholder-add" data-type="placeholder" data-value="'.$placeholder.'">'.$placeholder.'</button>';
|
||||
}
|
||||
?>
|
||||
</span><br /><br />
|
||||
<span><strong>Operator:</strong><br />
|
||||
<?php
|
||||
$operators = array('==','!=','>=','>','<=','<','&&','||','blank');
|
||||
foreach ($operators as $operator) {
|
||||
echo ' <button type="button" class="btn btn-warning btn-sm" data-target="#operator-add" id="operator-add" name="operator-add" data-type="operator" data-value="'.$operator.'">'.$operator.'</button>';
|
||||
}
|
||||
?>
|
||||
<br /><br />
|
||||
<small><em>Free text - press enter to add</em></small><br />
|
||||
<input type="text" class="form-control" id="value" name="value" autocomplete="off"><br /><br />
|
||||
<input type="text" class="form-control" id="line" name="line"><br /><br />
|
||||
<input type="hidden" name="template_id" id="template_id">
|
||||
<button type="button" class="btn btn-primary" id="add_line" name="add_line">Add line</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
|
||||
$('#alert-template').on('show.bs.modal', function (event) {
|
||||
var button = $(event.relatedTarget);
|
||||
var template_id = button.data('template_id');
|
||||
var action = button.data('template_action');
|
||||
$('#line').val('');
|
||||
$('#value').val('');
|
||||
if(action == 'edit') {
|
||||
$('#template_id').val(template_id);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/ajax_form.php",
|
||||
data: { type: "parse-alert-template", template_id: template_id },
|
||||
dataType: "json",
|
||||
success: function(output) {
|
||||
$('#template').append(output['template']);
|
||||
$('#name').val(output['name']);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#create-template').click('', function(e) {
|
||||
e.preventDefault();
|
||||
var template = $("#template").val();
|
||||
var template_id = $("#template_id").val();
|
||||
var name = $("#name").val();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/ajax_form.php",
|
||||
data: { type: "alert-templates", template: template , name: name, template_id: template_id},
|
||||
dataType: "html",
|
||||
success: function(msg){
|
||||
if(msg.indexOf("ERROR:") <= -1) {
|
||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
$("#alert-template").modal('hide');
|
||||
setTimeout(function() {
|
||||
location.reload(1);
|
||||
}, 1000);
|
||||
} else {
|
||||
$("#error").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#error").html('<div class="alert alert-info">An error occurred updating this alert template.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#add_line').click('', function(e) {
|
||||
e.preventDefault();
|
||||
var line = $('#line').val();
|
||||
$('#template').append(line + '\r\n');
|
||||
$('#line').val('');
|
||||
});
|
||||
|
||||
$('button[name="control-add"],button[name="placeholder-add"],button[name="operator-add"]').click('', function(e) {
|
||||
event.preventDefault();
|
||||
var type = $(this).data("type");
|
||||
var value = $(this).data("value");
|
||||
var line = $('#line').val();
|
||||
var new_line = '';
|
||||
if(type == 'control') {
|
||||
$('button[name="control-add"]').prop('disabled',true);
|
||||
if(value == 'if') {
|
||||
new_line = '{if ';
|
||||
} else if(value == 'endif') {
|
||||
new_line = '{/if}';
|
||||
$('button[name="control-add"]').prop('disabled',false);
|
||||
} else if(value == 'else') {
|
||||
new_line = ' {else} ';
|
||||
} else if(value == 'foreach') {
|
||||
new_line = '{foreach ';
|
||||
} else if(value == 'endforeach') {
|
||||
new_line = '{/foreach} ';
|
||||
$('button[name="control-add"]').prop('disabled',false);
|
||||
}
|
||||
} else if(type == 'placeholder') {
|
||||
if($('button[name="control-add"]').prop('disabled') === true) {
|
||||
$('button[name="placeholder-add"]').prop('disabled',true);
|
||||
}
|
||||
if(value == 'new line') {
|
||||
new_line = '\\r\\n ';
|
||||
} else {
|
||||
new_line = '%'+value+' ';
|
||||
}
|
||||
if(value == 'key' || value == 'value' || value == 'new line') {
|
||||
$('button[name="placeholder-add"]').prop('disabled',false);
|
||||
}
|
||||
} else if(type == 'operator') {
|
||||
if(value == 'blank') {
|
||||
$('button[name="control-add"]').prop('disabled',false);
|
||||
$('button[name="placeholder-add"]').prop('disabled',false);
|
||||
new_line = '}';
|
||||
} else {
|
||||
$('button[name="operator-add"]').prop('disabled',true);
|
||||
new_line = value+' ';
|
||||
}
|
||||
}
|
||||
$('#line').val(line + new_line);
|
||||
$('#valuee').focus();
|
||||
});
|
||||
|
||||
$('#value').keypress(function (e) {
|
||||
if(e.which == 13) {
|
||||
updateLine($('#value').val());
|
||||
$('#value').val('');
|
||||
}
|
||||
});
|
||||
|
||||
function updateLine(value) {
|
||||
var line = $('#line').val();
|
||||
//$('#value').prop('disabled',true);
|
||||
if($('button[name="placeholder-add"]').prop('disabled') === true) {
|
||||
value = '"'+value+'" } ';
|
||||
//$('#value').prop('disabled',false);
|
||||
} else {
|
||||
value = value + ' ';
|
||||
}
|
||||
$('#line').val(line + value);
|
||||
$('button[name="control-add"]').prop('disabled',false);
|
||||
$('button[name="placeholder-add"]').prop('disabled',false);
|
||||
$('button[name="operator-add"]').prop('disabled',false);
|
||||
}
|
||||
|
||||
</script>
|
||||
102
html/includes/modal/attach_alert_template.inc.php
Normal file
102
html/includes/modal/attach_alert_template.inc.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
if(is_admin() === false) {
|
||||
die('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal fade" id="attach-alert-template" tabindex="-1" role="dialog" aria-labelledby="Attach" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h5 class="modal-title" id="Attach">Attach template to rules...</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Please select the rules that you would like to assign this template to.</p>
|
||||
<form class="form-group">
|
||||
<div class="form-group">
|
||||
<label for="rules_list">Select rules</label>
|
||||
<select multiple="multiple" class="form-control" id="rules_list" name="rules_list" size="10">
|
||||
<option></option>
|
||||
<?php
|
||||
|
||||
foreach(dbFetchRows("SELECT `id`,`rule` FROM `alert_rules` where `disabled` = 0", array()) as $rule) {
|
||||
echo '<option value="'.$rule['id'].'">'.$rule['rule'].'</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
<span id="template_error"></span><br />
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<form role="form" class="attach_rule_form">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-danger danger" id="alert-template-attach" data-target="alert-template-attach">Attach</button>
|
||||
<input type="hidden" name="template_id" id="template_id" value="">
|
||||
<input type="hidden" name="confirm" id="confirm" value="yes">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$('#attach-alert-template').on('show.bs.modal', function(e) {
|
||||
event.preventDefault();
|
||||
template_id = $(e.relatedTarget).data('template_id');
|
||||
$("#template_id").val(template_id);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/ajax_form.php",
|
||||
data: { type: "parse-template-rules", template_id: template_id },
|
||||
dataType: "json",
|
||||
success: function(output) {
|
||||
arr = [];
|
||||
$.each( output.rule_id, function( i, elem) {
|
||||
$('#rules_list option[value='+elem+']').attr("selected", true);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#alert-template-attach').click('', function(event) {
|
||||
event.preventDefault();
|
||||
var template_id = $("#template_id").val();
|
||||
var items = [];
|
||||
$('#rules_list :selected').each(function(i, selectedElement) {
|
||||
items.push($(selectedElement).val());
|
||||
});
|
||||
var rules = items.join(', ');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: { type: "attach-alert-template", template_id: template_id, rule_id: rules },
|
||||
dataType: "html",
|
||||
success: function(msg) {
|
||||
if(msg.indexOf("ERROR:") <= -1) {
|
||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
$("#attach-alert-template").modal('hide');
|
||||
} else {
|
||||
$('#template_error').html('<div class="alert alert-info">'+msg+'</div>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$("#template_error").html('<div class="alert alert-info">The alert rules could not be attached to this template.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
70
html/includes/modal/delete_alert_rule.inc.php
Normal file
70
html/includes/modal/delete_alert_rule.inc.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
if(is_admin() === false) {
|
||||
die('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="Delete" aria-hidden="true">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h5 class="modal-title" id="Delete">Confirm Delete</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>If you would like to remove the alert rule then please click Delete.</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<form role="form" class="remove_token_form">
|
||||
<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>
|
||||
<input type="hidden" name="alert_id" id="alert_id" value="">
|
||||
<input type="hidden" name="confirm" id="confirm" value="yes">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$('#confirm-delete').on('show.bs.modal', function(e) {
|
||||
event.preventDefault();
|
||||
alert_id = $(e.relatedTarget).data('alert_id');
|
||||
$("#alert_id").val(alert_id);
|
||||
});
|
||||
|
||||
$('#alert-rule-removal').click('', function(event) {
|
||||
event.preventDefault();
|
||||
var alert_id = $("#alert_id").val();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: { type: "delete-alert-rule", alert_id: alert_id },
|
||||
dataType: "html",
|
||||
success: function(msg) {
|
||||
if(msg.indexOf("ERROR:") <= -1) {
|
||||
$("#row_"+alert_id).remove();
|
||||
}
|
||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
$("#confirm-delete").modal('hide');
|
||||
},
|
||||
error: function() {
|
||||
$("#message").html('<div class="alert alert-info">The alert rule could not be deleted.</div>');
|
||||
$("#confirm-delete").modal('hide');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
70
html/includes/modal/delete_alert_template.inc.php
Normal file
70
html/includes/modal/delete_alert_template.inc.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
if(is_admin() === false) {
|
||||
die('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal fade" id="confirm-delete-alert-template" tabindex="-1" role="dialog" aria-labelledby="Delete" aria-hidden="true">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h5 class="modal-title" id="Delete">Confirm Delete</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>If you would like to remove the alert template then please click Delete.</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<form role="form" class="remove_alert_templet_form">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-danger danger" id="alert-template-removal" data-target="alert-template-removal">Delete</button>
|
||||
<input type="hidden" name="template_id" id="template_id" value="">
|
||||
<input type="hidden" name="confirm" id="confirm" value="yes">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$('#confirm-delete-alert-template').on('show.bs.modal', function(e) {
|
||||
event.preventDefault();
|
||||
template_id = $(e.relatedTarget).data('template_id');
|
||||
$("#template_id").val(template_id);
|
||||
});
|
||||
|
||||
$('#alert-template-removal').click('', function(event) {
|
||||
event.preventDefault();
|
||||
var template_id = $("#template_id").val();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: { type: "delete-alert-template", template_id: template_id },
|
||||
dataType: "html",
|
||||
success: function(msg) {
|
||||
if(msg.indexOf("ERROR:") <= -1) {
|
||||
$("#row_"+template_id).remove();
|
||||
}
|
||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
$("#confirm-delete-alert-template").modal('hide');
|
||||
},
|
||||
error: function() {
|
||||
$("#message").html('<div class="alert alert-info">The alert template could not be deleted.</div>');
|
||||
$("#confirm-delete-alert-template").modal('hide');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
211
html/includes/modal/new_alert_rule.inc.php
Normal file
211
html/includes/modal/new_alert_rule.inc.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
if(is_admin() === false) {
|
||||
die('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal fade bs-example-modal-sm" id="create-alert" tabindex="-1" role="dialog" aria-labelledby="Create" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h5 class="modal-title" id="Create">Alert Rules</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" role="form" id="rules" class="form-horizontal alerts-form">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<span id="response"></span>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="device_id" id="device_id" value="">
|
||||
<input type="hidden" name="alert_id" id="alert_id" value="">
|
||||
<input type="hidden" name="type" id="type" value="create-alert-item">
|
||||
<div class="form-group">
|
||||
<label for='entity' class='col-sm-3 control-label'>Entity: </label>
|
||||
<div class="col-sm-5">
|
||||
<input type='text' id='suggest' name='entity' class='form-control' placeholder='I.e: devices.status'/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-9">
|
||||
<p>Start typing for suggestions, use '.' for indepth selection</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for='condition' class='col-sm-3 control-label'>Condition: </label>
|
||||
<div class="col-sm-5">
|
||||
<select id='condition' name='condition' placeholder='Condition' class='form-control'>
|
||||
<option value='='>Equals</option>
|
||||
<option value='!='>Not Equals</option>
|
||||
<option value='~'>Like</option>
|
||||
<option value='!~'>Not Like</option>
|
||||
<option value='>'>Larger than</option>
|
||||
<option value='>='>Larger than or Equals</option>
|
||||
<option value='<'>Smaller than</option>
|
||||
<option value='<='>Smaller than or Equals</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for='value' class='col-sm-3 control-label'>Value: </label>
|
||||
<div class="col-sm-5">
|
||||
<input type='text' id='value' name='value' class='form-control'/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for='rule-glue' class='col-sm-3 control-label'>Connection: </label>
|
||||
<div class="col-sm-5">
|
||||
<button class="btn btn-default btn-sm" type="submit" name="rule-glue" value="&&" id="and" name="and">And</button>
|
||||
<button class="btn btn-default btn-sm" type="submit" name="rule-glue" value="||" id="or" name="or">Or</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for='severity' class='col-sm-3 control-label'>Severity: </label>
|
||||
<div class="col-sm-5">
|
||||
<select name='severity' id='severity' placeholder='Severity' class='form-control'>
|
||||
<option value='ok'>OK</option>
|
||||
<option value='warning'>Warning</option>
|
||||
<option value='critical' selected>Critical</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for='count' class='col-sm-3 control-label'>Max alerts: </label>
|
||||
<div class='col-sm-2'>
|
||||
<input type='text' id='count' name='count' class='form-control'>
|
||||
</div>
|
||||
<label for='delay' class='col-sm-3 control-label'>Alert delay: </label>
|
||||
<div class='col-sm-2'>
|
||||
<input type='text' id='delay' name='delay' class='form-control'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='mute' class='col-sm-3 control-label'>Mute alerts: </label>
|
||||
<div class='col-sm-2'>
|
||||
<input type="checkbox" name="mute" id="mute">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-3">
|
||||
<button class="btn btn-default btn-sm" type="submit" name="rule-submit" id="rule-submit" value="save">Save Rule</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
$("[name='mute']").bootstrapSwitch('offColor','danger');
|
||||
|
||||
$('#create-alert').on('show.bs.modal', function (event) {
|
||||
var button = $(event.relatedTarget);
|
||||
var device_id = button.data('device_id');
|
||||
var alert_id = button.data('alert_id');
|
||||
var modal = $(this)
|
||||
$('#device_id').val(device_id);
|
||||
$('#alert_id').val(alert_id);
|
||||
$('#response').tagmanager({
|
||||
strategy: 'array',
|
||||
tagFieldName: 'rules[]'
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/ajax_form.php",
|
||||
data: { type: "parse-alert-rule", alert_id: alert_id },
|
||||
dataType: "json",
|
||||
success: function(output) {
|
||||
var arr = [];
|
||||
for (elem in output['rules']) {
|
||||
arr.push(output['rules'][elem]);
|
||||
}
|
||||
$('#response').data('tagmanager').populate(arr);
|
||||
$('#severity').val(output['severity']).change;
|
||||
var extra = $.parseJSON(output['extra']);
|
||||
$('#count').val(extra['count']);
|
||||
if((extra['delay'] / 86400) >= 1) {
|
||||
var delay = extra['delay'] / 86400 + ' d';
|
||||
} else if((extra['delay'] / 3600) >= 1) {
|
||||
var delay = extra['delay'] / 3600 + ' h';
|
||||
} else if((extra['delay'] / 60) >= 1) {
|
||||
var delay = extra['delay'] / 60 + ' m';
|
||||
} else {
|
||||
var delay = extra['delay'];
|
||||
}
|
||||
$('#delay').val(delay);
|
||||
if(extra['mute']) {
|
||||
$('#mute').click();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
var cache = {};
|
||||
$('#suggest').typeahead([
|
||||
{
|
||||
name: 'suggestion',
|
||||
remote : '/ajax_rulesuggest.php?device_id=<?php echo $device['device_id'];?>&term=%QUERY',
|
||||
template: '{{name}}',
|
||||
valueKey:"name",
|
||||
engine: Hogan
|
||||
}
|
||||
]);
|
||||
|
||||
$('#and, #or').click('', function(e) {
|
||||
e.preventDefault();
|
||||
var entity = $('#suggest').val();
|
||||
var condition = $('#condition').val();
|
||||
var value = $('#value').val();
|
||||
var glue = $(this).val();
|
||||
if(entity != '' && condition != '') {
|
||||
$('#response').tagmanager({
|
||||
strategy: 'array',
|
||||
tagFieldName: 'rules[]'
|
||||
});
|
||||
$('#response').data('tagmanager').populate([ '%'+entity+' '+condition+' "'+value+'" '+glue ]);
|
||||
}
|
||||
});
|
||||
|
||||
$('#rule-submit').click('', function(e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/ajax_form.php",
|
||||
data: $('form.alerts-form').serialize(),
|
||||
success: function(msg){
|
||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
$("#create-alert").modal('hide');
|
||||
if(msg.indexOf("ERROR:") <= -1) {
|
||||
$('#response').data('tagmanager').empty();
|
||||
setTimeout(function() {
|
||||
location.reload(1);
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">An error occurred creating this alert.</div>');
|
||||
$("#create-alert").modal('hide');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
208
html/includes/print-alert-rules.php
Normal file
208
html/includes/print-alert-rules.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<span id="message"></span>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
require_once('includes/modal/new_alert_rule.inc.php');
|
||||
require_once('includes/modal/delete_alert_rule.inc.php');
|
||||
|
||||
?>
|
||||
<form method="post" action="" id="result_form">
|
||||
<?php
|
||||
|
||||
if(isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
|
||||
$results = $_POST['results'];
|
||||
} else {
|
||||
$results = 50;
|
||||
}
|
||||
|
||||
echo '<div class="table-responsive">
|
||||
<table class="table table-hover table-condensed" width="100%">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Rule</th>
|
||||
<th>Severity</th>
|
||||
<th>Status</th>
|
||||
<th>Extra</th>
|
||||
<th>Enabled</th>
|
||||
<th>Action</th>
|
||||
</tr>';
|
||||
|
||||
echo ('<td colspan="6">');
|
||||
if ($_SESSION['userlevel'] == '10') {
|
||||
echo('<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#create-alert" data-device_id="'. $device['device_id'] .'">Create new alert rule</button>');
|
||||
}
|
||||
echo ('</td>
|
||||
<td><select name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">');
|
||||
$result_options = array('10','50','100','250','500','1000','5000');
|
||||
foreach($result_options as $option) {
|
||||
echo "<option value='$option'";
|
||||
if($results == $option) {
|
||||
echo " selected";
|
||||
}
|
||||
echo ">$option</option>";
|
||||
}
|
||||
echo('</select></td>');
|
||||
|
||||
$rulei=1;
|
||||
$count_query = "SELECT COUNT(id)";
|
||||
$full_query = "SELECT *";
|
||||
if(isset($device['device_id']) && $device['device_id'] > 0) {
|
||||
$sql = 'WHERE (device_id=? OR device_id="-1")';
|
||||
$param = array($device['device_id']);
|
||||
}
|
||||
$query = " FROM alert_rules $sql ORDER BY device_id,id";
|
||||
$count_query = $count_query . $query;
|
||||
$count = dbFetchCell($count_query,$param);
|
||||
if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) {
|
||||
$page_number = 1;
|
||||
} else {
|
||||
$page_number = $_POST['page_number'];
|
||||
}
|
||||
$start = ($page_number - 1) * $results;
|
||||
$full_query = $full_query . $query . " LIMIT $start,$results";
|
||||
|
||||
foreach( dbFetchRows($full_query, $param) as $rule ) {
|
||||
$sub = dbFetchRows("SELECT * FROM alerts WHERE rule_id = ? ORDER BY id DESC LIMIT 1", array($rule['id']));
|
||||
$ico = "ok";
|
||||
$col = "success";
|
||||
$extra = "";
|
||||
if( sizeof($sub) == 1 ) {
|
||||
$sub = $sub[0];
|
||||
if( (int) $sub['state'] === 0 ) {
|
||||
$ico = "ok";
|
||||
$col = "success";
|
||||
} elseif( (int) $sub['state'] === 1 ) {
|
||||
$ico = "remove";
|
||||
$col = "danger";
|
||||
$extra = "danger";
|
||||
} elseif( (int) $sub['state'] === 2 ) {
|
||||
$ico = "time";
|
||||
$col = "default";
|
||||
$extra = "warning";
|
||||
}
|
||||
}
|
||||
$alert_checked = '';
|
||||
$orig_ico = $ico;
|
||||
$orig_col = $col;
|
||||
$orig_class = $extra;
|
||||
if( $rule['disabled'] ) {
|
||||
$ico = "pause";
|
||||
$col = "";
|
||||
$extra = "active";
|
||||
} else {
|
||||
$alert_checked = 'checked';
|
||||
}
|
||||
$rule_extra = json_decode($rule['extra'],TRUE);
|
||||
echo "<tr class='".$extra."' id='row_".$rule['id']."'>";
|
||||
echo "<td><i>#".((int) $rulei++)."</i></td>";
|
||||
echo "<td><i>".htmlentities($rule['rule'])."</i></td>";
|
||||
echo "<td>".$rule['severity']."</td>";
|
||||
echo "<td><span id='alert-rule-".$rule['id']."' class='glyphicon glyphicon-".$ico." glyphicon-large text-".$col."'></span> ";
|
||||
if($rule_extra['mute'] === true) {
|
||||
echo "<span class='glyphicon glyphicon-volume-off glyphicon-large text-primary' aria-hidden='true'></span></td>";
|
||||
}
|
||||
echo "<td><small>Max: ".$rule_extra['count']."<br />Delay: ".$rule_extra['delay']."</small></td>";
|
||||
echo "<td>";
|
||||
if ($_SESSION['userlevel'] == '10') {
|
||||
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'>";
|
||||
}
|
||||
echo "</td>";
|
||||
echo "<td>";
|
||||
if ($_SESSION['userlevel'] == '10') {
|
||||
echo "<button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#create-alert' data-device_id='".$rule['device_id']."' data-alert_id='".$rule['id']."' name='edit-alert-rule'><span class='glyphicon glyphicon-pencil' aria-hidden='true'></span></button> ";
|
||||
echo "<button type='button' class='btn btn-danger btn-sm' aria-label='Delete' data-toggle='modal' data-target='#confirm-delete' data-alert_id='".$rule['id']."' name='delete-alert-rule'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></button>";
|
||||
}
|
||||
echo "</td>";
|
||||
echo "</tr>\r\n";
|
||||
}
|
||||
if($count % $results > 0) {
|
||||
echo(' <tr>
|
||||
<td colspan="7" align="center">'. generate_pagination($count,$results,$page_number) .'</td>
|
||||
</tr>');
|
||||
}
|
||||
echo '</table>
|
||||
<input type="hidden" name="page_number" id="page_number" value="'.$page_number.'">
|
||||
<input type="hidden" name="results_amount" id="results_amount" value="'.$results.'">
|
||||
</form>
|
||||
</div>';
|
||||
?>
|
||||
|
||||
<script>
|
||||
$('#ack-alert').click('', function(e) {
|
||||
event.preventDefault();
|
||||
var alert_id = $(this).data("alert_id");
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/ajax_form.php",
|
||||
data: { type: "ack-alert", alert_id: alert_id },
|
||||
success: function(msg){
|
||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
if(msg.indexOf("ERROR:") <= -1) {
|
||||
setTimeout(function() {
|
||||
location.reload(1);
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">An error occurred acking this alert.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("[name='alert-rule']").bootstrapSwitch('offColor','danger');
|
||||
$('input[name="alert-rule"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||
event.preventDefault();
|
||||
var $this = $(this);
|
||||
var alert_id = $(this).data("alert_id");
|
||||
var orig_state = $(this).data("orig_state");
|
||||
var orig_colour = $(this).data("orig_colour");
|
||||
var orig_class = $(this).data("orig_class");
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: { type: "update-alert-rule", alert_id: alert_id, state: state },
|
||||
dataType: "html",
|
||||
success: function(msg) {
|
||||
if(msg.indexOf("ERROR:") <= -1) {
|
||||
if(state) {
|
||||
$('#alert-rule-'+alert_id).removeClass('glyphicon-pause');
|
||||
$('#alert-rule-'+alert_id).addClass('glyphicon-'+orig_state);
|
||||
$('#alert-rule-'+alert_id).removeClass('text-default');
|
||||
$('#alert-rule-'+alert_id).addClass('text-'+orig_colour);
|
||||
$('#row_'+alert_id).removeClass('active');
|
||||
$('#row_'+alert_id).addClass(orig_class);
|
||||
} else {
|
||||
$('#alert-rule-'+alert_id).removeClass('glyphicon-'+orig_state);
|
||||
$('#alert-rule-'+alert_id).addClass('glyphicon-pause');
|
||||
$('#alert-rule-'+alert_id).removeClass('text-'+orig_colour);
|
||||
$('#alert-rule-'+alert_id).addClass('text-default');
|
||||
$('#row_'+alert_id).removeClass('warning');
|
||||
$('#row_'+alert_id).addClass('active');
|
||||
}
|
||||
} else {
|
||||
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
|
||||
$('#'+alert_id).bootstrapSwitch('toggleState',true );
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$("#message").html('<div class="alert alert-info">This alert could not be updated.</div>');
|
||||
$('#'+alert_id).bootstrapSwitch('toggleState',true );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function updateResults(results) {
|
||||
$('#results_amount').val(results.value);
|
||||
$('#page_number').val(1);
|
||||
$('#result_form').submit();
|
||||
}
|
||||
|
||||
function changePage(page,e) {
|
||||
e.preventDefault();
|
||||
$('#page_number').val(page);
|
||||
$('#result_form').submit();
|
||||
}
|
||||
</script>
|
||||
84
html/includes/print-alert-templates.php
Normal file
84
html/includes/print-alert-templates.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<span id="message"></span>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
require_once('includes/modal/alert_template.inc.php');
|
||||
require_once('includes/modal/delete_alert_template.inc.php');
|
||||
require_once('includes/modal/attach_alert_template.inc.php');
|
||||
?>
|
||||
|
||||
<form method="post" action="" id="result_form">
|
||||
<?php
|
||||
|
||||
if(isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
|
||||
$results = $_POST['results'];
|
||||
} else {
|
||||
$results = 50;
|
||||
}
|
||||
|
||||
echo '<div class="table-responsive">
|
||||
<table class="table table-hover table-condensed" width="100%">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>';
|
||||
|
||||
if ($_SESSION['userlevel'] == '10') {
|
||||
echo('<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#alert-template">Create new alert template</button>');
|
||||
}
|
||||
|
||||
echo '</td>
|
||||
<td><select name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">';
|
||||
$result_options = array('10','50','100','250','500','1000','5000');
|
||||
foreach($result_options as $option) {
|
||||
echo "<option value='$option'";
|
||||
if($results == $option) {
|
||||
echo " selected";
|
||||
}
|
||||
echo ">$option</option>";
|
||||
}
|
||||
echo('</select></td>');
|
||||
|
||||
$count_query = "SELECT COUNT(id)";
|
||||
$full_query = "SELECT *";
|
||||
|
||||
$query = " FROM `alert_templates`";
|
||||
|
||||
$count_query = $count_query . $query;
|
||||
$count = dbFetchCell($count_query,$param);
|
||||
if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) {
|
||||
$page_number = 1;
|
||||
} else {
|
||||
$page_number = $_POST['page_number'];
|
||||
}
|
||||
$start = ($page_number - 1) * $results;
|
||||
$full_query = $full_query . $query . " LIMIT $start,$results";
|
||||
|
||||
foreach( dbFetchRows($full_query, $param) as $template ) {
|
||||
echo '<tr id="row_'.$template['id'].'">
|
||||
<td>'.$template['name'].'</td>
|
||||
<td>';
|
||||
if ($_SESSION['userlevel'] == '10') {
|
||||
echo "<button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#alert-template' data-template_id='".$template['id']."' data-template_action='edit' name='edit-alert-template'><span class='glyphicon glyphicon-pencil' aria-hidden='true'></span></button> ";
|
||||
echo "<button type='button' class='btn btn-danger btn-sm' data-toggle='modal' data-target='#confirm-delete-alert-template' data-template_id='".$template['id']."' name='delete-alert-template'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></button> ";
|
||||
echo "<button type='button' class='btn btn-warning btn-sm' data-toggle='modal' data-target='#attach-alert-template' data-template_id='".$template['id']."' name='attach-alert-template'><span class='glyphicon glyphicon-th-list' aria-hidden='true'></span></button>";
|
||||
}
|
||||
echo ' </td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
if($count % $results > 0) {
|
||||
echo(' <tr>
|
||||
<td colspan="2" align="center">'. generate_pagination($count,$results,$page_number) .'</td>
|
||||
</tr>');
|
||||
}
|
||||
|
||||
echo '</table>
|
||||
<input type="hidden" name="page_number" id="page_number" value="'.$page_number.'">
|
||||
<input type="hidden" name="results_amount" id="results_amount" value="'.$results.'">
|
||||
</form>
|
||||
</div>';
|
||||
142
html/includes/print-alerts.php
Normal file
142
html/includes/print-alerts.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<span id="message"></span>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
require_once('includes/modal/new_alert_rule.inc.php');
|
||||
?>
|
||||
<form method="post" action="" id="result_form">
|
||||
<?php
|
||||
|
||||
if(isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
|
||||
$results = $_POST['results'];
|
||||
} else {
|
||||
$results = 50;
|
||||
}
|
||||
|
||||
echo '<div class="table-responsive">
|
||||
<table class="table table-hover table-condensed" width="100%">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Rule</th>
|
||||
<th>Hostname</th>
|
||||
<th>Timestamp</th>
|
||||
<th>Severity</th>
|
||||
<th>Status</th>
|
||||
<th>Acknowledge</th>
|
||||
</tr>';
|
||||
|
||||
echo ('<td colspan="6">');
|
||||
if ($_SESSION['userlevel'] == '10') {
|
||||
echo('<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#create-alert" data-device_id="'. $device['device_id'] .'">Create new alert rule</button>');
|
||||
}
|
||||
echo ('</td>
|
||||
<td><select name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">');
|
||||
$result_options = array('10','50','100','250','500','1000','5000');
|
||||
foreach($result_options as $option) {
|
||||
echo "<option value='$option'";
|
||||
if($results == $option) {
|
||||
echo " selected";
|
||||
}
|
||||
echo ">$option</option>";
|
||||
}
|
||||
echo('</select></td>');
|
||||
|
||||
$rulei=1;
|
||||
$count_query = "SELECT COUNT(alerts.id)";
|
||||
$full_query = "SELECT alerts.*, devices.hostname";
|
||||
if(isset($device['device_id']) && $device['device_id'] > 0) {
|
||||
$sql = 'AND `alerts`.`device_id`=?';
|
||||
$param = array($device['device_id']);
|
||||
}
|
||||
$query = " FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id` RIGHT JOIN alert_rules ON alerts.rule_id=alert_rules.id WHERE `state`= 1 $sql ORDER BY `alerts`.`timestamp` DESC";
|
||||
$count_query = $count_query . $query;
|
||||
$count = dbFetchCell($count_query,$param);
|
||||
if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) {
|
||||
$page_number = 1;
|
||||
} else {
|
||||
$page_number = $_POST['page_number'];
|
||||
}
|
||||
$start = ($page_number - 1) * $results;
|
||||
$full_query = $full_query . $query . " LIMIT $start,$results";
|
||||
|
||||
foreach( dbFetchRows($full_query, $param) as $alert ) {
|
||||
$rule = dbFetchRow("SELECT * FROM alert_rules WHERE id = ? LIMIT 1", array($alert['rule_id']));
|
||||
$ico = "ok";
|
||||
$col = "green";
|
||||
$extra = "";
|
||||
if( (int) $alert['state'] === 0 ) {
|
||||
$ico = "ok";
|
||||
$col = "green";
|
||||
} elseif( (int) $alert['state'] === 1 ) {
|
||||
$ico = "remove";
|
||||
$col = "red";
|
||||
$extra = "danger";
|
||||
} elseif( (int) $alert['state'] === 2 ) {
|
||||
$ico = "time";
|
||||
$col = "#800080";
|
||||
$extra = "warning";
|
||||
}
|
||||
$alert_checked = '';
|
||||
$orig_ico = $ico;
|
||||
$orig_col = $col;
|
||||
$orig_class = $extra;
|
||||
echo "<tr class='".$extra."' id='row_".$alert['id']."'>";
|
||||
echo "<td><i>#".((int) $rulei++)."</i></td>";
|
||||
echo "<td><i>".htmlentities($rule['rule'])."</i></td>";
|
||||
echo "<td>".$alert['hostname']."</td>";
|
||||
echo "<td>".($alert['timestamp'] ? $alert['timestamp'] : "N/A")."</td>";
|
||||
echo "<td>".$rule['severity']."</td>";
|
||||
echo "<td><i id='alert-rule-".$rule['id']."' class='glyphicon glyphicon-".$ico."' style='color:".$col."; font-size: 24px;' > </i></td>";
|
||||
echo "<td>";
|
||||
if ($_SESSION['userlevel'] == '10') {
|
||||
echo "<button type='button' class='btn btn-warning btn-sm' data-target='#ack-alert' data-alert_id='".$alert['id']."' name='ack-alert' id='ack-alert'><span class='glyphicon glyphicon-volume-off' aria-hidden='true'></span></button>";
|
||||
}
|
||||
echo "</td>";
|
||||
echo "</tr>\r\n";
|
||||
}
|
||||
if($count % $results > 0) {
|
||||
echo(' <tr>
|
||||
<td colspan="7" align="center">'. generate_pagination($count,$results,$page_number) .'</td>
|
||||
</tr>');
|
||||
}
|
||||
echo '</table>
|
||||
<input type="hidden" name="page_number" id="page_number" value="'.$page_number.'">
|
||||
<input type="hidden" name="results_amount" id="results_amount" value="'.$results.'">
|
||||
</form>
|
||||
</div>';
|
||||
?>
|
||||
|
||||
<script>
|
||||
$('#ack-alert').click('', function(e) {
|
||||
event.preventDefault();
|
||||
var alert_id = $(this).data("alert_id");
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/ajax_form.php",
|
||||
data: { type: "ack-alert", alert_id: alert_id },
|
||||
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>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function updateResults(results) {
|
||||
$('#results_amount').val(results.value);
|
||||
$('#page_number').val(1);
|
||||
$('#result_form').submit();
|
||||
}
|
||||
|
||||
function changePage(page,e) {
|
||||
e.preventDefault();
|
||||
$('#page_number').val(page);
|
||||
$('#result_form').submit();
|
||||
}
|
||||
</script>
|
||||
@@ -41,6 +41,15 @@ if (isset($config['enable_bgp']) && $config['enable_bgp'])
|
||||
<a href="<?php echo(generate_url(array('page'=>'overview'))); ?>" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown"><img src="images/16/lightbulb.png" border="0" align="absmiddle" /> Overview<b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="<?php echo(generate_url(array('page'=>'overview'))); ?>"><img src="images/16/lightbulb.png" border="0" align="absmiddle" /> Overview</a></li>
|
||||
<li><a href="<?php echo(generate_url(array('page'=>'alerts'))); ?>"><img src="images/16/monitor_error.png" border="0" align="absmiddle" /> Alerts</a></li>
|
||||
<?php
|
||||
if ($_SESSION['userlevel'] == '10') {
|
||||
?>
|
||||
<li><a href="<?php echo(generate_url(array('page'=>'alert-rules'))); ?>"><img src="images/16/monitor_go.png" border="0" align="absmiddle" /> Alert Rules</a></li>
|
||||
<li><a href="<?php echo(generate_url(array('page'=>'templates'))); ?>"><img src="images/16/monitor_link.png" border="0" align="absmiddle" /> Alert Templates</a></li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<li role="presentation" class="divider"></li>
|
||||
<?php if (isset($config['enable_map']) && $config['enable_map']) {
|
||||
echo(' <li><a href="'.generate_url(array('page'=>'overview')).'"><img src="images/16/map.png" border="0" align="absmiddle" /> Network Map</a></li>');
|
||||
@@ -460,15 +469,12 @@ if ($_SESSION['authenticated'])
|
||||
<li><a href="about/"><img src="images/16/information.png" border="0" align="absmiddle" /> About <?php echo($config['project_name']); ?></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li style="padding-top:10px">
|
||||
<form role="form" class="form-inline">
|
||||
<div class="form-group">
|
||||
<input class="form-control" type="search" id="gsearch" name="gsearch" placeholder="Global Search" style="width: 250px">
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<form role="search" class="navbar-form navbar-left">
|
||||
<div class="form-group">
|
||||
<input class="form-control" type="search" id="gsearch" name="gsearch" placeholder="Global Search" style="width: 250px">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
Reference in New Issue
Block a user