diff --git a/html/api_v0.php b/html/api_v0.php index dec3e890e..e5f8aa71b 100644 --- a/html/api_v0.php +++ b/html/api_v0.php @@ -30,12 +30,13 @@ $app->setName('api'); $app->group('/api', function() use ($app) { $app->group('/v0', function() use ($app) { $app->group('/devices', function() use ($app) { - $app->get('/:hostname/ports/:ifname/:type', 'authToken', 'get_graph_by_port_hostname');//api/v1/devices/$hostname/ports/$ifName/$type - $app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname');//api/v1/devices/$hostname/$type - $app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname');//api/v1/devices/$hostname/ports/$ifName + $app->get('/:hostname/ports/:ifname/:type', 'authToken', 'get_graph_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName/$type + $app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname');//api/v0/devices/$hostname/$type + $app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName }); - $app->get('/devices', 'authToken', 'list_devices');//api/v1/devices - $app->post('/devices', 'authToken', 'add_device');//api/v1/devices (json data needs to be passed) + $app->get('/devices', 'authToken', 'list_devices');//api/v0/devices + $app->post('/devices', 'authToken', 'add_device');//api/v0/devices (json data needs to be passed) + $app->delete('/devices/:hostname', 'authToken', 'del_device');//api/v0/devices (json data needs to be passed) }); }); diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index 01eb31acb..8845b26ca 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -343,7 +343,7 @@ function add_device() } if(empty($message)) { - require_once("functions.php"); + require_once("../includes/functions.php"); $result = addHost($hostname, $snmpver, $port, $transport, 1); if($result) { @@ -360,3 +360,41 @@ function add_device() $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); } + + +function del_device() +{ + // This will add a device using the data passed encoded with json + global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $hostname = $router['hostname']; + // Default status to error and change it if we need to. + $status = "error"; + if(empty($hostname)) + { + $message = "No hostname has been provided to delete this device"; + } + elseif(empty($hostname)) + { + $message = "Missing the device hostname"; + } + if(empty($message)) + { + require_once("../includes/functions.php"); + $device_id = get_device_id($hostname); + $response = delete_device($device_id); + if(empty($response)) + { + $message = "Device couldn't be deleted"; + } + else + { + $message = $response; + $status = "ok"; + } + } + $output = array("status" => $status, "message" => $message); + $app->response->headers->set('Content-Type', 'application/json'); + echo _json_encode($output); +} diff --git a/html/pages/api-docs.inc.php b/html/pages/api-docs.inc.php index 78f998e93..b42d875b8 100644 --- a/html/pages/api-docs.inc.php +++ b/html/pages/api-docs.inc.php @@ -193,6 +193,26 @@ if ($_SESSION['userlevel'] == '10')
curl -X POST -d '{"hostname":"localhost.localdomain","version":"v1","community":"public"}' \
-H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v1/devices"curl -X DELETE -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v1/devices/localhost"