Skip to content
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

feat: Added user/firewall endpoint and Tests #258

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e8edcd9
feat(bgp): Neighbour path and best path count (#115)
Jul 15, 2021
f9210e1
feat: add probe selection capability from configuration file (#118)
IMSdevsecu Aug 11, 2021
43d4fb4
refactor(config): Add re-init function for testing (#125)
bluecmd Aug 13, 2021
8bbc181
feat(probe): Add probe for vpn SSL users (#119)
IMSdevsecu Aug 18, 2021
3380b7a
Add probe for vpn SSL stats (#120)
IMSdevsecu Aug 19, 2021
372c990
doc(readme): Update how the -insecure flag works (#128)
bluecmd Aug 22, 2021
3b71952
feat(probe): Log/Fortianalyzer: Add probe for fortianalyzer state and…
IMSdevsecu Aug 24, 2021
e53817f
fix(probe/vpn-ssl): increment value for fortigate_vpn_users in case …
IMSdevsecu Aug 24, 2021
043439c
feat(probe): Log/DiskUsage: Add probe for log disk usage (#123)
IMSdevsecu Aug 26, 2021
2683a03
ci(semantic-release): fix version in binary builds (#130)
secustor Aug 27, 2021
a5f7eb6
feat(probe): Add probe for Fsso Infos (#132)
IMSdevsecu Aug 30, 2021
48c0a1d
doc(readme): Matrix chat room (#136)
bluecmd Aug 30, 2021
f7fad23
refactor(probe): BGP Neighbor : fix typos and improve condition crite…
IMSdevsecu Sep 2, 2021
5164039
doc(readme): detail permissions per probe + update global monitor pro…
IMSdevsecu Sep 2, 2021
a24acbc
feat(probe): Add probe for fortigate internal clock time (#137)
IMSdevsecu Sep 3, 2021
7d6aa7b
ci(Makefile): add coverage report and run additional tests (#143)
secustor Sep 4, 2021
7f96dd5
fix(probe): System/Time/Clock moved on top of probe list for better t…
IMSdevsecu Sep 9, 2021
8502bf3
chore(deps): update actions/setup-node action to v3
renovate-bot Apr 25, 2022
a0831b8
chore(deps): update actions/setup-go action to v3
renovate[bot] Aug 7, 2022
f995797
chore(deps): update actions/checkout action to v3
renovate[bot] Aug 7, 2022
a84be45
fix(deps): update module github.com/google/go-jsonnet to v0.18.0
renovate[bot] Aug 7, 2022
b4aa78a
doc(CONTRIBUTING.md): Add contributing page to the project (#141)
IMSdevsecu Aug 7, 2022
fdfe388
chore(builder): Update builders to newer versions
bluecmd Aug 7, 2022
1811e9e
fix(arm64): Revert back to using Dockerhub
bluecmd Aug 7, 2022
36e2deb
feat(probe): Add probe for fortigate sensors (#140)
IMSdevsecu Aug 7, 2022
dc69a3b
feat(probe): Add probe for Fortimanager connection and registration s…
IMSdevsecu Aug 7, 2022
fe44f63
fix(release): use gomodules for goimports
bluecmd Aug 7, 2022
ffacd20
doc(readme): Example how to exclude sensors info
bluecmd Aug 7, 2022
6805023
fix(wifi_ap_status): Fix for FortiOS 7.0 (#185)
bluecmd Aug 10, 2022
11b4022
feat(probe): Add system reboot and snapshot time (#184)
bluecmd Aug 10, 2022
8bd16bb
feat(probe): Adding ha metrics for failover detection (#186)
galcorlo Aug 23, 2022
b3d0ddf
chore(deps): update actions/setup-go action to v4 (#207)
renovate[bot] Mar 25, 2023
87b8520
fix(deps): update module github.com/prometheus/client_golang to v1.14…
renovate[bot] Mar 25, 2023
6826671
fix(deps): update module github.com/google/go-jsonnet to v0.19.1 (#197)
renovate[bot] Mar 25, 2023
ba524d0
fix(deps): update module gopkg.in/yaml.v2 to v3 (#202)
renovate[bot] Mar 25, 2023
5c56405
feat: Add support for managed switches (#215)
thenodon Apr 27, 2023
f5a87de
fix(ci): use node 18
bluecmd Apr 27, 2023
3a448e1
feat(config): Add support for "dynamic" configuration (#216)
thenodon May 3, 2023
6fa8348
fix(deps): update module gopkg.in/yaml.v2 to v3 (#227)
renovate[bot] Jul 17, 2023
171aa25
doc(readme): Elaborate which parts are user specified (#221)
faizan-syed Jul 17, 2023
dbd209d
fix(deps): update module github.com/google/go-jsonnet to v0.20.0 (#213)
renovate[bot] Jul 17, 2023
e29ee54
fix(deps): update module gopkg.in/yaml.v2 to v3 (#233)
renovate[bot] Jul 17, 2023
53fdf65
fix(deps): update module github.com/prometheus/client_golang to v1.16…
renovate[bot] Jul 17, 2023
32445be
fix(deps): update module gopkg.in/yaml.v2 to v3 (#234)
renovate[bot] Jul 17, 2023
8089ea2
docs(contributing): commit message format (#235)
bluecmd Jul 17, 2023
75f55df
ci(pr): Create semantic.yml (#236)
bluecmd Jul 17, 2023
70b1b25
feat(probe): status of SDN Connectors (#210)
neilschelly Jul 19, 2023
ff3127a
fix(deps): fix renovates go.mod mess
bluecmd Jul 20, 2023
b3531d2
feat(probe): BGP session state as value (#237)
33Fraise33 Jul 25, 2023
e788a2c
doc(probe): improve metric descriptions (#239)
33Fraise33 Jul 25, 2023
c7660e9
feat(probe): support for ippool info (#240)
33Fraise33 Aug 14, 2023
6d1f8fb
feat: added OSPF metrics and corresponding testcase (#255)
xerox81 Nov 24, 2023
856fc24
fix(deps): update module github.com/prometheus/client_golang to v1.17…
renovate[bot] Nov 24, 2023
85e52d3
chore(ci): bump actions versions
bluecmd Nov 24, 2023
16df82a
Added user/firewall endpoint and
jahknem Dec 1, 2023
2a299cd
Added changes to readme
jahknem Dec 1, 2023
b66e958
Fixed erroneous jsonnet for user firewall
jahknem Dec 1, 2023
a27d630
awc
jahknem Dec 5, 2023
f871485
Merge branch 'master' into master
jahknem Dec 9, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# IDEs
.idea
.vscode

# artifacts
target
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ Per-VDOM:
* `fortigate_system_sdn_connector_last_update_seconds`
* _User/Fsso_
* `fortigate_user_fsso_info`
* _User/Firewall_
* `fortigate_user_firewall_duration_seconds`
* `fortigate_user_firewall_traffic_bytes`
* _VPN/Ssl/Connections_
* `fortigate_vpn_connections`
* `fortigate_vpn_users`
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ services:
ports:
- 9710:9710
volumes:
- /path/to/fortigate-key.yaml:/config/fortigate-key.yaml
- ./fortigate-key.yaml:/config/fortigate-key.yaml
restart: unless-stopped
command: ["-auth-file", "/config/fortigate-key.yaml", "-insecure"]
7 changes: 7 additions & 0 deletions fortigate-key.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"https://hk-tel-fw-lo.hessenkom.net:7443":
token: dqwds6t6jhbwcHrkf6H09GymhrNqf8
# If you have a smaller fortigate unit you might want
# to exclude sensors as they do not have any
probes:
exclude:
- System/SensorInfo
1 change: 1 addition & 0 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc
{"System/Status", probeSystemStatus},
{"System/VDOMResources", probeSystemVDOMResources},
{"System/HAChecksum", probeSystemHAChecksum},
{"User/Firewall", probeUserFirewall},
{"User/Fsso", probeUserFsso},
{"VPN/IPSec", probeVPNIPSec},
{"VPN/Ssl/Connections", probeVPNSsl},
Expand Down
49 changes: 49 additions & 0 deletions pkg/probe/testdata/user-firewall.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# api/v2/monitor/user/firewall
[
{
"http_method":"GET",
"results":[
{
"type":"auth_logon",
"id":0,
"duration_secs":21476,
"auth_type":3,
"ipaddr":"192.168.24.18",
"src_type":"ip4",
"expiry_secs":7196,
"traffic_vol_bytes":908744605,
"method":"Firewall"
},
{
"type":"auth_logon",
"id":0,
"duration_secs":6366,
"auth_type":3,
"ipaddr":"192.168.24.25",
"src_type":"ip4",
"expiry_secs":7168,
"traffic_vol_bytes":1738875,
"method":"Firewall"
},
{
"type":"auth_logon",
"id":0,
"duration_secs":39266,
"auth_type":3,
"ipaddr":"192.168.27.150",
"src_type":"ip4",
"expiry_secs":4717,
"traffic_vol_bytes":79707852,
"method":"Firewall"
}
],
"vdom":"VD_ES-WIFI",
"path":"user",
"name":"firewall",
"action":"",
"status":"success",
"serial":"ABCDxxxEFGH",
"version":"v7.0.12",
"build":523
}
]
68 changes: 68 additions & 0 deletions pkg/probe/user_firewall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package probe

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

type UserFirewallResult struct {
Type string `json:"type"`
ID int `json:"id"`
DurationSecs int `json:"duration_secs"`
AuthType int `json:"auth_type"`
IPAddr string `json:"ipaddr"`
SrcType string `json:"src_type"`
ExpirySecs int `json:"expiry_secs"`
TrafficVolBytes int64 `json:"traffic_vol_bytes"`
Method string `json:"method"`
}

type UserFirewall struct {
HttpMethod string `json:"http_method"`
Results []UserFirewallResult `json:"results"`
VDOM string `json:"vdom"`
Path string `json:"path"`
Name string `json:"name"`
Action string `json:"action"`
Status string `json:"status"`
Serial string `json:"serial"`
Version string `json:"version"`
Build int `json:"build"`
}


func probeUserFirewall(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
var (
userFirewallDuration = prometheus.NewDesc(
"fortigate_user_firewall_duration_seconds",
"Duration of user firewall activity in seconds",
[]string{"vdom", "ipaddr", "method", "type"}, nil,
)
userFirewallTraffic = prometheus.NewDesc(
"fortigate_user_firewall_traffic_bytes",
"Traffic volume in bytes for user firewall activity",
[]string{"vdom", "ipaddr", "method", "type"}, nil,
)
)

var res []UserFirewall
if err := c.Get("/api/v2/monitor/user/firewall", "vdom=*", &res); err != nil {
log.Printf("Error: %v", err)
return nil, false
}

metrics := []prometheus.Metric{}
for _, fw := range res {
for _, r := range fw.Results {
metrics = append(metrics, prometheus.MustNewConstMetric(
userFirewallDuration, prometheus.GaugeValue, float64(r.DurationSecs), fw.VDOM, r.IPAddr, r.Method, r.Type,
))
metrics = append(metrics, prometheus.MustNewConstMetric(
userFirewallTraffic, prometheus.GaugeValue, float64(r.TrafficVolBytes), fw.VDOM, r.IPAddr, r.Method, r.Type,
))
}
}

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

import (
"strings"
"testing"

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

func TestUserFirewall(t *testing.T) {
c := newFakeClient()
c.prepare("/api/v2/monitor/user/firewall", "testdata/user-firewall.jsonnet")
r := prometheus.NewPedanticRegistry()
if !testProbe(probeUserFirewall, c, r) {
t.Errorf("probeUserFirewall() returned non-success")
}

em := `
# HELP fortigate_user_firewall_duration_seconds Duration of user firewall activity in seconds
# TYPE fortigate_user_firewall_duration_seconds gauge
fortigate_user_firewall_duration_seconds{ipaddr="192.168.24.18",method="Firewall",type="auth_logon",vdom="VD_ES-WIFI"} 21476
fortigate_user_firewall_duration_seconds{ipaddr="192.168.24.25",method="Firewall",type="auth_logon",vdom="VD_ES-WIFI"} 6366
fortigate_user_firewall_duration_seconds{ipaddr="192.168.27.150",method="Firewall",type="auth_logon",vdom="VD_ES-WIFI"} 39266
# HELP fortigate_user_firewall_traffic_bytes Traffic volume in bytes for user firewall activity
# TYPE fortigate_user_firewall_traffic_bytes gauge
fortigate_user_firewall_traffic_bytes{ipaddr="192.168.24.18",method="Firewall",type="auth_logon",vdom="VD_ES-WIFI"} 908744605
fortigate_user_firewall_traffic_bytes{ipaddr="192.168.24.25",method="Firewall",type="auth_logon",vdom="VD_ES-WIFI"} 1738875
fortigate_user_firewall_traffic_bytes{ipaddr="192.168.27.150",method="Firewall",type="auth_logon",vdom="VD_ES-WIFI"} 79707852
`


if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
t.Fatalf("metric compare: err %v", err)
}
}