Skip to content
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ Supported metrics right now as follows.
Global:

* _System/SensorInfo_
* `fortigate_sensor_alarm_status`
* `fortigate_sensor_fan_rpm`
* `fortigate_sensor_temperature_celsius`
* `fortigate_sensor_voltage_volts`
* `fortigate_sensor_thresholds`
* _System/Status_
* `fortigate_version_info`
* _System/Time/Clock_
Expand Down
2 changes: 1 addition & 1 deletion pkg/probe/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (p *testProbeCollector) Describe(c chan<- *prometheus.Desc) {
func testProbe(pf probeFunc, c http.FortiHTTP, r Registry) bool {
meta := &TargetMetadata{
VersionMajor: 7,
VersionMinor: 0,
VersionMinor: 4,
}
return testProbeWithMetadata(pf, c, meta, r)
}
Expand Down
57 changes: 47 additions & 10 deletions pkg/probe/system_sensor_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,12 @@ package probe

import (
"log"
"reflect"

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

type SystemSensorInfoResults struct {
Name string `json:"name"`
Type string `json:"type"`
Value float64 `json:"value"`
}

type SystemSensorInfo struct {
Results []SystemSensorInfoResults `json:"results"`
}

func probeSystemSensorInfo(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
var (
sensorTemperature = prometheus.NewDesc(
Expand All @@ -47,8 +38,39 @@ func probeSystemSensorInfo(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
"Sensor voltage in volts",
[]string{"name"}, nil,
)
sensorAlarm = prometheus.NewDesc(
"fortigate_sensor_alarm_status",
"Sensor alarm status",
[]string{"name"}, nil,
)
sensorThresholds = prometheus.NewDesc(
"fortigate_sensor_thresholds",
"Sensor threasholds",
[]string{"name", "threshold"}, nil,
)
)

type SystemSensorInfoResultsThresholds struct {
LowerNonRec float64 `json:"lower_non_recoverable,omitempty"`
LowerCrit float64 `json:"lower_critical,omitempty"`
LowerNonCrit float64 `json:"lower_non_critical,omitempty"`
UpperNonCrit float64 `json:"upper_non_critical,omitempty"`
UpperCrit float64 `json:"upper_critical,omitempty"`
UpperNonRec float64 `json:"upper_non_recoverable,omitempty"`
}

type SystemSensorInfoResults struct {
Name string `json:"name"`
Type string `json:"type"`
Value float64 `json:"value"`
Alarm bool `json:"alarm"`
Thresholds SystemSensorInfoResultsThresholds `json:"thresholds"`
}

type SystemSensorInfo struct {
Results []SystemSensorInfoResults `json:"results"`
}

var res SystemSensorInfo
if err := c.Get("api/v2/monitor/system/sensor-info", "vdom=root", &res); err != nil {
log.Printf("Warning: %v", err)
Expand All @@ -57,6 +79,21 @@ func probeSystemSensorInfo(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus

m := []prometheus.Metric{}
for _, r := range res.Results {
switch meta.VersionMajor {
case 7:
alarm := 0.0
if r.Alarm {
alarm = 1.0
}
m = append(m, prometheus.MustNewConstMetric(sensorAlarm, prometheus.GaugeValue, alarm, r.Name))
v := reflect.ValueOf(r.Thresholds)

for i := range v.NumField() {
if v.Field(i).Float() != 0 {
m = append(m, prometheus.MustNewConstMetric(sensorThresholds, prometheus.GaugeValue, v.Field(i).Float(), r.Name, v.Type().Field(i).Name))
}
}
}
switch r.Type {
case "temperature":
m = append(m, prometheus.MustNewConstMetric(sensorTemperature, prometheus.GaugeValue, r.Value, r.Name))
Expand Down
Loading
Loading