Added support for excluding devices from Oxidized api

This commit is contained in:
laf
2015-10-10 13:40:27 +00:00
parent 3bdf2f60d7
commit 37b7e8247d
5 changed files with 103 additions and 1 deletions

View File

@@ -856,7 +856,7 @@ function list_oxidized() {
$app->response->headers->set('Content-Type', 'application/json');
$devices = array();
foreach (dbFetchRows("SELECT hostname,os FROM `devices` WHERE `status`='1'") as $device) {
foreach (dbFetchRows("SELECT hostname,os FROM `devices` LEFT JOIN devices_attribs AS `DA` ON devices.device_id = DA.device_id AND `DA`.attrib_type='override_Oxidized_disable' WHERE `status`='1' AND (DA.attrib_value = 'false' OR DA.attrib_value IS NULL)") as $device) {
$devices[] = $device;
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
*
* 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.
*/
if (is_admin() === false) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
exit;
}
$device['device_id'] = mres($_POST['device_id']);
$attrib = mres($_POST['attrib']);
$state = mres($_POST['state']);
$status = 'error';
$message = 'Error with config';
if (empty($device['device_id'])) {
$message = 'No device passed';
}
else {
if ($state == true) {
set_dev_attrib($device, $attrib, $state);
}
else {
del_dev_attrib($device, $attrib);
}
$status = 'ok';
$message = 'Config has been updated';
}
$response = array(
'status' => $status,
'message' => $message,
);
echo _json_encode($response);

View File

@@ -1167,3 +1167,15 @@ function alert_details($details) {
}//end alert_details()
function dynamic_override_config($type, $name, $device) {
$attrib_val = get_dev_attrib($device,$name);
if ($attrib_val == 'true') {
$checked = 'checked';
}
else {
$checked = '';
}
if ($type == 'checkbox') {
return '<input type="checkbox" id="override_config" name="override_config" data-attrib="'.$name.'" data-device_id="'.$device['device_id'].'" data-size="small" '.$checked.'>';
}
}//end dynamic_override_config()

View File

@@ -36,6 +36,7 @@ else {
}
$panes['storage'] = 'Storage';
$panes['misc'] = 'Misc';
print_optionbar_start();

View File

@@ -0,0 +1,41 @@
<?php
echo '
<form class="form-horizontal">
<div class="form-group">
<label for="oxidized" class="col-sm-2 control-label">Exclude from Oxidized?</label>
<div class="col-sm-10">
'.dynamic_override_config('checkbox','override_Oxidized_disable', $device).'
</div>
</div>
</form>
';
?>
<script>
$("[name='override_config']").bootstrapSwitch('offColor','danger');
$('input[name="override_config"]').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault();
var $this = $(this);
var attrib = $this.data('attrib');
var device_id = $this.data('device_id');
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: 'override-config', device_id: device_id, attrib: attrib, state: state },
dataType: 'json',
success: function(data) {
if (data.status == 'ok') {
toastr.success(data.message);
}
else {
toastr.error(data.message);
}
},
error: function() {
toastr.error('Could not set this override');
}
});
});
</script>