Documentation ¶
Overview ¶
Host definition
Service definition
Index ¶
- Constants
- func DecodeNagiosCmd(cmd string) (name string, args []string, err error)
- func EncodeHostCheck(h Host) string
- func EncodeServiceCheck(s Service) string
- type Command
- type CommonFields
- type Host
- type HostCount
- type Notification
- type NrpeConfig
- type NrpePacket
- func (r *NrpePacket) CheckCRC()
- func (r *NrpePacket) Generate(w io.Writer) (err error)
- func (r *NrpePacket) GenerateBytes() (b []byte, err error)
- func (r *NrpePacket) GetMessage() (str string, err error)
- func (r *NrpePacket) PrepareRequest() (err error)
- func (r *NrpePacket) PrepareResponse() (err error)
- func (r *NrpePacket) SetMessage(msg string) (err error)
- type Service
- type ServiceCount
- type Status
- type Summary
Examples ¶
Constants ¶
const ( CmdAcknowledgeHostProblem = "ACKNOWLEDGE_HOST_PROBLEM" CmdAcknowledgeServiceProblem = "ACKNOWLEDGE_SVC_PROBLEM" // Schedule downtime and propagate to children CmdScheduleRecursiveDowntime = "SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME" // Schedule downtime and propagate to childrenon trigger CmdScheduleRecursiveTriggeredDowntime = "SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME" CmdScheduleForcedHostCheck = "SCHEDULE_FORCED_HOST_CHECK" CmdScheduleForcedServiceCheckAll = "SCHEDULE_FORCED_HOST_SVC_CHECKS" CmdScheduleForcedServiceCheck = "SCHEDULE_FORCED_SVC_CHECK" // Schedule downtime of all hosts in hostgroup CmdScheduleHostgroupHostsDowntime = "SCHEDULE_HOSTGROUP_HOST_DOWNTIME" // Schedule downtime of all services on hosts in hostgroup CmdScheduleHostgroupServiceDowntime = "SCHEDULE_HOSTGROUP_SVC_DOWNTIME" CmdScheduleHostCheck = "SCHEDULE_HOST_CHECK" CmdScheduleHostDowntime = "SCHEDULE_HOST_DOWNTIME" CmdScheduleHostServiceCheckAll = "SCHEDULE_HOST_SVC_CHECKS" CmdScheduleHostServiceDowntimeAll = "SCHEDULE_HOST_SVC_DOWNTIME" // schedule downtime for all hosts that have service in servicegroup CmdScheduleServicegroupHostDowntime = "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME" // schedule downtime for all services in the servicegroup CmdScheduleServicegroupServiceDowntime = "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME" CmdScheduleServiceCheck = "SCHEDULE_SVC_CHECK" CmdScheduleServiceDowntime = "SCHEDULE_SVC_DOWNTIME" // Process passive checks CmdProcessHostCheckResult = "PROCESS_HOST_CHECK_RESULT" CmdProcessServiceCheckResult = "PROCESS_SERVICE_CHECK_RESULT" )
const ( NrpeTypeQuery = 1 NrpeTypeResponse = 2 )
Nrpe packet types
const NRPE_MAX_PACKETBUFFER_LENGTH = 1024 // this length is hardcoded in nrpe.c
const NrpePacketSize = 1036 // struct size + 2 bytes. No idea why, but nrpe C client requires it
const StateCritical = "CRITICAL"
const StateDown = "DOWN"
const StateOk = "OK"
const StateUnknown = "UNKNOWN"
const StateUnreachable = "UNREACHABLE"
const StateUp = "UP"
const StateWarning = "WARNING"
Variables ¶
This section is empty.
Functions ¶
func DecodeNagiosCmd ¶ added in v0.0.2
func EncodeHostCheck ¶ added in v0.0.2
Encode host status into host check string (without PASSIVE_HOST_CHECK_RESULT header)
func EncodeServiceCheck ¶ added in v0.0.2
Types ¶
type Command ¶ added in v0.0.2
type Command struct { Filename string // contains filtered or unexported fields }
func NewCmd ¶ added in v0.0.2
NewCmd() creats command interface to a given command file. It should already exist (FIFO created by nagios)
type CommonFields ¶ added in v0.0.2
type CommonFields struct { sync.RWMutex Hostname string `json:"hostname,omitempty"` DisplayName string `json:"display_name,omitempty"` CheckMessage string `json:"check_message,omitempty"` State string `json:"state,omitempty"` PreviousState string `json:"previous_state,omitempty"` LastCheck time.Time `json:"last_check,omitempty"` NextCheck time.Time `json:"next_check,omitempty"` LastHardStateChange time.Time `json:"last_hard_state_change,omitempty"` LastStateChange time.Time `json:"last_state_change,omitempty"` StateHard bool `json:"state_hard"` Acknowledged bool `json:"ack"` Flapping bool `json:"flapping"` Downtime bool `json:"downtime"` NotificationsEnabled bool `json:"notifications_enabled"` }
update fields shared by host and service
func (*CommonFields) UpdateCommonFromMap ¶ added in v0.0.2
func (c *CommonFields) UpdateCommonFromMap(m map[string]string, dataType int) error
update common fields of service/host dataType should be either isService or isHost
func (*CommonFields) UpdateStatus ¶ added in v0.0.2
func (c *CommonFields) UpdateStatus(status string, message string)
type Host ¶
type Host struct { CommonFields HostGroups []string `json:"hostgroups"` Address string `json:"address"` Parents *[]Host `json:"parents"` }
func DecodeHostCheck ¶ added in v0.0.2
Decode host check string
func NewHostFromArgs ¶ added in v0.0.2
NewHostFromArgs creates host from nagios cmd args slice
func NewHostFromEnv ¶
Create host object from nagios env variables
func (*Host) MarshalCmd ¶ added in v0.0.2
type Notification ¶
type Notification struct { Host Host `json:"hostname"` Service Service `json:"service,omitempty"` Type string `json:"type"` Recipients []string `json:"recipients,omitempty"` HostState string `json:"host_state"` HostStateHard bool `json:"host_state_hard"` HostStateDuration time.Duration `json:"host_state_duration"` ServiceState string `json:"service_state,omitempty"` ServiceStateHard bool `json:"sevice_state_hard,omitempty"` ServiceStateDuration time.Duration `json:"service_state_duration,omitempty"` IsHost bool `json:"is_host,omitempty"` IsService bool `json:"is_service,omitempty"` }
Notification types:
*
func NewNotification ¶
func NewNotification() Notification
func NewNotificationFromEnv ¶
func NewNotificationFromEnv() (Notification, error)
Create notification from env passed by nagios Intended to be used with nagios notification command
type NrpeConfig ¶ added in v0.0.2
func ParseNrpeConfig ¶ added in v0.0.2
func ParseNrpeConfig(data io.Reader) (cfg NrpeConfig, err error)
Limitations: only key-value config so you can have config with only one include and only one include_dir
type NrpePacket ¶ added in v0.0.2
type NrpePacket struct { Version int16 Type int16 Crc uint32 ResultCore int16 Buffer [NRPE_MAX_PACKETBUFFER_LENGTH]byte Tail [2]byte // doesn't work without it, even if common.h packet struct says it should be 1024, it only works when total buffer is 1026 bytes }
Example ¶
sock, _ := net.Listen("tcp", ":5666") for { conn, _ := sock.Accept() go func(conn net.Conn) { req, _ := ReadNrpe(conn) msg, _ := req.GetMessage() fmt.Printf("request: %s\n", msg) var resp NrpePacket resp.SetMessage("OK") resp.PrepareResponse() // send response resp.Generate(conn) // and close conn.Close() }(conn) }
Output:
func ReadNrpeBytes ¶ added in v0.0.2
func ReadNrpeBytes(b []byte) (p *NrpePacket, err error)
func (*NrpePacket) CheckCRC ¶ added in v0.0.2
func (r *NrpePacket) CheckCRC()
func (*NrpePacket) Generate ¶ added in v0.0.2
func (r *NrpePacket) Generate(w io.Writer) (err error)
func (*NrpePacket) GenerateBytes ¶ added in v0.0.2
func (r *NrpePacket) GenerateBytes() (b []byte, err error)
func (*NrpePacket) GetMessage ¶ added in v0.0.2
func (r *NrpePacket) GetMessage() (str string, err error)
func (*NrpePacket) PrepareRequest ¶ added in v0.0.2
func (r *NrpePacket) PrepareRequest() (err error)
calculate crc, set version and type Should be called before generating packet
func (*NrpePacket) PrepareResponse ¶ added in v0.0.2
func (r *NrpePacket) PrepareResponse() (err error)
func (*NrpePacket) SetMessage ¶ added in v0.0.2
func (r *NrpePacket) SetMessage(msg string) (err error)
max 1023 BYTES(not characters), it WILL truncate it if you add more
type Service ¶
type Service struct { CommonFields Description string `json:"description,omitempty"` ServiceGroups []string `json:"servicegroups,omitempty"` // list of service groups this service belongs to Volatile bool `json:"volatile,omitempty"` Contacts []string `json:"contacts,omitempty"` // list of service contacts ContactGroups []string `json:"contactgroups,omitempty"` // list of service contact groups }
func DecodeServiceCheck ¶ added in v0.0.2
func NewService ¶
func NewService() Service
func NewServiceFromArgs ¶ added in v0.0.2
func NewServiceFromEnv ¶
create service from nagios env variables
func NewServiceFromMap ¶ added in v0.0.2
Generate service data from key/value pairs in "status.dat" format
func (*Service) MarshalCmd ¶ added in v0.0.2
type ServiceCount ¶ added in v0.0.2
type Status ¶ added in v0.0.2
type Summary ¶ added in v0.0.2
type Summary struct { HostCount `json:"all_host"` ServiceCount `json:"all_service"` }