Updated api routes to new format + moved includes file to correct location

This commit is contained in:
laf
2014-09-16 22:09:42 +01:00
parent 5d83c30708
commit a0b52743d0
3 changed files with 60 additions and 341 deletions

View File

@ -24,36 +24,18 @@ include_once("../includes/rrdtool.inc.php");
require 'includes/Slim/Slim.php'; require 'includes/Slim/Slim.php';
\Slim\Slim::registerAutoloader(); \Slim\Slim::registerAutoloader();
$app = new \Slim\Slim(); $app = new \Slim\Slim();
require_once("../includes/api_functions.inc.php"); require_once("includes/api_functions.inc.php");
$app->setName('api'); $app->setName('api');
$app->group('/api', function() use ($app) { $app->group('/api', function() use ($app) {
$app->group('/v1', function() use ($app) { $app->group('/v1', function() use ($app) {
$app->group('/get', function() use ($app) { $app->group('/devices', function() use ($app) {
$app->group('/graph', function() use ($app) { $app->get('/:hostname/ports/:ifname/:type', 'authToken', 'get_graph_by_port_hostname');//api/v1/devices/$hostname/ports/$ifName/$type
$app->group('/port', function() use ($app) { $app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname');//api/v1/devices/$hostname/$type
$app->get('/id/:id(/:type)(/:width)(/:height)(/:from)(/:to)(/)', 'authToken', 'get_graph_by_id');//api/v1/get/graph/port/id/$port_id $app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname');//api/v1/devices/$hostname/ports/$ifName
$app->get('/device/:id/:port(/:type)(/:width)(/:height)(/:from)(/:to)(/)', 'authToken', 'get_graph_by_port');//api/v1/get/graph/port/device/$device_id/$ifName
$app->get('/hostname/:hostname/:port(/:type)(/:width)(/:height)(/:from)(/:to)(/)', 'authToken', 'get_graph_by_port_hostname');//api/v1/get/graph/port/device/$hostname/$ifName
});
$app->group('/general', function() use ($app) {
$app->get('/device/:id/:type(/:width)(/:height)(/:from)(/:to)(/)', 'authToken', 'get_graph_generic_by_deviceid');//api/v1/get/graph/general/device/$device_id/$graph_type
$app->get('/hostname/:hostname/:type(/:width)(/:height)(/:from)(/:to)(/)', 'authToken', 'get_graph_generic_by_hostname');//api/v1/get/graph/general/hostname/$hostname/$graph_type
});
});
$app->group('/stats', function() use ($app) {
$app->group('/port', function() use ($app) {
$app->get('/id/:id(/)', 'authToken', 'get_port_stats_by_id');//api/v1/get/stats/port/id/$port_id
$app->get('/device/:id/:port(/)', 'authToken', 'get_port_stats_by_port');//api/v1/get/stats/port/device/$device_id/$ifName
});
});
});
$app->group('/list', function() use ($app) {
$app->get('/devices(/:order)(/:type)(/)', 'authToken', 'list_devices');//api/v1/list/devices (order can be any device column) (types = all, ignored, up, down, disabled)
});
$app->group('/add', function() use ($app) {
$app->post('/device(/)', 'authToken', 'add_device');//api/v1/add/device (json data needs to be passed)
}); });
$app->get('/devices', 'authToken', 'list_devices');//api/v1/devices
$app->post('/devices', 'authToken', 'add_device');//api/v1/devices (json data needs to be passed)
}); });
}); });

View File

@ -183,56 +183,6 @@ function authToken(\Slim\Route $route)
} }
} }
function get_graph_by_id()
{
// This will return a graph for a given port by the port id
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$vars = array();
$vars['id'] = $router['id'];
$vars['type'] = $router['type'] ?: 'port_bits';
if(!empty($router['from']))
{
$vars['from'] = $router['from'];
}
if(!empty($router['to']))
{
$vars['to'] = $router['to'];
}
$vars['width'] = $router['width'] ?: 1075;
$vars['height'] = $router['height'] ?: 300;
$auth = "1";
$app->response->headers->set('Content-Type', 'image/png');
require("includes/graphs/graph.inc.php");
}
function get_graph_by_port()
{
// This will return a graph for a given port by the ifName
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$device_id = $router['id'];
$vars = array();
$vars['port'] = urldecode($router['port']);
$vars['type'] = $router['type'] ?: 'port_bits';
if(!empty($router['from']))
{
$vars['from'] = $router['from'];
}
if(!empty($router['to']))
{
$vars['to'] = $router['to'];
}
$vars['width'] = $router['width'] ?: 1075;
$vars['height'] = $router['height'] ?: 300;
$auth = "1";
$vars['id'] = dbFetchCell("SELECT `P`.`port_id` FROM `ports` AS `P` WHERE `P`.`device_id`=? AND `P`.`ifName`=?", array($device_id,$vars['port']));
$app->response->headers->set('Content-Type', 'image/png');
require("includes/graphs/graph.inc.php");
}
function get_graph_by_port_hostname() function get_graph_by_port_hostname()
{ {
// This will return a graph for a given port by the ifName // This will return a graph for a given port by the ifName
@ -241,75 +191,37 @@ function get_graph_by_port_hostname()
$router = $app->router()->getCurrentRoute()->getParams(); $router = $app->router()->getCurrentRoute()->getParams();
$hostname = $router['hostname']; $hostname = $router['hostname'];
$vars = array(); $vars = array();
$vars['port'] = $router['port']; $vars['port'] = $router['ifname'];
$vars['type'] = $router['type'] ?: 'port_bits'; $vars['type'] = $router['type'] ?: 'port_bits';
if(!empty($router['from'])) if(!empty($_GET['from']))
{ {
$vars['from'] = $router['from']; $vars['from'] = $_GET['from'];
} }
if(!empty($router['to'])) if(!empty($_GET['to']))
{ {
$vars['to'] = $router['to']; $vars['to'] = $_GET['to'];
} }
$vars['width'] = $router['width'] ?: 1075; $vars['width'] = $_GET['width'] ?: 1075;
$vars['height'] = $router['height'] ?: 300; $vars['height'] = $_GET['height'] ?: 300;
$auth = "1"; $auth = "1";
$vars['id'] = dbFetchCell("SELECT `P`.`port_id` FROM `ports` AS `P` JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`hostname`=? AND `P`.`ifName`=?", array($hostname,$vars['port'])); $vars['id'] = dbFetchCell("SELECT `P`.`port_id` FROM `ports` AS `P` JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`hostname`=? AND `P`.`ifName`=?", array($hostname,$vars['port']));
$app->response->headers->set('Content-Type', 'image/png'); $app->response->headers->set('Content-Type', 'image/png');
require("includes/graphs/graph.inc.php"); require("includes/graphs/graph.inc.php");
} }
function get_port_stats_by_id() function get_port_stats_by_port_hostname()
{ {
// This will return port stats based on port id // This will return port stats based on a devices hostname and ifName
global $config; global $config;
$app = \Slim\Slim::getInstance(); $app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams(); $router = $app->router()->getCurrentRoute()->getParams();
$port_id = $router['id']; $ifName = $router['ifname'];
$stats = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($port_id)); $stats = dbFetchRow("SELECT * FROM `ports` WHERE `ifName`=?", array($ifName));
$output = array("status" => "ok", "port" => $stats);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function get_port_stats_by_port()
{
// This will return port stats based on ifName
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$device_id = $router['id'];
$if_name = $router['port'];
$stats = dbFetchRow("SELECT * FROM `ports` WHERE `device_id`=? AND `ifName`=?", array($device_id,$if_name));
$output = array("status" => "ok", "port" => $stats); $output = array("status" => "ok", "port" => $stats);
$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 get_graph_generic_by_deviceid()
{
// This will return a graph type given a device id.
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$vars = array();
$vars['device'] = $router['id'];
$vars['type'] = $router['type'] ?: 'port_bits';
if(!empty($router['from']))
{
$vars['from'] = $router['from'];
}
if(!empty($router['to']))
{
$vars['to'] = $router['to'];
}
$vars['width'] = $router['width'] ?: 1075;
$vars['height'] = $router['height'] ?: 300;
$auth = "1";
$app->response->headers->set('Content-Type', 'image/png');
require("includes/graphs/graph.inc.php");
}
function get_graph_generic_by_hostname() function get_graph_generic_by_hostname()
{ {
// This will return a graph type given a device id. // This will return a graph type given a device id.
@ -318,17 +230,17 @@ function get_graph_generic_by_hostname()
$router = $app->router()->getCurrentRoute()->getParams(); $router = $app->router()->getCurrentRoute()->getParams();
$hostname = $router['hostname']; $hostname = $router['hostname'];
$vars = array(); $vars = array();
$vars['type'] = $router['type'] ?: 'port_bits'; $vars['type'] = $router['type'] ?: 'device_uptime';
if(!empty($router['from'])) if(!empty($_GET['from']))
{ {
$vars['from'] = $router['from']; $vars['from'] = $_GET['from'];
} }
if(!empty($router['to'])) if(!empty($_GET['to']))
{ {
$vars['to'] = $router['to']; $vars['to'] = $_GET['to'];
} }
$vars['width'] = $router['width'] ?: 1075; $vars['width'] = $_GET['width'] ?: 1075;
$vars['height'] = $router['height'] ?: 300; $vars['height'] = $_GET['height'] ?: 300;
$auth = "1"; $auth = "1";
$vars['device'] = dbFetchCell("SELECT `D`.`device_id` FROM `devices` AS `D` WHERE `D`.`hostname`=?", array($hostname)); $vars['device'] = dbFetchCell("SELECT `D`.`device_id` FROM `devices` AS `D` WHERE `D`.`hostname`=?", array($hostname));
$app->response->headers->set('Content-Type', 'image/png'); $app->response->headers->set('Content-Type', 'image/png');
@ -341,8 +253,8 @@ function list_devices()
global $config; global $config;
$app = \Slim\Slim::getInstance(); $app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams(); $router = $app->router()->getCurrentRoute()->getParams();
$order = $router['order']; $order = $_GET['order'];
$type = $router['type']; $type = $_GET['type'];
if(empty($order)) if(empty($order))
{ {
$order = "hostname"; $order = "hostname";

View File

@ -23,11 +23,13 @@ if ($_SESSION['userlevel'] == '10')
<h3>Introduction</h3> <h3>Introduction</h3>
<p>The API is designed to enable you to interact with your <?php echo $config['project_name'];?> installtion from other systems, monitoring systems, apps or websites using any programming language that can make a web request and both send and receive json data. This documentation will provide you the methods, accepted parameters and responses from the API.</p> <p>The API is designed to enable you to interact with your <?php echo $config['project_name'];?> installtion from other systems, monitoring systems, apps or websites using any programming language that can make a web request and both send and receive json data. This documentation will provide you the methods, accepted parameters and responses from the API.</p>
<a name="tokens"></a> <a name="tokens"></a>
<hr><br />
<h3>Token authentication</h3> <h3>Token authentication</h3>
<p>Authentication against the API is done by tokens which are assigned to a user account. You can view and create tokens using the <a href="api-access">API access</a> link within the System > API menu.</p><br /> <p>Authentication against the API is done by tokens which are assigned to a user account. You can view and create tokens using the <a href="api-access">API access</a> link within the System > API menu.</p><br />
<p>To send the token to the API you need to do this by using the X-Auth-Token within the header. As example if your API token was 91c60e737e342c205be5bba8e2954d27 then you would send the following X-Auth-Token: 91c60e737e342c205be5bba8e2954d27. As an example using curl within PHP you would do something like this:</p> <p>To send the token to the API you need to do this by using the X-Auth-Token within the header. As example if your API token was 91c60e737e342c205be5bba8e2954d27 then you would send the following X-Auth-Token: 91c60e737e342c205be5bba8e2954d27. As an example using curl within PHP you would do something like this:</p>
<code>curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Auth-Token: 91c60e737e342c205be5bba8e2954d27'));</code><br /> <code>curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Auth-Token: 91c60e737e342c205be5bba8e2954d27'));</code><br />
<a name="responses"></a> <a name="responses"></a>
<hr><br />
<h3>API Responses</h3> <h3>API Responses</h3>
<p>The following responses are standard across each request type except for where an image would be returned directly, the response will be output in json format:</p> <p>The following responses are standard across each request type except for where an image would be returned directly, the response will be output in json format:</p>
<strong>status</strong><br /> <strong>status</strong><br />
@ -37,93 +39,8 @@ if ($_SESSION['userlevel'] == '10')
</ul> </ul>
<strong>message</strong><br /> <strong>message</strong><br />
<p>This will contain the reason for the success or failure of the request.</p><br /> <p>This will contain the reason for the success or failure of the request.</p><br />
<p>As an example to get you started quickly, here we use the API to request to list all devices:</p>
<pre>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" "https://librenms.example.com/api/v1/list/devices"
{
"status": "ok",
"devices": [
{
"device_id": "4",
"hostname": "example.co.uk",
"sysName": "example.co.uk",
"community": "public",
"authlevel": null,
"authname": null,
"authpass": null,
"authalgo": null,
"cryptopass": null,
"cryptoalgo": null,
"snmpver": "v1",
"port": "161",
"transport": "udp",
"timeout": null,
"retries": null,
"bgpLocalAs": null,
"sysObjectID": null,
"sysDescr": "Linux example.co.uk 2.6.18-238.19.1.el5 #1 SMP Fri Jul 15 07:31:24 EDT 2011 x86_64",
"sysContact": "root@localhost",
"version": "2.6.18-238.19.1.el5",
"hardware": "Generic x86 64-bit",
"features": null,
"location": "Unknown",
"os": "linux",
"status": "1",
"ignore": "0",
"disabled": "0",
"uptime": "90741309",
"agent_uptime": "0",
"last_polled": "2014-07-16 17:40:04",
"last_polled_timetaken": "2.16",
"last_discovered_timetaken": "3.15",
"last_discovered": "2014-07-16 12:33:44",
"purpose": "",
"type": "server",
"serial": null,
"icon": null
},
{
"device_id": "24",
"hostname": "localhost",
"sysName": "testing",
"community": "public",
"authlevel": "noAuthNoPriv",
"authname": "",
"authpass": "",
"authalgo": "MD5",
"cryptopass": "",
"cryptoalgo": "AES",
"snmpver": "v1",
"port": "161",
"transport": "udp",
"timeout": null,
"retries": null,
"bgpLocalAs": null,
"sysObjectID": null,
"sysDescr": "Linux testing 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64",
"sysContact": "root@localhost",
"version": "2.6.32-431.el6.x86_64",
"hardware": "Generic x86 64-bit",
"features": null,
"location": "Unknown",
"os": "linux",
"status": "1",
"ignore": "0",
"disabled": "0",
"uptime": "19355163",
"agent_uptime": "0",
"last_polled": "2014-07-16 17:40:04",
"last_polled_timetaken": "1.74",
"last_discovered_timetaken": "1.28",
"last_discovered": "2014-07-16 12:33:25",
"purpose": null,
"type": "server",
"serial": null,
"icon": null
}
]
}
</pre>
<a name="request-types"></a> <a name="request-types"></a>
<hr><br />
<h3>API request types</h3> <h3>API request types</h3>
<p>The following request types are currently used:</p> <p>The following request types are currently used:</p>
<ul class="list-unstyled"> <ul class="list-unstyled">
@ -133,6 +50,7 @@ if ($_SESSION['userlevel'] == '10')
<li><strong>DELETE</strong> - This is used to remove items.</li> <li><strong>DELETE</strong> - This is used to remove items.</li>
</ul> </ul>
<a name="requests"></a> <a name="requests"></a>
<hr><br />
<h3>Available requests</h3> <h3>Available requests</h3>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-bordered table-hover table-condensed"> <table class="table table-bordered table-hover table-condensed">
@ -140,21 +58,21 @@ if ($_SESSION['userlevel'] == '10')
<th></th> <th></th>
<th>Version</th> <th>Version</th>
<th>Path (required)</th> <th>Path (required)</th>
<th>Path (additional)</th> <th>Additional variables / JSON Data</th>
<th>Variables / JSON Data</th>
<th>Returns</th> <th>Returns</th>
</tr> </tr>
<a name="port_graphs"></a>
<tr class="success"> <tr class="success">
<td colspan="6"><a name="port_graphs"></a><strong>Port Graphs</strong></td> <td colspan="5"><strong>Port Graphs</strong></td>
</tr> </tr>
<tr> <tr>
<td>/api</td> <td>/api</td>
<td>/v1</td> <td>/v1</td>
<td>/get/graph/port/id/$id</td> <td>/devices/$hostname/ports/$ifName/$type</td>
<td>/$type/$width/$height/$from/$to</td>
<td> <td>
<ul class="list-unstyled"> <ul class="list-unstyled">
<li>$id = the ID of the port</li> <li>$hostname = the hostname of the device you want the graph for</li>
<li>$ifName = The ifName of the interface you want a graph for</li>
<li>$type = the type of graph for the port (port_bits,port_upkts)</li> <li>$type = the type of graph for the port (port_bits,port_upkts)</li>
<li>$width = the width of the graph to be returned</li> <li>$width = the width of the graph to be returned</li>
<li>$height = the height of the graph to be returned</li> <li>$height = the height of the graph to be returned</li>
@ -167,74 +85,22 @@ if ($_SESSION['userlevel'] == '10')
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/port/id/1" > /tmp/graph.png</code></td> <td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/devices/localhost/ports/eth0/port_bits" > /tmp/graph.png</code></td>
</tr> </tr>
<tr> <tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/port/id/1/port_bits/1024/768/1405457456/1405543856" > /tmp/graph.png</code></td> <td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/devices/localhost/ports/eth0/port_bits?width=1024&height=768&from=1405457456&to=1405543856" > /tmp/graph.png</code></td>
</tr>
<tr>
<td>/api</td>
<td>/v1</td>
<td>/get/graph/port/device/$device_id/$ifName</td>
<td>/$type/$width/$height/$from/$to</td>
<td>
<ul class="list-unstyled">
<li>$device_id = the ID of the device</li>
<li>$ifName = the ifName of an interface</li>
<li>$type = the type of graph for the port (port_bits,port_upkts)</li>
<li>$width = the width of the graph to be returned</li>
<li>$height = the height of the graph to be returned</li>
<li>$from = the from date/time of the graph (unix timestamp)</li>
<li>$to = the to date/time of the graph (unix timestamp)</li>
</ul>
</td>
<td>
PNG Image
</td>
</tr>
<tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/port/device/1/eth0" > /tmp/graph.png</code></td>
</tr>
<tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/port/device/1/eth0/port_bits/1024/768/1405457456/1405543856" > /tmp/graph.png</code></td>
</tr>
<tr>
<td>/api</td>
<td>/v1</td>
<td>/get/graph/port/hostname/$hostname/$ifName</td>
<td>/$type/$width/$height/$from/$to</td>
<td>
<ul class="list-unstyled">
<li>$hostname = the hostname of the device</li>
<li>$ifName = the ifName of an interface</li>
<li>$type = the type of graph for the port (port_bits,port_upkts)</li>
<li>$width = the width of the graph to be returned</li>
<li>$height = the height of the graph to be returned</li>
<li>$from = the from date/time of the graph (unix timestamp)</li>
<li>$to = the to date/time of the graph (unix timestamp)</li>
</ul>
</td>
<td>
PNG Image
</td>
</tr>
<tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/port/hostname/localhost/eth0" > /tmp/graph.png</code></td>
</tr>
<tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/port/hostname/localhost/eth0/port_bits/1024/768/1405457456/1405543856" > /tmp/graph.png</code></td>
</tr> </tr>
<a name="general_graphs"></a>
<tr class="success"> <tr class="success">
<td colspan="6"><a name="general_graphs"></a><strong>General Graphs</strong></td> <td colspan="5"><strong>General Graphs</strong></td>
</tr> </tr>
<tr> <tr>
<td>/api</td> <td>/api</td>
<td>/v1</td> <td>/v1</td>
<td>/get/graph/general/device/$device_id/$type</td> <td>/devices/$hostname/$type</td>
<td>/$width/$height/$from/$to</td>
<td> <td>
<ul class="list-unstyled"> <ul class="list-unstyled">
<li>$device_id = the ID of the device</li> <li>$hostname = the hostname of the device you want the graph for</li>
<li>$type = the type of graph for the device (device_processor,device_storage)</li> <li>$type = the type of graph for the device (device_processor,device_storage)</li>
<li>$width = the width of the graph to be returned</li> <li>$width = the width of the graph to be returned</li>
<li>$height = the height of the graph to be returned</li> <li>$height = the height of the graph to be returned</li>
@ -247,64 +113,22 @@ if ($_SESSION['userlevel'] == '10')
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/general/device/1/device_processor" > /tmp/graph.png</code></td> <td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/devices/localhost/device_processor" > /tmp/graph.png</code></td>
</tr> </tr>
<tr> <tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/general/device/1/device_processor/1024/768/1405457456/1405543856" > /tmp/graph.png</code></td> <td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/devices/localhost/device_processor?width=1024&height=768&from=1405457456&to=1405543856" > /tmp/graph.png</code></td>
</tr>
<a name="port_stats"></a>
<tr class="success">
<td colspan="5"><strong>Port Stats</strong></td>
</tr> </tr>
<tr> <tr>
<td>/api</td> <td>/api</td>
<td>/v1</td> <td>/v1</td>
<td>/get/graph/general/hostname/$hostname/$type</td> <td>/devices/$hostname/ports/$ifName</td>
<td>/$width/$height/$from/$to</td>
<td> <td>
<ul class="list-unstyled"> <ul class="list-unstyled">
<li>$hostname = the hostname of the device</li> <li>$hostname = the hostname of the device</li>
<li>$type = the type of graph for the device (device_processor,device_storage)</li>
<li>$width = the width of the graph to be returned</li>
<li>$height = the height of the graph to be returned</li>
<li>$from = the from date/time of the graph (unix timestamp)</li>
<li>$to = the to date/time of the graph (unix timestamp)</li>
</ul>
</td>
<td>
PNG Image
</td>
</tr>
<tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/general/hostname/localhost/device_processor" > /tmp/graph.png</code></td>
</tr>
<tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/graph/general/hostname/localhost/device_processor/1024/768/1405457456/1405543856" > /tmp/graph.png</code></td>
</tr>
<tr class="success">
<td colspan="6"><a name="port_stats"></a><strong>Port Stats</strong></td>
</tr>
<tr>
<td>/api</td>
<td>/v1</td>
<td>/get/stats/port/id/$port_id</td>
<td></td>
<td>
<ul class="list-unstyled">
<li>$port_id = the ID of the port</li>
</ul>
</td>
<td>
JSON
</td>
</tr>
<tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/stats/port/id/1"</code></td>
</tr>
<tr>
<td>/api</td>
<td>/v1</td>
<td>/get/stats/port/device/$device_id/$ifName</td>
<td></td>
<td>
<ul class="list-unstyled">
<li>$device_id = the ID of the device</li>
<li>$ifName = the ifName of the port</li> <li>$ifName = the ifName of the port</li>
</ul> </ul>
</td> </td>
@ -313,16 +137,16 @@ if ($_SESSION['userlevel'] == '10')
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/get/stats/port/device/1/eth0"</code></td> <td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/devices/localhost/ports/eth0"</code></td>
</tr> </tr>
<a name="list"></a>
<tr class="success"> <tr class="success">
<td colspan="6"><a name="list"></a><strong>List</strong></td> <td colspan="5"><strong>List</strong></td>
</tr> </tr>
<tr> <tr>
<td>/api</td> <td>/api</td>
<td>/v1</td> <td>/v1</td>
<td>/list/devices</td> <td>/list/devices</td>
<td>/$order/$type</td>
<td> <td>
<ul class="list-unstyled"> <ul class="list-unstyled">
<li>$order = the name of the column to order by</li> <li>$order = the name of the column to order by</li>
@ -334,19 +158,19 @@ if ($_SESSION['userlevel'] == '10')
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/list/devices"</code></td> <td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/devices"</code></td>
</tr> </tr>
<tr> <tr>
<td colspan="6"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/list/devices/hostname/all"</code></td> <td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/devices?order=hostname&type=all"</code></td>
</tr> </tr>
<a name="add"></a>
<tr class="success"> <tr class="success">
<td colspan="6"><a name="add"></a><strong>Add</strong></td> <td colspan="5"><strong>Add</strong></td>
</tr> </tr>
<tr> <tr>
<td>/api</td> <td>/api</td>
<td>/v1</td> <td>/v1</td>
<td>/add/device</td> <td>/devices</td>
<td></td>
<td> <td>
<ul class="list-unstyled"> <ul class="list-unstyled">
<li>hostname = the hostname to be added</li> <li>hostname = the hostname to be added</li>
@ -367,7 +191,7 @@ if ($_SESSION['userlevel'] == '10')
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="6"><code>curl -X POST -d '{"hostname":"localhost.localdomain","version":"v1","community":"public"}' \<br />-H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/add/device"</code></td> <td colspan="5"><code>curl -X POST -d '{"hostname":"localhost.localdomain","version":"v1","community":"public"}' \<br />-H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v1/devices"</code></td>
</tr> </tr>
</table> </table>
</div> </div>
@ -386,6 +210,7 @@ if ($_SESSION['userlevel'] == '10')
<li><a href="api-docs/#general_graphs">General Graphs</a></li> <li><a href="api-docs/#general_graphs">General Graphs</a></li>
<li><a href="api-docs/#port_stats">Port Stats</a></li> <li><a href="api-docs/#port_stats">Port Stats</a></li>
<li><a href="api-docs/#list">List</a></li> <li><a href="api-docs/#list">List</a></li>
<li><a href="api-docs/#add">Add</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>