diff --git a/main.go b/main.go index 9d0c02e..ecb768b 100644 --- a/main.go +++ b/main.go @@ -72,6 +72,7 @@ func getHandler(relPath string, w http.ResponseWriter, r *http.Request) { // Try to get monitor.log file logData, err := os.ReadFile(logFilePath) + var latestLine []byte if err != nil { logData = []byte("No log file found") } else { @@ -79,18 +80,18 @@ func getHandler(relPath string, w http.ResponseWriter, r *http.Request) { lines := bytes.Split(logData, []byte("\n")) var newLines [][]byte for i := len(lines) - 1; i >= 0; i-- { - if !bytes.Contains(lines[i], []byte("Test")) { + if !bytes.Contains(lines[i], []byte("Latest Check")) { newLines = append(newLines, lines[i]) } } // Add latest test line (excluding the last line which is empty) - newLines = append(newLines, lines[len(lines)-2]) + latestLine = lines[len(lines)-2] logData = bytes.Join(newLines, []byte("\n")) } // Create a map to hold the data - requestData := map[string]interface{}{"envMessage": message, "logContent": string(logData)} + requestData := map[string]interface{}{"envMessage": message, "logContent": string(logData), "latestLine": string(latestLine)} // Execute the template err = tmpl.Execute(w, requestData) diff --git a/monitor.log b/monitor.log index 8b13789..649e164 100644 --- a/monitor.log +++ b/monitor.log @@ -1 +1,10 @@ +Sat 22 Jun 2024 19:18:41 AEST - Latest Check +Sat 22 Jun 2024 19:18:53 AEST - Latest Check +Sat 22 Jun 2024 19:19:06 AEST - Latest Check +Sat 22 Jun 2024 19:19:17 AEST - Latest Check +Sat 22 Jun 2024 19:19:28 AEST - Latest Check +Sat 22 Jun 2024 19:19:40 AEST - Latest Check +Sat 22 Jun 2024 19:19:56 AEST - Latest Check +Latest Check: Sat 22 Jun 2024 19:20:09 AEST +Latest Check: Sat 22 Jun 2024 19:20:20 AEST diff --git a/templates/index.html b/templates/index.html index b91ed4f..c2b48da 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,6 +9,10 @@

HNSDoH Node Status

+ {{ if .latestLine}} +

{{ .latestLine}}

+ {{end}} + {{ if .logContent}}

Log Output

{{.logContent}}
diff --git a/test.sh b/test.sh index 98b23bb..46a7340 100755 --- a/test.sh +++ b/test.sh @@ -33,7 +33,7 @@ check_dig() { } # Save test time -echo "$(date) - Test" >> monitor.log +echo "Latest Check: $(date)" >> monitor.log # Loop over each IP and run the dig commands