mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
alert: Added ability to make notes for acking alerts + record who did so (#8433)
* alert: Added ability to make notes for acking alerts + record who did so * Updated schema * moved sql file * Updated from comments in PR * warning changed to blue * reset notes + keep notes on ack
This commit is contained in:
committed by
Tony Murray
parent
b3d190ec52
commit
1eee6e8195
@@ -1,26 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
/**
|
||||
* ack-alert.inc.php
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
||||
* LibreNMS ack-alert.inc.php
|
||||
*
|
||||
* 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.
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2018 Neil Lathwood
|
||||
* @author Neil Lathwood <gh+n@laf.io>
|
||||
*/
|
||||
header('Content-type: text/plain');
|
||||
|
||||
$alert_id = mres($_POST['alert_id']);
|
||||
$state = mres($_POST['state']);
|
||||
use LibreNMS\Config;
|
||||
|
||||
header('Content-type: application/json');
|
||||
|
||||
$alert_id = $vars['alert_id'];
|
||||
$state = $vars['state'];
|
||||
$ack_msg = $vars['ack_msg'];
|
||||
|
||||
$status = 'error';
|
||||
|
||||
if (!is_numeric($alert_id)) {
|
||||
echo 'ERROR: No alert selected';
|
||||
exit;
|
||||
$message = 'No alert selected';
|
||||
} elseif (!is_numeric($state)) {
|
||||
echo 'ERROR: No state passed';
|
||||
exit;
|
||||
$message = 'No state passed';
|
||||
} else {
|
||||
if ($state == 2) {
|
||||
$state = 1;
|
||||
@@ -30,11 +46,28 @@ if (!is_numeric($alert_id)) {
|
||||
$open = 1;
|
||||
}
|
||||
|
||||
if (dbUpdate(array('state' => $state, 'open' => $open), 'alerts', 'id=?', array($alert_id)) >= 0) {
|
||||
echo 'Alert acknowledged status changed.';
|
||||
exit;
|
||||
$data = ['state' => $state, 'open' => $open];
|
||||
if (!empty($ack_msg)) {
|
||||
$note = dbFetchCell('SELECT note FROM alerts WHERE id=?', [$alert_id]);
|
||||
if (!empty($note)) {
|
||||
$note .= PHP_EOL;
|
||||
}
|
||||
$data['note'] = $note . date(Config::get('dateformat.long')) . " - Ack ({$_SESSION['username']}) $ack_msg";
|
||||
}
|
||||
|
||||
if (dbUpdate($data, 'alerts', 'id=?', array($alert_id)) >= 0) {
|
||||
if ($state === 2) {
|
||||
$alert_info = dbFetchRow("SELECT `alert_rules`.`name`,`alerts`.`device_id` FROM `alert_rules` LEFT JOIN `alerts` ON `alerts`.`rule_id` = `alert_rules`.`id` WHERE `alerts`.`id` = ?", [$alert_id]);
|
||||
log_event("{$_SESSION['username']} acknowledged alert {$alert_info['name']}", $alert_info['device_id'], 'alert', 2, $alert_id);
|
||||
}
|
||||
$message = 'Alert acknowledged status changed.';
|
||||
$status = 'ok';
|
||||
} else {
|
||||
echo 'ERROR: Alert has not been acknowledged.';
|
||||
exit;
|
||||
$message = 'Alert has not been acknowledged.';
|
||||
}
|
||||
}//end if
|
||||
|
||||
die(json_encode([
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
]));
|
||||
|
||||
53
html/includes/forms/alert-notes.inc.php
Normal file
53
html/includes/forms/alert-notes.inc.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* alert-notes.inc.php
|
||||
*
|
||||
* LibreNMS alert-notes.inc.php
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2018 Neil Lathwood
|
||||
* @author Neil Lathwood <gh+n@laf.io>
|
||||
*/
|
||||
|
||||
header('Content-type: application/json');
|
||||
|
||||
$alert_id = $vars['alert_id'];
|
||||
$sub_type = $vars['sub_type'];
|
||||
$note = $vars['note'] ?: '';
|
||||
$status = 'error';
|
||||
|
||||
if (is_numeric($alert_id)) {
|
||||
if ($sub_type === 'get_note') {
|
||||
$note = dbFetchCell("SELECT `note` FROM `alerts` WHERE `id` = ?", [$alert_id]);
|
||||
$message = 'Alert note retrieved';
|
||||
$status = 'ok';
|
||||
} else {
|
||||
if (dbUpdate(['note' => $note], 'alerts', '`id` = ?', [$alert_id])) {
|
||||
$status = 'ok';
|
||||
$message = 'Note updated';
|
||||
} else {
|
||||
$message = 'Could not update note';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$message = 'Invalid alert id';
|
||||
}
|
||||
die(json_encode([
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'note' => $note,
|
||||
]));
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* alert-rules.inc.php
|
||||
*
|
||||
* LibreNMS alert-rules.inc.php for processor
|
||||
* LibreNMS alert-rules.inc.php
|
||||
*
|
||||
* 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
|
||||
@@ -150,7 +150,6 @@ if (is_numeric($rule_id) && $rule_id > 0) {
|
||||
dbSyncRelationship('alert_group_map', 'rule_id', $rule_id, 'group_id', $groups);
|
||||
}
|
||||
|
||||
|
||||
die(json_encode([
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
|
||||
Reference in New Issue
Block a user