api: Added ability to call get_graph_by_port_hostname() with hostname or id (#6936)

* Fix bug get_graph_by_port_hostname() only hostname

From the documentation:

Function: get_graph_by_port_hostname top
Get a graph of a port for a particular device.

hostname can be either the device hostname or id

But the function is only works with a hostname and not with a ID.
I have modified a few things that solve the problem.

* Update api_functions.inc.php
This commit is contained in:
Bitency
2017-07-04 23:41:22 +02:00
committed by Neil Lathwood
parent 51d50edc87
commit 2ba7093d9c

View File

@ -51,6 +51,7 @@ function get_graph_by_port_hostname()
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$hostname = $router['hostname'];
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$vars = array();
$vars['port'] = urldecode($router['ifname']);
$vars['type'] = $router['type'] ?: 'port_bits';
@ -71,7 +72,7 @@ function get_graph_by_port_hostname()
$vars['width'] = $_GET['width'] ?: 1075;
$vars['height'] = $_GET['height'] ?: 300;
$auth = '1';
$vars['id'] = dbFetchCell("SELECT `P`.`port_id` FROM `ports` AS `P` JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`hostname`=? AND `P`.`$port`=? AND `deleted` = 0 LIMIT 1", array($hostname, $vars['port']));
$vars['id'] = dbFetchCell("SELECT `P`.`port_id` FROM `ports` AS `P` JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`device_id`=? AND `P`.`$port`=? AND `deleted` = 0 LIMIT 1", array($device_id, $vars['port']));
$app->response->headers->set('Content-Type', get_image_type());
rrdtool_initialize(false);
include 'includes/graphs/graph.inc.php';