forked from prometheus-community/fortigate_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_available_certificates.go
More file actions
98 lines (85 loc) · 3.6 KB
/
Copy pathsystem_available_certificates.go
File metadata and controls
98 lines (85 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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 (
"log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/fortigate_exporter/pkg/fortigatehttpclient"
)
func probeSystemAvailableCertificates(c fortigatehttpclient.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
var (
certificateInfo = prometheus.NewDesc(
"fortigate_certificate_info",
"Info metric containing meta information about the certificate",
[]string{"name", "source", "scope", "vdom", "status", "type"}, nil,
)
certificateValidFrom = prometheus.NewDesc(
"fortigate_certificate_valid_from_seconds",
"Unix timestamp from which this certificate is valid",
[]string{"name", "source", "scope", "vdom"}, nil,
)
certificateValidTo = prometheus.NewDesc(
"fortigate_certificate_valid_to_seconds",
"Unix timestamp till which this certificate is valid",
[]string{"name", "source", "scope", "vdom"}, nil,
)
certificateCMDBReferences = prometheus.NewDesc(
"fortigate_certificate_cmdb_references",
"Number of times the certificate is referenced",
[]string{"name", "source", "scope", "vdom"}, nil,
)
)
type Results struct {
Name string `json:"name"`
Source string `json:"source"`
Type string `json:"type"`
Status string `json:"status"`
ValidFrom float64 `json:"valid_from"`
ValidTo float64 `json:"valid_to"`
QRef float64 `json:"q_ref"`
}
type Response struct {
Results []Results `json:"results"`
VDOM string `json:"vdom"`
Status string `json:"status"`
Scope string
}
var globalResponse Response
if err := c.Get("api/v2/monitor/system/available-certificates", "scope=global&with_remote=1", &globalResponse); err != nil {
log.Printf("Error: %v", err)
return nil, false
}
globalResponse.Scope = "global"
var vdomResponses []Response
if err := c.Get("api/v2/monitor/system/available-certificates", "vdom=*&with_remote=1", &vdomResponses); err != nil {
log.Printf("Error: %v", err)
return nil, false
}
for i := range vdomResponses {
vdomResponses[i].Scope = "vdom"
}
// combine responses
combinedResponses := make([]Response, 0)
combinedResponses = append(combinedResponses, vdomResponses...)
combinedResponses = append(combinedResponses, globalResponse)
m := []prometheus.Metric{}
for _, response := range combinedResponses {
for _, result := range response.Results {
m = append(m, prometheus.MustNewConstMetric(certificateInfo, prometheus.GaugeValue, 1, result.Name, result.Source, response.Scope, response.VDOM, result.Status, result.Type))
m = append(m, prometheus.MustNewConstMetric(certificateValidFrom, prometheus.GaugeValue, result.ValidFrom, result.Name, result.Source, response.Scope, response.VDOM))
m = append(m, prometheus.MustNewConstMetric(certificateValidTo, prometheus.GaugeValue, result.ValidTo, result.Name, result.Source, response.Scope, response.VDOM))
m = append(m, prometheus.MustNewConstMetric(certificateCMDBReferences, prometheus.GaugeValue, result.QRef, result.Name, result.Source, response.Scope, response.VDOM))
}
}
return m, true
}