mirror of
https://github.com/librenms/librenms.git
synced 2024-09-22 02:48:37 +00:00
api: Added new route for multiport bit graphs + asn list_bgp filter (#6129)
* api: Added new route for multiport bit graphs + asn list_bgp filter * fixed scrut errors
This commit is contained in:
parent
745eb7b120
commit
014682b60b
@ -37,6 +37,7 @@ source: API/API-Docs.md
|
|||||||
- [`get_port_info`](#api-route-get_port_info)
|
- [`get_port_info`](#api-route-get_port_info)
|
||||||
- [`get_port_ip_info`](#api-route-get_port_ip_info)
|
- [`get_port_ip_info`](#api-route-get_port_ip_info)
|
||||||
- [`portgroups`](#api-portgroups)
|
- [`portgroups`](#api-portgroups)
|
||||||
|
- [`get_graph_by_portgroup_multiport_bits`](#api-route-get_graph_by_portgroup_multiport_bits)
|
||||||
- [`get_graph_by_portgroup`](#api-route-get_graph_by_portgroup)
|
- [`get_graph_by_portgroup`](#api-route-get_graph_by_portgroup)
|
||||||
- [`routing`](#api-routing)
|
- [`routing`](#api-routing)
|
||||||
- [`list_bgp`](#api-route-1)
|
- [`list_bgp`](#api-route-1)
|
||||||
@ -1213,6 +1214,31 @@ Output:
|
|||||||
|
|
||||||
Output is an image.
|
Output is an image.
|
||||||
|
|
||||||
|
### <a name="api-route-get_graph_by_portgroup_multiport_bits">Function: `get_graph_by_portgroup_multiport_bits`</a> [`top`](#top)
|
||||||
|
|
||||||
|
Get the graph based on the multiple port id separated by commas `,`.
|
||||||
|
|
||||||
|
Route: /api/v0/devices/portgroups/multiport/bits/:id
|
||||||
|
|
||||||
|
- id is a comma separated list of port ids you want, I.e 1,2,3,4, etc. You can specify multiple IDs comma separated.
|
||||||
|
|
||||||
|
Input:
|
||||||
|
|
||||||
|
- from: This is the date you would like the graph to start - See http://oss.oetiker.ch/rrdtool/doc/rrdgraph.en.html for more information.
|
||||||
|
- to: This is the date you would like the graph to end - See http://oss.oetiker.ch/rrdtool/doc/rrdgraph.en.html for more information.
|
||||||
|
- width: The graph width, defaults to 1075.
|
||||||
|
- height: The graph height, defaults to 300.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```curl
|
||||||
|
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/portgroups/multiport/bits/1,2,3
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
Output is an image.
|
||||||
|
|
||||||
|
|
||||||
## <a name="api-routing">`Routing`</a> [`top`](#top)
|
## <a name="api-routing">`Routing`</a> [`top`](#top)
|
||||||
|
|
||||||
### <a name="api-route-1">Function: `list_bgp`</a> [`top`](#top)
|
### <a name="api-route-1">Function: `list_bgp`</a> [`top`](#top)
|
||||||
@ -1223,7 +1249,9 @@ Route: /api/v0/bgp
|
|||||||
|
|
||||||
Input:
|
Input:
|
||||||
|
|
||||||
- hostname = either the devices hostname or id.
|
- hostname = Either the devices hostname or id.
|
||||||
|
**OR**
|
||||||
|
- asn = The ASN you would like to filter by
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```curl
|
```curl
|
||||||
|
@ -82,8 +82,8 @@ $app->group(
|
|||||||
$app->group(
|
$app->group(
|
||||||
'/portgroups',
|
'/portgroups',
|
||||||
function () use ($app) {
|
function () use ($app) {
|
||||||
|
$app->get('/multiport/bits/:id', 'authToken', 'get_graph_by_portgroup')->name('get_graph_by_portgroup_multiport_bits');
|
||||||
$app->get('/:group', 'authToken', 'get_graph_by_portgroup')->name('get_graph_by_portgroup');
|
$app->get('/:group', 'authToken', 'get_graph_by_portgroup')->name('get_graph_by_portgroup');
|
||||||
// api/v0/portgroups/$group
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$app->group(
|
$app->group(
|
||||||
|
@ -457,14 +457,19 @@ function list_bgp()
|
|||||||
$message = 'Error retrieving bgpPeers';
|
$message = 'Error retrieving bgpPeers';
|
||||||
$sql = '';
|
$sql = '';
|
||||||
$sql_params = array();
|
$sql_params = array();
|
||||||
$hostname = $_GET['hostname'];
|
$hostname = $_GET['hostname'] ?: '';
|
||||||
|
$asn = $_GET['asn'] ?: '';
|
||||||
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||||
if (is_numeric($device_id)) {
|
if (is_numeric($device_id)) {
|
||||||
$sql = ' AND `device_id`=?';
|
$sql = ' AND `devices`.`device_id` = ?';
|
||||||
$sql_params = array($device_id);
|
$sql_params[] = $device_id;
|
||||||
|
}
|
||||||
|
if (!empty($asn)) {
|
||||||
|
$sql = ' AND `devices`.`bgpLocalAs` = ?';
|
||||||
|
$sql_params[] = $asn;
|
||||||
}
|
}
|
||||||
|
|
||||||
$bgp_sessions = dbFetchRows("SELECT * FROM bgpPeers WHERE `bgpPeerState` IS NOT NULL AND `bgpPeerState` != '' $sql", $sql_params);
|
$bgp_sessions = dbFetchRows("SELECT `bgpPeers`.* FROM `bgpPeers` LEFT JOIN `devices` ON `bgpPeers`.`device_id` = `devices`.`device_id` WHERE `bgpPeerState` IS NOT NULL AND `bgpPeerState` != '' $sql", $sql_params);
|
||||||
$total_bgp_sessions = count($bgp_sessions);
|
$total_bgp_sessions = count($bgp_sessions);
|
||||||
if (is_numeric($total_bgp_sessions)) {
|
if (is_numeric($total_bgp_sessions)) {
|
||||||
$code = 200;
|
$code = 200;
|
||||||
@ -489,7 +494,8 @@ function get_graph_by_portgroup()
|
|||||||
global $config;
|
global $config;
|
||||||
$app = \Slim\Slim::getInstance();
|
$app = \Slim\Slim::getInstance();
|
||||||
$router = $app->router()->getCurrentRoute()->getParams();
|
$router = $app->router()->getCurrentRoute()->getParams();
|
||||||
$group = $router['group'];
|
$group = $router['group'] ?: '';
|
||||||
|
$id = $router['id'] ?: '';
|
||||||
$vars = array();
|
$vars = array();
|
||||||
if (!empty($_GET['from'])) {
|
if (!empty($_GET['from'])) {
|
||||||
$vars['from'] = $_GET['from'];
|
$vars['from'] = $_GET['from'];
|
||||||
@ -502,13 +508,20 @@ function get_graph_by_portgroup()
|
|||||||
$vars['width'] = $_GET['width'] ?: 1075;
|
$vars['width'] = $_GET['width'] ?: 1075;
|
||||||
$vars['height'] = $_GET['height'] ?: 300;
|
$vars['height'] = $_GET['height'] ?: 300;
|
||||||
$auth = '1';
|
$auth = '1';
|
||||||
|
$if_list = '';
|
||||||
|
$ports = array();
|
||||||
|
|
||||||
$ports = get_ports_from_type(explode(',', $group));
|
if (!empty($id)) {
|
||||||
$if_list = '';
|
$if_list = $id;
|
||||||
$seperator = '';
|
} else {
|
||||||
foreach ($ports as $port) {
|
$ports = get_ports_from_type(explode(',', $group));
|
||||||
$if_list .= $seperator.$port['port_id'];
|
}
|
||||||
$seperator = ',';
|
if (empty($if_list)) {
|
||||||
|
$seperator = '';
|
||||||
|
foreach ($ports as $port) {
|
||||||
|
$if_list .= $seperator.$port['port_id'];
|
||||||
|
$seperator = ',';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($seperator);
|
unset($seperator);
|
||||||
@ -1421,6 +1434,7 @@ function list_ipsec()
|
|||||||
$code = 404;
|
$code = 404;
|
||||||
$message = '';
|
$message = '';
|
||||||
$hostname = $router['hostname'];
|
$hostname = $router['hostname'];
|
||||||
|
$total = 0;
|
||||||
// use hostname as device_id if it's all digits
|
// use hostname as device_id if it's all digits
|
||||||
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||||
if (!is_numeric($device_id)) {
|
if (!is_numeric($device_id)) {
|
||||||
@ -1451,6 +1465,7 @@ function list_arp()
|
|||||||
$code = 404;
|
$code = 404;
|
||||||
$message = '';
|
$message = '';
|
||||||
$ip = $router['ip'];
|
$ip = $router['ip'];
|
||||||
|
$total = 0;
|
||||||
if (empty($ip)) {
|
if (empty($ip)) {
|
||||||
$message = "No valid IP provided";
|
$message = "No valid IP provided";
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user