diff --git a/app/Http/Controllers/Widgets/AlertsController.php b/app/Http/Controllers/Widgets/AlertsController.php index 72d8c137d7..b9f708149f 100644 --- a/app/Http/Controllers/Widgets/AlertsController.php +++ b/app/Http/Controllers/Widgets/AlertsController.php @@ -43,6 +43,7 @@ class AlertsController extends WidgetController 'sort' => 1, 'hidenavigation' => 0, 'uncollapse_key_count' => 1, + 'unreachable' => null, ]; public function getView(Request $request) diff --git a/app/Models/MplsSap.php b/app/Models/MplsSap.php index 1aedf862fe..f987b61c00 100644 --- a/app/Models/MplsSap.php +++ b/app/Models/MplsSap.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use LibreNMS\Interfaces\Models\Keyable; -class MplsSap extends Model implements Keyable +class MplsSap extends DeviceRelatedModel implements Keyable { protected $primaryKey = 'sap_id'; public $timestamps = false; diff --git a/app/Models/MplsService.php b/app/Models/MplsService.php index ff1c2c9f75..a3fd66de3c 100644 --- a/app/Models/MplsService.php +++ b/app/Models/MplsService.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use LibreNMS\Interfaces\Models\Keyable; -class MplsService extends Model implements Keyable +class MplsService extends DeviceRelatedModel implements Keyable { protected $primaryKey = 'svc_id'; public $timestamps = false; diff --git a/doc/API/Routing.md b/doc/API/Routing.md index 4239d2baf6..43f814e059 100644 --- a/doc/API/Routing.md +++ b/doc/API/Routing.md @@ -507,3 +507,100 @@ Output: "count": 1 } ``` + +### `list_mpls_services` + +List MPLS services + +Route: `/api/v0/routing/mpls/services` + +Input: + +- hostname = Either the devices hostname or id + +Example: + +```curl +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/routing/mpls/services +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/routing/mpls/services?hostname=host.example.com + +``` + +Output: + +```json +{ + "status": "ok", + "mpls_services": [ + { + "svc_id": 1671, + "svc_oid": 27, + "device_id": 4, + "svcRowStatus": "active", + "svcType": "tls", + "svcCustId": 1, + "svcAdminStatus": "up", + "svcOperStatus": "up", + "svcDescription": "", + "svcMtu": 9008, + "svcNumSaps": 1, + "svcNumSdps": 0, + "svcLastMgmtChange": 2, + "svcLastStatusChange": 168, + "svcVRouterId": 0, + "svcTlsMacLearning": "enabled", + "svcTlsStpAdminStatus": "disabled", + "svcTlsStpOperStatus": "down", + "svcTlsFdbTableSize": 250, + "svcTlsFdbNumEntries": 0, + "hostname": "host.example.com" + } + ], + "count": 1 +} +``` + +### `list_mpls_saps` + +List MPLS SAPs + +Route: `/api/v0/routing/mpls/saps` + +Input: + +- hostname = Either the devices hostname or id + +Example: + +```curl +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/routing/mpls/saps +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/routing/mpls/saps?hostname=host.example.com +``` + +Output: + +```json +{ + "status": "ok", + "saps": [ + { + "sap_id": 1935, + "svc_id": 1660, + "svc_oid": 7, + "sapPortId": 16108921125, + "ifName": "1/1/c2/1", + "device_id": 3, + "sapEncapValue": "0", + "sapRowStatus": "active", + "sapType": "epipe", + "sapDescription": "", + "sapAdminStatus": "up", + "sapOperStatus": "down", + "sapLastMgmtChange": 2, + "sapLastStatusChange": 0, + "hostname": "hostname=host.example.com" + } + ], + "count": 1 +} +``` diff --git a/includes/html/api_functions.inc.php b/includes/html/api_functions.inc.php index 116b35d5b3..3ed1b558e3 100644 --- a/includes/html/api_functions.inc.php +++ b/includes/html/api_functions.inc.php @@ -16,6 +16,8 @@ use App\Models\Availability; use App\Models\Device; use App\Models\DeviceGroup; use App\Models\DeviceOutage; +use App\Models\MplsSap; +use App\Models\MplsService; use App\Models\OspfPort; use App\Models\Port; use App\Models\PortGroup; @@ -2187,6 +2189,38 @@ function get_vrf(Illuminate\Http\Request $request) return api_success($vrf, 'vrf'); } +function list_mpls_services(Illuminate\Http\Request $request) +{ + $hostname = $request->get('hostname'); + $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); + + $mpls_services = MplsService::hasAccess(Auth::user())->when($device_id, function ($query, $device_id) { + return $query->where('device_id', $device_id); + })->get(); + + if ($mpls_services->isEmpty()) { + return api_error(404, 'MPLS Services do not exist'); + } + + return api_success($mpls_services, 'mpls_services', null, 200, $mpls_services->count()); +} + +function list_mpls_saps(Illuminate\Http\Request $request) +{ + $hostname = $request->get('hostname'); + $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); + + $mpls_saps = MplsSap::hasAccess(Auth::user())->when($device_id, function ($query, $device_id) { + return $query->where('device_id', $device_id); + })->get(); + + if ($mpls_saps->isEmpty()) { + return api_error(404, 'SAPs do not exist'); + } + + return api_success($mpls_saps, 'saps', null, 200, $mpls_saps->count()); +} + function list_ipsec(Illuminate\Http\Request $request) { $hostname = $request->route('hostname'); diff --git a/includes/html/table/alerts.inc.php b/includes/html/table/alerts.inc.php index d3cb3a85c1..5f917666cb 100644 --- a/includes/html/table/alerts.inc.php +++ b/includes/html/table/alerts.inc.php @@ -44,6 +44,11 @@ if (is_numeric($vars['fired'])) { $where .= ' AND `alerts`.`alerted`=' . $alert_states['alerted']; } +if (is_numeric($vars['unreachable'])) { + // Sub-select to flag if at least one parent is set, and all parents are offline + $where .= ' AND (SELECT IF(COUNT(`dr`.`parent_device_id`) > 0 AND COUNT(`dr`.`parent_device_id`)=count(`d`.`device_id`),1,0) FROM `device_relationships` `dr` LEFT JOIN `devices` `d` ON `dr`.`parent_device_id`=`d`.`device_id` AND `d`.`status`=0 WHERE `dr`.`child_device_id`=`devices`.`device_id`)=' . $vars['unreachable']; +} + if (is_numeric($vars['state'])) { $where .= ' AND `alerts`.`state`=' . $vars['state']; if ($vars['state'] == $alert_states['recovered']) { diff --git a/resources/views/widgets/alerts.blade.php b/resources/views/widgets/alerts.blade.php index 31f95872b5..d485a24f9e 100644 --- a/resources/views/widgets/alerts.blade.php +++ b/resources/views/widgets/alerts.blade.php @@ -22,6 +22,7 @@ ...request, id: "alerts", acknowledged: '{{ $acknowledged }}', + unreachable: '{{ $unreachable }}', fired: '{{ $fired }}', min_severity: '{{ $min_severity }}', group: '{{ $device_group }}', diff --git a/resources/views/widgets/settings/alerts.blade.php b/resources/views/widgets/settings/alerts.blade.php index c58ed116ea..bc8a12d0c7 100644 --- a/resources/views/widgets/settings/alerts.blade.php +++ b/resources/views/widgets/settings/alerts.blade.php @@ -13,6 +13,14 @@ +