Documentation ¶
Overview ¶
package icinga provides a client to the Icinga2 HTTP API.
A Client manages interaction with an Icinga2 server. It is created using Dial:
client, err := icinga.Dial("icinga.example.com:5665", "icinga", "secret", http.DefaultClient) if err != nil { // handle error }
Icinga2 servers in the wild often serve self-signed certificates which fail verification by Go's tls client. To ignore the errors, Dial the server with a modified http.Client:
t := http.DefaultTransport.(*http.Transport) t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} c := http.DefaultClient c.Transport = t client, err := icinga.Dial(addr, user, pass, c) if err != nil { // handle error }
Methods on Client provide API actions like looking up users and creating hosts:
user, err := client.LookupUser("oliver") if err != nil { // handle error } host := Host{ Name: "myserver.example.com", CheckCommand: "hostalive" Address: "192.0.2.1" Address6: "2001:db8::1" } if err := client.CreateHost(host); err != nil { // handle error }
Since Client wraps http.Client, exported methods of http.Client such as Get and PostForm can be used to implement any extra functionality not provided by this package. For example:
resp, err := client.PostForm("https://icinga.example.com:5665", data) if err != nil { // handle error }
Index ¶
- Variables
- func NewRequest(method, url, username, password string, body io.Reader) (*http.Request, error)
- func Permissions(c *Client) ([]string, error)
- type CheckResult
- type Client
- func (c *Client) CheckHosts(filter string) error
- func (c *Client) CheckServices(filter string) error
- func (c *Client) CreateHost(host Host) error
- func (c *Client) CreateHostGroup(hostgroup HostGroup) error
- func (c *Client) CreateService(service Service) error
- func (c *Client) CreateUser(user User) error
- func (c *Client) DeleteHost(name string, cascade bool) error
- func (c *Client) DeleteHostGroup(name string, cascade bool) error
- func (c *Client) DeleteService(name string, cascade bool) error
- func (c *Client) DeleteUser(name string, cascade bool) error
- func (c *Client) HostGroups(filter string) ([]HostGroup, error)
- func (c *Client) Hosts(filter string) ([]Host, error)
- func (c *Client) LookupHost(name string) (Host, error)
- func (c *Client) LookupHostGroup(name string) (HostGroup, error)
- func (c *Client) LookupService(name string) (Service, error)
- func (c *Client) LookupUser(name string) (User, error)
- func (c *Client) Services(filter string) ([]Service, error)
- func (c *Client) Subscribe(typ, queue, filter string) (<-chan Event, error)
- func (c *Client) Users(filter string) ([]User, error)
- type Event
- type Host
- type HostGroup
- type HostState
- type Service
- type ServiceState
- type StateType
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrExist = errors.New("object already exists")
var ErrNoMatch = errors.New("no object matches filter")
var ErrNotExist = errors.New("object does not exist")
Functions ¶
func NewRequest ¶
NewRequest returns an authenticated HTTP request with appropriate header for sending to an Icinga2 server.
func Permissions ¶
Permissions returns the permissions granted to the Client.
Types ¶
type CheckResult ¶
type CheckResult struct { CheckSource string `json:"check_source"` Command interface{} Output string }
func (CheckResult) RawCommand ¶
func (cr CheckResult) RawCommand() string
type Client ¶
A Client represents a client connection to the Icinga2 HTTP API. It should be created using Dial. Since Client wraps http.Client, exported methods such as Get and PostForm can be used to implement any functionality not provided by methods of Client.
func Dial ¶
Dial returns a new Client connected to the Icinga2 server at addr. The recommended value for client is http.DefaultClient. But it may also be a modified client which, for example, skips TLS certificate verification.
func (*Client) CheckHosts ¶
CheckHosts schedules checks for all hosts matching the filter expression filter. If no hosts match the filter, error wraps ErrNoMatch.
func (*Client) CheckServices ¶
CheckHosts schedules checks for all services matching the filter expression filter. If no services match the filter, error wraps ErrNoMatch.
func (*Client) CreateHost ¶
CreateHost creates host. Some fields of host must be set for successful creation; see the type definition of Host for details.
func (*Client) CreateHostGroup ¶
CreateHostGroup creates hostgroup. Some fields of hostgroup must be set for successful creation; see the type definition of HostGroup for details.
func (*Client) CreateService ¶
CreateService creates service. Some fields of service must be set for successful creation; see the type definition of Service for details.
func (*Client) CreateUser ¶
CreateUser creates user. Some fields of user must be set for successful creation; see the type definition of User for details.
func (*Client) DeleteHost ¶
DeleteHost deletes the Host identified by name. If cascade is true, objects depending on the Host are also deleted. If no Host is found, error wraps ErrNotExist.
func (*Client) DeleteHostGroup ¶
DeleteHostGroup deletes the HostGroup identified by name. If cascade is true, objects depending on the HostGroup are also deleted. If no HostGroup is found, error wraps ErrNotExist.
func (*Client) DeleteService ¶
DeleteService deletes the Service identified by name. If cascade is true, objects depending on the Service are also deleted. If no Service is found, error wraps ErrNotExist.
func (*Client) DeleteUser ¶
DeleteUser deletes the User identified by name. If cascade is true, objects depending on the User are also deleted. If no User is found, error wraps ErrNotExist.
func (*Client) HostGroups ¶
HostGroups returns a slice of HostGroup matching the filter expression filter. If no hostgroups match, error wraps ErrNoMatch. To fetch all hostgroup, set filter to the empty string ("").
func (*Client) Hosts ¶
Hosts returns a slice of Host matching the filter expression filter. If no hosts match, error wraps ErrNoMatch. To fetch all host, set filter to the empty string ("").
func (*Client) LookupHost ¶
LookupHost returns the Host identified by name. If no Host is found, error wraps ErrNotExist.
func (*Client) LookupHostGroup ¶
LookupHostGroup returns the HostGroup identified by name. If no HostGroup is found, error wraps ErrNotExist.
func (*Client) LookupService ¶
LookupService returns the Service identified by name. If no Service is found, error wraps ErrNotExist.
func (*Client) LookupUser ¶
LookupUser returns the User identified by name. If no User is found, error wraps ErrNotExist.
func (*Client) Services ¶
Services returns a slice of Service matching the filter expression filter. If no services match, error wraps ErrNoMatch. To fetch all service, set filter to the empty string ("").
func (*Client) Subscribe ¶
Subscribe returns a channel through which events from the corresponding Icinga Event Stream named in typ are sent. Queue is a unique identifier Icinga uses to manage stream clients. Filter is a filter expression which modifies which events will be received; the empty string means all events are sent.
Any errors on initialising the connection are returned immediately as a value. Subsequent errors reading the stream are set in the Error field of sent Events. Callers should handle both cases and resubscribe as required.
type Event ¶
type Event struct { // Type indicates the type of the stream, such as CheckResult. Type string `json:"type"` // Host is the name of an Icinga Host object which this event relates to. Host string `json:"host"` // Service is the name of an Icinga Service object which this event relates to. // It is empty when a CheckResult event of a Host object is received. Service string `json:"service"` Acknowledgement bool `json:"acknowledgement"` CheckResult *CheckResult `json:"check_result"` Error error }
An Event represents an event from the Icinga Event Stream.
type Host ¶
type Host struct { Name string `json:"-"` Address string `json:"address"` Address6 string `json:"address6"` Groups []string `json:"groups,omitempty"` State HostState `json:"state,omitempty"` StateType StateType `json:"state_type,omitempty"` CheckCommand string `json:"check_command"` DisplayName string `json:"display_name,omitempty"` LastCheck time.Time `json:",omitempty"` LastCheckResult CheckResult `json:"last_check_result,omitempty"` Acknowledgement bool `json:",omitempty"` Notes string `json:"notes,omitempty"` NotesURL string `json:"notes_url,omitempty"` }
Host represents a Host object. To create a Host, the Name and CheckCommand fields must be set.
func (*Host) UnmarshalJSON ¶
UnmarhsalJSON unmarshals host attributes into more meaningful Host field types.
type Service ¶
type Service struct { Name string `json:"-"` Groups []string `json:"groups,omitempty"` State ServiceState `json:"state,omitempty"` StateType StateType `json:"state_type,omitempty"` CheckCommand string `json:"check_command"` DisplayName string `json:"display_name,omitempty"` LastCheck time.Time `json:",omitempty"` LastCheckResult CheckResult `json:"last_check_result,omitempty"` Acknowledgement bool `json:",omitempty"` Notes string `json:"notes,omitempty"` NotesURL string `json:"notes_url,omitempty"` }
Service represents a Service object.
func (*Service) UnmarshalJSON ¶
UnmarshalJSON unmarshals service attributes into more meaningful Service field types.
type ServiceState ¶
type ServiceState int
const ( ServiceOK ServiceState = 0 + iota ServiceWarning ServiceCritical ServiceUnknown )
func (ServiceState) String ¶
func (state ServiceState) String() string