GithubHelp home page GithubHelp logo

isabella232 / nscatools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tubemogul/nscatools

0.0 0.0 0.0 47 KB

A flexible NSCA server and client written in Go

License: Apache License 2.0

Makefile 2.18% Go 97.82%

nscatools's Introduction

Nsca tools library

GoDoc TravisBuild

Introduction

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

Prerequisites

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).

Usage examples

Create a NSCA server

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 (
  nsca "github.com/tubemogul/nscatools"
  "log"
  "os"
)

var dbg *log.Logger

func printData(p *nsca.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 := nsca.NewConfig("localhost", 5667, nsca.EncryptXOR, "toto", printData)
  nsca.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

Create a NSCA client

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"
  nsca "github.com/tubemogul/nscatools"
)

func main() {
  cfg := nsca.NewConfig("localhost", 5667, nsca.EncryptXOR, "toto", nil)
  err := nsca.SendStatus(cfg, "myHost", "my service", nsca.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")
  }
}

Using the Makefile

  • make lint: runs golint on your files (requires github.com/golang/lint/golint installed)
  • make fmt: checks that the files are compliant with the gofmt format
  • make vet: runs go tool vet on your files to ensure there's no problems
  • make test: runs make lint, make fmt, make vet before running all the test, printing also the percentage of code coverage
  • make race: runs the tests with the -race option to detect race conditions
  • make bench: runs the benchmarks
  • make gocov: runs a gocov report (requires github.com/axw/gocov/gocov)
  • make install: runs make test before running a clean and install
  • make / make all: run make test, make race and make bench

Contributions

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! :)

nscatools's People

Contributors

aerostitch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.