Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bgp peers route to display all bgp peers #335

Merged
merged 2 commits into from Nov 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions html/api_v0.php
Expand Up @@ -39,6 +39,7 @@
$app->get('/devices', 'authToken', 'list_devices')->name('list_devices');//api/v0/devices
$app->post('/devices', 'authToken', 'add_device')->name('add_device');//api/v0/devices (json data needs to be passed)
$app->delete('/devices/:hostname', 'authToken', 'del_device')->name('del_device');//api/v0/devices (json data needs to be passed)
$app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');//api/v0/bpg
});
$app->get('/v0', 'authToken', 'show_endpoints');//api/v0
});
Expand Down
27 changes: 27 additions & 0 deletions html/includes/api_functions.inc.php
Expand Up @@ -349,3 +349,30 @@ function show_endpoints() {
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}

function list_bgp() {
global $config;
$app = \Slim\Slim::getInstance();
$code = 500;
$status = 'error';
$message = 'Error retrieving bgpPeers';
$sql = '';
$sql_params = array();
$hostname = $_GET['hostname'];
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
if(is_numeric($device_id)) {
$sql = " AND `device_id`=?";
$sql_params = array($device_id);
}
$bgp_sessions = dbFetchRows("SELECT * FROM bgpPeers WHERE `bgpPeerState` IS NOT NULL AND `bgpPeerState` != '' $sql", $sql_params);
$total_bgp_sessions = count($bgp_sessions);
if(is_numeric($total_bgp_sessions)) {
$code = 200;
$status = 'ok';
$message = '';
}
$output = array("status" => "$status", "err-msg" => $message, "count" => $total_bgp_sessions, "bgp_sessions" => $bgp_sessions);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
18 changes: 18 additions & 0 deletions html/pages/api-docs.inc.php
Expand Up @@ -250,6 +250,24 @@
<tr>
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost/vlans"</code></td>
</tr>
<tr class="success">
<td colspan="5"><strong>List BGP Sessions</strong></td>
</tr>
<tr>
<td>/api</td>
<td>/v0</td>
<td>/bgp</td>
<td>
<ul class="list-unstyled">
</ul>
</td>
<td>
JSON
</td>
</tr>
<tr>
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/bgp"</code></td>
</tr>
</table>
</div>
</div>
Expand Down