Skip to content
This repository has been archived by the owner on Nov 9, 2024. It is now read-only.

feat: Added FortiGate Transceiver Information metric #304

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Global:
* `fortigate_sensor_voltage_volts`
* _System/Status_
* `fortigate_version_info`
* _System/Transceivers_
* `fortigate_interface_transceivers`
* _System/Time/Clock_
* `fortigate_time_seconds`
* _System/Resource/Usage_
Expand Down
1 change: 1 addition & 0 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc
{"System/Fortimanager/Status", probeSystemFortimanagerStatus},
{"System/HAStatistics", probeSystemHAStatistics},
{"System/Interface", probeSystemInterface},
{"System/Transceivers", probeSystemInterfaceTransceivers},
{"System/LinkMonitor", probeSystemLinkMonitor},
{"System/Resource/Usage", probeSystemResourceUsage},
{"System/SDNConnector", probeSystemSDNConnector},
Expand Down
42 changes: 42 additions & 0 deletions pkg/probe/system_interface_transceivers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package probe

import (
"log"

"github.com/bluecmd/fortigate_exporter/pkg/http"
"github.com/prometheus/client_golang/prometheus"
)

func probeSystemInterfaceTransceivers(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
var (
mVersion = prometheus.NewDesc(
"fortigate_interface_transceivers_info",
"List of transceivers being used by the FortiGate",
[]string{"name", "type", "vendor", "partnumber", "serialnumber", "description"}, nil,
)
)

type ifResult struct {
Description string
Interface string
Type string
Vendor string
VendorPartNr string `json:"vendor_part_number"`
VendorSerialNr string `json:"vendor_serial_number"`
}
type ifResponse struct {
Results []ifResult
}
var r ifResponse

if err := c.Get("api/v2/monitor/system/interface/transceivers", "scope=global", &r); err != nil {
log.Printf("Error: %v", err)
return nil, false
}

m := []prometheus.Metric{}
for _, result := range r.Results {
m = append(m, prometheus.MustNewConstMetric(mVersion, prometheus.GaugeValue, 1.0, result.Interface, result.Type, result.Vendor, result.VendorPartNr, result.VendorSerialNr, result.Description))
}
return m, true
}
31 changes: 31 additions & 0 deletions pkg/probe/system_interface_transceivers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package probe

import (
"strings"
"testing"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
)

func TestSystemInterfaceTransceivers(t *testing.T) {
c := newFakeClient()
c.prepare("api/v2/monitor/system/interface/transceivers", "testdata/interface-transceivers.jsonnet")
r := prometheus.NewPedanticRegistry()
if !testProbe(probeSystemInterfaceTransceivers, c, r) {
t.Errorf("probeSystemInterfaceTransceivers() returned non-success")
}

em := `
# HELP fortigate_interface_transceivers_info List of transceivers being used by the FortiGate
# TYPE fortigate_interface_transceivers_info gauge
fortigate_interface_transceivers_info{description="",name="ha1",partnumber="FTLX8574D3BCLFTN",serialnumber="U00000",type="SFP/SFP+/SFP28",vendor="FORTINET"} 1
fortigate_interface_transceivers_info{description="",name="ha2",partnumber="FTLX8574D3BCLFTN",serialnumber="U00000",type="SFP/SFP+/SFP28",vendor="FORTINET"} 1
fortigate_interface_transceivers_info{description="",name="port33",partnumber="FTL410QE4CFTN",serialnumber="U00000",type="QSFP/QSFP+",vendor="FORTINET"} 1
fortigate_interface_transceivers_info{description="",name="port34",partnumber="FTL410QE4CFTN",serialnumber="U00000",type="QSFP/QSFP+",vendor="FORTINET"} 1
`

if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
t.Fatalf("metric compare: err %v", err)
}
}
42 changes: 42 additions & 0 deletions pkg/probe/testdata/interface-transceivers.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# api/v2/monitor/system/interface/transceivers?scope=global
{
"http_method":"GET",
"results":[
{
"type":"QSFP\/QSFP+",
"vendor":"FORTINET",
"vendor_part_number":"FTL410QE4CFTN",
"vendor_serial_number":"U00000",
"interface":"port33"
},
{
"type":"QSFP\/QSFP+",
"vendor":"FORTINET",
"vendor_part_number":"FTL410QE4CFTN",
"vendor_serial_number":"U00000",
"interface":"port34"
},
{
"type":"SFP\/SFP+\/SFP28",
"vendor":"FORTINET",
"vendor_part_number":"FTLX8574D3BCLFTN",
"vendor_serial_number":"U00000",
"interface":"ha1"
},
{
"type":"SFP\/SFP+\/SFP28",
"vendor":"FORTINET",
"vendor_part_number":"FTLX8574D3BCLFTN",
"vendor_serial_number":"U00000",
"interface":"ha2"
}
],
"vdom":"root",
"path":"system",
"name":"interface",
"action":"transceivers",
"status":"success",
"serial":"F2K60FTK00000000",
"version":"v7.4.5",
"build":2702
}
Loading