icinga

package
v0.0.39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

README

icinga

This is a tool kit to help interact with icinga.

You should be able to do the following today.

  • Check to see if a hosts exists
  • Enable and Disable Active checks
  • Enable and Disable Notifications
  • Set or Reset Downtime

Flags and Environment

Currently here is the list of valid flags that can be used

  -icinga string
    	icinga address
  -icinga-password string
    	icinga password (optional)
  -icinga-tls-ca-cert string
    	The CA cert to use to validate the Icinga server's certificate
  -icinga-tls-client-cert string
    	The TLS client certificate to use when connecting to Icinga
  -icinga-tls-client-key string
    	The TLS client key to use when connecting to Icinga
  -icinga-tls-insecure
    	Whether or not to perform certificate hostname validation when connecting to the Nomad server
  -icinga-username string
    	icinga username (optional)

Currently the ENV this module will look for

gm_icinga
gm_icinga_username
gm_icinga_password
gm_icinga_tls_client_cert
gm_icinga_tls_client_key
gm_icinga_tls_ca_cert
gm_icinga_tls_insecure

Connection

It is recommended to use the TLS certs that icinga installation addes to /etc/icinga2/pki and not use the username/password.

Be default nodes do not have access to the icinga api. To give permission you need to add the following to the puppet config.

  @@firewall { "100 allow icinga2 api ${::fqdn}":
      state  => 'NEW',
      dport  => [5665],
      proto  => 'tcp',
      action => 'accept',
      source => $::facts[$ip_fact],
      tag    => ["api-${icinga::master_name}"]
    }

  # Configure an icinga api user for this machine
  @@icinga2::object::apiuser { "${::fqdn}-api" :
    client_cn   => $::fqdn,
    target      => "/etc/icinga2/zones.d/${icinga::master_name}/${::fqdn}.conf",
    permissions => [ '*' ],
    tag         => ["api-${icinga::master_name}"]
  }

Setup Client

// Parse the flags
icingaCfg := icinga.NewConfig(flag.CommandLine)
flag.Parse()

// Create a icinga client
ic, err := icingaCfg.Client()
if err != nil {
  l.Fatal("error", err)
}

Squelch a Host and all services

// Turn off notifications
if err := ic.SetAllNotifications(hostname, false); err != nil {
  return err
}

// Turn off active checks
if err := ic.SetAllActiveChecks(hostname, false); err != nil {
  return err
}

// Turn on downtimes
if err := ic.SetAllDowntime(hostname, "icinga-squelch", "Icinga squelch", time.Now(), time.Now().Add(time.Hour*24)); err != nil {
  return err
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResults

type APIResults struct {
	StatusCode int
	Exists     bool
	Results    []struct {
		Code   float64  `json:"code"`
		Errors []string `json:"errors"`
		Status string   `json:"status"`
		Name   string   `json:"name"`
		Type   string   `json:"type"`
		Attrs  struct {
			AttrsInfo map[string]interface{} `json:"-,"`
		} `json:"attrs"`
		Joins struct{} `json:"joins"`
		Meta  struct{} `json:"meta"`
	} `json:"results"`
}

APIResults response from icinga API StatusCode is the http code. Code is the code in the body from icinga

type ActiveCheck

type ActiveCheck struct {
	Filter string `json:"filter"`
	Attrs  struct {
		EnableActiveChecks bool `json:"enable_active_checks"`
	} `json:"attrs"`
}

ActiveCheck Basic body to disable active check on a host

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client holds the icinga2 http client

func (*Client) APIRequest

func (c *Client) APIRequest(method, APICall string, jsonString []byte) (APIResults, error)

APIRequest can change attributes to icinga objects. Example is active checks, downtime, notifications. This can also be used to create and delete new object in icinga.

func (*Client) HostExist

func (c *Client) HostExist(hostname string) (bool, error)

HostExist will check if the host exists

func (*Client) ResetAllDowntime

func (c *Client) ResetAllDowntime(hostname string) error

ResetAllDowntime will turn Downtime off for the host and all the services

func (*Client) ResetDowntime

func (c *Client) ResetDowntime(hostname, object string) error

ResetDowntime will turn Downtime off for either a host or service

func (*Client) SendNotification

func (c *Client) SendNotification(filter, checkType, author, message string, force bool) error

SendNotification will send a custom notification out

func (*Client) SetActiveChecks

func (c *Client) SetActiveChecks(hostname, path string, check bool) error

SetActiveChecks will set Active checks on or off for either a host or service

func (*Client) SetAllActiveChecks

func (c *Client) SetAllActiveChecks(hostname string, check bool) error

SetAllActiveChecks will turn Active check on or off for the host and all the services

func (*Client) SetAllDowntime

func (c *Client) SetAllDowntime(hostname, author, comment string, start, end time.Time) error

SetAllDowntime will turn Downtime for the host and all the services

func (*Client) SetAllNotifications

func (c *Client) SetAllNotifications(hostname string, check bool) error

SetAllNotifications will turn notifications on or off for the host and all the services

func (*Client) SetDowntime

func (c *Client) SetDowntime(hostname, object, author, comment string, start, end time.Time) error

SetDowntime will set Downtime for either a host or service

func (*Client) SetNotifications

func (c *Client) SetNotifications(hostname, path string, check bool) error

SetNotifications will set notifications on or off for either a host or service

type Config

type Config struct {
	BaseURL       string
	Username      string
	Password      string
	TLSClientCert string
	TLSClientKey  string
	TLSCACert     string
	TLSInsecure   bool
	// contains filtered or unexported fields
}

Config setups the information needed to connect to icinga If the system has icinga installed then you should use the cets used in /etc/icinga2/pki Username/Password should only used if it does not have a icinga2 agent installed.

func NewConfig

func NewConfig(flag *flag.FlagSet) *Config

NewConfig prepares a new configuration for the parsing icinga flags

func (*Config) Client

func (cfg *Config) Client() (*Client, error)

Client checks and applies the config and return a icinga client

type CustomNotification

type CustomNotification struct {
	Filter  string `json:"filter"`
	Type    string `json:"type"`
	Author  string `json:"author"`
	Comment string `json:"comment"`
	Force   bool   `json:"force"`
}

CustomNotification body to send custom notifications for a host or service

type Host

type Host struct {
	Filter string   `json:"filter,omitempty"`
	Attrs  []string `json:"attrs,omitempty"`
}

Host Basic Body needed to get Host information

type Notifications

type Notifications struct {
	Filter string `json:"filter"`
	Attrs  struct {
		EnableNotificationss bool `json:"enable_notifications"`
	} `json:"attrs"`
}

Notifications Basic body to disable notifications for a host or service

type ResetDowntime

type ResetDowntime struct {
	Type   string `json:"type"`
	Filter string `json:"filter"`
}

ResetDowntime Basic body to schedule downtime for a host

type ScheduleDowntime

type ScheduleDowntime struct {
	Type      string `json:"type"`
	Filter    string `json:"filter"`
	StartTime int64  `json:"start_time"`
	EndTime   int64  `json:"end_time"`
	Author    string `json:"author"`
	Comment   string `json:"comment"`
}

ScheduleDowntime Basic body to schedule downtime for a host

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL