Skip to content

Commit c65fa98

Browse files
author
Jared Hendrickson
committed
Created endpoint to read interface status and metrics, created unit test to test interface status endpoint, updated docs
1 parent 271d65e commit c65fa98

6 files changed

Lines changed: 185 additions & 2 deletions

File tree

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,10 @@ There is no limit to API calls at this time but is important to note that pfSens
637637

638638
* [Read Gateway Status](#1-read-gateway-status)
639639

640+
* [STATUS/INTERFACE](#statusinterface)
641+
642+
* [Read Interface Status](#1-read-interface-status)
643+
640644
* [STATUS/LOG](#statuslog)
641645

642646
* [Read Configuration History Status Log](#1-read-configuration-history-status-log)
@@ -3431,6 +3435,38 @@ URL: https://{{$hostname}}/api/v1/status/gateway
34313435

34323436

34333437

3438+
## STATUS/INTERFACE
3439+
3440+
3441+
3442+
### 1. Read Interface Status
3443+
3444+
3445+
Read interface status and metrics.<br><br>
3446+
3447+
_Requires at least one of the following privileges:_ [`page-all`, `page-status-interfaces`]
3448+
3449+
3450+
***Endpoint:***
3451+
3452+
```bash
3453+
Method: GET
3454+
Type: RAW
3455+
URL: https://{{$hostname}}/api/v1/status/interface
3456+
```
3457+
3458+
3459+
3460+
***Body:***
3461+
3462+
```js
3463+
{
3464+
3465+
}
3466+
```
3467+
3468+
3469+
34343470
## STATUS/LOG
34353471

34363472

docs/documentation.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4609,6 +4609,58 @@
46094609
"description": "API endpoints that read gateway statuses.",
46104610
"protocolProfileBehavior": {},
46114611
"_postman_isSubFolder": true
4612+
},
4613+
{
4614+
"name": "INTERFACE",
4615+
"item": [
4616+
{
4617+
"name": "Read Interface Status",
4618+
"protocolProfileBehavior": {
4619+
"disableBodyPruning": true
4620+
},
4621+
"request": {
4622+
"auth": {
4623+
"type": "bearer",
4624+
"bearer": [
4625+
{
4626+
"key": "token",
4627+
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwZlNlbnNlIiwiZXhwIjoxNTk4MDcwMTAzLCJuYmYiOjE1OTgwNjE3MDMsImRhdGEiOiJhZG1pbiJ9.hgvNu96Bvsehcq6ygTa9LPB8eymiLnxYu4V6J8_h0-o",
4628+
"type": "string"
4629+
}
4630+
]
4631+
},
4632+
"method": "GET",
4633+
"header": [],
4634+
"body": {
4635+
"mode": "raw",
4636+
"raw": "{\n \n}",
4637+
"options": {
4638+
"raw": {
4639+
"language": "json"
4640+
}
4641+
}
4642+
},
4643+
"url": {
4644+
"raw": "https://{{$hostname}}/api/v1/status/interface",
4645+
"protocol": "https",
4646+
"host": [
4647+
"{{$hostname}}"
4648+
],
4649+
"path": [
4650+
"api",
4651+
"v1",
4652+
"status",
4653+
"interface"
4654+
]
4655+
},
4656+
"description": "Read interface status and metrics.<br><br>\n\n_Requires at least one of the following privileges:_ [`page-all`, `page-status-interfaces`]"
4657+
},
4658+
"response": []
4659+
}
4660+
],
4661+
"description": "API endpoints that read interface statuses and metrics.",
4662+
"protocolProfileBehavior": {},
4663+
"_postman_isSubFolder": true
46124664
}
46134665
],
46144666
"description": "API endpoints that read and update system statuses.",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
// Copyright 2020 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIEndpoint.inc");
17+
18+
class APIStatusInterface extends APIEndpoint {
19+
public function __construct() {
20+
$this->url = "/api/v1/status/interface";
21+
}
22+
23+
protected function get() {
24+
return (new APIStatusInterfaceRead())->call();
25+
}
26+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
// Copyright 2020 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIModel.inc");
17+
require_once("api/framework/APIResponse.inc");
18+
19+
20+
class APIStatusInterfaceRead extends APIModel {
21+
# Create our method constructor
22+
public function __construct() {
23+
parent::__construct();
24+
$this->privileges = ["page-all", "page-status-interfaces"];
25+
}
26+
27+
public function action() {
28+
return APIResponse\get(0, $this->__get_metrics());
29+
}
30+
31+
private function __get_metrics() {
32+
$if_descrs = get_configured_interface_with_descr(true);
33+
$if_info = [];
34+
35+
foreach ($if_descrs as $if_descr => $if_name) {
36+
$if = ["name" => $if_descr, "descr" => $if_name];
37+
$if = $if + get_interface_info($if_descr);
38+
$if_info[] = $if;
39+
}
40+
return $if_info;
41+
}
42+
}

0 commit comments

Comments
 (0)