nrpe

package module
v0.0.0-...-f18abc5 Latest Latest
Warning

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

Go to latest
Published: May 30, 2016 License: MIT Imports: 10 Imported by: 0

README

nrpe client/server library

GoDoc Build Status Go Report Card Coverage Status

Package envimate/nrpe implements NRPE client/server library for go.

It supports plain and ssl modes and fully compatible with standard nrpe library. Hence you would need libssl-dev package installed on both the client and the server side. You would also need gcc to build the package.

Package includes check_nrpe command, which is alternate implementation of homonymous command shipped with nrpe package.

Requires libssl to compile and run.

Client Example

package main

import (
        "fmt"
        "github.com/envimate/nrpe"
        "net"
        "os"
)

func main() {
        conn, err := net.Dial("tcp", "127.0.0.1:5666")
        if err != nil {
                fmt.Println(err)
                return
        }

        command := nrpe.NewCommand("check_load")

        // ssl = true, timeout = 0
        result, err := nrpe.Run(conn, command, true, 0)
        if err != nil {
                fmt.Println(err)
                return
        }

        fmt.Println(result.StatusLine)
        os.Exit(int(result.StatusCode))
}

Server Example

package main

import (
	"fmt"
	"net"

	"github.com/envimate/nrpe"
)

func nrpeHandler(c nrpe.Command) (*nrpe.CommandResult, error) {
	// handle nrpe command here

	return &nrpe.CommandResult{
		StatusLine: "COMMAND=" + c.Name,
		StatusCode: nrpe.StatusOK,
	}, nil
}

func connectionHandler(conn net.Conn) {
	defer conn.Close()
	nrpe.ServeOne(conn, nrpeHandler, true, 0)
}

func main() {
	ln, err := net.Listen("tcp", ":5667")

	if err != nil {
		fmt.Println(err)
		return
	}

	for {
		conn, err := ln.Accept()

		if err != nil {
			fmt.Println(err)
			continue
		}

		go connectionHandler(conn)
	}
}

In-depth examples

You can also checkout our blog-post for the client and server for in-depth description and usage example with real microservice.

Checkout and compile check_nrpe

checkout

go get github.com/envimate/nrpe

compile

go build github.com/envimate/nrpe/cmd/check_nrpe

Documentation

Overview

Package nrpe implements NRPE client/server library for go.

It supports plain and ssl modes and fully compatible with standard nrpe library. Hence you would need libssl-dev package installed on both the client and the server side.

Index

Examples

Constants

View Source
const (
	StatusOK       = 0
	StatusWarning  = 1
	StatusCritical = 2
	StatusUnknown  = 3
)

Result status codes

Variables

This section is empty.

Functions

func ServeOne

func ServeOne(conn net.Conn, handler func(Command) (*CommandResult, error),
	isSSL bool, timeout time.Duration) error

ServeOne function will handle one request. After receiving request it will call handler callback function and the result of callback will be sent to requester.

Types

type Command

type Command struct {
	Name string
	Args []string
}

Command represents command name and argument list

func NewCommand

func NewCommand(name string, args ...string) Command

NewCommand creates Command object with the given name and optional argument list

type CommandResult

type CommandResult struct {
	StatusLine string
	StatusCode CommandStatus
}

CommandResult holds information returned from nrpe server

func Run

func Run(conn net.Conn, command Command, isSSL bool,
	timeout time.Duration) (*CommandResult, error)

Run specified command

Example
conn, err := net.Dial("tcp", "127.0.0.1:5666")
if err != nil {
	fmt.Println(err)
	return
}

command := NewCommand("check_load")

// ssl = true, timeout = 0
result, err := Run(conn, command, true, 0)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println(result.StatusLine)
os.Exit(int(result.StatusCode))
Output:

type CommandStatus

type CommandStatus int

CommandStatus represents result status code

Directories

Path Synopsis
cmd
check_nrpe
check_nrpe is a command line NRPE client.
check_nrpe is a command line NRPE client.

Jump to

Keyboard shortcuts

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