diff --git a/config.yml b/config.yml index fd4f1cc..ffc8a9a 100644 --- a/config.yml +++ b/config.yml @@ -8,15 +8,19 @@ auth: checks: hdd: + enabled: true max_percent: 80 load: + enabled: true max_load_1: 10 max_load_5: 8 max_load_15: 5 memory: + enabled: true max: 100 max_swap: 80 systemd: + enabled: true services: - sshd - test diff --git a/internal/pkg/checks/hdd.go b/internal/pkg/checks/hdd.go index 32f3b33..662cfd5 100644 --- a/internal/pkg/checks/hdd.go +++ b/internal/pkg/checks/hdd.go @@ -6,6 +6,7 @@ import ( type HDDConfig struct { MaxPercent int `yaml:"max_percent"` + Enabled bool `yaml:"enabled"` } type HDD struct { @@ -13,6 +14,9 @@ type HDD struct { } func (h HDD) Execute() (ok bool, data interface{}, err error) { + if h.Config.Enabled == false { + return true, nil, nil + } success := true parts, _ := disk.Partitions(false) usage := make(map[string]float64) diff --git a/internal/pkg/checks/load.go b/internal/pkg/checks/load.go index 19e12ea..b1c246f 100644 --- a/internal/pkg/checks/load.go +++ b/internal/pkg/checks/load.go @@ -8,6 +8,7 @@ type LoadConfig struct { MaxLoad1 float64 `yaml:"max_load_1"` MaxLoad5 float64 `yaml:"max_load_5"` MaxLoad15 float64 `yaml:"max_load_15"` + Enabled bool `yaml:"enabled"` } type Load struct { @@ -15,6 +16,9 @@ type Load struct { } func (h Load) Execute() (ok bool, data interface{}, err error) { + if h.Config.Enabled == false { + return true, nil, nil + } load, err := loadavg.Get() if load.Loadavg1 > h.Config.MaxLoad1 { return false,load, nil diff --git a/internal/pkg/checks/memory.go b/internal/pkg/checks/memory.go index 7ad9b37..d7e3218 100644 --- a/internal/pkg/checks/memory.go +++ b/internal/pkg/checks/memory.go @@ -8,6 +8,7 @@ import ( type MemoryConfig struct { Max float64 `yaml:"max"` MaxSwap float64 `yaml:"max_swap"` + Enabled bool `yaml:"enabled"` } type Memory struct { @@ -15,6 +16,9 @@ type Memory struct { } func (h Memory) Execute() (ok bool, data interface{}, err error) { + if h.Config.Enabled == false { + return true, nil, nil + } memory, err := memory.Get() fmt.Println(memory) p := float64(100) / float64(memory.Total) * float64(memory.Used) diff --git a/internal/pkg/checks/systemd.go b/internal/pkg/checks/systemd.go index 4b0c309..329ce23 100644 --- a/internal/pkg/checks/systemd.go +++ b/internal/pkg/checks/systemd.go @@ -8,6 +8,7 @@ import ( type SystemdConf struct { Services []string `yaml:"services"` + Enabled bool `yaml:"enabled"` } type Systemd struct { @@ -15,6 +16,9 @@ type Systemd struct { } func (h Systemd) Execute() (ok bool, data interface{}, err error) { + if h.Config.Enabled == false { + return true, nil, nil + } success := true servicelist := make(map[string]bool) diff --git a/main.go b/main.go index 4860999..2913087 100644 --- a/main.go +++ b/main.go @@ -100,6 +100,7 @@ func checkSystem() (map[string]ResultReturn, bool) { globaleResult := true wg := sync.WaitGroup{} res := make(map[string]ResultReturn) + mutex := sync.Mutex{} for _, c := range checkList { wg.Add(1) go func(check checks.Check) { @@ -113,10 +114,12 @@ func checkSystem() (map[string]ResultReturn, bool) { if s == false { globaleResult = false } + mutex.Lock() res[check.Name()] = ResultReturn{ Success: s, Data: data, } + mutex.Unlock() }(c) } wg.Wait() diff --git a/template/index.html b/template/index.html index cdbfcb8..f00d028 100644 --- a/template/index.html +++ b/template/index.html @@ -45,6 +45,7 @@
+ {{ if .checks.MemoryUsage.Data }} @@ -63,7 +64,7 @@
Ram
- + {{ end }}
@@ -76,6 +77,7 @@
+ {{ if .checks.SystemLoad.Data }} @@ -90,6 +92,7 @@
1{{ .checks.SystemLoad.Data.Loadavg15 }}
+ {{ end }}