-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollector.go
75 lines (65 loc) · 1.94 KB
/
collector.go
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
package main
import (
"log"
"time"
"github.com/prometheus/client_golang/prometheus"
)
const PROMETHEUS_NAMESPACE = "vuls"
type vulsCollector struct {
cveContents *prometheus.Desc
resultLastScanned *prometheus.Desc
}
func newVulsCollector() *vulsCollector {
return &vulsCollector{
cveContents: prometheus.NewDesc(
prometheus.BuildFQName(PROMETHEUS_NAMESPACE, "cve", "contents"),
"Aggregated Findings from CVE Contents exported by Vuls",
[]string{"database", "severity", "serverName", "state"}, nil,
),
resultLastScanned: prometheus.NewDesc(
prometheus.BuildFQName(PROMETHEUS_NAMESPACE, "server", "last_scanned"),
"Gauge to provide a timestamp on the server results Last Scanned by Vuls",
[]string{"serverName"}, nil,
),
}
}
func (collector *vulsCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- collector.cveContents
ch <- collector.resultLastScanned
}
func (collector *vulsCollector) Collect(ch chan<- prometheus.Metric) {
vulsResults := parseResults()
for server, results := range vulsResults {
timestamp, _ := time.Parse(time.RFC3339Nano, results.ScannedAt)
ch <- prometheus.MustNewConstMetric(
collector.resultLastScanned,
prometheus.GaugeValue,
float64(timestamp.Unix()),
server,
)
databaseSeverities := results.aggregateSeverities()
for database, severities := range databaseSeverities {
_, none := severities["none"]
if len(severities) == 1 && none {
if flagVerbose {
log.Printf("[TRACE] no severities found for %s - skipping.", database)
}
continue
}
for severity, findings := range severities {
ch <- prometheus.MustNewConstMetric(
collector.cveContents,
prometheus.GaugeValue,
float64(findings.FixedCVEs),
database, severity, server, "fixed",
)
ch <- prometheus.MustNewConstMetric(
collector.cveContents,
prometheus.GaugeValue,
float64(findings.OpenCVEs),
database, severity, server, "not_fixed",
)
}
}
}
}