Blame


1 2c4d16ae 2021-12-23 o package icinga
2 2c4d16ae 2021-12-23 o
3 2c4d16ae 2021-12-23 o import (
4 2c4d16ae 2021-12-23 o "fmt"
5 2c4d16ae 2021-12-23 o "net/http"
6 2c4d16ae 2021-12-23 o )
7 2c4d16ae 2021-12-23 o
8 2c4d16ae 2021-12-23 o type Client struct {
9 b74ab3b3 2021-12-30 o host string
10 b74ab3b3 2021-12-30 o username string
11 b74ab3b3 2021-12-30 o password string
12 007a3d09 2021-12-27 o *http.Client
13 2c4d16ae 2021-12-23 o }
14 2c4d16ae 2021-12-23 o
15 2c4d16ae 2021-12-23 o func Dial(host, username, password string, client *http.Client) (*Client, error) {
16 2c4d16ae 2021-12-23 o c := &Client{host, username, password, client}
17 2c4d16ae 2021-12-23 o if _, err := c.Status(); err != nil {
18 2c4d16ae 2021-12-23 o return nil, err
19 2c4d16ae 2021-12-23 o }
20 2c4d16ae 2021-12-23 o return c, nil
21 2c4d16ae 2021-12-23 o }
22 2c4d16ae 2021-12-23 o
23 2c4d16ae 2021-12-23 o func (c *Client) Status() (*http.Response, error) {
24 2c4d16ae 2021-12-23 o resp, err := c.get("/status")
25 2c4d16ae 2021-12-23 o if err != nil {
26 2c4d16ae 2021-12-23 o return nil, err
27 2c4d16ae 2021-12-23 o }
28 2c4d16ae 2021-12-23 o if resp.StatusCode != http.StatusOK {
29 2c4d16ae 2021-12-23 o return resp, fmt.Errorf("status %s", resp.Status)
30 2c4d16ae 2021-12-23 o }
31 2c4d16ae 2021-12-23 o return resp, nil
32 2c4d16ae 2021-12-23 o }