librenms-librenms/includes/html/forms/ack-alert.inc.php

90 lines
2.6 KiB
PHP
Raw Normal View History

2014-11-30 17:49:52 +00:00
<?php
/**
* ack-alert.inc.php
*
* 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.
2014-11-30 17:49:52 +00:00
*
* 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.
2014-11-30 17:49:52 +00:00
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://librenms.org
* @copyright 2018 Neil Lathwood
* @author Neil Lathwood <gh+n@laf.io>
2014-11-30 17:49:52 +00:00
*/
use LibreNMS\Config;
header('Content-type: application/json');
2020-09-21 15:40:17 +02:00
$alert_id = $vars['alert_id'];
$state = $vars['state'];
$ack_msg = $vars['ack_msg'];
$until_clear = $vars['ack_until_clear'];
$status = 'error';
2020-09-21 15:40:17 +02:00
if (! is_numeric($alert_id)) {
$message = 'No alert selected';
2020-09-21 15:40:17 +02:00
} elseif (! is_numeric($state)) {
$message = 'No state passed';
} else {
2015-07-13 20:10:26 +02:00
if ($state == 2) {
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
$state = 1;
$state_descr = 'UnAck';
2020-09-21 15:40:17 +02:00
$open = 1;
} elseif ($state >= 1) {
2015-07-13 20:10:26 +02:00
$state = 2;
$state_descr = 'Ack';
2020-09-21 15:40:17 +02:00
$open = 1;
2014-11-30 17:49:52 +00:00
}
if ($until_clear === 'true') {
$until_clear = true;
} else {
$until_clear = false;
}
$info = json_encode([
'until_clear' => $until_clear,
]);
$username = Auth::user()->username;
$data = [
'state' => $state,
'open' => $open,
'info' => $info,
];
$note = dbFetchCell('SELECT note FROM alerts WHERE id=?', [$alert_id]);
2020-09-21 15:40:17 +02:00
if (! empty($note)) {
$note .= PHP_EOL;
}
$data['note'] = $note . date(Config::get('dateformat.long')) . " - $state_descr ($username) $ack_msg";
if (dbUpdate($data, 'alerts', 'id=?', [$alert_id]) >= 0) {
if (in_array($state, [2, 22])) {
2020-09-21 15:59:34 +02:00
$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("$username acknowledged alert {$alert_info['name']} note: $ack_msg", $alert_info['device_id'], 'alert', 2, $alert_id);
}
$message = 'Alert acknowledged status changed.';
2020-09-21 15:40:17 +02:00
$status = 'ok';
} else {
$message = 'Alert has not been acknowledged.';
2015-07-13 20:10:26 +02:00
}
}//end if
2020-09-21 15:40:17 +02:00
exit(json_encode([
'status' => $status,
'message' => $message,
]));