项目作者: jakgibb

项目描述 :
A golang Nagios XI API client library
高级语言: Go
项目地址: git://github.com/jakgibb/goxi.git
创建时间: 2020-01-04T11:20:49Z
项目社区:https://github.com/jakgibb/goxi

开源协议:

下载


GoDoc
Go Report Card

Go XI

Go XI is a Golang library for interacting with the Nagios XI REST API allowing retrieval of information of hosts and services within the system

Usage

Clone the repository or use go get:

  1. $ go get https://github.com/jakgibb/goxi

Import the library into your project:

  1. import "github.com/jakgibb/goxi"

Examples

The library allows retreiving information of any host or service; optional filters can be configured to only query a subset of data

Example to retrieve informaion on specific hosts:

  1. // Create a client object passing into the URL of the Nagios instance and API key
  2. // The client is stateless and so can be reused
  3. client := goxi.NewClient(
  4. "https://nagios.example/nagiosxi",
  5. "apiKeyFromUserDashboard",
  6. )
  7. // Set up a Host Filter to retrieve information for hosts: server-a and server-b
  8. // See filter.go for a list of all available filters available
  9. hostFilter := goxi.HostFilter{
  10. Name: []string{"server-a", "server-b"},
  11. }
  12. // Pass the filter to GetHosts which will make a API call and retrieve all information for the two hosts
  13. // and return a slice of Host structs and an error value (nil for no error)
  14. hosts, err := client.GetHosts(hostFilter)
  15. if err != nil {
  16. fmt.Println(err)
  17. }
  18. // Range over the results and print the name of the host, address and alias
  19. // See host.go for a list of all available fields that can be accessed
  20. for _, v := range *hosts {
  21. fmt.Printf("Host: %s - Address: %s - Alias: %s", v.Name, v.Address, v.Alias)
  22. }
  23. `

Example to retrieve information on specific services:

  1. // Retrieve information for all services which are assigned the 'Linux Disk space' check
  2. // Limit the number of results returned to 10
  3. serviceFilter := goxi.ServiceFilter{
  4. Name: []string{"Linux Disk Space"},
  5. Records: "10",
  6. }
  7. services, err := client.GetServices(serviceFilter)
  8. if err != nil {
  9. fmt.Println(err)
  10. }
  11. for _, v := range *services {
  12. fmt.Printf("Service: %s - Check Command: %s - Status Output: %s", v.Name, v.CheckCommand, v.StatusText)
  13. }

To retireve information on all hosts or services, pass in an empty filter

  1. // To return the status information for all hosts or services, pass an empty filter
  2. serviceFilter := goxi.ServiceFilter{}
  3. hostFilter := goxi.HostFilter{}

More information on the Nagios API can be found within the ‘Help’ section of the dashboard

License

  1. GNU GENERAL PUBLIC LICENSE
  2. Version 3, 29 June 2007