API: System endpoint, more health graphs (#8730)

* API: System endpoint, more health graphs

* Add new line api_functions

* Get count of relationships

Using eloquent

* Add new lines in Models
This commit is contained in:
Paul Heinrichs
2018-05-19 00:36:06 -04:00
committed by Tony Murray
parent 57a23a7548
commit 2d7423cdaa
7 changed files with 115 additions and 0 deletions

View File

@@ -220,6 +220,11 @@ class Device extends BaseModel
return $this->hasMany('App\Models\Storage', 'device_id');
}
public function mempools()
{
return $this->hasMany('App\Models\Mempool', 'device_id');
}
public function syslogs()
{
return $this->hasMany('App\Models\General\Syslog', 'device_id', 'device_id');

18
app/Models/Mempool.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
class Mempool extends BaseModel
{
protected $table = 'mempools';
protected $primaryKey = 'mempool_id';
// ---- Define Relationships ----
public function device()
{
return $this->belongsTo('App\Models\Device', 'device_id', 'device_id');
}
}

18
app/Models/Storage.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
class Storage extends BaseModel
{
protected $table = 'storage';
protected $primaryKey = 'storage_id';
// ---- Define Relationships ----
public function device()
{
return $this->belongsTo('App\Models\Device', 'device_id', 'device_id');
}
}

37
doc/API/System.md Normal file
View File

@@ -0,0 +1,37 @@
source: API/System.md
### `system`
Display Librenms instance information.
Route: `/api/v0/system`
Input:
-
Example:
```curl
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/system
```
Output:
```json
{
"status": "ok",
"system": [
{
"local_ver": "1.37-234-g19103ee",
"local_sha": "19103ee36f68f009272c15be22e5a7e10a8b0b85",
"local_date": "1526480966",
"local_branch": "master",
"db_schema": 249,
"php_ver": "7.2.2",
"mysql_ver": "5.5.56-MariaDB",
"rrdtool_ver": "1.4.8",
"netsnmp_ver": "NET-SNMP 5.7.2"
}
],
"count": 1
}
```

View File

@@ -66,3 +66,4 @@ Output from the API currently is via two output types.
- [ARP](ARP.md)
- [Services](Services.md)
- [Logs](Logs.md)
- [System](System.md)

View File

@@ -825,6 +825,30 @@ function list_available_health_graphs()
'name' => 'device_'.$graph['sensor_class'],
);
}
$device = \App\Models\Device::find($device_id);
if ($device) {
if ($device->processors()->count() > 0) {
array_push($graphs, array(
'desc' => 'Processors',
'name' => 'device_processor'
));
}
if ($device->storage()->count() > 0) {
array_push($graphs, array(
'desc' => 'Storage',
'name' => 'device_storage'
));
}
if ($device->mempools()->count() > 0) {
array_push($graphs, array(
'desc' => 'Memory Pools',
'name' => 'device_mempool'
));
}
}
}
return api_success($graphs, 'graphs');
@@ -2136,3 +2160,14 @@ function add_service_for_host()
api_error(500, 'Failed to add the service');
}
}
/**
* Display Librenms Instance Info
*/
function server_info()
{
$versions = version_info();
api_success([
$versions
], 'system');
}

View File

@@ -43,6 +43,7 @@ $app->group(
$app->group(
'/v0',
function () use ($app) {
$app->get('/system', 'authToken', 'server_info')->name('server_info');
$app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');
$app->get('/bgp/:id', 'authToken', 'get_bgp')->name('get_bgp');
$app->get('/ospf', 'authToken', 'list_ospf')->name('list_ospf');