cmkapi

package module
Version: v0.0.0-...-e721445 Latest Latest
Warning

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

Go to latest
Published: May 16, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

cmkapi

This is a Check_MK API client implementation written in go. It's focused on Check_MK 1.5.x and may also work with earlier versions.

Before you run - make sure you have created the automation user in check_mk. For details please refer - https://mathias-kettner.de/checkmk_wato_webapi.

You have to use the existing TAG's defined in WATO , for standard installation its **Agent-Type - cmk-agent,snmp-only,snmp-v1,snmp-tcp,ping ** Criticality-Tag - prod,critical,test,offline

Work in Progress, created specifically for Terraform provider for check_mk

example

package main
import (
        "github.com/junaid18183/cmkapi"
//      "fmt"
)

func main() {

        // account credentials and url to connect to grafana
        user := "autouser"
        pass := "UPFKWAJJDPJWTOQMOWHY"
        host := "192.168.99.100:32768"
        sitename := "mva"
        client,error := cmkapi.NewClient(user,pass,host,sitename)

        if error == nil {
                //client.CreateHost("HostName", "Folder","Alias of host", "Agent-Type{cmk-agent,snmp-only,snmp-v1,snmp-tcp,ping}","Criticality-Tag{prod,critical,test,offline}","IP Address")
                client.CreateHost("winxp_1", "os/windows","Alias of winxp_1", "cmk-agent","prod","127.0.0.1")
                client.ReadHost("winxp_1")
                client.DeleteHost("winxp_1")

        }
}

Author

junaid18183

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivateResult

type ActivateResult struct {
	Result     activateResultSites `json:"result"`
	ResultCode int                 `json:"result_code"`
}

ActivateResult holds the result of a Check_MK webAPI update

type Attributes

type Attributes struct {
	Alias          string `json:"alias"`
	TagAgent       string `json:"tag_agent"`
	TagCriticality string `json:"tag_criticality"`
	Ipaddress      string `json:"ipaddress"`
}

Attributes describes the needed/optional tags for the Check_MK webAPI

type CheckMKException

type CheckMKException struct {
	Result     string `json:"result"`
	ResultCode int    `json:"result_code"`
}

CheckMKException holds exceptions thrown by CheckMK

type Client

type Client struct {
	User     string
	Password string
	Host     string
	// contains filtered or unexported fields
}

Client holds the struct for connecting to a Check_MK instance

func NewClient

func NewClient(user, password, host string) (*Client, error)

NewClient is the skeleton for instantiating a new Check_MK connection

func (*Client) ActivateChanges

func (c *Client) ActivateChanges() error

ActivateChanges activates the pending changes done to Check_MK after create/update/delete

func (*Client) CreateHost

func (c *Client) CreateHost(hostname string, folder string, activate bool, alias string, tag_agent string, tag_criticality string, ipaddress string) error

CreateHost creates a new host

func (*Client) DeleteHost

func (c *Client) DeleteHost(host string) error

DeleteHost deletes a host

func (*Client) NewAPIRequest

func (c *Client) NewAPIRequest(method, APICall string, body io.Reader) (resp_body []byte, resp_error error)

NewAPIRequest sends and receives the Check_MK webAPI

func (*Client) ReadALLHost

func (c *Client) ReadALLHost() error

ReadALLHost returns all hosts

func (*Client) ReadHost

func (c *Client) ReadHost(host string) (*Host, error)

ReadHost returns a single host

type Host

type Host struct {
	Attributes `json:"attributes"`
	Hostname   string `json:"hostname"`
	Folder     string `json:"folder"`
}

Host holds the data for a single host

type StructGetHostResult

type StructGetHostResult struct {
	Result struct {
		Attributes struct {
			NetworkScan struct {
				ScanInterval  int           `json:"scan_interval"`
				ExcludeRanges []interface{} `json:"exclude_ranges"`
				IPRanges      []interface{} `json:"ip_ranges"`
				RunAs         string        `json:"run_as"`
			} `json:"network_scan"`
			TagAgent          string        `json:"tag_agent"`
			SnmpCommunity     string        `json:"snmp_community"`
			Ipv6Address       string        `json:"ipv6address"`
			Alias             string        `json:"alias"`
			TagCriticality    string        `json:"tag_criticality"`
			Site              string        `json:"site"`
			TagAddressFamily  string        `json:"tag_address_family"`
			Contactgroups     contactGroups `json:"contactgroups"`
			NetworkScanResult struct {
				Start  interface{} `json:"start"`
				State  interface{} `json:"state"`
				End    interface{} `json:"end"`
				Output string      `json:"output"`
			} `json:"network_scan_result"`
			Parents       []interface{} `json:"parents"`
			Ipaddress     string        `json:"ipaddress"`
			TagNetworking string        `json:"tag_networking"`
		} `json:"attributes"`
		Hostname string `json:"hostname"`
		Path     string `json:"path"`
	} `json:"result"`
	ResultCode int `json:"result_code"`
}

StructGetHostResult holds the results of a Check_MK webAPI answer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL