mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 18:38:25 +00:00
api: Added retrieve BGP sessions by ID (#7825)
* add support for retrieving BGP sessions via id * fix syntax, use router params * use count properly * add get_bgp docs * streamlined get_bgp sql query
This commit is contained in:
parent
5871ee1c67
commit
e3082873f6
@ -29,6 +29,49 @@ Output:
|
||||
}
|
||||
```
|
||||
|
||||
### `get_bgp`
|
||||
|
||||
Retrieves a BGP session by ID
|
||||
|
||||
Route: `/api/v0/bgp/:id`
|
||||
|
||||
Input:
|
||||
|
||||
-
|
||||
|
||||
Example:
|
||||
```curl
|
||||
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/bgp/4
|
||||
```
|
||||
|
||||
Output:
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"bgp_session": [
|
||||
{
|
||||
"bgpPeer_id": "4",
|
||||
"device_id": "2",
|
||||
"astext": "",
|
||||
"bgpPeerIdentifier": "1234:1b80:1:12::2",
|
||||
"bgpPeerRemoteAs": "54321",
|
||||
"bgpPeerState": "established",
|
||||
"bgpPeerAdminStatus": "running",
|
||||
"bgpLocalAddr": "1234:1b80:1:12::1",
|
||||
"bgpPeerRemoteAddr": "0.0.0.0",
|
||||
"bgpPeerInUpdates": "3",
|
||||
"bgpPeerOutUpdates": "1",
|
||||
"bgpPeerInTotalMessages": "0",
|
||||
"bgpPeerOutTotalMessages": "0",
|
||||
"bgpPeerFsmEstablishedTime": "0",
|
||||
"bgpPeerInUpdateElapsedTime": "0",
|
||||
"context_name": ""
|
||||
}
|
||||
],
|
||||
"count": 1
|
||||
}
|
||||
```
|
||||
|
||||
### `list_ipsec`
|
||||
|
||||
List the current IPSec tunnels which are active.
|
||||
|
@ -40,6 +40,7 @@ $app->group(
|
||||
'/v0',
|
||||
function () use ($app) {
|
||||
$app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');
|
||||
$app->get('/bgp/:id', 'authToken', 'get_bgp')->name('get_bgp');
|
||||
$app->get('/ospf', 'authToken', 'list_ospf')->name('list_ospf');
|
||||
// api/v0/bgp
|
||||
$app->get('/oxidized(/:hostname)', 'authToken', 'list_oxidized')->name('list_oxidized');
|
||||
|
@ -506,6 +506,31 @@ function list_bgp()
|
||||
}
|
||||
|
||||
|
||||
function get_bgp()
|
||||
{
|
||||
check_is_read();
|
||||
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
|
||||
$bgpPeerId = $router['id'];
|
||||
if (!is_numeric($bgpPeerId)) {
|
||||
api_error(400, 'Invalid id has been provided');
|
||||
}
|
||||
|
||||
$bgp_session = dbFetchRows("SELECT * FROM `bgpPeers` WHERE `bgpPeerState` IS NOT NULL AND `bgpPeerState` != '' AND bgpPeer_id = ?", array($bgpPeerId));
|
||||
$bgp_session_count = count($bgp_session);
|
||||
if (!is_numeric($bgp_session_count)) {
|
||||
api_error(500, 'Error retrieving BGP peer');
|
||||
}
|
||||
if ($bgp_session_count == 0) {
|
||||
api_error(404, "BGP peer $bgpPeerId does not exist");
|
||||
}
|
||||
|
||||
api_success($bgp_session, 'bgp_session');
|
||||
}
|
||||
|
||||
|
||||
function list_ospf()
|
||||
{
|
||||
check_is_read();
|
||||
|
Loading…
Reference in New Issue
Block a user