mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Device Components.
The purpose of this feature is to provide a framework for discovery modules to store information in the database, without needing to add new tables for each feature. This Feature provides: - A database structure to store data. - An API to store and retrieve data from the database. - Integration to the LibreNMS APIv0. - Ability to disable/ignore components. - Default alerting rules. - The API returns $COMPONENT[$device_id][$component_id] to allow pulling of data for multiple devices. The intent is to be able to create 'Applications' the consolidate data from applications covering multiple devices. - Added some developer documentation
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
require_once '../includes/functions.php';
|
||||
require_once '../includes/component.php';
|
||||
|
||||
|
||||
function authToken(\Slim\Route $route) {
|
||||
@ -500,6 +501,59 @@ function get_graph_by_portgroup() {
|
||||
}
|
||||
|
||||
|
||||
function get_components() {
|
||||
global $config;
|
||||
$code = 200;
|
||||
$status = 'ok';
|
||||
$message = '';
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
$hostname = $router['hostname'];
|
||||
|
||||
// Do some filtering if the user requests.
|
||||
$options = array();
|
||||
if (isset($_GET['type'])) {
|
||||
// set a type = filter
|
||||
$options['filter']['type'] = array('=',$_GET['type']);
|
||||
}
|
||||
if (isset($_GET['id'])) {
|
||||
// set a id = filter
|
||||
$options['filter']['id'] = array('=',$_GET['id']);
|
||||
}
|
||||
if (isset($_GET['label'])) {
|
||||
// set a label like filter
|
||||
$options['filter']['label'] = array('LIKE',$_GET['label']);
|
||||
}
|
||||
if (isset($_GET['status'])) {
|
||||
// set a status = filter
|
||||
$options['filter']['status'] = array('=',$_GET['status']);
|
||||
}
|
||||
if (isset($_GET['disabled'])) {
|
||||
// set a disabled = filter
|
||||
$options['filter']['disabled'] = array('=',$_GET['disabled']);
|
||||
}
|
||||
if (isset($_GET['ignore'])) {
|
||||
// set a ignore = filter
|
||||
$options['filter']['ignore'] = array('=',$_GET['ignore']);
|
||||
}
|
||||
|
||||
// use hostname as device_id if it's all digits
|
||||
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||
$COMPONENT = new component();
|
||||
$components = $COMPONENT->getComponents($device_id,$options);
|
||||
|
||||
$output = array(
|
||||
'status' => "$status",
|
||||
'err-msg' => $message,
|
||||
'count' => count($components[$device_id]),
|
||||
'components' => $components[$device_id],
|
||||
);
|
||||
$app->response->setStatus($code);
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
echo _json_encode($output);
|
||||
}
|
||||
|
||||
|
||||
function get_graphs() {
|
||||
global $config;
|
||||
$code = 200;
|
||||
|
Reference in New Issue
Block a user