Code Monkey home page Code Monkey logo

go-nagios's Introduction

go-nagios

Golang package for Nagios plugins

Usage

import "github.com/xorpaul/go-nagios"
ExecuteCommand

VARIABLES

var (
    Debug bool
)


FUNCTIONS

func Debugf(s string)
    Debugf is a helper function for debug logging if Debug is true

func NagiosExit(nr NagiosResult)
    NagiosExit uses the NagiosResult struct to output Nagios plugin
    compatible output and exit codes


TYPES

type ExecResult struct {
    ReturnCode int
    Output     string
}


func ExecuteCommand(command string, timeout int, allowFail bool) ExecResult
    ExecuteCommand executes a shell command and provides the stdout and
    stderr output combined and the exit code. First arg is the command to
    execute as a simple string. Second arg is a timeout parameter as a int
    after which to kill the command and return. Third arg is a bool flag if
    the command is allowed to fail or not.



type NagiosResult struct {
    ExitCode  int
    Text      string
    Perfdata  string
    Multiline []string
}

Example usage

// create NagiosResult with default values (UNKNOWN in this case)
nr := nagios.NagiosResult{ExitCode: 3, Text: "uncatched case", Perfdata: ""}

// execute a command with ExecuteCommand
er := nagios.ExecuteCommand("nfsstat -c -l", 1, false)
nr = doSomethingWithTheCommandOutputOrExitCode(er.Output)

nagios.NagiosExit(nr)

Look at https://github.com/xorpaul/check_nfs_client as an example.

go-nagios's People

Contributors

xorpaul avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

unlimitedheaven

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.