-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (67 loc) · 2 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/yrs147/kubescape-exporter/api"
"github.com/yrs147/kubescape-exporter/collect"
"github.com/yrs147/kubescape-exporter/metrics"
)
func main() {
kubeconfig := flag.String("kubeconfig", "KUBECONFIG", "location of kubeconfig")
flag.Parse()
// Start Prometheus HTTP server
go func() {
http.Handle("/metrics", promhttp.Handler())
fmt.Println("Prometheus metrics server started on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}()
//To Monitor the severities in objects
for {
ns, err := api.GetConfigScanSummary(*kubeconfig)
if err != nil {
log.Fatalf("Error parsing YAML file: %v", err)
}
nssummary, err := collect.GetConfigscanSeverityValues(ns)
if err != nil {
fmt.Println("Error parsing YAML file: ", err)
os.Exit(1)
}
cluster, err := api.GetConfigScanSummary(*kubeconfig)
if err != nil {
log.Fatalf("Error parsing YAML file : %v", err)
}
clustersummary, err := collect.GetConfigscanSeverityValues(cluster)
if err != nil {
fmt.Println("Error parsing YAML file: ", err)
os.Exit(1)
}
vulnns, err := api.GetVulnerabilitySummary(*kubeconfig)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting CRD as YAML: %v\n", err)
os.Exit(1)
}
vulnnssummary, err := collect.GetVulnerabilitySeverityValues(vulnns)
if err != nil {
fmt.Println("Error parsing YAML : ", err)
os.Exit(1)
}
vulnclus, err := api.GetVulnerabilitySummary(*kubeconfig)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting CRD as YAML: %v\n", err)
os.Exit(1)
}
vulnclustersummary, err := collect.GetVulnerabilitySeverityValues(vulnclus)
if err != nil {
fmt.Println("Error parsing YAML : ", err)
os.Exit(1)
}
metrics.ProcessVulnNamespaceMetrics(vulnnssummary)
metrics.ProcessVulnClusterMetrics(vulnclustersummary)
metrics.ProcessConfigscanClusterMetrics(clustersummary)
metrics.ProcessConfigscanNamespaceMetrics(nssummary)
}
}