Better datetime display for problems
This commit is contained in:
parent
dd4bc27bc7
commit
185056cdf8
26
problem.go
26
problem.go
@ -147,11 +147,29 @@ func ProblemAcknowledge(id int, state bool) (err error) { // {{{
|
||||
func (p Problem) FormattedValues() string {
|
||||
out := []string{}
|
||||
for key, val := range p.DatapointValues {
|
||||
timeVal, ok := val.(time.Time)
|
||||
if ok {
|
||||
logger.Info("FOO", "timeVal", timeVal)
|
||||
var keyval string
|
||||
|
||||
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)
|
||||
}
|
||||
out = append(out, fmt.Sprintf("%s: %v", key, val))
|
||||
}
|
||||
|
||||
default:
|
||||
keyval = fmt.Sprintf("%s: %v", key, val)
|
||||
}
|
||||
|
||||
out = append(out, keyval)
|
||||
|
||||
}
|
||||
sort.Strings(out)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user