Skip to content

Commit 9da7dd6

Browse files
33Fraise33Gianni Stubbe
and
Gianni Stubbe
authored
feat(probe): support for ippool info (#240)
* feat(ippool): Added support for ippool info This merge adds support for ippool information. This closes #231 * fix(naming): Updated metric names to be in line with prometheus conventions * test(ippool): Added tests for the firewall ippool feature * style: Updated tests and readme to align for new naming * style: Changed metric name to match other percentage metrics * fix(ippool): Updated value percentage to be 0-1.0 --------- Co-authored-by: Gianni Stubbe <[email protected]>
1 parent a863650 commit 9da7dd6

File tree

5 files changed

+172
-0
lines changed

5 files changed

+172
-0
lines changed

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ Per-VDOM:
6363
* `fortigate_policy_bytes_total`
6464
* `fortigate_policy_hit_count_total`
6565
* `fortigate_policy_packets_total`
66+
* _Firewall/IpPool_
67+
* `fortigate_ippool_available_ratio`
68+
* `fortigate_ippool_used_ips`
69+
* `fortigate_ippool_total_ips`
70+
* `fortigate_ippool_clients`
71+
* `fortigate_ippool_used_items`
72+
* `fortigate_ippool_total_items`
6673
* _System/Fortimanager/Status_
6774
* `fortigate_fortimanager_connection_status`
6875
* `fortigate_fortimanager_registration_status`
@@ -386,6 +393,7 @@ To improve security, limit permissions to required ones only (least privilege pr
386393
|BGP/NeighborPaths/IPv6 | netgrp.route-cfg |api/v2/monitor/router/bgp/paths6 |
387394
|BGP/Neighbors/IPv4 | netgrp.route-cfg |api/v2/monitor/router/bgp/neighbors |
388395
|BGP/Neighbors/IPv6 | netgrp.route-cfg |api/v2/monitor/router/bgp/neighbors6 |
396+
|Firewall/IpPool | fwgrp.policy |api/v2/monitor/firewall/ippool |
389397
|Firewall/LoadBalance | fwgrp.others |api/v2/monitor/firewall/load-balance |
390398
|Firewall/Policies | fwgrp.policy |api/v2/monitor/firewall/policy/select<br>api/v2/monitor/firewall/policy6/select<br>api/v2/cmdb/firewall/policy<br>api/v2/cmdb/firewall/policy6 |
391399
|License/Status | *any* |api/v2/monitor/license/status/select |

Diff for: pkg/probe/firewall_ippool.go

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package probe
2+
3+
import (
4+
"log"
5+
6+
"github.com/bluecmd/fortigate_exporter/pkg/http"
7+
"github.com/prometheus/client_golang/prometheus"
8+
)
9+
10+
type IpPool struct {
11+
Name string `json:"name"`
12+
IPTotal int `json:"natip_total"`
13+
IPInUse int `json:"natip_in_use"`
14+
Clients int `json:"clients"`
15+
Available float64 `json:"available"`
16+
Used int `json:"used"`
17+
Total int `json:"total"`
18+
}
19+
20+
type IpPoolResponse struct {
21+
Results map[string]IpPool `json:"results"`
22+
VDOM string `json:"vdom"`
23+
Version string `json:"version"`
24+
}
25+
26+
func probeFirewallIpPool(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
27+
var (
28+
mAvailable = prometheus.NewDesc(
29+
"fortigate_ippool_available_ratio",
30+
"Percentage available in ippool (0 - 1.0)",
31+
[]string{"vdom", "name"}, nil,
32+
)
33+
)
34+
var (
35+
mIpUsed = prometheus.NewDesc(
36+
"fortigate_ippool_used_ips",
37+
"Ip addresses in use in ippool",
38+
[]string{"vdom", "name"}, nil,
39+
)
40+
)
41+
var (
42+
mIpTotal = prometheus.NewDesc(
43+
"fortigate_ippool_total_ips",
44+
"Ip addresses total in ippool",
45+
[]string{"vdom", "name"}, nil,
46+
)
47+
)
48+
var (
49+
mClients = prometheus.NewDesc(
50+
"fortigate_ippool_clients",
51+
"Amount of clients using ippool",
52+
[]string{"vdom", "name"}, nil,
53+
)
54+
)
55+
var (
56+
mUsed = prometheus.NewDesc(
57+
"fortigate_ippool_used_items",
58+
"Amount of items used in ippool",
59+
[]string{"vdom", "name"}, nil,
60+
)
61+
)
62+
var (
63+
mTotal = prometheus.NewDesc(
64+
"fortigate_ippool_total_items",
65+
"Amount of items total in ippool",
66+
[]string{"vdom", "name"}, nil,
67+
)
68+
)
69+
70+
var rs []IpPoolResponse
71+
72+
if err := c.Get("api/v2/monitor/firewall/ippool", "vdom=*", &rs); err != nil {
73+
log.Printf("Error: %v", err)
74+
return nil, false
75+
}
76+
77+
m := []prometheus.Metric{}
78+
79+
for _, r := range rs {
80+
for _, ippool := range r.Results {
81+
m = append(m, prometheus.MustNewConstMetric(mAvailable, prometheus.GaugeValue, ippool.Available/100, r.VDOM, ippool.Name))
82+
m = append(m, prometheus.MustNewConstMetric(mIpUsed, prometheus.GaugeValue, float64(ippool.IPInUse), r.VDOM, ippool.Name))
83+
m = append(m, prometheus.MustNewConstMetric(mIpTotal, prometheus.GaugeValue, float64(ippool.IPTotal), r.VDOM, ippool.Name))
84+
m = append(m, prometheus.MustNewConstMetric(mClients, prometheus.GaugeValue, float64(ippool.Clients), r.VDOM, ippool.Name))
85+
m = append(m, prometheus.MustNewConstMetric(mUsed, prometheus.GaugeValue, float64(ippool.Used), r.VDOM, ippool.Name))
86+
m = append(m, prometheus.MustNewConstMetric(mTotal, prometheus.GaugeValue, float64(ippool.Total), r.VDOM, ippool.Name))
87+
}
88+
}
89+
90+
return m, true
91+
}

Diff for: pkg/probe/firewall_ippool_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 TestFirewallIpPool(t *testing.T) {
12+
c := newFakeClient()
13+
c.prepare("api/v2/monitor/firewall/ippool", "testdata/fw-ippool.jsonnet")
14+
r := prometheus.NewPedanticRegistry()
15+
if !testProbe(probeFirewallIpPool, c, r) {
16+
t.Errorf("probeFirewallIpPool() returned non-success")
17+
}
18+
19+
em := `
20+
# HELP fortigate_ippool_available_ratio Percentage available in ippool (0 - 1.0)
21+
# TYPE fortigate_ippool_available_ratio gauge
22+
fortigate_ippool_available_ratio{name="ippool_name",vdom="FG-traffic"} 1
23+
# HELP fortigate_ippool_clients Amount of clients using ippool
24+
# TYPE fortigate_ippool_clients gauge
25+
fortigate_ippool_clients{name="ippool_name",vdom="FG-traffic"} 0
26+
# HELP fortigate_ippool_total_ips Ip addresses total in ippool
27+
# TYPE fortigate_ippool_total_ips gauge
28+
fortigate_ippool_total_ips{name="ippool_name",vdom="FG-traffic"} 1
29+
# HELP fortigate_ippool_total_items Amount of items total in ippool
30+
# TYPE fortigate_ippool_total_items gauge
31+
fortigate_ippool_total_items{name="ippool_name",vdom="FG-traffic"} 472
32+
# HELP fortigate_ippool_used_ips Ip addresses in use in ippool
33+
# TYPE fortigate_ippool_used_ips gauge
34+
fortigate_ippool_used_ips{name="ippool_name",vdom="FG-traffic"} 0
35+
# HELP fortigate_ippool_used_items Amount of items used in ippool
36+
# TYPE fortigate_ippool_used_items gauge
37+
fortigate_ippool_used_items{name="ippool_name",vdom="FG-traffic"} 0
38+
`
39+
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
40+
t.Fatalf("metric compare: err %v", err)
41+
}
42+
}

Diff for: pkg/probe/probe.go

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc
122122
{"BGP/Neighbors/IPv6", probeBGPNeighborsIPv6},
123123
{"Firewall/LoadBalance", probeFirewallLoadBalance},
124124
{"Firewall/Policies", probeFirewallPolicies},
125+
{"Firewall/IpPool", probeFirewallIpPool},
125126
{"License/Status", probeLicenseStatus},
126127
{"Log/Fortianalyzer/Status", probeLogAnalyzer},
127128
{"Log/Fortianalyzer/Queue", probeLogAnalyzerQueue},

Diff for: pkg/probe/testdata/fw-ippool.jsonnet

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# api/v2/monitor/firewall/ippool?vdom=*
2+
3+
[
4+
{
5+
"http_method": "GET",
6+
"results": {
7+
"ippool_name": {
8+
"name": "ippool_name",
9+
"blocks": 8,
10+
"block_size": 128,
11+
"fixed_port": false,
12+
"pba_per_ip": 472,
13+
"used": 0,
14+
"total": 472,
15+
"available": 100.0,
16+
"clients": 0,
17+
"natip_in_use": 0,
18+
"natip_total": 1
19+
}
20+
},
21+
"vdom":"FG-traffic",
22+
"path":"firewall",
23+
"name":"ippool",
24+
"action":"",
25+
"status":"success",
26+
"serial":"FGVMEVZFNTS3OAC8",
27+
"version":"v7.0.11",
28+
"build":489
29+
}
30+
]

0 commit comments

Comments
 (0)