From a58c857ed2f3da7e5133066346802abbe73e1662 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sat, 27 Sep 2014 15:23:32 +1000 Subject: [PATCH] Provide more useful diagnostics when adding a device via the API --- html/includes/api_functions.inc.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index 7eee46d77a..4a657f7542 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -341,21 +341,25 @@ function add_device() { $message = "You haven't specified an SNMP version to use"; } + $code = 200; if(empty($message)) { require_once("../includes/functions.php"); $result = addHost($hostname, $snmpver, $port, $transport, 1); if($result) { - $status = 'ok'; - $message = 'Device has been added successfully'; + $status = "ok"; + $message = "Device $hostname has been added successfully"; } else { + $code = 500; + $status = "error"; $message = "Failed adding $hostname"; } } + $app->response->setStatus($code); $output = array("status" => $status, "message" => $message); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output);