Skip to content

Commit 4b496fd

Browse files
Merge branch 'main' into repo_sync
2 parents bc36373 + 8d406ff commit 4b496fd

60 files changed

Lines changed: 841 additions & 122 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
with:
2929
persist-credentials: false
3030
- name: Install Go
31-
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
31+
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
3232
with:
3333
go-version: 1.25.x
3434
- name: Install snmp_exporter/generator dependencies

MAINTAINERS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* Ben Kochie <superq@gmail.com> @SuperQ
2+
* Basti Schubert <basti@schubert.digital> @bastischubert

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ Prometheus exporter for FortiGate® firewalls.
99

1010
---
1111

12-
**This repository is archived due to lack of time from the maintainer, as well as lack of support from Fortinet to provide documentation. The constant fight to reverse engineer the APIs for new versions takes too much time for a few developers. Feel free to fork this project and continue the work!**
13-
14-
---
15-
1612
**NOTE:** This is not an official Fortinet product, it is developed fully independently by professionals and hobbyists alike.
1713

1814
* [Supported Metrics](#supported-metrics)
@@ -182,6 +178,7 @@ To improve security, limit permissions to required ones only (least privilege pr
182178
|System/AvailableCertificates | *any* |api/v2/monitor/system/available-certificates |
183179
|System/Central-management/Status | sysgrp.cfg |api/v2/monitor/system/central-management/status|
184180
|System/Fortimanager/Status | sysgrp.cfg |api/v2/monitor/system/fortimanager/status |
181+
|System/Global/Location | sysgrp.cfg |api/v2/cmdb/system/global |
185182
|System/HAStatistics | sysgrp.cfg |api/v2/monitor/system/ha-statistics<br>api/v2/cmdb/system/ha |
186183
|System/Ha-peer | sysgrp.cfg |api/v2/monitor/system/ha-peer |
187184
|System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select |

fortigate_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
"github.com/prometheus/client_golang/prometheus/promhttp"
4343

4444
"github.com/prometheus-community/fortigate_exporter/internal/config"
45-
fortiHTTP "github.com/prometheus-community/fortigate_exporter/pkg/http"
45+
fortiHTTP "github.com/prometheus-community/fortigate_exporter/pkg/fortigatehttpclient"
4646
"github.com/prometheus-community/fortigate_exporter/pkg/probe"
4747
)
4848

metrics.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Global:
44

55
* _Network/Dns/Latency_
66
* `fortigate_network_dns_latency_`
7+
* _System/Global/Location_
8+
* `fortigate_location_info`
79
* _System/SensorInfo_
810
* `fortigate_sensor_alarm_status`
911
* `fortigate_sensor_fan_rpm`
@@ -12,6 +14,7 @@ Global:
1214
* `fortigate_sensor_thresholds`
1315
* _System/Status_
1416
* `fortigate_version_info`
17+
* `fortigate_system_status_log_disk_state`
1518
* _System/Transceivers_
1619
* `fortigate_interface_transceivers`
1720
* _System/Time/Clock_
@@ -89,6 +92,7 @@ Per-VDOM:
8992
* _System/Interface/Transceivers_
9093
* `fortigate_inteface_transceivers_info`
9194
* _System/SDNConnector_
95+
* `fortigate_system_sdn_connector_state`
9296
* `fortigate_system_sdn_connector_status`
9397
* `fortigate_system_sdn_connector_last_update_seconds`
9498
* _/System/CentralManagement/Status_
@@ -178,8 +182,10 @@ Per-VDOM:
178182
Per-BGP-Neighbor and VDOM:
179183
* _BGP/Neighbors/IPv4_
180184
* `fortigate_bgp_neighbor_ipv4_info`
185+
* `fortigate_bgp_neighbor_ipv4_state`
181186
* _BGP/Neighbors/IPv6_
182187
* `fortigate_bgp_neighbor_ipv6_info`
188+
* `fortigate_bgp_neighbor_ipv6_state`
183189
* _BGP/NeighborPaths/IPv4_
184190
* `fortigate_bgp_neighbor_ipv4_paths`
185191
* `fortigate_bgp_neighbor_ipv4_best_paths`

pkg/http/forti_token_client.go renamed to pkg/fortigatehttpclient/forti_token_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// You should have received a copy of the GNU General Public License
2929
// along with this program. If not, see <http://www.gnu.org/licenses/>.
3030

31-
package http
31+
package fortigatehttpclient
3232

3333
import (
3434
"context"

pkg/http/forti_token_client_test.go renamed to pkg/fortigatehttpclient/forti_token_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// You should have received a copy of the GNU General Public License
2929
// along with this program. If not, see <http://www.gnu.org/licenses/>.
3030

31-
package http
31+
package fortigatehttpclient
3232

3333
import (
3434
"context"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
package http
14+
package fortigatehttpclient
1515

1616
import (
1717
"context"

pkg/probe/bgp_neighbor_routes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/prometheus/client_golang/prometheus"
2121

2222
"github.com/prometheus-community/fortigate_exporter/internal/config"
23-
"github.com/prometheus-community/fortigate_exporter/pkg/http"
23+
"github.com/prometheus-community/fortigate_exporter/pkg/fortigatehttpclient"
2424
)
2525

2626
type BGPPath struct {
@@ -39,7 +39,7 @@ type PathCount struct {
3939
VDOM string
4040
}
4141

42-
func probeBGPNeighborPathsIPv4(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
42+
func probeBGPNeighborPathsIPv4(c fortigatehttpclient.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
4343
savedConfig := config.GetConfig()
4444
MaxBGPPaths := savedConfig.MaxBGPPaths
4545

@@ -107,7 +107,7 @@ func probeBGPNeighborPathsIPv4(c http.FortiHTTP, meta *TargetMetadata) ([]promet
107107
return m, true
108108
}
109109

110-
func probeBGPNeighborPathsIPv6(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
110+
func probeBGPNeighborPathsIPv6(c fortigatehttpclient.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
111111
savedConfig := config.GetConfig()
112112
MaxBGPPaths := savedConfig.MaxBGPPaths
113113

pkg/probe/bgp_neighbors.go

Lines changed: 126 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ import (
1919

2020
"github.com/prometheus/client_golang/prometheus"
2121

22-
"github.com/prometheus-community/fortigate_exporter/pkg/http"
22+
"github.com/prometheus-community/fortigate_exporter/pkg/fortigatehttpclient"
2323
)
2424

25-
type BGPNeighbor struct {
25+
type BGPNeighbor7_4 struct {
2626
NeighborIP string `json:"neighbor_ip"`
2727
LocalIP string `json:"local_ip"`
2828
RemoteAS int `json:"remote_as"`
2929
AdminStatus bool `json:"admin_status"`
3030
State string `json:"state"`
3131
}
3232

33-
type BGPNeighborResponse struct {
34-
Results []BGPNeighbor `json:"results"`
35-
VDOM string `json:"vdom"`
36-
Version string `json:"version"`
33+
type BGPNeighborResponse7_4 struct {
34+
Results []BGPNeighbor7_4 `json:"results"`
35+
VDOM string `json:"vdom"`
36+
Version string `json:"version"`
3737
}
3838

39-
func probeBGPNeighborsIPv4(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
39+
func probeBGPNeighborsIPv47_4(c fortigatehttpclient.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
4040
if meta.VersionMajor < 7 {
4141
// not supported version. Before 7.0.0 the requested endpoint doesn't exist
4242
return nil, true
@@ -47,7 +47,7 @@ func probeBGPNeighborsIPv4(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
4747
[]string{"vdom", "remote_as", "state", "admin_status", "local_ip", "neighbor_ip"}, nil,
4848
)
4949

50-
var rs []BGPNeighborResponse
50+
var rs []BGPNeighborResponse7_4
5151

5252
if err := c.Get("api/v2/monitor/router/bgp/neighbors", "vdom=*", &rs); err != nil {
5353
log.Printf("Error: %v", err)
@@ -65,7 +65,7 @@ func probeBGPNeighborsIPv4(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
6565
return m, true
6666
}
6767

68-
func probeBGPNeighborsIPv6(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
68+
func probeBGPNeighborsIPv67_4(c fortigatehttpclient.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
6969
if meta.VersionMajor < 7 {
7070
// not supported version. Before 7.0.0 the requested endpoint doesn't exist
7171
return nil, true
@@ -77,7 +77,7 @@ func probeBGPNeighborsIPv6(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
7777
[]string{"vdom", "remote_as", "state", "admin_status", "local_ip", "neighbor_ip"}, nil,
7878
)
7979

80-
var rs []BGPNeighborResponse
80+
var rs []BGPNeighborResponse7_4
8181

8282
if err := c.Get("api/v2/monitor/router/bgp/neighbors6", "vdom=*", &rs); err != nil {
8383
log.Printf("Error: %v", err)
@@ -113,3 +113,119 @@ func bgpStateToNumber(bgpState string) float64 {
113113
return 0
114114
}
115115
}
116+
117+
type BGPNeighbor struct {
118+
NeighborIP string `json:"neighbor_ip"`
119+
LocalIP string `json:"local_ip"`
120+
RemoteAS string `json:"remote_as"`
121+
AdminStatus bool `json:"admin_status"`
122+
State string `json:"state"`
123+
}
124+
125+
type BGPNeighborResponse struct {
126+
Results []BGPNeighbor `json:"results"`
127+
VDOM string `json:"vdom"`
128+
Version string `json:"version"`
129+
}
130+
131+
func probeBGPNeighborsIPv4(c fortigatehttpclient.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
132+
if meta.VersionMajor == 7 && meta.VersionMinor < 6 {
133+
return probeBGPNeighborsIPv47_4(c, meta)
134+
}
135+
136+
mBGPNeighborState := prometheus.NewDesc(
137+
"fortigate_bgp_neighbor_ipv4_state",
138+
"Configured bgp neighbor over ipv4 state",
139+
[]string{"vdom", "remote_as", "admin_status", "local_ip", "neighbor_ip", "state"}, nil,
140+
)
141+
142+
var rs []BGPNeighborResponse
143+
144+
if err := c.Get("api/v2/monitor/router/bgp/neighbors", "vdom=*", &rs); err != nil {
145+
log.Printf("Error: %v", err)
146+
return nil, false
147+
}
148+
149+
m := []prometheus.Metric{}
150+
151+
for _, r := range rs {
152+
for _, peer := range r.Results {
153+
t := []prometheus.Metric{
154+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Idle"),
155+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Connect"),
156+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Active"),
157+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Open sent"),
158+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Open confirm"),
159+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Established"),
160+
}
161+
switch peer.State {
162+
case "Idle":
163+
t[0] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
164+
case "Connect":
165+
t[1] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
166+
case "Active":
167+
t[2] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
168+
case "Open sent":
169+
t[3] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
170+
case "Open confirm":
171+
t[4] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
172+
case "Established":
173+
t[5] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
174+
}
175+
m = append(m, t...)
176+
}
177+
}
178+
179+
return m, true
180+
}
181+
182+
func probeBGPNeighborsIPv6(c fortigatehttpclient.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
183+
if meta.VersionMajor == 7 && meta.VersionMinor < 6 {
184+
return probeBGPNeighborsIPv67_4(c, meta)
185+
}
186+
187+
mBGPNeighborState := prometheus.NewDesc(
188+
"fortigate_bgp_neighbor_ipv6_state",
189+
"Configured bgp neighbor over ipv6 state",
190+
[]string{"vdom", "remote_as", "admin_status", "local_ip", "neighbor_ip", "state"}, nil,
191+
)
192+
193+
var rs []BGPNeighborResponse
194+
195+
if err := c.Get("api/v2/monitor/router/bgp/neighbors6", "vdom=*", &rs); err != nil {
196+
log.Printf("Error: %v", err)
197+
return nil, false
198+
}
199+
200+
m := []prometheus.Metric{}
201+
202+
for _, r := range rs {
203+
for _, peer := range r.Results {
204+
t := []prometheus.Metric{
205+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Idle"),
206+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Connect"),
207+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Active"),
208+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Open sent"),
209+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Open confirm"),
210+
prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 0.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, "Established"),
211+
}
212+
switch peer.State {
213+
case "Idle":
214+
t[0] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
215+
case "Connect":
216+
t[1] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
217+
case "Active":
218+
t[2] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
219+
case "Open sent":
220+
t[3] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
221+
case "Open confirm":
222+
t[4] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
223+
case "Established":
224+
t[5] = prometheus.MustNewConstMetric(mBGPNeighborState, prometheus.GaugeValue, 1.0, r.VDOM, peer.RemoteAS, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP, peer.State)
225+
}
226+
m = append(m, t...)
227+
}
228+
}
229+
230+
return m, true
231+
}

0 commit comments

Comments
 (0)