icinga

Icinga2 API client in Go
git clone https://git.olowe.co/icinga
Log | Files | Refs | README | LICENSE

commit 83f511305d76af055cecefced0265cee26d63d75
parent 8635d20e62566f62e2365441d2091b721cd8ef71
Author: Oliver Lowe <o@olowe.co>
Date:   Fri,  7 Jan 2022 00:02:36 +1100

add Icinga service and host states

Nothing actually uses these yet but they will soon!

Diffstat:
Mhttp.go | 8++++----
Micinga.go | 15+++++++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/http.go b/http.go @@ -63,7 +63,7 @@ func newRequest(method, host, path string, body io.Reader) (*http.Request, error } func (c *Client) get(path string) (*http.Response, error) { - req, err := newRequest(http.MethodGet, c.host, path, nil) + req, err := newRequest(http.MethodGet, c.addr, path, nil) if err != nil { return nil, err } @@ -71,7 +71,7 @@ func (c *Client) get(path string) (*http.Response, error) { } func (c *Client) post(path string, body io.Reader) (*http.Response, error) { - req, err := newRequest(http.MethodPost, c.host, path, body) + req, err := newRequest(http.MethodPost, c.addr, path, body) if err != nil { return nil, err } @@ -79,7 +79,7 @@ func (c *Client) post(path string, body io.Reader) (*http.Response, error) { } func (c *Client) put(path string, body io.Reader) error { - req, err := newRequest(http.MethodPut, c.host, path, body) + req, err := newRequest(http.MethodPut, c.addr, path, body) if err != nil { return err } @@ -99,7 +99,7 @@ func (c *Client) put(path string, body io.Reader) error { } func (c *Client) delete(path string) error { - req, err := newRequest(http.MethodDelete, c.host, path, nil) + req, err := newRequest(http.MethodDelete, c.addr, path, nil) if err != nil { return err } diff --git a/icinga.go b/icinga.go @@ -28,6 +28,21 @@ import ( "net/http" ) +type State int + +const ( + StateOK State = 0 + iota + StateWarning + StateCritical + StateUnknown +) + +const ( + HostUp State = 0 + iota + HostDown + HostUnknown +) + // A Client represents a client connection to the Icinga2 HTTP API. // It should be created using Dial. // Since Client wraps http.Client, standard methods such as Get and