2014-11-30 17:49:52 +00:00
< ? php
2018-04-26 06:00:56 +01:00
/**
* 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
*
2018-04-26 06:00:56 +01: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
*
2018-04-26 06:00:56 +01: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 />.
*
* @ package LibreNMS
* @ link http :// librenms . org
* @ copyright 2018 Neil Lathwood
* @ author Neil Lathwood < gh + n @ laf . io >
2014-11-30 17:49:52 +00:00
*/
2018-04-26 06:00:56 +01:00
use LibreNMS\Config ;
header ( 'Content-type: application/json' );
$alert_id = $vars [ 'alert_id' ];
$state = $vars [ 'state' ];
$ack_msg = $vars [ 'ack_msg' ];
$status = 'error' ;
2015-07-13 20:10:26 +02:00
if ( ! is_numeric ( $alert_id )) {
2018-04-26 06:00:56 +01:00
$message = 'No alert selected' ;
2016-08-18 20:28:22 -05:00
} elseif ( ! is_numeric ( $state )) {
2018-04-26 06:00:56 +01:00
$message = 'No state passed' ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
if ( $state == 2 ) {
2018-03-14 20:25:19 +00:00
$state = 1 ;
2016-06-16 00:50:22 +01:00
$open = 1 ;
2016-08-18 20:28:22 -05:00
} elseif ( $state >= 1 ) {
2015-07-13 20:10:26 +02:00
$state = 2 ;
2016-06-16 00:50:22 +01:00
$open = 1 ;
2014-11-30 17:49:52 +00:00
}
2018-04-26 06:00:56 +01:00
$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' ;
2016-08-18 20:28:22 -05:00
} else {
2018-04-26 06:00:56 +01:00
$message = 'Alert has not been acknowledged.' ;
2015-07-13 20:10:26 +02:00
}
} //end if
2018-04-26 06:00:56 +01:00
die ( json_encode ([
'status' => $status ,
'message' => $message ,
]));