Commit 73a696a6 authored by nimrod's avatar nimrod
Browse files

Remove Go code.

I'm disappointed with the Go language. I find it inadequate for this
project so I'm deleting the Go code and I'm going to rewrite it in
Python. For the single binary I'm going to use Pyinstaller (I think).
parent 62f1a2f4
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -2,19 +2,3 @@
include:
  - project: shore/ci-templates
    file: templates/pre-commit.yml

before_script:
  - >-
    echo 'deb http://deb.debian.org/debian buster-backports main'
    >> /etc/apt/sources.list
  - apt-get update
  - apt-get install -y -t buster-backports golang
  - go version

build:
  stage: build
  image: registry.hub.docker.com/library/golang:1.16-alpine
  before_script:
    - go build
  script:
    - ./mnpw -h
+0 −6
Original line number Diff line number Diff line
@@ -37,9 +37,3 @@ repos:
        args:
          - "--server"
          - https://git.shore.co.il

  - repo: https://github.com/tekwizely/pre-commit-golang.git
    rev: v0.8.3
    hooks:
      - id: go-fmt
      - id: go-vet

go.mod

deleted100644 → 0
+0 −3
Original line number Diff line number Diff line
module git.shore.co.il/shore/mnpw

go 1.15

mnpw.go

deleted100644 → 0
+0 −27
Original line number Diff line number Diff line
package main

import (
	"flag"
	"fmt"
	//	"git.shore.co.il/shore/mnpw/pkg/nagios"
	"os"
)

func main() {
	var verbose bool
	var args []string
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "My Nagios Plugin Wrapper\n")
		fmt.Fprintf(os.Stderr, "Usage of %s: [OPTION] command [parameter [parameter] ...]\n", os.Args[0])
		flag.PrintDefaults()
	}
	flag.BoolVar(&verbose, "verbose", false, "Enable verbose output.")
	flag.BoolVar(&verbose, "v", false, "Enable verbose output (shorthand).")
	flag.Parse()
	args = flag.Args()
	if len(args) == 0 {
		flag.Usage()
		os.Exit(3)
	}
	os.Exit(0)
}

pkg/nagios/check.go

deleted100644 → 0
+0 −76
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
}
Loading