Skip to content

Commit c0810a2

Browse files
committed
Lint 2.0
Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se>
1 parent 7682cb4 commit c0810a2

8 files changed

Lines changed: 62 additions & 63 deletions

pkg/probe/probe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (p *Collector) Probe(ctx context.Context, target map[string]string, hc *htt
155155
{"System/SDNConnector", probeSystemSDNConnector},
156156
{"System/SensorInfo", probeSystemSensorInfo},
157157
{"System/Status", probeSystemStatus},
158-
{"System/VDOMResource",probeSystemVdomResource},
158+
{"System/VDOMResource", probeSystemVdomResource},
159159
{"System/HAChecksum", probeSystemHAChecksum},
160160
{"System/Sandbox/Connection", probeSystemSandboxConnection},
161161
{"System/Sandbox/Status", probeSystemSandboxStatus},

pkg/probe/system_sandbox_connection.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ package probe
1616
import (
1717
"log"
1818

19-
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2019
"github.com/prometheus/client_golang/prometheus"
20+
21+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2122
)
2223

23-
func probeSystemSandboxConnection(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
24-
var (
25-
connectionStatus = prometheus.NewDesc(
26-
"fortigate_sandbox_connection_status",
27-
"Sandbox connection status, (unreachable=0, reachable=1, disabled=-1)",
28-
[]string{"sandbox_type"}, nil,
29-
)
24+
func probeSystemSandboxConnection(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
25+
connectionStatus := prometheus.NewDesc(
26+
"fortigate_sandbox_connection_status",
27+
"Sandbox connection status, (unreachable=0, reachable=1, disabled=-1)",
28+
[]string{"sandbox_type"}, nil,
3029
)
3130

3231
type SystemSandboxConnection struct {
@@ -38,14 +37,14 @@ func probeSystemSandboxConnection(c http.FortiHTTP, meta *TargetMetadata) ([]pro
3837
Results []SystemSandboxConnection `json:"results"`
3938
}
4039
var res SystemSandboxConnectionResult
41-
if err := c.Get("api/v2/monitor/system/sandbox/connection","", &res); err != nil {
40+
if err := c.Get("api/v2/monitor/system/sandbox/connection", "", &res); err != nil {
4241
log.Printf("Warning: %v", err)
4342
return nil, false
4443
}
4544

4645
m := []prometheus.Metric{}
4746
for _, r := range res.Results {
48-
switch r.Status {
47+
switch r.Status {
4948
case "unreachable":
5049
m = append(m, prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 0, r.Type))
5150
case "reachable":
@@ -55,4 +54,4 @@ func probeSystemSandboxConnection(c http.FortiHTTP, meta *TargetMetadata) ([]pro
5554
}
5655
}
5756
return m, true
58-
}
57+
}

pkg/probe/system_sandbox_connection_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ func TestSystemSandboxConnection(t *testing.T) {
3838
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
3939
t.Fatalf("metric compare: err %v", err)
4040
}
41-
}
41+
}

pkg/probe/system_sandbox_stats.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ package probe
1616
import (
1717
"log"
1818

19-
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2019
"github.com/prometheus/client_golang/prometheus"
20+
21+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2122
)
2223

23-
func probeSystemSandboxStats (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
24+
func probeSystemSandboxStats(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
2425
var (
2526
numberDetected = prometheus.NewDesc(
2627
"fortigate_sandbox_stats_detected_total",
@@ -60,19 +61,19 @@ func probeSystemSandboxStats (c http.FortiHTTP, meta *TargetMetadata) ([]prometh
6061
Low float64 `json:"risk_low"`
6162
Medium float64 `json:"risk_med"`
6263
High float64 `json:"risk_high"`
63-
Submitted float64
64+
Submitted float64
6465
}
6566

6667
type SystemSandboxStatsResult struct {
6768
Results []SystemSandboxStats `json:"results"`
6869
}
6970

7071
var res SystemSandboxStatsResult
71-
if err := c.Get("api/v2/monitor/system/sandbox/stats","", &res); err != nil {
72+
if err := c.Get("api/v2/monitor/system/sandbox/stats", "", &res); err != nil {
7273
log.Printf("Warning: %v", err)
7374
return nil, false
7475
}
75-
var m = []prometheus.Metric{}
76+
m := []prometheus.Metric{}
7677

7778
for _, r := range res.Results {
7879
m = append(m, prometheus.MustNewConstMetric(numberDetected, prometheus.CounterValue, r.Detected))
@@ -83,4 +84,4 @@ func probeSystemSandboxStats (c http.FortiHTTP, meta *TargetMetadata) ([]prometh
8384
m = append(m, prometheus.MustNewConstMetric(numberSubmitted, prometheus.CounterValue, r.Submitted))
8485
}
8586
return m, true
86-
}
87+
}

pkg/probe/system_sandbox_stats_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ func TestSystemSandboxStats(t *testing.T) {
5353
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
5454
t.Fatalf("metric compare: err %v", err)
5555
}
56-
}
56+
}

pkg/probe/system_sandbox_status.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ import (
1717
"log"
1818
"strconv"
1919

20-
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2120
"github.com/prometheus/client_golang/prometheus"
21+
22+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2223
)
2324

24-
func probeSystemSandboxStatus (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
25-
var (
26-
Count = prometheus.NewDesc(
27-
"fortigate_system_sandbox_status_signatures",
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,
30-
)
25+
func probeSystemSandboxStatus(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
26+
Count := prometheus.NewDesc(
27+
"fortigate_system_sandbox_status_signatures",
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,
3130
)
3231

3332
type SystemSandboxStatus struct {
@@ -68,4 +67,4 @@ func probeSystemSandboxStatus (c http.FortiHTTP, meta *TargetMetadata) ([]promet
6867
res.VDOM),
6968
)
7069
return m, true
71-
}
70+
}

pkg/probe/system_sandbox_status_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ func TestSandboxStatus(t *testing.T) {
3838
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
3939
t.Fatalf("metric compare: err %v", err)
4040
}
41-
}
41+
}

pkg/probe/system_vdom-resource.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ package probe
1616
import (
1717
"log"
1818

19-
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2019
"github.com/prometheus/client_golang/prometheus"
20+
21+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2122
)
2223

23-
func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
24-
24+
func probeSystemVdomResource(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
2525
vdomDesc := make(map[string]*prometheus.Desc)
2626
vdomDesc["cpu"] = prometheus.NewDesc(
2727
"fortigate_vdom_resource_cpu_usage_ratio",
@@ -46,12 +46,12 @@ func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]promethe
4646
vdomDesc["id"] = prometheus.NewDesc(
4747
"fortigate_vdom_resource_object_id",
4848
"Object Resource ID",
49-
[]string{"vdom", "object"},nil,
49+
[]string{"vdom", "object"}, nil,
5050
)
5151
vdomDesc["custom_max"] = prometheus.NewDesc(
5252
"fortigate_vdom_resource_object_custom_max",
5353
"Object Custom Max",
54-
[]string{"vdom", "object"},nil,
54+
[]string{"vdom", "object"}, nil,
5555
)
5656
vdomDesc["min_custom_value"] = prometheus.NewDesc(
5757
"fortigate_vdom_resource_object_custom_min_value",
@@ -61,42 +61,42 @@ func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]promethe
6161
vdomDesc["max_custom_value"] = prometheus.NewDesc(
6262
"fortigate_vdom_resource_object_custom_max_value",
6363
"Object Maximum custom value",
64-
[]string{"vdom", "object"},nil,
64+
[]string{"vdom", "object"}, nil,
6565
)
6666
vdomDesc["guaranteed"] = prometheus.NewDesc(
6767
"fortigate_vdom_resource_object_guaranteed",
6868
"Object Guaranteed",
69-
[]string{"vdom", "object"},nil,
69+
[]string{"vdom", "object"}, nil,
7070
)
7171
vdomDesc["min_guaranteed_value"] = prometheus.NewDesc(
7272
"fortigate_vdom_resource_object_guaranteed_max_value",
7373
"Object Minimum guaranteed value",
74-
[]string{"vdom", "object"},nil,
74+
[]string{"vdom", "object"}, nil,
7575
)
7676
vdomDesc["max_guaranteed_value"] = prometheus.NewDesc(
7777
"fortigate_vdom_resource_object_guaranteed_min_value",
7878
"Object Maximum guaranteed value",
79-
[]string{"vdom", "object"},nil,
79+
[]string{"vdom", "object"}, nil,
8080
)
8181
vdomDesc["global_max"] = prometheus.NewDesc(
8282
"fortigate_vdom_resource_object_global_max",
8383
"Object Global max",
84-
[]string{"vdom", "object"},nil,
84+
[]string{"vdom", "object"}, nil,
8585
)
8686
vdomDesc["current_usage"] = prometheus.NewDesc(
8787
"fortigate_vdom_resource_object_current_usage",
8888
"Object Current usage",
89-
[]string{"vdom", "object"},nil,
89+
[]string{"vdom", "object"}, nil,
9090
)
9191
vdomDesc["usage_percent"] = prometheus.NewDesc(
9292
"fortigate_vdom_resource_object_usage_ratio",
9393
"Object Usage percentage",
94-
[]string{"vdom", "object"},nil,
94+
[]string{"vdom", "object"}, nil,
9595
)
9696

9797
type VDOMResourceResult struct {
98-
Result interface{} `json:"results"`
99-
Vdom string `json:"vdom"`
98+
Result any `json:"results"`
99+
Vdom string `json:"vdom"`
100100
}
101101

102102
var res []VDOMResourceResult
@@ -107,7 +107,7 @@ func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]promethe
107107

108108
m := []prometheus.Metric{}
109109
for _, result := range res {
110-
for k, elem := range result.Result.(map[string]interface{}) {
110+
for k, elem := range result.Result.(map[string]any) {
111111
switch k {
112112
case "cpu", "memory", "setup_rate":
113113
m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, elem.(float64), result.Vdom))
@@ -118,24 +118,24 @@ func probeSystemVdomResource(c http.FortiHTTP, meta *TargetMetadata) ([]promethe
118118
m = append(m, prometheus.MustNewConstMetric(vdomDesc[k], prometheus.GaugeValue, 0, result.Vdom))
119119
}
120120
case "session",
121-
"ipsec-phase1",
122-
"ipsec-phase2",
123-
"ipsec-phase1-interface",
124-
"ipsec-phase2-interface",
125-
"dialup-tunnel",
126-
"firewall-policy",
127-
"firewall-address",
128-
"firewall-addrgrp",
129-
"custom-service",
130-
"service-group",
131-
"onetime-schedule",
132-
"recurring-schedule",
133-
"user",
134-
"user-group",
135-
"sslvpn",
136-
"proxy",
137-
"log-disk-quota":
138-
for val, e := range elem.(map[string]interface{}) {
121+
"ipsec-phase1",
122+
"ipsec-phase2",
123+
"ipsec-phase1-interface",
124+
"ipsec-phase2-interface",
125+
"dialup-tunnel",
126+
"firewall-policy",
127+
"firewall-address",
128+
"firewall-addrgrp",
129+
"custom-service",
130+
"service-group",
131+
"onetime-schedule",
132+
"recurring-schedule",
133+
"user",
134+
"user-group",
135+
"sslvpn",
136+
"proxy",
137+
"log-disk-quota":
138+
for val, e := range elem.(map[string]any) {
139139
m = append(m, prometheus.MustNewConstMetric(vdomDesc[val], prometheus.GaugeValue, e.(float64), result.Vdom, k))
140140
}
141141
default:

0 commit comments

Comments
 (0)