Blob


1 // Code generated by ./crud.sh -o crud.go; DO NOT EDIT.
3 package icinga
5 import "fmt"
7 // Hosts returns a slice of Host matching the filter expression filter.
8 // If no hosts match, error wraps ErrNoMatch.
9 // To fetch all host, set filter to the empty string ("").
10 func (c *Client) Hosts(filter string) ([]Host, error) {
11 objects, err := c.filterObjects("/objects/hosts", filter)
12 if err != nil {
13 return nil, fmt.Errorf("get hosts filter %s: %w", filter, err)
14 }
15 var hosts []Host
16 for _, o := range objects {
17 v, ok := o.(Host)
18 if !ok {
19 return nil, fmt.Errorf("get hosts filter %s: %T in response", filter, v)
20 }
21 hosts = append(hosts, v)
22 }
23 return hosts, nil
24 }
26 // LookupHost returns the Host identified by name. If no Host is found, error
27 // wraps ErrNotExist.
28 func (c *Client) LookupHost(name string) (Host, error) {
29 obj, err := c.lookupObject("/objects/hosts/" + name)
30 if err != nil {
31 return Host{}, fmt.Errorf("lookup host %s: %w", name, err)
32 }
33 v, ok := obj.(Host)
34 if !ok {
35 return Host{}, fmt.Errorf("lookup host %s: result type %T is not Host", name, v)
36 }
37 return v, nil
38 }
40 // CreateHost creates host. Some fields of host must be set for successful
41 // creation; see the type definition of Host for details.
42 func (c *Client) CreateHost(host Host) error {
43 if err := c.createObject(host); err != nil {
44 return fmt.Errorf("create host %s: %w", host.Name, err)
45 }
46 return nil
47 }
49 // DeleteHost deletes the Host identified by name. If cascade is true, objects
50 // depending on the Host are also deleted. If no Host is found, error wraps
51 // ErrNotExist.
52 func (c *Client) DeleteHost(name string, cascade bool) error {
53 if err := c.deleteObject("/objects/hosts/"+name, cascade); err != nil {
54 return fmt.Errorf("delete host %s: %w", name, err)
55 }
56 return nil
57 }
58 // Services returns a slice of Service matching the filter expression filter.
59 // If no services match, error wraps ErrNoMatch.
60 // To fetch all service, set filter to the empty string ("").
61 func (c *Client) Services(filter string) ([]Service, error) {
62 objects, err := c.filterObjects("/objects/services", filter)
63 if err != nil {
64 return nil, fmt.Errorf("get services filter %s: %w", filter, err)
65 }
66 var services []Service
67 for _, o := range objects {
68 v, ok := o.(Service)
69 if !ok {
70 return nil, fmt.Errorf("get services filter %s: %T in response", filter, v)
71 }
72 services = append(services, v)
73 }
74 return services, nil
75 }
77 // LookupService returns the Service identified by name. If no Service is found, error
78 // wraps ErrNotExist.
79 func (c *Client) LookupService(name string) (Service, error) {
80 obj, err := c.lookupObject("/objects/services/" + name)
81 if err != nil {
82 return Service{}, fmt.Errorf("lookup service %s: %w", name, err)
83 }
84 v, ok := obj.(Service)
85 if !ok {
86 return Service{}, fmt.Errorf("lookup service %s: result type %T is not Service", name, v)
87 }
88 return v, nil
89 }
91 // CreateService creates service. Some fields of service must be set for successful
92 // creation; see the type definition of Service for details.
93 func (c *Client) CreateService(service Service) error {
94 if err := c.createObject(service); err != nil {
95 return fmt.Errorf("create service %s: %w", service.Name, err)
96 }
97 return nil
98 }
100 // DeleteService deletes the Service identified by name. If cascade is true, objects
101 // depending on the Service are also deleted. If no Service is found, error wraps
102 // ErrNotExist.
103 func (c *Client) DeleteService(name string, cascade bool) error {
104 if err := c.deleteObject("/objects/services/"+name, cascade); err != nil {
105 return fmt.Errorf("delete service %s: %w", name, err)
107 return nil
109 // Users returns a slice of User matching the filter expression filter.
110 // If no users match, error wraps ErrNoMatch.
111 // To fetch all user, set filter to the empty string ("").
112 func (c *Client) Users(filter string) ([]User, error) {
113 objects, err := c.filterObjects("/objects/users", filter)
114 if err != nil {
115 return nil, fmt.Errorf("get users filter %s: %w", filter, err)
117 var users []User
118 for _, o := range objects {
119 v, ok := o.(User)
120 if !ok {
121 return nil, fmt.Errorf("get users filter %s: %T in response", filter, v)
123 users = append(users, v)
125 return users, nil
128 // LookupUser returns the User identified by name. If no User is found, error
129 // wraps ErrNotExist.
130 func (c *Client) LookupUser(name string) (User, error) {
131 obj, err := c.lookupObject("/objects/users/" + name)
132 if err != nil {
133 return User{}, fmt.Errorf("lookup user %s: %w", name, err)
135 v, ok := obj.(User)
136 if !ok {
137 return User{}, fmt.Errorf("lookup user %s: result type %T is not User", name, v)
139 return v, nil
142 // CreateUser creates user. Some fields of user must be set for successful
143 // creation; see the type definition of User for details.
144 func (c *Client) CreateUser(user User) error {
145 if err := c.createObject(user); err != nil {
146 return fmt.Errorf("create user %s: %w", user.Name, err)
148 return nil
151 // DeleteUser deletes the User identified by name. If cascade is true, objects
152 // depending on the User are also deleted. If no User is found, error wraps
153 // ErrNotExist.
154 func (c *Client) DeleteUser(name string, cascade bool) error {
155 if err := c.deleteObject("/objects/users/"+name, cascade); err != nil {
156 return fmt.Errorf("delete user %s: %w", name, err)
158 return nil
160 // HostGroups returns a slice of HostGroup matching the filter expression filter.
161 // If no hostgroups match, error wraps ErrNoMatch.
162 // To fetch all hostgroup, set filter to the empty string ("").
163 func (c *Client) HostGroups(filter string) ([]HostGroup, error) {
164 objects, err := c.filterObjects("/objects/hostgroups", filter)
165 if err != nil {
166 return nil, fmt.Errorf("get hostgroups filter %s: %w", filter, err)
168 var hostgroups []HostGroup
169 for _, o := range objects {
170 v, ok := o.(HostGroup)
171 if !ok {
172 return nil, fmt.Errorf("get hostgroups filter %s: %T in response", filter, v)
174 hostgroups = append(hostgroups, v)
176 return hostgroups, nil
179 // LookupHostGroup returns the HostGroup identified by name. If no HostGroup is found, error
180 // wraps ErrNotExist.
181 func (c *Client) LookupHostGroup(name string) (HostGroup, error) {
182 obj, err := c.lookupObject("/objects/hostgroups/" + name)
183 if err != nil {
184 return HostGroup{}, fmt.Errorf("lookup hostgroup %s: %w", name, err)
186 v, ok := obj.(HostGroup)
187 if !ok {
188 return HostGroup{}, fmt.Errorf("lookup hostgroup %s: result type %T is not HostGroup", name, v)
190 return v, nil
193 // CreateHostGroup creates hostgroup. Some fields of hostgroup must be set for successful
194 // creation; see the type definition of HostGroup for details.
195 func (c *Client) CreateHostGroup(hostgroup HostGroup) error {
196 if err := c.createObject(hostgroup); err != nil {
197 return fmt.Errorf("create hostgroup %s: %w", hostgroup.Name, err)
199 return nil
202 // DeleteHostGroup deletes the HostGroup identified by name. If cascade is true, objects
203 // depending on the HostGroup are also deleted. If no HostGroup is found, error wraps
204 // ErrNotExist.
205 func (c *Client) DeleteHostGroup(name string, cascade bool) error {
206 if err := c.deleteObject("/objects/hostgroups/"+name, cascade); err != nil {
207 return fmt.Errorf("delete hostgroup %s: %w", name, err)
209 return nil