mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added bgp peers route to display all bgp peers
This commit is contained in:
@ -39,6 +39,7 @@ $app->group('/api', function() use ($app) {
|
|||||||
$app->get('/devices', 'authToken', 'list_devices')->name('list_devices');//api/v0/devices
|
$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->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->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
|
$app->get('/v0', 'authToken', 'show_endpoints');//api/v0
|
||||||
});
|
});
|
||||||
|
@ -349,3 +349,23 @@ function show_endpoints() {
|
|||||||
$app->response->headers->set('Content-Type', 'application/json');
|
$app->response->headers->set('Content-Type', 'application/json');
|
||||||
echo _json_encode($output);
|
echo _json_encode($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function list_bgp() {
|
||||||
|
global $config;
|
||||||
|
$app = \Slim\Slim::getInstance();
|
||||||
|
$router = $app->router()->getCurrentRoute()->getParams();
|
||||||
|
$code = 500;
|
||||||
|
$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);
|
||||||
|
$code = 200;
|
||||||
|
$output = array("status" => "ok", "count" => $total_bgp_sessions, "bgp_sessions" => $bgp_sessions);
|
||||||
|
$app->response->setStatus($code);
|
||||||
|
$app->response->headers->set('Content-Type', 'application/json');
|
||||||
|
echo _json_encode($output);
|
||||||
|
}
|
||||||
|
@ -250,6 +250,24 @@ if ($_SESSION['userlevel'] == '10')
|
|||||||
<tr>
|
<tr>
|
||||||
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost/vlans"</code></td>
|
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost/vlans"</code></td>
|
||||||
</tr>
|
</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>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user