Skip to content

Commit

Permalink
Merge pull request #87 from CameronRP/add-salt-update-datetime
Browse files Browse the repository at this point in the history
Add time of last salt update
  • Loading branch information
CameronRP authored Jan 13, 2020
2 parents 70b86b7 + 296f81e commit 9277d7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 5 additions & 1 deletion html/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ <h3>Device<br></h3>
<td>API Identifier</td>
<td id="APIID">{{.DeviceID}}</td>
</tr>
<tr>
<td>Last Salt Update</td>
<td>{{.LastSaltUpdate}}</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -103,4 +107,4 @@ <h3>Installed Packages<br></h3>

</body>

</html>
</html>
25 changes: 22 additions & 3 deletions management-interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"sort"
"strconv"
"strings"
"time"

goconfig "github.com/TheCacophonyProject/go-config"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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.
Expand Down

0 comments on commit 9277d7d

Please sign in to comment.