diff --git a/config.go b/config.go index 4f24303..75f15c1 100644 --- a/config.go +++ b/config.go @@ -24,6 +24,7 @@ type Config struct { Load checks.LoadConfig `yaml:"load"` Memory checks.MemoryConfig `yaml:"memory"` Systemd checks.SystemdConf `yaml:"systemd"` + Version checks.VersionConfig `yaml:"version"` } `yaml:"checks"` } @@ -43,4 +44,6 @@ func readConfig() { if err != nil { log.Fatal().Err(err).Msg("Cant parse yaml file") } + + c.Checks.Version.Version = version } \ No newline at end of file diff --git a/config.yml b/config.yml index ffc8a9a..e783ca9 100644 --- a/config.yml +++ b/config.yml @@ -25,3 +25,5 @@ checks: - sshd - test - docker + version: + enabled: true diff --git a/internal/pkg/checks/version.go b/internal/pkg/checks/version.go new file mode 100644 index 0000000..8204c38 --- /dev/null +++ b/internal/pkg/checks/version.go @@ -0,0 +1,44 @@ +package checks + +import ( + "encoding/json" + "fmt" + "io" + "net/http" +) + +type VersionConfig struct { + Enabled bool `yaml:"enabled"` + Version string +} + +type Version struct { + Config VersionConfig +} + +func (h Version) Execute() (ok bool, data interface{}, err error) { + if h.Config.Enabled == false { + return true, nil, nil + } + resp, err := http.Get("https://git.keks.cloud/api/v1/repos/kekskurse/http-server-status/releases?limit=1") + + var g []struct { + TagName string `json:"tag_name"` + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + return false, nil, err + } + + json.Unmarshal(body, &g) + + if g[0].TagName == fmt.Sprintf("v%v", h.Config.Version) { + return true, map[string]string{"version": g[0].TagName}, nil + } + return false, map[string]string{"version": g[0].TagName}, nil +} + +func (h Version) Name() string { + return "Version" +} \ No newline at end of file diff --git a/main.go b/main.go index 2913087..4d407cf 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ var checkList []checks.Check func init() { readConfig() log.Debug().Int("max_percent", c.Checks.HDD.MaxPercent).Msg("HDD CHECK") - checkList = append(checkList, checks.HDD{c.Checks.HDD}, checks.Memory{Config: c.Checks.Memory}, checks.Load{Config: c.Checks.Load}, checks.Systemd{Config: c.Checks.Systemd}) + checkList = append(checkList, checks.HDD{c.Checks.HDD}, checks.Memory{Config: c.Checks.Memory}, checks.Load{Config: c.Checks.Load}, checks.Systemd{Config: c.Checks.Systemd}, checks.Version{Config: c.Checks.Version}) } func auth(fn http.HandlerFunc) http.HandlerFunc { diff --git a/template/index.html b/template/index.html index f00d028..0cc8201 100644 --- a/template/index.html +++ b/template/index.html @@ -116,7 +116,24 @@ +
+
+
+
+ Version + +
+
+ Newest Version: {{ .checks.Version.Data.version }} +
+
+
+
+
+
+ +