Skip to content

Commit 84114a2

Browse files
committed
Correct testdata and fixes
Signed-off-by: Örnfeldt Philip (66140321) <[email protected]>
1 parent 6e70fec commit 84114a2

File tree

3 files changed

+49
-37
lines changed

3 files changed

+49
-37
lines changed

pkg/probe/system_sandbox_status.go

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,57 @@ package probe
1515

1616
import (
1717
"log"
18+
"strconv"
1819

1920
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2021
"github.com/prometheus/client_golang/prometheus"
2122
)
2223

23-
func probeSystemSandboxStatus(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
24+
func probeSystemSandboxStatus (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
2425
var (
25-
signatureCount = prometheus.NewDesc(
26-
"fortigate_sandbox_status_signature_count",
27-
"Sandbox signature counts",
28-
[]string{"server", "region", "version", "type"}, nil,
26+
Count = prometheus.NewDesc(
27+
"fortigate_system_sandbox_status_signatures_count",
28+
"The number of signatures that have been loaded on the FortiSandbox.",
29+
[]string{"configured", "type", "cloud_region", "server", "malware_package_version", "signatures_loaded", "vdom"}, nil,
2930
)
3031
)
3132

3233
type SystemSandboxStatus struct {
33-
Server string `json:"server"`
34-
Type string `json:"type"`
35-
Region string `json:"cloud_region"`
36-
Version string `json:"malware_package_version"`
37-
Count float64 `json:"signatures_count"`
34+
Configured bool `json:"configured"`
35+
Type string `json:"type"`
36+
Cloud string `json:"cloud_region"`
37+
Server string `json:"server"`
38+
MPV string `json:"malware_package_version"`
39+
Loaded bool `json:"signatures_loaded"`
40+
Count float64 `json:"signatures_count"`
3841
}
3942

4043
type SystemSandboxStatusResult struct {
41-
Results []SystemSandboxStatus `json:"results"`
44+
Result SystemSandboxStatus `json:"results"`
45+
VDOM string `json:"vdom"`
4246
}
4347

4448
var res SystemSandboxStatusResult
45-
if err := c.Get("api/v2/monitor/system/sandbox/status","", &res); err != nil {
49+
if err := c.Get("api/v2/monitor/system/sandbox/status", "", &res); err != nil {
4650
log.Printf("Warning: %v", err)
4751
return nil, false
4852
}
49-
5053
m := []prometheus.Metric{}
51-
for _, r := range res.Results {
52-
m = append(m, prometheus.MustNewConstMetric(signatureCount, prometheus.GaugeValue, r.Count, r.Server, r.Region, r.Version, r.Type))
54+
cloude := "null"
55+
if res.Result.Cloud != "" {
56+
cloude = res.Result.Cloud
5357
}
54-
58+
m = append(m, prometheus.MustNewConstMetric(
59+
Count,
60+
prometheus.GaugeValue,
61+
res.Result.Count,
62+
strconv.FormatBool(res.Result.Configured),
63+
res.Result.Type,
64+
cloude,
65+
res.Result.Server,
66+
res.Result.MPV,
67+
strconv.FormatBool(res.Result.Loaded),
68+
res.VDOM),
69+
)
5570
return m, true
5671
}

pkg/probe/system_sandbox_status_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/prometheus/client_golang/prometheus/testutil"
2222
)
2323

24-
func TestSystemSandboxStatus(t *testing.T) {
24+
func TestSandboxStatus(t *testing.T) {
2525
c := newFakeClient()
2626
c.prepare("api/v2/monitor/system/sandbox/status", "testdata/system-sandbox-status.jsonnet")
2727
r := prometheus.NewPedanticRegistry()
@@ -30,9 +30,9 @@ func TestSystemSandboxStatus(t *testing.T) {
3030
}
3131

3232
em := `
33-
# HELP fortigate_sandbox_status_signature_count Sandbox signature counts
34-
# TYPE fortigate_sandbox_status_signature_count gauge
35-
fortigate_sandbox_status_signature_count{region="Sweden",server="127.0.0.1",type="cloud",version="v17.0.3"} 252891
33+
# HELP fortigate_system_sandbox_status_signatures_count The number of signatures that have been loaded on the FortiSandbox.
34+
# TYPE fortigate_system_sandbox_status_signatures_count gauge
35+
fortigate_system_sandbox_status_signatures_count{cloud_region="null",configured="true",malware_package_version="5.125",server="0.0.0.0",signatures_loaded="false",type="appliance",vdom="root"} 0
3636
`
3737

3838
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
# api/v2/monitor/system/sandbox/status
21
{
32
"http_method":"GET",
4-
"results":[
5-
{
6-
"configured": true,
7-
"type": "cloud",
8-
"cloud_region": "Sweden",
9-
"server": "127.0.0.1",
10-
"malware_package_version": "v17.0.3",
11-
"signatures_loaded": true,
12-
"signatures_count": 252891
13-
}
14-
],
15-
"vdom":"google",
3+
"results": {
4+
"configured":true,
5+
"type":"appliance",
6+
"cloud_region":"",
7+
"server":"0.0.0.0",
8+
"malware_package_version":"5.125",
9+
"signatures_loaded":false,
10+
"signatures_count":0
11+
},
12+
"vdom":"root",
1613
"path":"system",
17-
"name":"sdn-connector",
14+
"name":"sandbox",
1815
"action":"status",
1916
"status":"success",
20-
"serial":"FGABCDEF12345678",
21-
"version":"v7.0.9",
22-
"build":444
17+
"serial":"g43sags54rh5es",
18+
"version":"v7.4.8",
19+
"build":2795
2320
}

0 commit comments

Comments
 (0)