Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

otaviof/gonrpe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gonrpe Go Adapter for NRPE Protocol

Abstract

This is a simple Go implementation of NRPE protocol, where you can receive and respond check_nrpe calls, in other words, Nagios passive check calls handled by your own Go based daemon.

CGo Based

By using CGo based implementation we can have the same data struct sent by check_nrpe on the Go side, and then transformed into a pure Go struct.

Usage

First of all have the source code on your workstatation, by using:

go get -v github.com/otaviof/gonrpe

Example Snippet

And then on your own project, you might be looking for supporting Nagios’ NRPE type of packets on the network level, so consider this basic example using Go’s net package to accept connections on 5666 port:

package main

import (
    "github.com/otaviof/gonrpe"
    "log"
    "net"
)

func main() {
    var listener net.Listener
    var conn net.Conn
    var buf []byte
    var n int
    var err error
    var pkt *gonrpe.NrpePacket
    var cmd string
    var args []string

    listener, _ = net.Listen("tcp", "0.0.0.0:5666")

    for {
        // accept a new connection on the network listener
        conn, _ = ns.listener.Accept()
        defer conn.Close()

        // allocating the buffer using default NRPE packet size
        buf = make([]byte, gonrpe.NRPE_PACKET_SIZE)

        // reading connection payload into "buf" slice of bytes
        if n, err = conn.Read(buf); n == 0 || err != nil {
            log.Println("Error on reading from connection:", err)
            continue
        }

        // transforming bytes into a NRPE packet object
        pkt, _ = gonrpe.NewNrpePacket(buf, n)

        // from a packet we can have the command and it's arguments
        if cmd, args, err = pkt.ExtractCmdAndArgsFromBuffer(); err != nil {
            panic("Error on parsing packet's buffer:", err)
        }

        log.Printf("Received (Command: '%s', Arguments: '%v')", cmd, args)

        /* Do something else... */
    }
}

Limitations

This project is not yet tested on production environments, nor part of a more feature rich project like employing SSL based connection, so feel free to report bugs and let me know the outcomes of your attempts.

Contributing

Fork this project and have a look on the tests suite, for example:

go test -v github.com/otaviof/gonrpe

When you’re done, please send pull-request. Thanks!

About

Nagios' NRPE packet support for Go.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages