feat: Add better logging
All checks were successful
Build Docker / BuildSite (push) Successful in 1m24s

This commit is contained in:
Nathan Woodburn 2024-06-22 19:20:26 +10:00
parent 903f602119
commit d8b1ac3fb0
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
4 changed files with 18 additions and 4 deletions

View File

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

View File

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

View File

@ -9,6 +9,10 @@
</head>
<body>
<h1>HNSDoH Node Status</h1>
{{ if .latestLine}}
<h3>{{ .latestLine}}</h3>
{{end}}
{{ if .logContent}}
<h2>Log Output</h2>
<pre>{{.logContent}}</pre>

View File

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