Git Product home page Git Product logo

nscapi's Introduction

NSCAPI: a server that ingests nsca calls and exposes the result via a json API

TravisBuild

Introduction

Nscapi is a go application meant to help moving from a nsca model to a pull model by providing a JSON endpoint to summarize the state of the nsca calls it received.

The tool is split into 3 main parts:

  • Server that receive nsca calls and put them in a non-locking queue
  • Worker that reads from the non-locking queue and put the data in a cache
  • HTTP server that will read from the cache and display the check results in a json format in response to a call on /api/reports based on a template. The rest of the calls will display a usage summary based on another template

Usage

Command-line options

To try to stick to the 12 factors principle, our configuration can be provider from command-line arguments but also from environment variables. Note that the command-line arguments have a higher priority than the environment variables.

Usage of ./nscapi:
  -api-ip string
    	IP the API should listen on. Default to the NSCAPI_API_IP environment variable. Fallback: 0.0.0.0 (default "0.0.0.0")
  -api-port uint
    	Port the API should listen on. Default to the NSCAPI_API_PORT environment variable. Fallback: 8080 (default 8080)

  -api-templates-root string
    	Root directory the API should use to look for its templates (root.tmpl and reports_element.tmpl). Default to the NSCAPI_API_TEMPLATES_ROOT environment variable. Fallback: templates (default "templates")

  -api-custom-fields-root string
    	Root directory the API should use as root of the custom fields hierarchy. Default to the NSCAPI_API_CUSTOM_FIELDS_ROOT environment variable. Fallback: custom_fields (default "custom_fields")

  -nsca-server-ip string
    	IP the NSCA server should listen on. Default to the NSCAPI_NSCA_IP environment variable. Fallback: 0.0.0.0 (default "0.0.0.0")
  -nsca-server-port uint
    	Port the NSCA server should listen on. Default to the NSCAPI_NSCA_PORT environment variable. Fallback: 5667 (default 5667)

  -nsca-server-password string
    	Password the NSCA server should use. Default to the NSCAPI_NSCA_PASSWORD environment variable. Fallback: ''

  -nsca-server-encryption uint
    	Number corresponding to the encryption to be used by the NSCA server. Default to the NSCAPI_NSCA_ENCRYPTION environment variable. Fallback: 0. See 'DECRYPTION METHOD' on https://github.com/NagiosEnterprises/nsca/blob/master/sample-config/nsca.cfg.in for more details. Must be <27.

The list of encryption algorithm code number can be found here

In this example, the API server will run on port 8081 (listening on all available network interfaces), the NSCA server will be listening on localhost on port 5668, without encryption:

export NSCAPI_NSCA_IP=localhost
./nscapi -nsca-server-port 5668

Note that we recommend not to mix the environment variables and command-line arguments as it might end up being confusing. Just use either of them and stick to it for readability (the application has no problem handling both but whoever take back the work after might be confused).

Custom fields

A custom field is a key-value couple that is not contained in the nsca check itself but will be returned by the API based on the values of the check itself.

The custom fields are defined in a hiera-style hierarchy.

Provided that:

  • %{hostgroup} is the hostname received in the nsca check result minus any trailing number
  • %{check name} is the name of the check as received in the nsca check result

The level of importance is defined as follows:

  • common.yaml is where the default values are defined.
  • service/%{hostgroup}/all.yaml is where you define the default values of your custom fields per host group. It has the priority over the custom fields already defined in common.yaml and can also add new fields of its own. If a host don't match any of the defined hostgroups, only the custom fields defined in common.yaml will be applied.
  • service/%{hostgroup}/%{check name}.yaml has the highest priority. Any field value in this file will overwrite the values of the previously defined custom fields.

Using the Makefile

The Makefile is used as a helper for building and testing the project. Current capabilities:

  • 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 dep: gets (with update option -u) the go dependencies required by the application
  • make build: runs make dep and make test before running a clean and build the binary
  • make install: runs make dep and make test before running a clean and install the application
  • make / make all: run make test and make race

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 most likely not be accepted (we can help building the tests if needed).

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

nscapi's People

Contributors

aerostitch avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

aerostitch ynnt

nscapi's Issues

Ideas for the HTTP API engine improvments

the http api engine

  • access the list of hosts in the cache /api/hosts
  • access checks results by host /api/host/{hostName}
  • access check list by host /api/host/{hostName}/checks
  • access the list of checks on a host /api/checks/{hostName}
  • access a check on a specific host /api/check/{hostName}/{checkName}
  • access by check on all hosts /api/reports/{checkName}

Cache improvements

1 cache worker:

  • track current status start timestamp => see PR #12
  • function that takes the data from the cache and pushes it to disk
  • function that loads the data from json on start
  • cache entry expiration policy

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.