Skip to content

Commit af010e4

Browse files
committed
New probe for transceivers
Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se>
1 parent 3a48cc5 commit af010e4

4 files changed

Lines changed: 45 additions & 27 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Per-VDOM:
9191
* `fortigate_interface_receive_bytes_total`
9292
* `fortigate_interface_transmit_errors_total`
9393
* `fortigate_interface_receive_errors_total`
94+
* _System/Interface/Transceivers_
95+
* `fortigate_inteface_transceivers`
9496
* _System/SDNConnector_
9597
* `fortigate_system_sdn_connector_status`
9698
* `fortigate_system_sdn_connector_last_update_seconds`
@@ -417,6 +419,7 @@ To improve security, limit permissions to required ones only (least privilege pr
417419
|System/Fortimanager/Status | sysgrp.cfg |api/v2/monitor/system/fortimanager/status |
418420
|System/HAStatistics | sysgrp.cfg |api/v2/monitor/system/ha-statistics<br>api/v2/cmdb/system/ha |
419421
|System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select |
422+
|System/Interface/Transceivers| *any* |api/v2/monitor/system/interface/transceivers |
420423
|System/LinkMonitor | sysgrp.cfg |api/v2/monitor/system/link-monitor |
421424
|System/Resource/Usage | sysgrp.cfg |api/v2/monitor/system/resource/usage |
422425
|System/SensorInfo | sysgrp.cfg |api/v2/monitor/system/sensor-info |

pkg/probe/probe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc
144144
{"System/Fortimanager/Status", probeSystemFortimanagerStatus},
145145
{"System/HAStatistics", probeSystemHAStatistics},
146146
{"System/Interface", probeSystemInterface},
147-
{"System/Transceivers", probeSystemInterfaceTransceivers},
147+
{"System/Interface/Transceivers", probeSystemInterfaceTransceivers},
148148
{"System/LinkMonitor", probeSystemLinkMonitor},
149149
{"System/Resource/Usage", probeSystemResourceUsage},
150150
{"System/SDNConnector", probeSystemSDNConnector},
Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,56 @@
1+
// Copyright 2025 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
114
package probe
215

316
import (
417
"log"
5-
6-
"github.com/bluecmd/fortigate_exporter/pkg/http"
18+
19+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
720
"github.com/prometheus/client_golang/prometheus"
821
)
922

1023
func probeSystemInterfaceTransceivers(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
1124
var (
12-
mVersion = prometheus.NewDesc(
13-
"fortigate_interface_transceivers",
14-
"List of transceivers being used by the FortiGate",
15-
[]string{"name", "type", "vendor", "partnumber", "description"}, nil,
25+
interfaceTransceivers = prometheus.NewDesc(
26+
"fortigate_inteface_transceivers",
27+
"Interface transceivers information",
28+
[]string{"interface", "type", "vendor", "vendorpartnumber", "vendorserialnumber"}, nil,
1629
)
1730
)
1831

19-
type ifResult struct {
20-
Description string
21-
Interface string
22-
Type string
23-
Vendor string
24-
VendorPartNr string `json:"vendor_part_number"`
32+
type SystemInterfaceTransceiversResult struct {
33+
Interface string `json:"interface"`
34+
Type string `json:"type"`
35+
Vendor string `json:"vendor"`
36+
VendorPartNumber string `json:"vendor_part_number"`
37+
VendorSerialNumber string `json:"vendor_serial_number"`
2538
}
26-
type ifResponse struct {
27-
Results []ifResult
39+
40+
type SystemInterfaceTransceivers struct {
41+
Results []SystemInterfaceTransceiversResult `json:"results"`
2842
}
29-
var r ifResponse
3043

31-
if err := c.Get("api/v2/monitor/system/interface/transceivers", "scope=global", &r); err != nil {
32-
log.Printf("Error: %v", err)
44+
var res SystemInterfaceTransceivers
45+
if err := c.Get("api/v2/monitor/system/interface/transceivers", "scope=global", &res); err != nil {
46+
log.Printf("Warning: %v", err)
3347
return nil, false
3448
}
3549

3650
m := []prometheus.Metric{}
37-
for _, result := range r.Results {
38-
m = append(m, prometheus.MustNewConstMetric(mVersion, prometheus.GaugeValue, 1.0, result.Interface, result.Type, result.Vendor, result.VendorPartNr, result.Description))
51+
for _, r := range res.Results {
52+
m = append(m, prometheus.MustNewConstMetric(interfaceTransceivers, prometheus.GaugeValue, 1.0, r.Interface, r.Type, r.Vendor, r.VendorPartNumber, r.VendorSerialNumber))
3953
}
54+
4055
return m, true
41-
}
56+
}

pkg/probe/system_interface_transceivers_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ func TestSystemInterfaceTransceivers(t *testing.T) {
1717
}
1818

1919
em := `
20-
# HELP fortigate_interface_transceivers List of transceivers being used by the FortiGate
21-
# TYPE fortigate_interface_transceivers gauge
22-
fortigate_interface_transceivers{description="",name="ha1",partnumber="FTLX8574D3BCLFTN",type="SFP/SFP+/SFP28",vendor="FORTINET"} 1
23-
fortigate_interface_transceivers{description="",name="ha2",partnumber="FTLX8574D3BCLFTN",type="SFP/SFP+/SFP28",vendor="FORTINET"} 1
24-
fortigate_interface_transceivers{description="",name="port33",partnumber="FTL410QE4CFTN",type="QSFP/QSFP+",vendor="FORTINET"} 1
25-
fortigate_interface_transceivers{description="",name="port34",partnumber="FTL410QE4CFTN",type="QSFP/QSFP+",vendor="FORTINET"} 1
20+
# HELP fortigate_inteface_transceivers Interface transceivers information
21+
# TYPE fortigate_inteface_transceivers gauge
22+
fortigate_inteface_transceivers{interface="ha1",type="SFP/SFP+/SFP28",vendor="FORTINET",vendorpartnumber="FTLX8574D3BCLFTN",vendorserialnumber="U00000"} 1
23+
fortigate_inteface_transceivers{interface="ha2",type="SFP/SFP+/SFP28",vendor="FORTINET",vendorpartnumber="FTLX8574D3BCLFTN",vendorserialnumber="U00000"} 1
24+
fortigate_inteface_transceivers{interface="port33",type="QSFP/QSFP+",vendor="FORTINET",vendorpartnumber="FTL410QE4CFTN",vendorserialnumber="U00000"} 1
25+
fortigate_inteface_transceivers{interface="port34",type="QSFP/QSFP+",vendor="FORTINET",vendorpartnumber="FTL410QE4CFTN",vendorserialnumber="U00000"} 1
2626
`
2727

2828
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {

0 commit comments

Comments
 (0)