Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ To improve security, limit permissions to required ones only (least privilege pr
|System/AvailableCertificates | *any* |api/v2/monitor/system/available-certificates |
|System/Central-management/Status | sysgrp.cfg |api/v2/monitor/system/central-management/status|
|System/Fortimanager/Status | sysgrp.cfg |api/v2/monitor/system/fortimanager/status |
|System/Global/Location | sysgrp.cfg |api/v2/cmdb/system/global |
|System/HAStatistics | sysgrp.cfg |api/v2/monitor/system/ha-statistics<br>api/v2/cmdb/system/ha |
|System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select |
|System/Interface/Transceivers| *any* |api/v2/monitor/system/interface/transceivers |
Expand All @@ -190,19 +191,23 @@ To improve security, limit permissions to required ones only (least privilege pr
|System/Ntp/Status | netgrp.cfg |api/v2/monitor/system/ntp/status |
|System/Resource/Usage | sysgrp.cfg |api/v2/monitor/system/resource/usage |
|System/Resource/Usage/VDOM | sysgrp.cfg |api/v2/monitor/system/resource/usage |
|System/SDNConnector | sysgrp.cfg |api/v2/monitor/system/sdn-connector/status |
|System/SensorInfo | sysgrp.cfg |api/v2/monitor/system/sensor-info |
|System/Status | *any* |api/v2/monitor/system/status |
|System/Time/Clock | sysgrp.cfg |api/v2/monitor/system/time |
|System/System/VDOMResource | sysgrp.cfg |api/v2/monitor/system/vdom-resource |
|System/VDOMResource | sysgrp.cfg |api/v2/monitor/system/vdom-resource |
|System/HAChecksum | sysgrp.cfg |api/v2/monitor/system/ha-checksums |
|User/Fsso | authgrp |api/v2/monitor/user/fsso |
|VPN/IPSec | vpngrp |api/v2/monitor/vpn/ipsec |
|VPN/Ssl/Connections | vpngrp |api/v2/monitor/vpn/ssl |
|VPN/Ssl/Stats | vpngrp |api/v2/monitor/vpn/ssl/stats |
|VirtualWAN/HealthCheck | netgrp.cfg |api/v2/monitor/virtual-wan/health-check |
|WebUI/State | sysgrp.cfg |api/v2/monitor/web-ui/state |
|Wifi/APStatus | wifi |api/v2/monitor/wifi/ap_status |
|Wifi/Clients | wifi |api/v2/monitor/wifi/client |
|Wifi/ManagedAP | wifi |api/v2/monitor/wifi/managed_ap |
|Switch/ManagedSwitch | switch |api/v2/monitor/switch-controller/managed-switch|
|OSPF/Neighbors | netgrp.route-cfg |api/v2/monitor/router/ospf/neighbors |
If you omit to grant some of these permissions you will receive log messages warning about
403 errors and relevant metrics will be unavailable, but other metrics will still work.
If you do not need some probes to be run, do not grant permission for them and use `include/exclude` feature (see `Usage` section).
Expand Down
2 changes: 2 additions & 0 deletions metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Global:

* _Network/Dns/Latency_
* `fortigate_network_dns_latency_`
* _System/Global/Location_
* `fortigate_location_info`
* _System/SensorInfo_
* `fortigate_sensor_alarm_status`
* `fortigate_sensor_fan_rpm`
Expand Down
1 change: 1 addition & 0 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (p *Collector) Probe(ctx context.Context, target map[string]string, hc *htt
{"System/AvailableCertificates", probeSystemAvailableCertificates},
{"System/Central-Management/Status", probeSystemCentralManagementStatus},
{"System/Fortimanager/Status", probeSystemFortimanagerStatus},
{"System/Global/Location",probeSystemGlobalLocation},
{"System/HAStatistics", probeSystemHAStatistics},
{"System/Interface", probeSystemInterface},
{"System/Interface/Transceivers", probeSystemInterfaceTransceivers},
Expand Down
75 changes: 75 additions & 0 deletions pkg/probe/system_global_location.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package probe

import (
"encoding/json"
"log"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/fortigate_exporter/pkg/http"
)

func probeSystemGlobalLocation(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {

location := prometheus.NewDesc(
"fortigate_location_info",
"System geographic location (static metadata)",
[]string{"latitude", "longitude"},
nil,
)

type SystemGlobalLocation struct {
Latitude string `json:"gui-device-latitude"`
Longitude string `json:"gui-device-longitude"`
}

type systemGlobalLocationResponse struct {
Results json.RawMessage `json:"results"`
}

var resp systemGlobalLocationResponse

if err := c.Get("api/v2/cmdb/system/global", "vdom=root", &resp); err != nil {
log.Printf("Error: %v", err)
return nil, false
}

var loc SystemGlobalLocation

// Try object first
if err := json.Unmarshal(resp.Results, &loc); err != nil {
// Fallback to array
var arr []SystemGlobalLocation
if err := json.Unmarshal(resp.Results, &arr); err != nil || len(arr) == 0 {
return nil, true
}
loc = arr[0]
}

if loc.Latitude == "" || loc.Longitude == "" {
return nil, true
}

m := []prometheus.Metric{
prometheus.MustNewConstMetric(
location,
prometheus.GaugeValue,
1,
loc.Latitude,
loc.Longitude,
),
}
return m, true
}
41 changes: 41 additions & 0 deletions pkg/probe/system_global_location_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package probe

import (
"strings"
"testing"

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

func TestSystemGlobalLocation(t *testing.T) {
c := newFakeClient()
c.prepare("api/v2/cmdb/system/global", "testdata/system-global-location.jsonnet")
r := prometheus.NewPedanticRegistry()
if !testProbe(probeSystemGlobalLocation, c, r) {
t.Errorf("probeSystemGlobalLocation() returned non-success")
}

em := `
# HELP fortigate_location_info System geographic location (static metadata)
# TYPE fortigate_location_info gauge
fortigate_location_info{latitude="66.543508", longitude="25.8467468"} 1
`

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