Use Exceptions

Use exceptions for addHost()
Gets rid of silly mixed return and only returns the device_id.  Throwing an exception if we run into any issues.
Slightly modifies api add host output again to include device_id
This commit is contained in:
Tony Murray
2016-08-07 12:16:40 -05:00
parent f1268848b0
commit f3fc6f2906
6 changed files with 77 additions and 55 deletions

View File

@@ -289,14 +289,13 @@ function add_device() {
$message = "You haven't specified an SNMP version to use";
}
if (empty($message)) {
$result = addHost($hostname, $snmpver, $port, $transport, 1, $poller_group, $force_add);
if (is_numeric($result)) {
try {
$device_id = addHost($hostname, $snmpver, $port, $transport, $poller_group, $force_add);
$code = 201;
$status = 'ok';
$message = "Device $hostname has been added successfully";
}
else {
$message = $result;
$message = "Device $hostname ($device_id) has been added successfully";
} catch (Exception $e) {
$message = $e->getMessage();
}
}