|
| 1 | +package probe |
| 2 | + |
| 3 | +import ( |
| 4 | + "log" |
| 5 | + |
| 6 | + "github.com/bluecmd/fortigate_exporter/pkg/http" |
| 7 | + "github.com/prometheus/client_golang/prometheus" |
| 8 | +) |
| 9 | + |
| 10 | +type IpPool struct { |
| 11 | + Name string `json:"name"` |
| 12 | + IPTotal int `json:"natip_total"` |
| 13 | + IPInUse int `json:"natip_in_use"` |
| 14 | + Clients int `json:"clients"` |
| 15 | + Available float64 `json:"available"` |
| 16 | + Used int `json:"used"` |
| 17 | + Total int `json:"total"` |
| 18 | +} |
| 19 | + |
| 20 | +type IpPoolResponse struct { |
| 21 | + Results map[string]IpPool `json:"results"` |
| 22 | + VDOM string `json:"vdom"` |
| 23 | + Version string `json:"version"` |
| 24 | +} |
| 25 | + |
| 26 | +func probeFirewallIpPool(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { |
| 27 | + var ( |
| 28 | + mAvailable = prometheus.NewDesc( |
| 29 | + "fortigate_ippool_available_ratio", |
| 30 | + "Percentage available in ippool (0 - 1.0)", |
| 31 | + []string{"vdom", "name"}, nil, |
| 32 | + ) |
| 33 | + ) |
| 34 | + var ( |
| 35 | + mIpUsed = prometheus.NewDesc( |
| 36 | + "fortigate_ippool_used_ips", |
| 37 | + "Ip addresses in use in ippool", |
| 38 | + []string{"vdom", "name"}, nil, |
| 39 | + ) |
| 40 | + ) |
| 41 | + var ( |
| 42 | + mIpTotal = prometheus.NewDesc( |
| 43 | + "fortigate_ippool_total_ips", |
| 44 | + "Ip addresses total in ippool", |
| 45 | + []string{"vdom", "name"}, nil, |
| 46 | + ) |
| 47 | + ) |
| 48 | + var ( |
| 49 | + mClients = prometheus.NewDesc( |
| 50 | + "fortigate_ippool_clients", |
| 51 | + "Amount of clients using ippool", |
| 52 | + []string{"vdom", "name"}, nil, |
| 53 | + ) |
| 54 | + ) |
| 55 | + var ( |
| 56 | + mUsed = prometheus.NewDesc( |
| 57 | + "fortigate_ippool_used_items", |
| 58 | + "Amount of items used in ippool", |
| 59 | + []string{"vdom", "name"}, nil, |
| 60 | + ) |
| 61 | + ) |
| 62 | + var ( |
| 63 | + mTotal = prometheus.NewDesc( |
| 64 | + "fortigate_ippool_total_items", |
| 65 | + "Amount of items total in ippool", |
| 66 | + []string{"vdom", "name"}, nil, |
| 67 | + ) |
| 68 | + ) |
| 69 | + |
| 70 | + var rs []IpPoolResponse |
| 71 | + |
| 72 | + if err := c.Get("api/v2/monitor/firewall/ippool", "vdom=*", &rs); err != nil { |
| 73 | + log.Printf("Error: %v", err) |
| 74 | + return nil, false |
| 75 | + } |
| 76 | + |
| 77 | + m := []prometheus.Metric{} |
| 78 | + |
| 79 | + for _, r := range rs { |
| 80 | + for _, ippool := range r.Results { |
| 81 | + m = append(m, prometheus.MustNewConstMetric(mAvailable, prometheus.GaugeValue, ippool.Available/100, r.VDOM, ippool.Name)) |
| 82 | + m = append(m, prometheus.MustNewConstMetric(mIpUsed, prometheus.GaugeValue, float64(ippool.IPInUse), r.VDOM, ippool.Name)) |
| 83 | + m = append(m, prometheus.MustNewConstMetric(mIpTotal, prometheus.GaugeValue, float64(ippool.IPTotal), r.VDOM, ippool.Name)) |
| 84 | + m = append(m, prometheus.MustNewConstMetric(mClients, prometheus.GaugeValue, float64(ippool.Clients), r.VDOM, ippool.Name)) |
| 85 | + m = append(m, prometheus.MustNewConstMetric(mUsed, prometheus.GaugeValue, float64(ippool.Used), r.VDOM, ippool.Name)) |
| 86 | + m = append(m, prometheus.MustNewConstMetric(mTotal, prometheus.GaugeValue, float64(ippool.Total), r.VDOM, ippool.Name)) |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + return m, true |
| 91 | +} |
0 commit comments