1 // package icinga provides a client to the Icinga2 HTTP API.
3 // A Client manages interaction with an Icinga2 server.
4 // It is created using Dial:
6 // client, err := icinga.Dial("icinga.example.com:5665", "icinga", "secret", http.DefaultClient)
10 // host, err := client.LookupHost("myserver.example.com")
15 // Since Client wraps http.Client, exported methods of http.Client such
16 // as Get and PostForm can be used to implement any extra functionality
17 // not provided by this package. For example:
19 // resp, err := client.PostForm("https://icinga.example.com:5665", data)
31 // A Client represents a client connection to the Icinga2 HTTP API.
32 // It should be created using Dial.
33 // Since Client wraps http.Client, standard methods such as Get and
34 // PostForm can be used to implement any functionality not provided by
43 var ErrNotExist = errors.New("object does not exist")
44 var ErrExist = errors.New("object already exists")
45 var ErrNoMatch = errors.New("no object matches filter")
47 // Dial returns a new Client connected to the Icinga2 server at addr.
48 // The recommended value for client is http.DefaultClient.
49 // But it may also be a modified client which, for example,
50 // skips TLS certificate verification.
51 func Dial(addr, username, password string, client *http.Client) (*Client, error) {
52 c := &Client{addr, username, password, client}
53 if _, err := c.Permissions(); err != nil {
59 func (c *Client) Permissions() (response, error) {
60 resp, err := c.get("", "")
62 return response{}, err
64 if resp.StatusCode == http.StatusOK {
65 return response{}, nil
67 return response{}, errors.New(resp.Status)