api: Added simple OSPF API route

This commit is contained in:
Thom Seddon
2017-09-07 20:04:36 +01:00
committed by Neil Lathwood
parent 542fdfc97e
commit 20aa23508f
2 changed files with 37 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ $app->group(
'/v0',
function () use ($app) {
$app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');
$app->get('/ospf', 'authToken', 'list_ospf')->name('list_ospf');
// api/v0/bgp
$app->get('/oxidized', 'authToken', 'list_oxidized')->name('list_oxidized');
$app->group(

View File

@@ -493,6 +493,42 @@ function list_bgp()
}
function list_ospf()
{
global $config;
$app = \Slim\Slim::getInstance();
$code = 500;
$status = 'error';
$message = 'Error retrieving ospf_nbrs';
$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);
}
$ospf_neighbours = dbFetchRows("SELECT * FROM ospf_nbrs WHERE `ospfNbrState` IS NOT NULL AND `ospfNbrState` != '' $sql", $sql_params);
$total_ospf_neighbours = count($ospf_neighbours);
if (is_numeric($total_ospf_neighbours)) {
$code = 200;
$status = 'ok';
$message = '';
}
$output = array(
'status' => "$status",
'err-msg' => $message,
'count' => $total_ospf_neighbours,
'ospf_neighbours' => $ospf_neighbours,
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function get_graph_by_portgroup()
{
global $config;