mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
BGP API: Allow to filter by local and remote peer address. (#11340)
This commit is contained in:
@@ -10,14 +10,10 @@ Route: `/api/v0/bgp`
|
||||
Input:
|
||||
|
||||
- hostname = Either the devices hostname or id.
|
||||
|
||||
**OR**
|
||||
|
||||
- asn = The local ASN you would like to filter by
|
||||
|
||||
Then you can filter by remote ASN
|
||||
|
||||
- remote_asn = The remote ASN
|
||||
- remote_asn = Filter by remote peer ASN
|
||||
- remote_address = Filter by remote peer address
|
||||
- local_address = Filter by local address
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +24,7 @@ curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/bgp
|
||||
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/bgp?hostname=host.example.com
|
||||
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/bgp?asn=1234
|
||||
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/bgp?remote_asn=1234
|
||||
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/bgp?local_address=1.1.1.1&remote_address=2.2.2.2
|
||||
```
|
||||
|
||||
Output:
|
||||
|
@@ -500,6 +500,8 @@ function list_bgp(\Illuminate\Http\Request $request)
|
||||
$hostname = $request->get('hostname');
|
||||
$asn = $request->get('asn');
|
||||
$remote_asn = $request->get('remote_asn');
|
||||
$local_address = $request->get('local_address');
|
||||
$remote_address = $request->get('remote_address');
|
||||
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||
if (is_numeric($device_id)) {
|
||||
$sql .= ' AND `devices`.`device_id` = ?';
|
||||
@@ -513,6 +515,14 @@ function list_bgp(\Illuminate\Http\Request $request)
|
||||
$sql .= ' AND `bgpPeers`.`bgpPeerRemoteAs` = ?';
|
||||
$sql_params[] = $remote_asn;
|
||||
}
|
||||
if (!empty($local_address)) {
|
||||
$sql .= ' AND `bgpPeers`.`bgpLocalAddr` = ?';
|
||||
$sql_params[] = $local_address;
|
||||
}
|
||||
if (!empty($remote_address)) {
|
||||
$sql .= ' AND `bgpPeers`.`bgpPeerIdentifier` = ?';
|
||||
$sql_params[] = $remote_address;
|
||||
}
|
||||
|
||||
$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);
|
||||
|
Reference in New Issue
Block a user