Skip to content

envimate/nrpe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

NRPE nagios plugin client and server implementation in golang

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages