-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added ARP Table informatio and corresponding testcase
- Loading branch information
1 parent
9d74331
commit dd26248
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] |