-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathvpn_ipsec.go
More file actions
67 lines (62 loc) · 1.98 KB
/
Copy pathvpn_ipsec.go
File metadata and controls
67 lines (62 loc) · 1.98 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
package probe
import (
"log"
"strconv"
"github.com/bluecmd/fortigate_exporter/pkg/http"
"github.com/prometheus/client_golang/prometheus"
)
func probeVPNIPSec(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
var (
status = prometheus.NewDesc(
"fortigate_ipsec_tunnel_up",
"Status of IPsec tunnel",
[]string{"vdom", "name", "p2serial", "parent"}, nil,
)
transmitted = prometheus.NewDesc(
"fortigate_ipsec_tunnel_transmit_bytes_total",
"Total number of bytes transmitted over the IPsec tunnel",
[]string{"vdom", "name", "p2serial", "parent"}, nil,
)
received = prometheus.NewDesc(
"fortigate_ipsec_tunnel_receive_bytes_total",
"Total number of bytes received over the IPsec tunnel",
[]string{"vdom", "name", "p2serial", "parent"}, nil,
)
)
type proxyid struct {
Name string `json:"p2name"`
P2serial int `json:"p2serial"`
Status string `json:"status"`
Incoming float64 `json:"incoming_bytes"`
Outgoing float64 `json:"outgoing_bytes"`
}
type tunnel struct {
Name string `json:"name"`
Type string `json:"type"`
ProxyID []proxyid `json:"proxyid"`
}
type ipsecResult struct {
Results []tunnel `json:"results"`
VDOM string
}
var res []ipsecResult
if err := c.Get("api/v2/monitor/vpn/ipsec", "vdom=*", &res); err != nil {
log.Printf("Error: %v", err)
return nil, false
}
m := []prometheus.Metric{}
for _, v := range res {
for _, i := range v.Results {
for _, t := range i.ProxyID {
s := 0.0
if t.Status == "up" {
s = 1.0
}
m = append(m, prometheus.MustNewConstMetric(status, prometheus.GaugeValue, s, v.VDOM, t.Name, strconv.Itoa(t.P2serial), i.Name))
m = append(m, prometheus.MustNewConstMetric(transmitted, prometheus.CounterValue, t.Outgoing, v.VDOM, t.Name, strconv.Itoa(t.P2serial), i.Name))
m = append(m, prometheus.MustNewConstMetric(received, prometheus.CounterValue, t.Incoming, v.VDOM, t.Name, strconv.Itoa(t.P2serial), i.Name))
}
}
}
return m, true
}