BGP API: Add filter by remote ASN (#11204)

* BGP API: Add filter by remote ASN

* Fix blocked merge
This commit is contained in:
Mathieu Poussin
2020-02-26 14:29:44 +01:00
committed by GitHub
parent 0baeab567b
commit baf2f9a4ce
3 changed files with 16 additions and 3 deletions

View File

@@ -13,7 +13,13 @@ Input:
**OR**
- asn = The ASN you would like to filter by
- asn = The local ASN you would like to filter by
Then you can filter by remote ASN
- remote_asn = The remote ASN
Example:
@@ -21,6 +27,7 @@ Example:
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
```
Output:

View File

@@ -499,15 +499,20 @@ function list_bgp(\Illuminate\Http\Request $request)
$sql_params = [];
$hostname = $request->get('hostname');
$asn = $request->get('asn');
$remote_asn = $request->get('remote_asn');
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
if (is_numeric($device_id)) {
$sql = ' AND `devices`.`device_id` = ?';
$sql .= ' AND `devices`.`device_id` = ?';
$sql_params[] = $device_id;
}
if (!empty($asn)) {
$sql = ' AND `devices`.`bgpLocalAs` = ?';
$sql .= ' AND `devices`.`bgpLocalAs` = ?';
$sql_params[] = $asn;
}
if (!empty($remote_asn)) {
$sql .= ' AND `bgpPeers`.`bgpPeerRemoteAs` = ?';
$sql_params[] = $remote_asn;
}
$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);

View File

@@ -110,6 +110,7 @@ nav:
- Services: API/Services.md
- System: API/System.md
- Logs: API/Logs.md
- Logs: API/Locations.md
- 8. Alerting:
- Intro: Alerting/index.md
- Introduction: Alerting/Introduction.md