mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 08:02:41 +02:00
Alerts gui commit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
?>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user