librenms-librenms/includes/html/forms/sensor-alert-update.inc.php

64 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/*
2014-06-17 00:51:02 +01:00
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
* Copyright (c) 2018 TheGreatDoc <https://github.com/TheGreatDoc>
2014-06-17 00:51:02 +01:00
*
* 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.
*/
header('Content-type: application/json');
2020-09-21 15:40:17 +02:00
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
2020-09-21 15:40:17 +02:00
];
echo _json_encode($response);
exit;
}
2020-09-21 15:40:17 +02:00
if (isset($_POST['sub_type']) && ! empty($_POST['sub_type'])) {
$status = 'error';
$message = 'Error removing custom';
2020-09-21 15:40:17 +02:00
if (dbUpdate(['sensor_custom' => 'No'], 'sensors', '`sensor_id` = ?', [$_POST['sensor_id']]) >= 0) {
$status = 'ok';
$message = 'Custom limit removed. New one will be set up in rediscovery';
} else {
$message = 'Couldn\'t not remove custom. Enable debug and check logfile';
}
} else {
2020-09-21 15:40:17 +02:00
if (! is_numeric($_POST['device_id']) || ! is_numeric($_POST['sensor_id'])) {
$message = "Invalid device or sensor id";
} else {
2015-07-13 20:10:26 +02:00
if ($_POST['state'] == 'true') {
$state = 1;
$state_string = "enabled";
} elseif ($_POST['state'] == 'false') {
2015-07-13 20:10:26 +02:00
$state = 0;
$state_string = "disabled";
} else {
2015-07-13 20:10:26 +02:00
$state = 0;
$state_string = "disabled";
2015-07-13 20:10:26 +02:00
}
2020-09-21 15:40:17 +02:00
if (dbUpdate(['sensor_alert' => $state], 'sensors', '`sensor_id` = ? AND `device_id` = ?', [$_POST['sensor_id'], $_POST['device_id']]) >= 0) {
$status = ($state == 0) ? 'info' : 'ok';
$message = 'Alerts ' . $state_string . ' for sensor ' . $_POST['sensor_desc'];
} else {
$status = 'error';
$message = 'Couldn\'t ' . substr($state_string, 0, -1) . ' alerts for sensor ' . $_POST['sensor_desc'] . '. Enable debug and check librenms.log';
2015-07-13 20:10:26 +02:00
}
}
}
2020-09-21 15:40:17 +02:00
$response = [
'status' => $status,
2020-09-21 15:40:17 +02:00
'message' => $message,
];
echo _json_encode($response);