diff --git a/html/about.html b/html/about.html index 09794ca..a7acedf 100644 --- a/html/about.html +++ b/html/about.html @@ -53,6 +53,10 @@

Device

API Identifier {{.DeviceID}} + + Last Salt Update + {{.LastSaltUpdate}} + @@ -103,4 +107,4 @@

Installed Packages

- \ No newline at end of file + diff --git a/management-interface.go b/management-interface.go index e01e26e..eb06d1a 100644 --- a/management-interface.go +++ b/management-interface.go @@ -36,6 +36,7 @@ import ( "sort" "strconv" "strings" + "time" goconfig "github.com/TheCacophonyProject/go-config" @@ -125,18 +126,34 @@ func getRaspberryPiSerialNumber() string { // Return the salt minion ID for the device. func getSaltMinionID() string { + return strings.TrimSpace(readFile("/etc/salt/minion_id")) +} +// Return the time of the last salt update. +func getLastSaltUpdate() string { + timeStr := strings.TrimSpace(readFile("/etc/cacophony/last-salt-update")) + if timeStr == "" { + return "" + } + t, err := time.Parse(time.RFC3339, timeStr) + if err != nil { + return "" + } + return t.Format("2006-01-02 15:04:05") +} + +// Return context from file returning an empty string if on windows or if read fails +func readFile(file string) string { if runtime.GOOS == "windows" { return "" } // The /etc/salt/minion_id file contains the ID. - out, err := ioutil.ReadFile("/etc/salt/minion_id") + out, err := ioutil.ReadFile(file) if err != nil { return "" } - - return strings.TrimSpace(string(out)) + return string(out) } // Get the directory of where this executable was started. @@ -607,6 +624,7 @@ func AboutHandler(w http.ResponseWriter, r *http.Request, conf *goconfig.Config) SaltMinionID string Group string DeviceID int + LastSaltUpdate string PackageDataRows [][]string ErrorMessage string } @@ -626,6 +644,7 @@ func AboutHandler(w http.ResponseWriter, r *http.Request, conf *goconfig.Config) SaltMinionID: getSaltMinionID(), Group: device.Group, DeviceID: device.ID, + LastSaltUpdate: getLastSaltUpdate(), } // Get installed packages.