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 CheckCommand string `json:"check_command"`
19 DisplayName string `json:"display_name:"`
20 }
22 type ServiceState int
24 const (
25 ServiceOK ServiceState = 0 + iota
26 ServiceWarning
27 ServiceCritical
28 ServiceUnknown
29 )
31 func (s ServiceState) String() string {
32 switch s {
33 case ServiceOK:
34 return "ServiceOK"
35 case ServiceWarning:
36 return "ServiceWarning"
37 case ServiceCritical:
38 return "ServiceCritical"
39 case ServiceUnknown:
40 return "ServiceUnknown"
41 }
42 return "unhandled service state"
43 }
45 func (s Service) MarshalJSON() ([]byte, error) {
46 attrs := make(map[string]interface{})
47 if len(s.Groups) > 0 {
48 attrs["groups"] = s.Groups
49 }
50 attrs["check_command"] = s.CheckCommand
51 attrs["display_name"] = s.DisplayName
52 jservice := &struct {
53 Attrs map[string]interface{} `json:"attrs"`
54 }{Attrs: attrs}
55 return json.Marshal(jservice)
56 }