This library is based Nagios's NSCA server but written in Go.
The goal is to have a library to receive the nsca calls and do whatever you want with the data you receive. Working on that for another application I'm writing.
The technical documentation is available on godoc: https://godoc.org/github.com/tubemogul/nscatools
For now, due to libmcrypt specificities, this library uses directly the C
bindings of libmcrypt, so you will need the libmcrypt4
and libmcrypt-dev
packages installed (at least that's their names on Debian-based systems).
This example shows how to use this library to the detail of every packets you receive. Not very useful as is but simple enough for everybody to understand it.
package main
import (
nsrv "github.com/tubemogul/nscatools"
"log"
"os"
)
var dbg *log.Logger
func printData(p *nsrv.DataPacket) error {
dbg.Printf("version: %d\n", p.Version)
dbg.Printf("crc: %d\n", p.Crc)
dbg.Printf("timestamp: %d\n", p.Timestamp)
dbg.Printf("state: %d\n", p.State)
dbg.Printf("hostname: %s\n", p.HostName)
dbg.Printf("service: %s\n", p.Service)
dbg.Printf("Plugin output: %s\n", p.PluginOutput)
return nil
}
func main() {
debugHandle := os.Stdout
dbg = log.New(debugHandle, "[DEBUG] ", log.Ldate|log.Ltime|log.Lshortfile)
cfg := nsrv.NewConfig("localhost", 5667, nsrv.EncryptXOR, "toto", printData)
nsrv.StartServer(cfg, true)
}
To do functionnal testing, you can, for example, use the following send_nsca.cfg file:
password=toto
encryption_method=1
And use the following command:
echo "myhost mysvc 1 mymessage" | sudo /usr/sbin/send_nsca -H 127.0.0.1 -p 5667 -d ' ' -c send_nsca.cfg
This example shows how to implement a nsca client using this library. You can use it directly with the running server you created in the previous example.
package main
import (
"fmt"
nsrv "github.com/tubemogul/nscatools"
)
func main() {
cfg := nsrv.NewConfig("localhost", 5667, nsrv.EncryptXOR, "toto", nil)
err := nsrv.SendStatus(cfg, "myHost", "my service", nsrv.StateWarning, "You'd better fix me before I go critical")
if err != nil {
fmt.Printf("SendStatus returned an error: %s\n", err)
} else {
fmt.Println("Packet sent successfuly")
}
}
make lint
: runs golint on your files (requiresgithub.com/golang/lint/golint
installed)make fmt
: checks that the files are compliant with the gofmt formatmake vet
: runsgo tool vet
on your files to ensure there's no problemsmake test
: runsmake lint
,make fmt
,make vet
before running all the test, printing also the percentage of code coveragemake race
: runs the tests with the-race
option to detect race conditionsmake bench
: runs the benchmarksmake gocov
: runs a gocov report (requiresgithub.com/axw/gocov/gocov
)make install
: runsmake test
before running a clean and installmake
/make all
: runmake test
,make race
andmake bench
Contributions to this project are welcome, though please file an issue. before starting work on anything major as someone else could already be working on it.
Contributions that do not provide the corresponding tests will not be accepted. Contributions that do not pass the basic gofmt, vet and other basic checks provided in the Makefile will not be accepted. It's just a question of trying to keep a basic code standard. Thanks for your help! :)
For now the following algorithms are not properly handled, so they need to be fixed:
- 3WAY
- ARCFOUR
- WAKE
- ENIGMA
- SAFER64
- SAFER128
Nice to have:
- get rid of the libmcrypt C bindings to rely only on pure Go
- write examples
- write more benchmark