Blob


1 package icinga
3 import "encoding/json"
5 func (s Service) name() string {
6 return s.Name
7 }
9 func (s Service) path() string {
10 return "/objects/services/" + s.Name
11 }
13 // Service represents a Service object.
14 type Service struct {
15 Name string `json:"__name"`
16 Groups []string
17 State ServiceState
18 StateType StateType `json:"state_type"`
19 CheckCommand string `json:"check_command"`
20 DisplayName string `json:"display_name"`
21 LastCheckResult CheckResult `json:"last_check_result"`
22 }
24 type CheckResult struct {
25 Output string
26 }
28 type ServiceState int
30 const (
31 ServiceOK ServiceState = 0 + iota
32 ServiceWarning
33 ServiceCritical
34 ServiceUnknown
35 )
37 func (s ServiceState) String() string {
38 switch s {
39 case ServiceOK:
40 return "ServiceOK"
41 case ServiceWarning:
42 return "ServiceWarning"
43 case ServiceCritical:
44 return "ServiceCritical"
45 case ServiceUnknown:
46 return "ServiceUnknown"
47 }
48 return "unhandled service state"
49 }
51 func (s Service) MarshalJSON() ([]byte, error) {
52 attrs := make(map[string]interface{})
53 if len(s.Groups) > 0 {
54 attrs["groups"] = s.Groups
55 }
56 attrs["check_command"] = s.CheckCommand
57 attrs["display_name"] = s.DisplayName
58 jservice := &struct {
59 Attrs map[string]interface{} `json:"attrs"`
60 }{Attrs: attrs}
61 return json.Marshal(jservice)
62 }