mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 16:04:35 +02:00
Merge pull request #3304 from adaniels21487/issue-3264
Component API Additions
This commit is contained in:
+3
-1
@@ -50,7 +50,9 @@ $app->group(
|
||||
$app->get('/:hostname/ports', 'authToken', 'get_port_graphs')->name('get_port_graphs');
|
||||
// api/v0/devices/$hostname/ports
|
||||
$app->get('/:hostname/components', 'authToken', 'get_components')->name('get_components');
|
||||
// api/v0/devices/$hostname/components
|
||||
$app->post('/:hostname/components/:type', 'authToken', 'add_components')->name('add_components');
|
||||
$app->put('/:hostname/components', 'authToken', 'edit_components')->name('edit_components');
|
||||
$app->delete('/:hostname/components/:component', 'authToken', 'delete_components')->name('delete_components');
|
||||
$app->get('/:hostname/groups', 'authToken', 'get_device_groups')->name('get_device_groups');
|
||||
$app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname')->name('get_graph_generic_by_hostname');
|
||||
// api/v0/devices/$hostname/$type
|
||||
|
||||
@@ -535,8 +535,8 @@ function get_components() {
|
||||
unset ($_GET['label']);
|
||||
}
|
||||
// Add the rest of the options with an equals query
|
||||
foreach ($_GET as $k) {
|
||||
$options['filter'][$k] = array('=',$_GET[$k]);
|
||||
foreach ($_GET as $k => $v) {
|
||||
$options['filter'][$k] = array('=',$v);
|
||||
}
|
||||
|
||||
// use hostname as device_id if it's all digits
|
||||
@@ -556,6 +556,100 @@ function get_components() {
|
||||
}
|
||||
|
||||
|
||||
function add_components() {
|
||||
global $config;
|
||||
$code = 200;
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
$hostname = $router['hostname'];
|
||||
$ctype = $router['type'];
|
||||
|
||||
// use hostname as device_id if it's all digits
|
||||
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||
$COMPONENT = new component();
|
||||
$component = $COMPONENT->createComponent($device_id,$ctype);
|
||||
|
||||
$output = array(
|
||||
'status' => "$status",
|
||||
'err-msg' => $message,
|
||||
'count' => count($component),
|
||||
'components' => $component,
|
||||
);
|
||||
$app->response->setStatus($code);
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
echo _json_encode($output);
|
||||
}
|
||||
|
||||
|
||||
function edit_components() {
|
||||
global $config;
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
$hostname = $router['hostname'];
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
// use hostname as device_id if it's all digits
|
||||
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||
$COMPONENT = new component();
|
||||
|
||||
if ($COMPONENT->setComponentPrefs($device_id,$data)) {
|
||||
// Edit Success.
|
||||
$code = 200;
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
}
|
||||
else {
|
||||
// Edit Failure.
|
||||
$code = 500;
|
||||
$status = 'error';
|
||||
$message = 'Components could not be edited.';
|
||||
}
|
||||
|
||||
$output = array(
|
||||
'status' => "$status",
|
||||
'err-msg' => $message,
|
||||
'count' => count($data),
|
||||
);
|
||||
|
||||
$app->response->setStatus($code);
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
echo _json_encode($output);
|
||||
}
|
||||
|
||||
|
||||
function delete_components() {
|
||||
global $config;
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
$cid = $router['component'];
|
||||
|
||||
$COMPONENT = new component();
|
||||
if ($COMPONENT->deleteComponent($cid)) {
|
||||
// Edit Success.
|
||||
$code = 200;
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
}
|
||||
else {
|
||||
// Edit Failure.
|
||||
$code = 500;
|
||||
$status = 'error';
|
||||
$message = 'Components could not be deleted.';
|
||||
}
|
||||
|
||||
$output = array(
|
||||
'status' => "$status",
|
||||
'err-msg' => $message,
|
||||
);
|
||||
|
||||
$app->response->setStatus($code);
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
echo _json_encode($output);
|
||||
}
|
||||
|
||||
|
||||
function get_graphs() {
|
||||
global $config;
|
||||
$code = 200;
|
||||
|
||||
Reference in New Issue
Block a user