Skip to content

Commit 31d00d9

Browse files
PhilldomdSuperQ
andauthored
Feature/sensor info 7.4 (#331)
* Added Alarm status and thresholds, version lift Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> * Updated README Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> * No reason for structs to be public Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> --------- Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> Co-authored-by: Ben Kochie <superq@gmail.com>
1 parent ecb0a44 commit 31d00d9

5 files changed

Lines changed: 395 additions & 17 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ Supported metrics right now as follows.
3838
Global:
3939

4040
* _System/SensorInfo_
41+
* `fortigate_sensor_alarm_status`
4142
* `fortigate_sensor_fan_rpm`
4243
* `fortigate_sensor_temperature_celsius`
4344
* `fortigate_sensor_voltage_volts`
45+
* `fortigate_sensor_thresholds`
4446
* _System/Status_
4547
* `fortigate_version_info`
4648
* _System/Time/Clock_

pkg/probe/probe_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (p *testProbeCollector) Describe(c chan<- *prometheus.Desc) {
107107
func testProbe(pf probeFunc, c http.FortiHTTP, r Registry) bool {
108108
meta := &TargetMetadata{
109109
VersionMajor: 7,
110-
VersionMinor: 0,
110+
VersionMinor: 4,
111111
}
112112
return testProbeWithMetadata(pf, c, meta, r)
113113
}

pkg/probe/system_sensor_info.go

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,12 @@ package probe
1515

1616
import (
1717
"log"
18+
"reflect"
1819

1920
"github.com/prometheus-community/fortigate_exporter/pkg/http"
2021
"github.com/prometheus/client_golang/prometheus"
2122
)
2223

23-
type SystemSensorInfoResults struct {
24-
Name string `json:"name"`
25-
Type string `json:"type"`
26-
Value float64 `json:"value"`
27-
}
28-
29-
type SystemSensorInfo struct {
30-
Results []SystemSensorInfoResults `json:"results"`
31-
}
32-
3324
func probeSystemSensorInfo(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
3425
var (
3526
sensorTemperature = prometheus.NewDesc(
@@ -47,8 +38,39 @@ func probeSystemSensorInfo(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
4738
"Sensor voltage in volts",
4839
[]string{"name"}, nil,
4940
)
41+
sensorAlarm = prometheus.NewDesc(
42+
"fortigate_sensor_alarm_status",
43+
"Sensor alarm status",
44+
[]string{"name"}, nil,
45+
)
46+
sensorThresholds = prometheus.NewDesc(
47+
"fortigate_sensor_thresholds",
48+
"Sensor threasholds",
49+
[]string{"name", "threshold"}, nil,
50+
)
5051
)
5152

53+
type SystemSensorInfoResultsThresholds struct {
54+
LowerNonRec float64 `json:"lower_non_recoverable,omitempty"`
55+
LowerCrit float64 `json:"lower_critical,omitempty"`
56+
LowerNonCrit float64 `json:"lower_non_critical,omitempty"`
57+
UpperNonCrit float64 `json:"upper_non_critical,omitempty"`
58+
UpperCrit float64 `json:"upper_critical,omitempty"`
59+
UpperNonRec float64 `json:"upper_non_recoverable,omitempty"`
60+
}
61+
62+
type SystemSensorInfoResults struct {
63+
Name string `json:"name"`
64+
Type string `json:"type"`
65+
Value float64 `json:"value"`
66+
Alarm bool `json:"alarm"`
67+
Thresholds SystemSensorInfoResultsThresholds `json:"thresholds"`
68+
}
69+
70+
type SystemSensorInfo struct {
71+
Results []SystemSensorInfoResults `json:"results"`
72+
}
73+
5274
var res SystemSensorInfo
5375
if err := c.Get("api/v2/monitor/system/sensor-info", "vdom=root", &res); err != nil {
5476
log.Printf("Warning: %v", err)
@@ -57,6 +79,21 @@ func probeSystemSensorInfo(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
5779

5880
m := []prometheus.Metric{}
5981
for _, r := range res.Results {
82+
switch meta.VersionMajor {
83+
case 7:
84+
alarm := 0.0
85+
if r.Alarm {
86+
alarm = 1.0
87+
}
88+
m = append(m, prometheus.MustNewConstMetric(sensorAlarm, prometheus.GaugeValue, alarm, r.Name))
89+
v := reflect.ValueOf(r.Thresholds)
90+
91+
for i := range v.NumField() {
92+
if v.Field(i).Float() != 0 {
93+
m = append(m, prometheus.MustNewConstMetric(sensorThresholds, prometheus.GaugeValue, v.Field(i).Float(), r.Name, v.Type().Field(i).Name))
94+
}
95+
}
96+
}
6097
switch r.Type {
6198
case "temperature":
6299
m = append(m, prometheus.MustNewConstMetric(sensorTemperature, prometheus.GaugeValue, r.Value, r.Name))

0 commit comments

Comments
 (0)