Files
librenms-librenms/includes/html/forms/processor-update.inc.php

54 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/*
* LibreNMS
*
* Copyright (c) 2015 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.
*/
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, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
exit;
}
2020-09-21 15:40:17 +02:00
$status = 'error';
$message = 'Error updating processor information';
$device_id = $_POST['device_id'];
$processor_id = $_POST['processor_id'];
$data = $_POST['data'];
2020-09-21 15:40:17 +02:00
if (! is_numeric($device_id)) {
$message = 'Missing device id';
2020-09-21 15:40:17 +02:00
} elseif (! is_numeric($processor_id)) {
$message = 'Missing processor id';
2020-09-21 15:40:17 +02:00
} elseif (! is_numeric($data)) {
$message = 'Missing value';
} else {
2020-09-21 15:40:17 +02:00
if (dbUpdate(['processor_perc_warn'=>$data], 'processors', '`processor_id`=? AND `device_id`=?', [$processor_id, $device_id]) >= 0) {
$message = 'Processor information updated';
$status = 'ok';
} else {
$message = 'Could not update processor information';
}
}
2020-09-21 15:40:17 +02:00
$response = [
'status' => $status,
'message' => $message,
'extra' => $extra,
2020-09-21 15:40:17 +02:00
];
echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);