Skip to content

feat: added ARP Table informatio and corresponding testcase #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Per-VDOM:
* _System/Fortimanager/Status_
* `fortigate_fortimanager_connection_status`
* `fortigate_fortimanager_registration_status`
* `fortigate_ippool_total_items`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy paste error?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, sorry, don't really know if to remove I have to recommit

* _System/Network/Arp
* `fortigate_arp_entry_age_seconds`
* _System/Interface_
* `fortigate_interface_link_up`
* `fortigate_interface_speed_bps`
Expand Down
1 change: 1 addition & 0 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc
{"Log/Fortianalyzer/Queue", probeLogAnalyzerQueue},
{"Log/DiskUsage", probeLogCurrentDiskUsage},
{"System/AvailableCertificates", probeSystemAvailableCertificates},
{"System/ArpTable", probeSystemArpTable},
{"System/Fortimanager/Status", probeSystemFortimanagerStatus},
{"System/HAStatistics", probeSystemHAStatistics},
{"System/Interface", probeSystemInterface},
Expand Down
45 changes: 45 additions & 0 deletions pkg/probe/system_arp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package probe

import (
"log"

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

func probeSystemArpTable(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
var (
mArpEntryAge = prometheus.NewDesc(
"fortigate_arp_entry_age_seconds",
"Age of ARP table entry in seconds",
[]string{"ip", "mac", "interface"}, nil,
)
)

type arpEntry struct {
IP string `json:"ip"`
Age int `json:"age"`
MAC string `json:"mac"`
Interface string `json:"interface"`
}

type arpResponse struct {
Results []arpEntry `json:"results"`
VDOM string `json:"vdom"`
}

var r arpResponse

if err := c.Get("api/v2/monitor/network/arp/select", "", &r); err != nil {
log.Printf("Error: %v", err)
return nil, false
}

metrics := []prometheus.Metric{}
for _, entry := range r.Results {
metrics = append(metrics, prometheus.MustNewConstMetric(mArpEntryAge, prometheus.GaugeValue, float64(entry.Age), entry.IP, entry.MAC, entry.Interface))
// Add more metrics if needed
}

return metrics, true
}
28 changes: 28 additions & 0 deletions pkg/probe/system_arp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package probe

import (
"strings"
"testing"

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

func TestSystemArpTable(t *testing.T) {
c := newFakeClient()
c.prepare("api/v2/monitor/network/arp/select", "testdata/arp.jsonnet")
r := prometheus.NewPedanticRegistry()
if !testProbe(probeSystemArpTable, c, r) {
t.Errorf("probeSystemArpTable() returned non-success")
}

em := `
# HELP fortigate_arp_entry_age_seconds Age of ARP table entry in seconds
# TYPE fortigate_arp_entry_age_seconds gauge
fortigate_arp_entry_age_seconds{ip="192.168.1.23",mac="aa:05:f3:a6:33:2a",interface="port1"} 0
fortigate_arp_entry_age_seconds{ip="192.168.1.1",mac="80:16:05:f8:71:10",interface="port1"} 35
`
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
t.Fatalf("metric compare: err %v", err)
}
}
28 changes: 28 additions & 0 deletions pkg/probe/testdata/arp.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# api/v2/monitor/network/arp/select?vdom=*
[
{
"http_method": "GET",
"results": [
{
"ip": "192.168.1.23",
"age": 0,
"mac": "aa:05:f3:a6:33:2a",
"interface": "port1"
},
{
"ip": "192.168.1.1",
"age": 35,
"mac": "80:16:05:f8:71:10",
"interface": "port1"
}
],
"vdom": "root",
"path": "network",
"name": "arp",
"action": "",
"status": "success",
"serial": "FGVMEVHX1X8UNJ34",
"version": "v7.0.5",
"build": 304
}
]