History fixes
This commit is contained in:
parent
3403857442
commit
4ebd2271bf
4 changed files with 17 additions and 15 deletions
|
|
@ -3,6 +3,7 @@ package scan
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/aceberg/WatchYourLAN/internal/db"
|
"github.com/aceberg/WatchYourLAN/internal/db"
|
||||||
"github.com/aceberg/WatchYourLAN/internal/models"
|
"github.com/aceberg/WatchYourLAN/internal/models"
|
||||||
|
|
@ -31,6 +32,8 @@ func hostsCompare() {
|
||||||
|
|
||||||
} else if oneHost.Now == 1 {
|
} else if oneHost.Now == 1 {
|
||||||
oneHost.Now = 0
|
oneHost.Now = 0
|
||||||
|
oneHost.Date = time.Now().Format("2006-01-02 15:04:05")
|
||||||
|
|
||||||
db.Update(appConfig.DbPath, oneHost)
|
db.Update(appConfig.DbPath, oneHost)
|
||||||
|
|
||||||
histAdd(oneHost, 0)
|
histAdd(oneHost, 0)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
<th>IP</th>
|
<th>IP</th>
|
||||||
<th>Mac</th>
|
<th>Mac</th>
|
||||||
<th>Hardware</th>
|
<th>Hardware</th>
|
||||||
<th>First/Last seen</th>
|
<th>Time</th>
|
||||||
<th>Known</th>
|
<th>Known</th>
|
||||||
<th>State</th>
|
<th>State</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
||||||
|
|
@ -101,22 +101,16 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Host ID</th>
|
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>IP</th>
|
<th>IP</th>
|
||||||
<th>Mac</th>
|
<th>Time</th>
|
||||||
<th>Hardware</th>
|
|
||||||
<th>First/Last seen</th>
|
|
||||||
<th>Known</th>
|
<th>Known</th>
|
||||||
<th>State</th>
|
<th>State</th>
|
||||||
</tr>
|
</tr>
|
||||||
{{ range .Hist }}
|
{{ range .Hist }}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/host?id={{ .Host }}">{{ .Host }}</a></td>
|
|
||||||
<td>{{ .Name }}</td>
|
<td>{{ .Name }}</td>
|
||||||
<td><a href="http://{{ .IP }}" target="_blank">{{ .IP }}</a></td>
|
<td><a href="http://{{ .IP }}" target="_blank">{{ .IP }}</a></td>
|
||||||
<td><a href="/host?id={{ .Host }}">{{ .Mac }}</a></td>
|
|
||||||
<td>{{ .Hw }}</td>
|
|
||||||
<td>{{ .Date }}</td>
|
<td>{{ .Date }}</td>
|
||||||
<td>
|
<td>
|
||||||
{{ if eq .Known 1 }}
|
{{ if eq .Known 1 }}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -13,25 +13,30 @@ func trimHistoryRoutine() {
|
||||||
for {
|
for {
|
||||||
trimHistory()
|
trimHistory()
|
||||||
|
|
||||||
time.Sleep(time.Duration(1) * time.Hour)
|
time.Sleep(time.Duration(1) * time.Hour) // Every hour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func trimHistory() {
|
func trimHistory() {
|
||||||
|
|
||||||
days, _ := strconv.Atoi(AppConfig.HistDays)
|
days, _ := strconv.Atoi(AppConfig.HistDays)
|
||||||
now := time.Now()
|
|
||||||
|
nowStr := time.Now().Format("2006-01-02 15:04:05") // This needed so all time is
|
||||||
|
now, _ := time.Parse("2006-01-02 15:04:05", nowStr) // in one format
|
||||||
|
nowMinus := now.Add(-time.Duration(days) * 24 * time.Hour)
|
||||||
|
|
||||||
history := db.SelectHist(AppConfig.DbPath)
|
history := db.SelectHist(AppConfig.DbPath)
|
||||||
|
|
||||||
|
if AppConfig.LogLevel != "short" {
|
||||||
|
log.Println("INFO: removing all history before", nowMinus.Format("2006-01-02 15:04:05"))
|
||||||
|
}
|
||||||
|
|
||||||
for _, hist := range history {
|
for _, hist := range history {
|
||||||
date, _ := time.Parse("2006-01-02 15:04:05", hist.Date)
|
date, _ := time.Parse("2006-01-02 15:04:05", hist.Date)
|
||||||
datePlus := date.Add(time.Duration(days) * 24 * time.Hour)
|
|
||||||
|
|
||||||
if now.After(datePlus) {
|
if date.Before(nowMinus) {
|
||||||
|
|
||||||
db.DeleteHist(AppConfig.DbPath, hist.ID)
|
db.DeleteHist(AppConfig.DbPath, hist.ID)
|
||||||
|
|
||||||
// log.Println("REMOVED DATE =", hist.Date)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue