From 1558252809787e2cf7e201b15f61b869e6bfa953 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Thu, 25 Nov 2021 02:01:27 +0100 Subject: [PATCH] Remove all Javascript --- internal/pkg/checks/hdd.go | 2 +- internal/pkg/checks/load.go | 2 +- internal/pkg/checks/memory.go | 2 +- internal/pkg/checks/systemd.go | 2 +- main.go | 13 ++- template/index.html | 173 ++++++++++++--------------------- 6 files changed, 79 insertions(+), 115 deletions(-) diff --git a/internal/pkg/checks/hdd.go b/internal/pkg/checks/hdd.go index fddbb54..32f3b33 100644 --- a/internal/pkg/checks/hdd.go +++ b/internal/pkg/checks/hdd.go @@ -30,5 +30,5 @@ func (h HDD) Execute() (ok bool, data interface{}, err error) { } func (h HDD) Name() string { - return "Disc space" + return "DiscSpace" } \ No newline at end of file diff --git a/internal/pkg/checks/load.go b/internal/pkg/checks/load.go index 908ff22..19e12ea 100644 --- a/internal/pkg/checks/load.go +++ b/internal/pkg/checks/load.go @@ -32,5 +32,5 @@ func (h Load) Execute() (ok bool, data interface{}, err error) { } func (h Load) Name() string { - return "System Load" + return "SystemLoad" } \ No newline at end of file diff --git a/internal/pkg/checks/memory.go b/internal/pkg/checks/memory.go index f6cf2c1..7ad9b37 100644 --- a/internal/pkg/checks/memory.go +++ b/internal/pkg/checks/memory.go @@ -39,5 +39,5 @@ func (h Memory) Execute() (ok bool, data interface{}, err error) { } func (h Memory) Name() string { - return "Memory usage" + return "MemoryUsage" } \ No newline at end of file diff --git a/internal/pkg/checks/systemd.go b/internal/pkg/checks/systemd.go index 4b53954..4b0c309 100644 --- a/internal/pkg/checks/systemd.go +++ b/internal/pkg/checks/systemd.go @@ -33,7 +33,7 @@ func (h Systemd) Execute() (ok bool, data interface{}, err error) { } func (h Systemd) Name() string { - return "Systemd Status" + return "SystemdStatus" } func (h Systemd) getStatus(name string) (bool, error) { diff --git a/main.go b/main.go index 01898c1..334366e 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( checks "http-server-status/internal/pkg/checks" "net/http" "sync" + "text/template" ) //go:embed template/index.html @@ -23,11 +24,19 @@ func init() { func main() { http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { - _, gloableRes := checkSystem() + res, gloableRes := checkSystem() if gloableRes == false { writer.WriteHeader(http.StatusInternalServerError) } - writer.Write([]byte(s)) + + t, err := template.New("todos").Parse(s) + if err != nil { + panic(err) + } + + t.Execute(writer, map[string]interface{}{"checks":res}) + + //writer.Write([]byte(s)) }) http.HandleFunc("/data.json", handler) err := http.ListenAndServe(c.HTTP.Listen, nil) diff --git a/template/index.html b/template/index.html index 74ca228..f40431c 100644 --- a/template/index.html +++ b/template/index.html @@ -19,26 +19,54 @@
-
+
Check HDD
-

- HDD 1: -

-
25%
-
-

+ + + {{range $key, $val := .checks.DiscSpace.Data}} + + + + + {{end }} +
{{ $key }} +
+
{{ $val }}%
+
+
+ +
-
+
Check RAM +
-

Some quick example text to build on the card title and make up the bulk of the card's content.

+ + + + + + + + + +
Ram +
+
{{ .checks.MemoryUsage.Data.ram }}%
+
+
Swap +
+
{{ .checks.MemoryUsage.Data.swap }}%
+
+
+
@@ -46,121 +74,48 @@
-
+
Check Load +
-

...

+ + + + + + + + + + + + + +
1{{ .checks.SystemLoad.Data.Loadavg1 }}
5{{ .checks.SystemLoad.Data.Loadavg5 }}
15{{ .checks.SystemLoad.Data.Loadavg15 }}
-
+
Systemd Check
-

...

+ + {{range $key, $val := .checks.SystemdStatus.Data}} + + + + + {{end }} +
{{ $key }} + {{ $val }} +
- \ No newline at end of file