Versions Check
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Kekskurse 2021-11-29 07:31:30 +01:00
parent 2199301dc7
commit 07cd22131f
Signed by: kekskurse
GPG Key ID: 728ACCB59341E7E4
5 changed files with 67 additions and 1 deletions

View File

@ -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
}

View File

@ -25,3 +25,5 @@ checks:
- sshd
- test
- docker
version:
enabled: true

View File

@ -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"
}

View File

@ -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 {

View File

@ -116,7 +116,24 @@
</div>
</div>
</div>
<div class="row" style="margin-top: 20px;">
<div class="col-md-6">
<div class="card">
<div class="card-header {{if .checks.Version.Success }}bg-success{{else}}bg-danger{{end}}" id="loadtitle">
Version
</div>
<div class="card-body">
Newest Version: {{ .checks.Version.Data.version }}
</div>
</div>
</div>
<div class="col-md-6">
</div>
</div>
</div>
</div>
<div class="container">