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