mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
Added api call to delete device
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user