-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
57 lines (44 loc) · 1.54 KB
/
main.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
package main
import (
"net/http"
"time"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/prometheus-exporter/api"
"github.com/kubescape/prometheus-exporter/metrics"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
storageClient := api.NewStorageClient()
// Start Prometheus HTTP server
go func() {
http.Handle("/metrics", promhttp.Handler())
logger.L().Info("prometheus metrics server started", helpers.Int("port", 8080), helpers.String("path", "/metrics"))
logger.L().Fatal(http.ListenAndServe(":8080", nil).Error())
}()
// monitor the severities in objects
for {
handleConfigScanSummaries(storageClient)
handleVulnScanSummaries(storageClient)
// FIXME: get interval from config/env
time.Sleep(120 * time.Second)
}
}
func handleConfigScanSummaries(storageClient *api.StorageClientImpl) {
configScanSummaries, err := storageClient.GetConfigScanSummaries()
if err != nil {
logger.L().Warning("failed getting configuration scan summaries", helpers.Error(err))
return
}
metrics.ProcessConfigscanClusterMetrics(configScanSummaries)
metrics.ProcessConfigscanNamespaceMetrics(configScanSummaries)
}
func handleVulnScanSummaries(storageClient *api.StorageClientImpl) {
vulnScanSummaries, err := storageClient.GetVulnerabilitySummaries()
if err != nil {
logger.L().Warning("failed getting vulnerability scan summaries", helpers.Error(err))
return
}
metrics.ProcessVulnNamespaceMetrics(vulnScanSummaries)
metrics.ProcessVulnClusterMetrics(vulnScanSummaries)
}