Alerts gui commit

This commit is contained in:
laf 2014-11-30 17:49:52 +00:00 committed by Neil Lathwood
parent 05d998c1f8
commit 807fc9a3ba
42 changed files with 2068 additions and 170 deletions

0
alerts.php Executable file → Normal file
View File

116
html/ajax_rulesuggest.php Normal file
View File

@ -0,0 +1,116 @@
<?php
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>
* 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/>. */
/**
* Rule Suggestion-AJAX
* @author Daniel Preussker <f0o@devilcode.org>
* @copyright 2014 f0o, LibreNMS
* @license GPL
* @package LibreNMS/Alerts
*/
session_start();
if( !isset($_SESSION['authenticated']) ) {
die("Unauthorized.");
}
require_once("../includes/defaults.inc.php");
require_once("../config.php");
require_once("../includes/definitions.inc.php");
require_once("../includes/functions.php");
/**
* Levenshtein Sort
* @param string $base Comparisson basis
* @param array $obj Object to sort
* @return array
*/
function levsort($base, $obj) {
$ret = array();
foreach( $obj as $elem ) {
$lev = levenshtein($base, $elem, 1, 10, 10);
if( $lev == 0 ) {
return array(array('name'=>$elem));
} else {
while( isset($ret["$lev"]) ) {
$lev += 0.1;
}
$ret["$lev"] = array('name'=>$elem);
}
}
ksort($ret);
return $ret;
}
$obj = array(array('name'=>'Error: No suggestions found.'));
if( isset($_GET['term'],$_GET['device_id']) ) {
$chk = array();
$_GET['term'] = mres($_GET['term']);
$_GET['device_id'] = mres($_GET['device_id']);
if( strstr($_GET['term'],".") ) {
$term = explode(".",$_GET['term']);
if( $config['memcached']['enable'] ) {
$chk = $memcache->get('rule-suggest_'.$term[0]);
}
if( !(sizeof($chk) > 0) || $chk === false ) {
$tmp = dbFetchRows('SHOW COLUMNS FROM '.$term[0]);
foreach( $tmp as $tst ) {
if( isset($tst['Field']) ) {
$chk[] = $term[0].'.'.$tst['Field'];
}
}
}
$current = true;
} else {
if( $config['memcached']['enable'] ) {
$chk = $memcache->get('rule-suggest-toplvl');
}
if( !(sizeof($chk) > 0) || $chk === false ) {
$tmp = dbFetchRows('SHOW TABLES');
foreach( $tmp as $tst ) {
$tbl = array_shift($tst);
$chhk = dbFetchRows('SELECT device_id FROM '.$tbl.' LIMIT 1');
if( isset($chhk[0]['device_id']) ) {
$chk[] = $tbl.'.';
}
}
}
}
if( sizeof($chk) > 0 ) {
if( $config['memcached']['enable'] ) {
$memcache->set('rule-suggest-'.$oterm,$chk,86400); //Cache for 24h
}
$obj = levsort($_GET['term'],$chk);
$obj = array_chunk($obj,20,true);
$obj = $obj[0];
if( $current == true ) {
foreach( $obj as $fld ) {
$flds[] = $fld['name'];
}
$qry = dbFetchRows("SELECT ".implode(", ",$flds)." FROM ".$term[0]." WHERE device_id = ?", array($_GET['device_id']));
foreach( $obj as $lev=>$fld ) {
list($tbl, $chk) = explode(".",$fld['name']);
$val = array();
foreach( $qry as $row ) {
$val[] = $row[$chk];
}
$ret[$lev] = array('name'=>$fld['name'],'current'=>$val);
}
$obj = $ret;
}
}
}
die(json_encode($obj));
?>

View File

@ -35,8 +35,8 @@ $app->group('/api', function() use ($app) {
$app->get('/:hostname', 'authToken', 'get_device')->name('get_device');//api/v0/devices/$hostname
$app->get('/:hostname/vlans', 'authToken', 'get_vlans')->name('get_vlans');//api/v0/devices/$hostname/vlans
$app->get('/:hostname/graphs', 'authToken', 'get_graphs')->name('get_graphs');//api/v0/devices/$hostname/graphs
$app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname')->name('get_graph_generic_by_hostname');//api/v0/devices/$hostname/$type
$app->get('/:hostname/ports', 'authToken', 'get_port_graphs')->name('get_port_graphs');//api/v0/devices/$hostname/ports
$app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname')->name('get_graph_generic_by_hostname');//api/v0/devices/$hostname/$type
$app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname')->name('get_port_stats_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName
$app->get('/:hostname/ports/:ifname/:type', 'authToken', 'get_graph_by_port_hostname')->name('get_graph_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName/$type
});
@ -45,6 +45,10 @@ $app->group('/api', function() use ($app) {
$app->group('/portgroups', function() use ($app) {
$app->get('/:group', 'authToken', 'get_graph_by_portgroup')->name('get_graph_by_portgroup');//api/v0/portgroups/$group
});
$app->group('/bills', function() use ($app) {
$app->get('/:bill_id', 'authToken', 'list_bills')->name('get_bill');//api/v0/bills/$bill_id
});
$app->get('/bills', 'authToken', 'list_bills')->name('list_bills');//api/v0/bills
});
$app->get('/v0', 'authToken', 'show_endpoints');//api/v0
});

7
html/css/jquery-ui.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1612,3 +1612,20 @@ tr.search:nth-child(odd) {
width: 250px;
}
.ui-autocomplete {
max-height: 100px;
overflow-y: auto;
overflow-x: hidden;
}
/* IE 6 doesn't support max-height
* we use height instead, but this forces the menu to always be this tall
*/
* html .ui-autocomplete {
height: 100px;
}
.glyphicon-large {
font-size: 2.5em;
}

21
html/css/tagmanager.css Normal file
View File

@ -0,0 +1,21 @@
.tagmanagerTag {
background: none repeat scroll 0 0 #cde69c;
border: 1px solid #a5d24a;
border-radius: 3px;
color: #638421;
display: block;
float: left;
font-size: 13px;
margin-bottom: 5px;
margin-right: 5px;
padding: 6px 5px 5px 5px;
text-decoration: none;
vertical-align: middle;
line-height: 18px;
height: 30px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
}
.tagmanagerRemoveTag {
color: #c0c0c0;
padding-left: 8px;
}

View File

@ -0,0 +1,28 @@
<?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.
*/
$alert_id = mres($_POST['alert_id']);
if(!is_numeric($alert_id)) {
echo('ERROR: No alert selected');
exit;
} else {
if(dbUpdate(array('state' => '2'), 'alerts', 'id=?',array($alert_id))) {
echo('Alert has been acknowledged.');
exit;
} else {
echo('ERROR: Alert has not been acknowledged.');
exit;
}
}

View File

@ -0,0 +1,78 @@
<?php
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>
* 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/>. */
/**
* Alert Templates
* @author f0o <f0o@devilcode.org>
* @copyright 2014 f0o, LibreNMS
* @license GPL
* @package LibreNMS
* @subpackage Alerts
*/
if(is_admin() === false) {
die('ERROR: You need to be admin');
}
$ok = '';
$error = '';
$name = mres($_POST['name']);
if(!empty($name)) {
if( is_numeric($_REQUEST['template_id']) && $_REQUEST['rule_id'] ) {
//Update the template/rule mapping
if( is_array($_REQUEST['rule_id']) ) {
$_REQUEST['rule_id'] = implode(",",$_REQUEST['rule_id']);
}
if( substr($_REQUEST['rule_id'], 0,1) != "," ){
$_REQUEST['rule_id'] = ",".$_REQUEST['rule_id'];
}
if( substr($_REQUEST['rule_id'],-1,1) != "," ){
$_REQUEST['rule_id'] .= ",";
}
if(dbUpdate(array('rule_id' => mres($_REQUEST['rule_id']), 'name' => $name), "alert_templates", "id = ?", array($_REQUEST['template_id']))) {
$ok = "Updated template and rule id mapping";
} else {
$error ="Failed to update the template and rule id mapping";
}
} elseif( $_REQUEST['template'] && is_numeric($_REQUEST['template_id']) ) {
//Update template-text
if($ret = dbUpdate(array('template' => $_REQUEST['template'], 'name' => $name), "alert_templates", "id = ?", array($_REQUEST['template_id']))) {
$ok = "Updated template";
} else {
$error = "Failed to update the template";
}
} elseif( $_REQUEST['template'] ) {
//Create new template
if(dbInsert(array('template' => $_REQUEST['template'], 'name' => $name), "alert_templates")) {
$ok = "Alert template has been created.";
} else {
$error = "Could not create aler template";
}
} else {
$error = "We could not work out what you wanted to do!";
}
} else {
$error = "You haven't given your template a name, it feels sad :( - $name";
}
if(!empty( $ok )) {
die("$ok");
} else {
die("ERROR: $error");
}
?>

View File

@ -0,0 +1,31 @@
<?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');
}
if(!is_numeric($_POST['template_id'])) {
echo('ERROR: No template selected');
exit;
} else {
if(dbUpdate(array('rule_id' => mres($_POST['rule_id'])), 'alert_templates', '`id`=?', array($_POST['template_id'])) >= 0) {
echo('Alert rules have been attached to this template.');
exit;
} else {
echo('ERROR: Alert rules have not been attached to this template.');
exit;
}
}

View File

@ -0,0 +1,58 @@
<?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');
}
$rule = implode(" ", $_POST['rules']);
$rule = rtrim($rule,'&&');
$rule = rtrim($rule,'||');
$alert_id = $_POST['alert_id'];
$count = mres($_POST['count']);
$delay = mres($_POST['delay']);
$mute = mres($_POST['mute']);
if(empty($rule)) {
$update_message = "ERROR: No rule was generated";
} elseif(validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1') {
$device_id = $_POST['device_id'];
if(!is_numeric($count)) {
$count='-1';
}
$delay_sec = convert_delay($delay);
if($mute == 'on') {
$mute = true;
} else {
$mute = false;
}
$extra = array('mute'=>$mute,'count'=>$count,'delay'=>$delay_sec);
$extra_json = json_encode($extra);
if(is_numeric($alert_id) && $alert_id > 0) {
if(dbUpdate(array('rule' => $rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json), 'alert_rules', 'id=?',array($alert_id)) >= 0) {
$update_message = "Edited Rule: <i>".$rule."</i>";
} else {
$update_message = "ERROR: Failed to edit Rule: <i>".$rule."</i>";
}
} else {
if( dbInsert(array('device_id'=>$device_id,'rule'=>$rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json),'alert_rules') ) {
$update_message = "Added Rule: <i>".$rule.$mute."</i>";
} else {
$update_message = "ERROR: Failed to add Rule: <i>".$rule."</i>";
}
}
} else {
$update_message = "ERROR: invalid device ID or not a global alert";
}
echo $update_message;

View File

@ -0,0 +1,31 @@
<?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');
}
if(!is_numeric($_POST['alert_id'])) {
echo('ERROR: No alert selected');
exit;
} else {
if(dbDelete('alert_rules', "`id` = ?", array($_POST['alert_id']))) {
echo('Alert rule has been deleted.');
exit;
} else {
echo('ERROR: Alert rule has not been deleted.');
exit;
}
}

View File

@ -0,0 +1,31 @@
<?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');
}
if(!is_numeric($_POST['template_id'])) {
echo('ERROR: No template selected');
exit;
} else {
if(dbDelete('alert_templates', "`id` = ?", array($_POST['template_id']))) {
echo('Alert template has been deleted.');
exit;
} else {
echo('ERROR: Alert template has not been deleted.');
exit;
}
}

View File

@ -0,0 +1,28 @@
<?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');
}
$alert_id = $_POST['alert_id'];
if(is_numeric($alert_id) && $alert_id > 0) {
$rule = dbFetchRow("SELECT * FROM `alert_rules` WHERE `id` = ? LIMIT 1",array($alert_id));
$rule_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\ \"\'\!\~]+[&&||]+)/',$rule['rule'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$count = count($rule_split) - 1;
$rule_split[$count] = $rule_split[$count].'&&';
$output = array('severity'=>$rule['severity'],'extra'=>$rule['extra'],'rules'=>$rule_split);
echo _json_encode($output);
}

View File

@ -0,0 +1,25 @@
<?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');
}
$template_id = ($_POST['template_id']);
if(is_numeric($template_id) && $template_id > 0) {
$template = dbFetchRow("SELECT * FROM `alert_templates` WHERE `id` = ? LIMIT 1",array($template_id));
$output = array('template'=>$template['template'],'name'=>$template['name']);
echo _json_encode($output);
}

View File

@ -0,0 +1,26 @@
<?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');
}
$template_id = ($_POST['template_id']);
if(is_numeric($template_id) && $template_id > 0) {
$template = dbFetchCell("SELECT `rule_id` FROM `alert_templates` WHERE `id` = ? LIMIT 1",array($template_id));
$rule_id = split(",", $template);
$output = array('rule_id'=>$rule_id);
echo _json_encode($output);
}

View File

@ -0,0 +1,50 @@
<?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');
}
if(!is_numeric($_POST['alert_id']))
{
echo('ERROR: No alert selected');
exit;
}
else
{
if($_POST['state'] == 'true')
{
$state = 0;
}
elseif($_POST['state'] == 'false')
{
$state = 1;
}
else
{
$state = 1;
}
$update = dbUpdate(array('disabled' => $state), 'alert_rules', '`id`=?', array($_POST['alert_id']));
if(!empty($update) || $update == '0')
{
echo('Alert rule has been updated.');
exit;
}
else
{
echo('ERROR: Alert rule has not been updated.');
exit;
}
}

View File

@ -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);
}

View File

@ -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;
}
}
?>

View 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">&times;</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>

View 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">&times;</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>

View 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">&times;</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>

View 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">&times;</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>

View 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">&times;</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>

View 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>

View 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>';

View 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;' >&nbsp;</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>

View File

@ -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&nbsp;<?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>

View File

@ -132,6 +132,8 @@ if ($config['page_refresh']) { echo(' <meta http-equiv="refresh" content="'.$co
<link href="css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
<link href="css/toastr.min.css" rel="stylesheet" type="text/css" />
<link href="css/typeahead.js-bootstrap.css" rel="stylesheet" type="text/css" />
<link href="css/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/tagmanager.css" rel="stylesheet" type="text/css" />
<link href="<?php echo($config['stylesheet']); ?>" rel="stylesheet" type="text/css" />
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
@ -142,6 +144,8 @@ if ($config['page_refresh']) { echo(' <meta http-equiv="refresh" content="'.$co
<script src="js/moment.min.js"></script>
<script src="js/bootstrap-datetimepicker.min.js"></script>
<script src="js/typeahead.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/tagmanager.js"></script>
<?php
if ($config['favicon']) { echo(' <link rel="shortcut icon" href="'.$config['favicon'].'" />' . "\n"); }
?>

File diff suppressed because one or more lines are too long

179
html/js/tagmanager.js Normal file
View File

@ -0,0 +1,179 @@
var TagManager = (function () {
function TagManager(element, options) {
var defaults = {
strategy: 'array',
tagFieldName: 'tags[]',
ajaxCreate: null,
ajaxRemove: null,
initialCap: true,
backspaceChars: [
8
],
delimiterChars: [
13,
44,
188
],
createHandler: function (tagManager, tag, isImport) {
return;
},
removeHandler: function (tagManager, tag, isEmpty) {
return true;
},
createElementHandler: function (tagManager, tagElement, isImport) {
tagManager.$element.before(tagElement);
},
validateHandler: function (tagManager, tag, isImport) {
return tag;
}
};
this.$element = $(element);
this.tagIds = [];
this.tagStrings = [];
this.options = $.extend({
}, defaults, options);
$(element).data('tagmanager', this);
this.listen();
}
TagManager.prototype.keypress = function (e) {
if($.inArray(e.which, this.options.backspaceChars) != -1) {
if(!this.$element.val()) {
e.preventDefault();
this.pop();
}
}
if($.inArray(e.which, this.options.delimiterChars) != -1) {
e.preventDefault();
e.stopPropagation();
if(this.$element.data('typeahead') && this.$element.data('typeahead').shown && this.$element.data('typeahead').$menu.find('.active').length) {
return false;
}
this.create(this.$element.val());
}
};
TagManager.prototype.empty = function () {
var manager = this;
$(this.tagIds).each(function (index, value) {
manager.remove(value, true);
});
};
TagManager.prototype.pop = function () {
if(this.tagIds.length > 0) {
this.remove(this.tagIds[this.tagIds.length - 1]);
}
};
TagManager.prototype.remove = function (tagId, isEmpty) {
var tagString = $('#' + tagId).attr('tag');
if(this.options.removeHandler) {
if(!this.options.removeHandler(this, tagString, isEmpty)) {
return;
}
}
if(this.options.strategy == 'ajax' && this.options.ajaxRemove && !isEmpty) {
$.ajax({
url: this.options.ajaxRemove,
type: 'post',
data: {
tag: tagString
},
dataType: 'json'
});
}
var index = $.inArray(tagId, this.tagIds);
this.tagStrings.splice(index, 1);
this.tagIds.splice(index, 1);
$('#' + tagId).remove();
};
TagManager.prototype.populate = function (tags) {
var manager = this;
$.each(tags, function (key, val) {
manager.create(val, true);
});
};
TagManager.prototype.create = function (rawTag, isImport) {
var tag = $.trim(rawTag);
if(!tag) {
this.$element.val('');
return;
}
if(this.options.initialCap) {
tag = tag.charAt(0).toUpperCase() + tag.slice(1);
}
tag = this.options.validateHandler(this, tag, isImport);
if(!tag) {
this.$element.val('');
return;
}
if(this.options.strategy == 'ajax' && this.options.ajaxCreate && !isImport) {
$.ajax({
url: this.options.ajaxCreate,
type: 'post',
data: {
tag: tag
},
dataType: 'json'
});
}
if(this.options.createHandler) {
this.options.createHandler(this, tag, isImport);
}
var randomString = function (length) {
var result = '';
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for(var i = length; i > 0; --i) {
result += chars[Math.round(Math.random() * (chars.length - 1))];
}
return result;
};
var id = 'tag_' + randomString(32);
this.tagIds.push(id);
this.tagStrings.push(tag);
var tagClass = new Tag(this, id, tag);
this.options.createElementHandler(this, tagClass.render(), isImport);
this.$element.val('');
this.$element.focus();
};
TagManager.prototype.listen = function () {
this.$element.on('keypress', $.proxy(this.keypress, this));
};
return TagManager;
})();
var Tag = (function () {
function Tag(manager, id, value) {
this.manager = manager;
this.id = id;
this.tag = value;
}
Tag.prototype.validate = function () {
if(this.manager.options.strategy == 'array' && !this.manager.options.tagFieldName) {
alert('Array strategy used with no field name');
}
};
Tag.prototype.render = function () {
this.validate();
var tagHtml = $('<span />').addClass('tagmanagerTag').attr('tag', this.tag).attr('id', this.id).data('tagmanager', this.manager).text(this.tag);
if(this.manager.options.strategy == 'array') {
$('<input>').attr('type', 'hidden').attr('name', this.manager.options.tagFieldName).val(this.tag).appendTo(tagHtml);
}
var tagRemover = $('<a />').addClass('tagmanagerRemoveTag').attr('title', 'Remove').attr('href', '#').text('x').appendTo(tagHtml);
var id = this.id;
var manager = this.manager;
$(tagRemover).click(function (e) {
manager.remove(id);
return false;
});
return tagHtml;
};
return Tag;
})();
$.fn.tagmanager = function (option) {
return this.each(function () {
var $this = $(this), data = $this.data('tagmanager'), options = typeof option == 'object' && option;
if(!data) {
$this.data('tagmanager', (data = new TagManager(this, options)));
}
if(typeof option == 'string') {
data[option]();
}
});
};

View File

@ -0,0 +1,19 @@
<?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.
*/
$device['device_id'] = '-1';
require_once('includes/print-alert-rules.php');
unset($device['device_id']);
?>

19
html/pages/alerts.inc.php Normal file
View File

@ -0,0 +1,19 @@
<?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.
*/
$device['device_id'] = '-1';
require_once('includes/print-alerts.php');
unset($device['device_id']);
?>

View File

@ -319,6 +319,47 @@ if ($_SESSION['userlevel'] == '10')
<tr>
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost/ports?columns=ifDescr,ifName"</code></td>
</tr>
<tr class="success">
<td colspan="5"><strong>List Bills</strong></td>
</tr>
<tr>
<td>/api</td>
<td>/v0</td>
<td>/bills</td>
<td>
<ul class="list-unstyled">
<li>custid = the customer reference for the bill</li>
<li>ref = the billing reference for the bill</li>
</ul>
</td>
<td>
JSON
</td>
</tr>
<tr>
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/bills"</code></td>
</tr>
<tr>
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/bills?custid=Testing"</code></td>
</tr>
<tr class="success">
<td colspan="5"><strong>Retrieve Bill information</strong></td>
</tr>
<tr>
<td>/api</td>
<td>/v0</td>
<td>/bills/$bill_id</td>
<td>
<ul class="list-unstyled">
</ul>
</td>
<td>
JSON
</td>
</tr>
<tr>
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/bills/$bill_id"</code></td>
</tr>
</table>
</div>
</div>

View File

@ -13,18 +13,18 @@ if ($bill_data['bill_type'] == "quota") {
$tmp['mb'] = $data / $base / $base;
$tmp['gb'] = $data / $base / $base / $base;
$tmp['tb'] = $data / $base / $base / $base / $base;
if (($tmp['tb']>1) and ($tmp['tb']<$base)) { $quota = array("type" => "tb", "select_tb" => " selected", "data" => $tmp['tb']); }
elseif (($tmp['gb']>1) and ($tmp['gb']<$base)) { $quota = array("type" => "gb", "select_gb" => " selected", "data" => $tmp['gb']); }
elseif (($tmp['mb']>1) and ($tmp['mb']<$base)) { $quota = array("type" => "mb", "select_mb" => " selected", "data" => $tmp['mb']); }
if ($tmp['tb']>=1) { $quota = array("type" => "tb", "select_tb" => " selected", "data" => $tmp['tb']); }
elseif (($tmp['gb']>=1) and ($tmp['gb']<$base)) { $quota = array("type" => "gb", "select_gb" => " selected", "data" => $tmp['gb']); }
elseif (($tmp['mb']>=1) and ($tmp['mb']<$base)) { $quota = array("type" => "mb", "select_mb" => " selected", "data" => $tmp['mb']); }
}
if ($bill_data['bill_type'] == "cdr") {
$data = $bill_data['bill_cdr'];
$tmp['kbps'] = $data / $base / $base;
$tmp['mbps'] = $data / $base / $base / $base;
$tmp['gbps'] = $data / $base / $base / $base / $base;
if ($tmp['gbps']>1 and ($tmp['mbps']<$base)) { $cdr = array("type" => "gbps", "select_tbps" => " selected", "data" => $tmp['gbps']); }
elseif (($tmp['mbps']>1) and ($tmp['mbps']<$base)) { $cdr = array("type" => "mbps", "select_gbps" => " selected", "data" => $tmp['mbps']); }
elseif (($tmp['kbps']>1) and ($tmp['kbps']<$base)) { $cdr = array("type" => "kbps", "select_mbps" => " selected", "data" => $tmp['kbps']); }
$tmp['kbps'] = $data / $base;
$tmp['mbps'] = $data / $base / $base;
$tmp['gbps'] = $data / $base / $base / $base;
if ($tmp['gbps']>=1) { $cdr = array("type" => "gbps", "select_gbps" => " selected", "data" => $tmp['gbps']); }
elseif (($tmp['mbps']>=1) and ($tmp['mbps']<$base)) { $cdr = array("type" => "mbps", "select_mbps" => " selected", "data" => $tmp['mbps']); }
elseif (($tmp['kbps']>=1) and ($tmp['kbps']<$base)) { $cdr = array("type" => "kbps", "select_kbps" => " selected", "data" => $tmp['kbps']); }
}
?>

View File

@ -1,90 +1,17 @@
<?php
$glo_conditions = cache_conditions_global();
/*
* 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.
*/
#echo("<pre>");
#print_r($glo_conditions);
#echo("</pre>");
echo('<table cellspacing="0" cellpadding=5 class="sortable" width="100%">
<tr class="tablehead">
<th width=10></th>
<th class=paddedcell width=150>Type</th>
<th class=paddedcell width=150>Subtype</th>
<th class=paddedcell width=150>Metric</th>
<th class=paddedcell width=100>Operator</th>
<th class=paddedcell width=100>Value</th>
<th class=paddedcell width=75>Severity</th>
<th class=paddedcell width=50>On</th>
<th class=paddedcell width=50>Status</th>
<th class=paddedcell></th>
</tr>');
function get_entity_list($type, $subtype = "*", $device_id = "*", $entry)
{
if ($type == "storage") { $table = $type; } else { $table = $type.'s'; }
if ($type == "port") { $deleted = "deleted"; } else { $deleted = $type.'_deleted'; }
$query = 'SELECT '.$type.'_id AS id, '.$deleted.' FROM '.$table.' WHERE 1';
$args = array();
if (is_numeric($device_id))
{
$query .= " AND device_id = ?";
$args[] = $device_id;
}
if (is_numeric($entry['entity']))
{
$query .= " AND ".$type."_id = ?";
$args[] = $entry['entity'];
}
$entities_db = dbFetchRows($query, $args);
foreach ($entities_db as $entity_db)
{
// Is this entity marked as deleted?
if ($entity_db['deleted'] != "1")
{
$entities[] = $entity_db['id'];
}
}
return $entities;
}
foreach ($glo_conditions as $type => $subtypes)
{
foreach ($subtypes as $subtype => $metrics)
{
if (empty($subtype)) { $subtype = "*"; }
foreach ($metrics as $metric => $entries)
{
foreach ($entries as $entry_id => $entry)
{
if ($entry['enable'] == 1) { $enabled = '<img align=absmiddle src="images/16/tick.png" />'; } else { $enabled = '<img align=absmiddle src="images/16/stop.png" />'; }
echo('<tr class=list>');
echo('<td></td><td><strong>'.$type.'</strong></td><td>'.$subtype.'</td><td>'.$metric.'</td><td>'.htmlentities($entry['operator']).'</td><td>'.$entry['value'].'</td><td>'.$entry['severity'].'</td><td>'.$enabled.'</td>');
echo('<td></td><td></td>');
echo('</tr>');
// Get which entities match this checker
$entities = get_entity_list($type, $subtype, $device['device_id'], $entry['entity']);
if (!empty($entities))
{
echo('<tr class=list><td></td><td colspan=9><strong>');
foreach ($entities as $entity)
{
echo('<span style="padding:3px 5px; margin: 0px 3px; background-color: #e5e5e5;">'.generate_entity_link($type, $entity)."</span>");
}
echo('</strong></td></tr>');
}
}
}
}
}
echo('</table>');
require_once('includes/print-alerts.php');
?>

View File

@ -19,7 +19,8 @@ if ($_SESSION['userlevel'] < '7')
}
$panes['apps'] = 'Applications';
$panes['alerts'] = 'Alerts';
$panes['alerts'] = 'Alert Settings';
$panes['alert-rules'] = 'Alert Rules';
$panes['modules'] = 'Modules';
if ($config['enable_services'])

View File

@ -0,0 +1,17 @@
<?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.
*/
require_once('includes/print-alert-rules.php');
?>

View File

@ -1,5 +1,4 @@
<?php
if ($_POST['editing'])
{
if ($_SESSION['userlevel'] > "7")
@ -33,6 +32,12 @@ $override_sysContact_string = get_dev_attrib($device,'override_sysContact_string
$disable_notify = get_dev_attrib($device,'disable_notify');
?>
<div class="row">
<div class="col-md-12">
<span id="message"></span>
</div>
</div>
<h3>Alert settings</h3>
<form id="edit" name="edit" method="post" action="" role="form" class="form-horizontal">
@ -58,3 +63,8 @@ $disable_notify = get_dev_attrib($device,'disable_notify');
</div>
<button class="btn btn-default btn-sm" type="submit" name="Submit">Save</button>
</form>
<?php
require_once("includes/modal/new_alert_rule.inc.php");
?>
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#create-alert" data-device_id="<?php echo $device['device_id'];?>">Create new alert rule</button>

View File

@ -0,0 +1,17 @@
<?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.
*/
require_once('includes/print-alert-templates.php');
?>

0
includes/alerts.inc.php Executable file → Normal file
View File

View File

@ -1094,4 +1094,21 @@ function _json_format($json, $options = 448)
return $result;
}
function convert_delay($delay) {
$delay = preg_replace('/\s/','',$delay);
if(strstr($delay, 'm',TRUE)) {
$delay_sec = $delay * 60;
} elseif(strstr($delay, 'h',TRUE)) {
$delay_sec = $delay * 3600;
} elseif(strstr($delay, 'd',TRUE)) {
$delay_sec = $delay * 86400;
} elseif(is_numeric($delay)) {
$delay_sec = $delay;
} else {
$delay_sec = 0;
}
return($delay_sec);
}
?>

0
poller.php Executable file → Normal file
View File