Provide more useful diagnostics when adding a device via the API

This commit is contained in:
Paul Gear 2014-09-27 15:23:32 +10:00
parent 4a8f54dafc
commit a58c857ed2

View File

@ -341,21 +341,25 @@ function add_device()
{ {
$message = "You haven't specified an SNMP version to use"; $message = "You haven't specified an SNMP version to use";
} }
$code = 200;
if(empty($message)) if(empty($message))
{ {
require_once("../includes/functions.php"); require_once("../includes/functions.php");
$result = addHost($hostname, $snmpver, $port, $transport, 1); $result = addHost($hostname, $snmpver, $port, $transport, 1);
if($result) if($result)
{ {
$status = 'ok'; $status = "ok";
$message = 'Device has been added successfully'; $message = "Device $hostname has been added successfully";
} }
else else
{ {
$code = 500;
$status = "error";
$message = "Failed adding $hostname"; $message = "Failed adding $hostname";
} }
} }
$app->response->setStatus($code);
$output = array("status" => $status, "message" => $message); $output = array("status" => $status, "message" => $message);
$app->response->headers->set('Content-Type', 'application/json'); $app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output); echo _json_encode($output);