commit - f4705a64149eb5336dd9f69e1a32ebf7d886a132
commit + 8f08828e8134e1160b4be74544d3b6020059366e
blob - 06a63ce3ee17549ea8e373106a3ad58600e9e86f
blob + 27ad6d6ed237df31a19942fa9698a7817eb54162
--- service.go
+++ service.go
package icinga
-import "encoding/json"
+import (
+ "encoding/json"
+ "strings"
+ "time"
+)
func (s Service) name() string {
return s.Name
StateType StateType `json:"state_type,omitempty"`
CheckCommand string `json:"check_command"`
DisplayName string `json:"display_name,omitempty"`
+ LastCheck time.Time `json:",omitempty"`
LastCheckResult *CheckResult `json:"last_check_result,omitempty"`
Acknowledgement bool `json:",omitempty"`
}
type CheckResult struct {
- Output string
+ CheckSource string `json:"check_source"`
+ Command interface{}
+ Output string
}
type ServiceState int
type alias Service
aux := &struct {
Acknowledgement int
+ LastCheck float64 `json:"last_check"`
*alias
}{
alias: (*alias)(s),
if aux.Acknowledgement != 0 {
s.Acknowledgement = true
}
+ s.LastCheck = time.Unix(int64(aux.LastCheck), 0)
return nil
}
+
+func (s Service) Host() string {
+ return strings.SplitN(s.Name, "!", 2)[0]
+}
+
+func (cr CheckResult) RawCommand() string {
+ switch v := cr.Command.(type) {
+ case string:
+ return v
+ case []interface{}:
+ var cmd []string
+ for i := range v {
+ if arg, ok := v[i].(string); ok {
+ cmd = append(cmd, arg)
+ }
+ }
+ return strings.Join(cmd, " ")
+ }
+ return "no command"
+}