Skip to content

Commit 1afd2d2

Browse files
authored
Merge branch 'bluecmd:master' into fortiswitch_port_stats
2 parents 54a9da6 + 1007fc1 commit 1afd2d2

File tree

10 files changed

+2581
-11
lines changed

10 files changed

+2581
-11
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v3
1616

1717
- name: Set up Go
18-
uses: actions/setup-go@v3
18+
uses: actions/setup-go@v4
1919
with:
2020
go-version: ^1.18
2121
id: go

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
# Go setup
1515
- name: Set up Go
16-
uses: actions/setup-go@v3
16+
uses: actions/setup-go@v4
1717
with:
1818
go-version: ^1.18
1919
id: go
@@ -43,7 +43,7 @@ jobs:
4343
- name: Setup Node.js
4444
uses: actions/setup-node@v3
4545
with:
46-
node-version: 16
46+
node-version: 18
4747
- name: Add execution plugin
4848
run: npm install @semantic-release/exec
4949
- name: Release to GitHub

README.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Prometheus exporter for FortiGate® firewalls.
1111

1212
* [Supported Metrics](#supported-metrics)
1313
* [Usage](#usage)
14+
+ [Dynamic configuration](#dynamic-configuration)
1415
+ [Available CLI parameters](#available-cli-parameters)
1516
+ [Fortigate Configuration](#fortigate-configuration)
1617
+ [Prometheus Configuration](#prometheus-configuration)
@@ -245,6 +246,37 @@ Per-VDOM, managed access point and interface:
245246
* `fortigate_wifi_managed_ap_interface_rx_dropped_packets_total`
246247
* `fortigate_wifi_managed_ap_interface_tx_dropped_packets_total`
247248

249+
Per-VDOM, managed switch and interface:
250+
* _Switch/ManagedSwitch_
251+
* `fortigate_managed_switch_collisions_total`
252+
* `fortigate_managed_switch_crc_alignments_total`
253+
* `fortigate_managed_switch_fragments_total`
254+
* `fortigate_managed_switch_info`
255+
* `fortigate_managed_switch_jabbers_total`
256+
* `fortigate_managed_switch_l3_packets_total`
257+
* `fortigate_managed_switch_max_poe_budget_watt`
258+
* `fortigate_managed_switch_port_info`
259+
* `fortigate_managed_switch_port_power_status`
260+
* `fortigate_managed_switch_port_power_watt`
261+
* `fortigate_managed_switch_port_status`
262+
* `fortigate_managed_switch_rx_bcast_packets_total`
263+
* `fortigate_managed_switch_rx_bytes_total`
264+
* `fortigate_managed_switch_rx_drops_total`
265+
* `fortigate_managed_switch_rx_errors_total`
266+
* `fortigate_managed_switch_rx_mcast_packets_total`
267+
* `fortigate_managed_switch_rx_oversize_total`
268+
* `fortigate_managed_switch_rx_packets_total`
269+
* `fortigate_managed_switch_rx_ucast_packets_total`
270+
* `fortigate_managed_switch_tx_bcast_packets_total`
271+
* `fortigate_managed_switch_tx_bytes_total`
272+
* `fortigate_managed_switch_tx_drops_total`
273+
* `fortigate_managed_switch_tx_errors_total`
274+
* `fortigate_managed_switch_tx_mcast_packets_total`
275+
* `fortigate_managed_switch_tx_oversize_total`
276+
* `fortigate_managed_switch_tx_packets_total`
277+
* `fortigate_managed_switch_tx_ucast_packets_total`
278+
* `fortigate_managed_switch_under_size_total`
279+
248280
## Usage
249281

250282
Example:
@@ -323,6 +355,39 @@ Special cases:
323355

324356
To probe a FortiGate, do something like `curl 'localhost:9710/probe?target=https://my-fortigate'`
325357

358+
### Dynamic configuration
359+
In use cases where the Fortigates that is to be scraped through the fortigate-exporter is configured in
360+
Prometheus using some discovery method it becomes problematic that the `fortigate-key.yaml` configuration also
361+
has to be updated for each fortigate, and that the fortigate-exporter needs to be restarted on each change.
362+
For that scenario the token can be passed as a query parameter, `token`, to the fortigate.
363+
364+
Example:
365+
```bash
366+
curl 'localhost:9710/probe?target=https://192.168.2.31&token=ghi6eItWzWewgbrFMsazvBVwDjZzzb'
367+
```
368+
It is also possible to pass a `profile` query parameter. The value will match an entry in the `fortigate-key.yaml`
369+
file, but only to use the `probes` section for include/exclude directives.
370+
371+
Example:
372+
```bash
373+
curl 'localhost:9710/probe?target=https://192.168.2.31&token=ghi6eItWzWewgbrFMsazvBVwDjZzzb&profile=fs124e'
374+
```
375+
The `profile=fs124e` would match the following entry in `fortigate-key.yaml`.
376+
377+
Example:
378+
```yaml
379+
fs124e:
380+
# token: not used
381+
probes:
382+
include:
383+
- System
384+
- Firewall
385+
exclude:
386+
- System/LinkMonitor
387+
```
388+
389+
390+
326391
### Available CLI parameters
327392
328393
| flag | default value | description |
@@ -374,7 +439,7 @@ To improve security, limit permissions to required ones only (least privilege pr
374439
|Wifi/APStatus | wifi |api/v2/monitor/wifi/ap_status |
375440
|Wifi/Clients | wifi |api/v2/monitor/wifi/client |
376441
|Wifi/ManagedAP | wifi |api/v2/monitor/wifi/managed_ap |
377-
442+
|Switch/ManagedSwitch | switch |api/v2/monitor/switch-controller/managed-switch|
378443
If you omit to grant some of these permissions you will receive log messages warning about
379444
403 errors and relevant metrics will be unavailable, but other metrics will still work.
380445
If you do not need some probes to be run, do not grant permission for them and use `include/exclude` feature (see `Usage` section).
@@ -438,6 +503,40 @@ An example configuration for Prometheus looks something like this:
438503
replacement: '[::1]:9710'
439504
```
440505

506+
If using [Dynamic configuration](#dynamic-configuration):
507+
```yaml
508+
- job_name: 'fortigate_exporter'
509+
metrics_path: /probe
510+
file_sd_configs:
511+
- files:
512+
- /etc/prometheus/file_sd/fws/*.yml
513+
params:
514+
profile:
515+
- fs124e
516+
relabel_configs:
517+
- source_labels: [__address__]
518+
target_label: __param_target
519+
- source_labels: [token]
520+
target_label: __param_token
521+
- source_labels: [__param_target]
522+
regex: '(?:.+)(?::\/\/)([^:]*).*'
523+
target_label: instance
524+
- target_label: __address__
525+
replacement: '[::1]:9710'
526+
- action: labeldrop
527+
regex: token
528+
```
529+
> Make sure to use the last labeldrop on the `token` label so that the tokens is not be part of your time series.
530+
531+
> Since `token` is a label it will be shown in the Prometheus webgui at `http://<your prometheus>:9090/targets`.
532+
>
533+
> **Make sure you protect your Prometheus if you add the token part of your prometheus config**
534+
>
535+
> Some options to protect Prometheus:
536+
> - Only expose UI to localhost --web.listen-address="127.0.0.1:9090"
537+
> - Basic authentication access - https://prometheus.io/docs/guides/basic-auth/
538+
> - **It is your responsibility!**
539+
441540
### Docker
442541

443542
You can either use the automatic builds on

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module github.com/bluecmd/fortigate_exporter
33
go 1.18
44

55
require (
6-
github.com/google/go-jsonnet v0.18.0
7-
github.com/prometheus/client_golang v1.13.0
6+
github.com/google/go-jsonnet v0.19.1
7+
github.com/prometheus/client_golang v1.14.0
88
gopkg.in/yaml.v2 v2.4.0
9+
gopkg.in/yaml.v3 v3.0.1
910
)
1011

1112
require (
@@ -14,10 +15,10 @@ require (
1415
github.com/davecgh/go-spew v1.1.1 // indirect
1516
github.com/golang/protobuf v1.5.2 // indirect
1617
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
17-
github.com/prometheus/client_model v0.2.0 // indirect
18+
github.com/prometheus/client_model v0.3.0 // indirect
1819
github.com/prometheus/common v0.37.0 // indirect
1920
github.com/prometheus/procfs v0.8.0 // indirect
20-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
21+
golang.org/x/sys v0.1.0 // indirect
2122
google.golang.org/protobuf v1.28.1 // indirect
2223
sigs.k8s.io/yaml v1.1.0 // indirect
2324
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
5959
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
6060
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
6161
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
62+
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
6263
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
6364
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
6465
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -114,6 +115,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
114115
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
115116
github.com/google/go-jsonnet v0.18.0 h1:/6pTy6g+Jh1a1I2UMoAODkqELFiVIdOxbNwv0DDzoOg=
116117
github.com/google/go-jsonnet v0.18.0/go.mod h1:C3fTzyVJDslXdiTqw/bTFk7vSGyCtH3MGRbDfvEwGd0=
118+
github.com/google/go-jsonnet v0.19.1 h1:MORxkrG0elylUqh36R4AcSPX0oZQa9hvI3lroN+kDhs=
119+
github.com/google/go-jsonnet v0.19.1/go.mod h1:5JVT33JVCoehdTj5Z2KJq1eIdt3Nb8PCmZ+W5D8U350=
117120
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
118121
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
119122
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -170,11 +173,15 @@ github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqr
170173
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
171174
github.com/prometheus/client_golang v1.13.0 h1:b71QUfeo5M8gq2+evJdTPfZhYMAU0uKPkyPJ7TPsloU=
172175
github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ=
176+
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
177+
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
173178
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
174179
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
175180
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
176181
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
177182
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
183+
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
184+
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
178185
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
179186
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
180187
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
@@ -331,6 +338,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
331338
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
332339
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
333340
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
341+
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
342+
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
334343
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
335344
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
336345
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -478,6 +487,7 @@ gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
478487
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
479488
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
480489
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
490+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
481491
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
482492
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
483493
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

pkg/probe/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ func ProbeHandler(w http.ResponseWriter, r *http.Request) {
1616
savedConfig := config.GetConfig()
1717

1818
params := r.URL.Query()
19+
paramMap := make(map[string]string)
1920
target := params.Get("target")
21+
paramMap["target"] = params.Get("target")
22+
if params.Get("token") != "" {
23+
paramMap["token"] = params.Get("token")
24+
}
25+
if params.Get("profile") != "" {
26+
paramMap["profile"] = params.Get("profile")
27+
}
28+
2029
if target == "" {
2130
http.Error(w, "Target parameter missing or empty", http.StatusBadRequest)
2231
return
@@ -37,7 +46,7 @@ func ProbeHandler(w http.ResponseWriter, r *http.Request) {
3746
start := time.Now()
3847
pc := &ProbeCollector{}
3948
registry.MustRegister(pc)
40-
success, err := pc.Probe(ctx, target, &http.Client{}, savedConfig)
49+
success, err := pc.Probe(ctx, paramMap, &http.Client{}, savedConfig)
4150
if err != nil {
4251
log.Printf("Probe request rejected; error is: %v", err)
4352
http.Error(w, fmt.Sprintf("probe: %v", err), http.StatusBadRequest)

0 commit comments

Comments
 (0)