Skip to content

Commit 022bee0

Browse files
xerox81Philldomd
authored andcommitted
[feat] Interface transceivers metrics support
Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se>
1 parent afcfb5f commit 022bee0

5 files changed

Lines changed: 135 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Global:
4343
* `fortigate_sensor_voltage_volts`
4444
* _System/Status_
4545
* `fortigate_version_info`
46+
* _System/Transceivers_
47+
* `fortigate_interface_transceivers`
4648
* _System/Time/Clock_
4749
* `fortigate_time_seconds`
4850
* _System/Resource/Usage_
@@ -89,6 +91,8 @@ Per-VDOM:
8991
* `fortigate_interface_receive_bytes_total`
9092
* `fortigate_interface_transmit_errors_total`
9193
* `fortigate_interface_receive_errors_total`
94+
* _System/Interface/Transceivers_
95+
* `fortigate_inteface_transceivers`
9296
* _System/SDNConnector_
9397
* `fortigate_system_sdn_connector_status`
9498
* `fortigate_system_sdn_connector_last_update_seconds`
@@ -415,6 +419,7 @@ To improve security, limit permissions to required ones only (least privilege pr
415419
|System/Fortimanager/Status | sysgrp.cfg |api/v2/monitor/system/fortimanager/status |
416420
|System/HAStatistics | sysgrp.cfg |api/v2/monitor/system/ha-statistics<br>api/v2/cmdb/system/ha |
417421
|System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select |
422+
|System/Interface/Transceivers| *any* |api/v2/monitor/system/interface/transceivers |
418423
|System/LinkMonitor | sysgrp.cfg |api/v2/monitor/system/link-monitor |
419424
|System/Resource/Usage | sysgrp.cfg |api/v2/monitor/system/resource/usage |
420425
|System/SensorInfo | sysgrp.cfg |api/v2/monitor/system/sensor-info |

pkg/probe/probe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +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/Interface/Transceivers", probeSystemInterfaceTransceivers},
147148
{"System/LinkMonitor", probeSystemLinkMonitor},
148149
{"System/Resource/Usage", probeSystemResourceUsage},
149150
{"System/SDNConnector", probeSystemSDNConnector},
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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+
14+
package probe
15+
16+
import (
17+
"log"
18+
19+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
20+
"github.com/prometheus/client_golang/prometheus"
21+
)
22+
23+
func probeSystemInterfaceTransceivers(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
24+
var (
25+
interfaceTransceivers = prometheus.NewDesc(
26+
"fortigate_inteface_transceivers",
27+
"Interface transceivers information",
28+
[]string{"interface", "type", "vendor", "vendorpartnumber", "vendorserialnumber"}, nil,
29+
)
30+
)
31+
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"`
38+
}
39+
40+
type SystemInterfaceTransceivers struct {
41+
Results []SystemInterfaceTransceiversResult `json:"results"`
42+
}
43+
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)
47+
return nil, false
48+
}
49+
50+
m := []prometheus.Metric{}
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))
53+
}
54+
55+
return m, true
56+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package probe
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
"github.com/prometheus/client_golang/prometheus"
8+
"github.com/prometheus/client_golang/prometheus/testutil"
9+
)
10+
11+
func TestSystemInterfaceTransceivers(t *testing.T) {
12+
c := newFakeClient()
13+
c.prepare("api/v2/monitor/system/interface/transceivers", "testdata/interface-transceivers.jsonnet")
14+
r := prometheus.NewPedanticRegistry()
15+
if !testProbe(probeSystemInterfaceTransceivers, c, r) {
16+
t.Errorf("probeSystemInterfaceTransceivers() returned non-success")
17+
}
18+
19+
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="FTL",type="SFP/SFP+/SFP28",vendor="FORTINET"} 1
23+
fortigate_interface_transceivers{description="",name="ha2",partnumber="FTL",type="SFP/SFP+/SFP28",vendor="FORTINET"} 1
24+
fortigate_interface_transceivers{description="",name="port33",partnumber="FTL",type="QSFP/QSFP+",vendor="FORTINET"} 1
25+
fortigate_interface_transceivers{description="",name="port34",partnumber="FTL",type="QSFP/QSFP+",vendor="FORTINET"} 1
26+
`
27+
28+
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
29+
t.Fatalf("metric compare: err %v", err)
30+
}
31+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# api/v2/monitor/system/interface/transceivers?scope=global
2+
{
3+
"http_method":"GET",
4+
"results":[
5+
{
6+
"type":"QSFP\/QSFP+",
7+
"vendor":"FORTINET",
8+
"vendor_part_number":"FTL",
9+
"vendor_serial_number":"U00000",
10+
"interface":"port33"
11+
},
12+
{
13+
"type":"QSFP\/QSFP+",
14+
"vendor":"FORTINET",
15+
"vendor_part_number":"FTL",
16+
"vendor_serial_number":"U00000",
17+
"interface":"port34"
18+
},
19+
{
20+
"type":"SFP\/SFP+\/SFP28",
21+
"vendor":"FORTINET",
22+
"vendor_part_number":"FTL",
23+
"vendor_serial_number":"U00000",
24+
"interface":"ha1"
25+
},
26+
{
27+
"type":"SFP\/SFP+\/SFP28",
28+
"vendor":"FORTINET",
29+
"vendor_part_number":"FTL",
30+
"vendor_serial_number":"U00000",
31+
"interface":"ha2"
32+
}
33+
],
34+
"vdom":"root",
35+
"path":"system",
36+
"name":"interface",
37+
"action":"transceivers",
38+
"status":"success",
39+
"serial":"F2",
40+
"version":"v7.4.5",
41+
"build":2702
42+
}

0 commit comments

Comments
 (0)