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 := icinga.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)
34 StateOK State = 0 + iota
41 HostUp State = 0 + iota
46 // A Client represents a client connection to the Icinga2 HTTP API.
47 // It should be created using Dial.
48 // Since Client wraps http.Client, standard methods such as Get and
49 // PostForm can be used to implement any functionality not provided by
58 // Dial returns a new Client connected to the Icinga2 server at addr.
59 // The recommended value for client is http.DefaultClient.
60 // But it may also be a modified client which, for example,
61 // skips TLS certificate verification.
62 func Dial(addr, username, password string, client *http.Client) (*Client, error) {
63 c := &Client{addr, username, password, client}
64 if _, err := c.Status(); err != nil {
70 func (c *Client) Status() (*http.Response, error) {
71 resp, err := c.get("/status")
75 if resp.StatusCode != http.StatusOK {
76 return resp, fmt.Errorf("status %s", resp.Status)