Loading pkg/nagios/check.go 0 → 100644 +76 −0 Original line number Diff line number Diff line /* Deal with Nagios plugin checks. Mainly running the command and checking the exit code. */ package nagios import ( "errors" "os/exec" ) /* Although exit codes can't be a negative, int is used to match ExitCode in os.ProcessState. */ type ReturnCode int /* The agreed upon exit codes that a plugin uses to pass the state of the check. */ const ( OK ReturnCode = 0 WARNING = 1 CRITICAL = 2 UNKNOWN = 3 ) /* Represents a check that is going to run or has run. */ type Check struct { Command string Args []string Code int Result ReturnCode } /* Returns a new Check struct, one that hasn't run yet. */ func New(command string, args []string) (*Check, error) { if command == "" { return nil, errors.New("Empty command.") } check := new(Check) check.Command = command check.Args = args check.Code = -1 check.Result = -1 return check, nil } /* Run a check that hasn't been run yet. */ func Run(check Check) error { if check.Command == "" { return errors.New("Empty command.") } if check.Code != -1 { return errors.New("Command has already run.") } cmd := exec.Command(check.Command, check.Args...) err := cmd.Run() if err == nil { check.Code = 0 check.Result = OK return nil } check.Code = cmd.ProcessState.ExitCode() if check.Code == WARNING || check.Code == CRITICAL || check.Code == UNKNOWN { check.Result = ReturnCode(check.Code) return nil } return err } pkg/nagios/nagios.godeleted 100644 → 0 +0 −12 Original line number Diff line number Diff line package nagios // Although exit codes can't be a negative, int is used to match // ExitCode in *os.ProcessState. type ReturnCode int const ( OK ReturnCode = 0 WARNING = 1 CRITICAL = 2 UNKNOWN = 3 ) Loading
pkg/nagios/check.go 0 → 100644 +76 −0 Original line number Diff line number Diff line /* Deal with Nagios plugin checks. Mainly running the command and checking the exit code. */ package nagios import ( "errors" "os/exec" ) /* Although exit codes can't be a negative, int is used to match ExitCode in os.ProcessState. */ type ReturnCode int /* The agreed upon exit codes that a plugin uses to pass the state of the check. */ const ( OK ReturnCode = 0 WARNING = 1 CRITICAL = 2 UNKNOWN = 3 ) /* Represents a check that is going to run or has run. */ type Check struct { Command string Args []string Code int Result ReturnCode } /* Returns a new Check struct, one that hasn't run yet. */ func New(command string, args []string) (*Check, error) { if command == "" { return nil, errors.New("Empty command.") } check := new(Check) check.Command = command check.Args = args check.Code = -1 check.Result = -1 return check, nil } /* Run a check that hasn't been run yet. */ func Run(check Check) error { if check.Command == "" { return errors.New("Empty command.") } if check.Code != -1 { return errors.New("Command has already run.") } cmd := exec.Command(check.Command, check.Args...) err := cmd.Run() if err == nil { check.Code = 0 check.Result = OK return nil } check.Code = cmd.ProcessState.ExitCode() if check.Code == WARNING || check.Code == CRITICAL || check.Code == UNKNOWN { check.Result = ReturnCode(check.Code) return nil } return err }
pkg/nagios/nagios.godeleted 100644 → 0 +0 −12 Original line number Diff line number Diff line package nagios // Although exit codes can't be a negative, int is used to match // ExitCode in *os.ProcessState. type ReturnCode int const ( OK ReturnCode = 0 WARNING = 1 CRITICAL = 2 UNKNOWN = 3 )