Skip to content

Commit 4076976

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

4 files changed

Lines changed: 48 additions & 49 deletions

File tree

pkg/probe/probe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (p *Collector) Probe(ctx context.Context, target map[string]string, hc *htt
156156
{"System/SDNConnector", probeSystemSDNConnector},
157157
{"System/SensorInfo", probeSystemSensorInfo},
158158
{"System/Status", probeSystemStatus},
159-
{"System/VDOMResource",probeSystemVdomResource},
159+
{"System/VDOMResource", probeSystemVdomResource},
160160
{"System/HAChecksum", probeSystemHAChecksum},
161161
{"User/Fsso", probeUserFsso},
162162
{"VPN/IPSec", probeVPNIPSec},

pkg/probe/system_ha_peer.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,27 @@ 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 probeSystemHaPeer (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
25-
var (
26-
Priority = prometheus.NewDesc(
27-
"fortigate_ha_peer",
28-
"True when the peer device is the HA primary.",
29-
[]string{"serial","vcluster","hostname","master","primary","priority"}, nil,
30-
)
25+
func probeSystemHaPeer(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
26+
Priority := prometheus.NewDesc(
27+
"fortigate_ha_peer",
28+
"True when the peer device is the HA primary.",
29+
[]string{"serial", "vcluster", "hostname", "master", "primary", "priority"}, nil,
3130
)
3231

3332
type SystemHaPeer struct {
3433
Serial string `json:"serial_no"`
35-
Vcluster int64 `json:"vcluster_id"`
34+
Vcluster int64 `json:"vcluster_id"`
3635
Priority float64 `json:"priority"`
3736
Hostname string `json:"hostname"`
38-
Master bool `json:"master"`
39-
Primary bool `json:"primary"`
37+
Master bool `json:"master"`
38+
Primary bool `json:"primary"`
4039
}
41-
40+
4241
type SystemHaPeerResult struct {
4342
Result []SystemHaPeer `json:"results"`
4443
}
@@ -51,7 +50,7 @@ func probeSystemHaPeer (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Me
5150
m := []prometheus.Metric{}
5251
for _, r := range res.Result {
5352
if meta.VersionMajor >= 7 && meta.VersionMinor >= 4 {
54-
if (r.Primary) {
53+
if r.Primary {
5554
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 1, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "true", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
5655
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 0, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "false", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
5756
} else {
@@ -64,4 +63,4 @@ func probeSystemHaPeer (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Me
6463
}
6564
}
6665
return m, true
67-
}
66+
}

pkg/probe/system_ha_peer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ func TestSystemHaPeerAfter74(t *testing.T) {
6868
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
6969
t.Fatalf("metric compare: err %v", err)
7070
}
71-
}
71+
}

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)