mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix wireless sensor edit messages and collection alert rule (#9624)
* Fix wireless sensor edit messages and collection alert rule * fix alert rule quotes * json type
This commit is contained in:
@@ -15,20 +15,35 @@
|
|||||||
|
|
||||||
use LibreNMS\Authentication\LegacyAuth;
|
use LibreNMS\Authentication\LegacyAuth;
|
||||||
|
|
||||||
header('Content-type: text/plain');
|
header('Content-type: application/json');
|
||||||
|
|
||||||
// FUA
|
// FUA
|
||||||
|
|
||||||
if (!LegacyAuth::user()->hasGlobalAdmin()) {
|
if (!LegacyAuth::user()->hasGlobalAdmin()) {
|
||||||
die('ERROR: You need to be admin');
|
die(json_encode([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'You need to be admin'
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
|
if (isset($_POST['sub_type']) && $_POST['sub_type'] == 'remove-custom') {
|
||||||
dbUpdate(array('sensor_custom' => 'No'), 'wireless_sensors', '`sensor_id` = ?', array($_POST['sensor_id']));
|
if (dbUpdate(['sensor_custom' => 'No'], 'wireless_sensors', '`sensor_id` = ?', array($_POST['sensor_id']))) {
|
||||||
|
die(json_encode([
|
||||||
|
'status' => 'ok',
|
||||||
|
'message' => 'Custom limit removed'
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
die(json_encode([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Could not remove custom. Check librenms.log'
|
||||||
|
]));
|
||||||
} else {
|
} else {
|
||||||
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) {
|
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) {
|
||||||
echo 'error with data';
|
die(json_encode([
|
||||||
exit;
|
'status' => 'error',
|
||||||
|
'message' => 'Invalid values given'
|
||||||
|
]));
|
||||||
} else {
|
} else {
|
||||||
if ($_POST['state'] == 'true') {
|
if ($_POST['state'] == 'true') {
|
||||||
$state = 1;
|
$state = 1;
|
||||||
@@ -39,17 +54,21 @@ if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$update = dbUpdate(
|
$update = dbUpdate(
|
||||||
array('sensor_alert' => $state),
|
['sensor_alert' => $state],
|
||||||
'wireless_sensors',
|
'wireless_sensors',
|
||||||
'`sensor_id` = ? AND `device_id` = ?',
|
'`sensor_id` = ? AND `device_id` = ?',
|
||||||
array($_POST['sensor_id'], $_POST['device_id'])
|
[$_POST['sensor_id'], $_POST['device_id']]
|
||||||
);
|
);
|
||||||
if (!empty($update) || $update == '0') {
|
if (!empty($update) || $update == '0') {
|
||||||
echo 'success';
|
die(json_encode([
|
||||||
exit;
|
'status' => 'ok',
|
||||||
|
'message' => 'Updated sensor value'
|
||||||
|
]));
|
||||||
} else {
|
} else {
|
||||||
echo 'error';
|
die(json_encode([
|
||||||
exit;
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to update sensor value'
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,29 +15,38 @@
|
|||||||
|
|
||||||
use LibreNMS\Authentication\LegacyAuth;
|
use LibreNMS\Authentication\LegacyAuth;
|
||||||
|
|
||||||
header('Content-type: text/plain');
|
header('Content-type: application/json');
|
||||||
|
|
||||||
// FUA
|
// FUA
|
||||||
|
|
||||||
if (!LegacyAuth::user()->hasGlobalAdmin()) {
|
if (!LegacyAuth::user()->hasGlobalAdmin()) {
|
||||||
die('ERROR: You need to be admin');
|
die(json_encode([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'You need to be admin'
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || !isset($_POST['data'])) {
|
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || !isset($_POST['data'])) {
|
||||||
echo 'error with data';
|
die(json_encode([
|
||||||
exit;
|
'status' => 'error',
|
||||||
|
'message' => 'Invalid values given'
|
||||||
|
]));
|
||||||
} else {
|
} else {
|
||||||
$update = dbUpdate(
|
$update = dbUpdate(
|
||||||
array($_POST['value_type'] => set_null($_POST['data'], array('NULL')), 'sensor_custom' => 'Yes'),
|
[$_POST['value_type'] => set_null($_POST['data'], ['NULL']), 'sensor_custom' => 'Yes'],
|
||||||
'wireless_sensors',
|
'wireless_sensors',
|
||||||
'`sensor_id` = ? AND `device_id` = ?',
|
'`sensor_id` = ? AND `device_id` = ?',
|
||||||
array($_POST['sensor_id'], $_POST['device_id'])
|
[$_POST['sensor_id'], $_POST['device_id']]
|
||||||
);
|
);
|
||||||
if (!empty($update) || $update == '0') {
|
if (!empty($update) || $update == '0') {
|
||||||
echo 'success';
|
die(json_encode([
|
||||||
exit;
|
'status' => 'ok',
|
||||||
|
'message' => 'Updated sensor value'
|
||||||
|
]));
|
||||||
} else {
|
} else {
|
||||||
echo 'error';
|
die(json_encode([
|
||||||
exit;
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to update sensor value'
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ $('#newThread').on('click', function(e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
error:function(){
|
error:function(data){
|
||||||
toastr.error(data.message);
|
toastr.error(data.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -169,7 +169,7 @@ $( ".sensor" ).bind('blur keyup',function(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
error:function(){
|
error:function(data){
|
||||||
toastr.error(data.message);
|
toastr.error(data.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -198,7 +198,7 @@ $('input[name="alert-status"]').on('switchChange.bootstrapSwitch', function(eve
|
|||||||
toastr.error(data.message);
|
toastr.error(data.message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error:function(){
|
error:function(data){
|
||||||
toastr.error(data.message);
|
toastr.error(data.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -216,7 +216,7 @@ $("[name='remove-custom']").on('click', function(event) {
|
|||||||
toastr.success(data.message);
|
toastr.success(data.message);
|
||||||
$this.addClass('disabled');
|
$this.addClass('disabled');
|
||||||
},
|
},
|
||||||
error:function(){
|
error:function(data){
|
||||||
toastr.error(data.message);
|
toastr.error(data.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
"name": "Device discovered within the last 60 minutes"
|
"name": "Device discovered within the last 60 minutes"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"rule": "wireless_sensors.sensor_class = 'clients' && wireless_sensors.sensor_current >= wireless_sensors.sensor_limit && wireless_sensors.sensor_alert = \"1\" && macros.device_up = \"1\"",
|
"rule": "wireless_sensors.sensor_class = \"clients\" && wireless_sensors.sensor_current >= `wireless_sensors.sensor_limit` && wireless_sensors.sensor_alert = \"1\" && macros.device_up = \"1\"",
|
||||||
"name": "Too many wireless clients"
|
"name": "Too many wireless clients"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user