Better datetime display for problems

This commit is contained in:
Magnus Åhall 2024-07-04 09:21:24 +02:00
parent dd4bc27bc7
commit 185056cdf8

View File

@ -147,11 +147,29 @@ func ProblemAcknowledge(id int, state bool) (err error) { // {{{
func (p Problem) FormattedValues() string { func (p Problem) FormattedValues() string {
out := []string{} out := []string{}
for key, val := range p.DatapointValues { for key, val := range p.DatapointValues {
timeVal, ok := val.(time.Time) var keyval string
if ok {
logger.Info("FOO", "timeVal", timeVal) switch val.(type) {
case int:
keyval = fmt.Sprintf("%s: %d", key, val)
case string:
if str, ok := val.(string); ok {
timeVal, err := time.Parse(time.RFC3339, str)
if err == nil {
formattedTime := timeVal.Format("2006-01-02 15:04:05")
keyval = fmt.Sprintf("%s: %s", key, formattedTime)
} else {
keyval = fmt.Sprintf("%s: %s", key, val)
}
}
default:
keyval = fmt.Sprintf("%s: %v", key, val)
} }
out = append(out, fmt.Sprintf("%s: %v", key, val))
out = append(out, keyval)
} }
sort.Strings(out) sort.Strings(out)