diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index a033f85..7a4a520 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -23,7 +23,7 @@ jobs: with: go-version: ${{ matrix.go-version }} - - name: Build plugins + - name: Build plugins for all architectures run: | make build-cross diff --git a/Makefile b/Makefile index 9bbe2e5..0136704 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -BINNAME = go-monitoring +BINNAME = gomonop BINDIR = $(CURDIR)/bin TARGETS = linux/amd64 linux/386 linux/arm linux/arm64 @@ -17,10 +17,10 @@ BINARY_VERSION ?= $(GIT_TAG) LDFLAGS += -w -s ifneq ($(BINARY_VERSION),) - LDFLAGS += -X nocternity.net/go-monitoring/pkg/version.version=${BINARY_VERSION} + LDFLAGS += -X nocternity.net/gomonop/pkg/version.version=${BINARY_VERSION} endif -LDFLAGS += -X nocternity.net/go-monitoring/pkg/version.commit=${GIT_COMMIT} -LDFLAGS += -X nocternity.net/go-monitoring/pkg/version.status=${GIT_STATUS} +LDFLAGS += -X nocternity.net/gomonop/pkg/version.commit=${GIT_COMMIT} +LDFLAGS += -X nocternity.net/gomonop/pkg/version.status=${GIT_STATUS} .PHONY: all @@ -33,15 +33,15 @@ build: build-target symlink .PHONY: symlink symlink: - @ln -sf $(BINDIR)/$(GOOS)/$(GOARCH)/$(BINNAME) $(BINDIR)/$(BINNAME) + @ln -sf $(BINDIR)/$(GOOS)-$(GOARCH)/$(BINNAME) $(BINDIR)/$(BINNAME) .PHONY: build-target -build-target: LDFLAGS += -X nocternity.net/go-monitoring/pkg/version.target=${GOOS}/${GOARCH} -build-target: $(BINDIR)/$(GOOS)/$(GOARCH)/$(BINNAME) +build-target: LDFLAGS += -X nocternity.net/gomonop/pkg/version.target=${GOOS}/${GOARCH} +build-target: $(BINDIR)/$(GOOS)-$(GOARCH)/$(BINNAME) -$(BINDIR)/$(GOOS)/$(GOARCH)/$(BINNAME): $(SRC) - @mkdir -p $(BINDIR)/$(GOOS)/$(GOARCH) - @CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BINDIR)/$(GOOS)/$(GOARCH)/$(BINNAME) . +$(BINDIR)/$(GOOS)-$(GOARCH)/$(BINNAME): $(SRC) + @mkdir -p $(BINDIR)/$(GOOS)-$(GOARCH) + @CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BINDIR)/$(GOOS)-$(GOARCH)/$(BINNAME) . .PHONY: test test: build diff --git a/README.md b/README.md index 6aecd2c..7853766 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,13 @@ -Various monitoring plugins in golang -===================================== +gomonop - Various monitoring plugins in golang +============================================== -This repository is meant to host various monitoring plugins for Nagios (or -Centreon, or Icinga) written in golang. I will update it as I rewrite my old -shell-based scripts or write new ones. +This project is a collection of various monitoring plugins (such as Nagios, +Centreon, or Icinga) written in golang. All plugins are available through a +single executable, `gomonop`. The actual plugin can be selected either +by creating a symlink to the main executable with the appropriate name or by +calling the executable directly with the first argument being the name of the +plugin. -Building ---------- - -Running the `build.sh` bash script will build the plugins for both the `amd64` -and `386` architectures. It will create a `bin/` directory with -architecture-specific subdirectories. Plugins -------- @@ -48,4 +45,17 @@ supports the following command-line flags: * `-r name`/`--rs-hostname name`: the host name or address of the reference server. * `-p port`/`--rs-port port`: the port to use on the reference server - (defaults to 53). \ No newline at end of file + (defaults to 53). + + +Building from source +-------------------- + +The plugin can be built for the current host OS and architecture using +`make build`. The actual executable will be created under the `bin` directory, +in a subdirectory named after the host OS and architecture (e.g. +`bin/linux-amd64`). The executable will be named `gomonop`, and a +symlink to the executable for the host OS and architecture will be created +under the `bin` directory. + +It is possible to build for other architectures using `make build-cross`. diff --git a/cmd/sslcert/main.go b/cmd/sslcert/main.go index fefccf4..d5d38fc 100644 --- a/cmd/sslcert/main.go +++ b/cmd/sslcert/main.go @@ -1,4 +1,4 @@ -package sslcert // import nocternity.net/go-monitoring/cmd/sslcert +package sslcert // import nocternity.net/gomonop/cmd/sslcert import ( "bufio" @@ -12,9 +12,9 @@ import ( "strings" "time" - "nocternity.net/go-monitoring/pkg/perfdata" - "nocternity.net/go-monitoring/pkg/plugin" - "nocternity.net/go-monitoring/pkg/program" + "nocternity.net/gomonop/pkg/perfdata" + "nocternity.net/gomonop/pkg/plugin" + "nocternity.net/gomonop/pkg/program" "github.com/karrick/golf" ) diff --git a/cmd/zoneserial/main.go b/cmd/zoneserial/main.go index af78d50..1d29b8e 100644 --- a/cmd/zoneserial/main.go +++ b/cmd/zoneserial/main.go @@ -1,4 +1,4 @@ -package zoneserial // import nocternity.net/go-monitoring/cmd/zoneserial +package zoneserial // import nocternity.net/gomonop/cmd/zoneserial import ( "fmt" @@ -8,9 +8,9 @@ import ( "strings" "time" - "nocternity.net/go-monitoring/pkg/perfdata" - "nocternity.net/go-monitoring/pkg/plugin" - "nocternity.net/go-monitoring/pkg/program" + "nocternity.net/gomonop/pkg/perfdata" + "nocternity.net/gomonop/pkg/plugin" + "nocternity.net/gomonop/pkg/program" "github.com/karrick/golf" "github.com/miekg/dns" diff --git a/go.mod b/go.mod index b9ffb1a..fbbf082 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module nocternity.net/go-monitoring +module nocternity.net/gomonop go 1.22 diff --git a/main.go b/main.go index dff10ed..b669b15 100644 --- a/main.go +++ b/main.go @@ -5,10 +5,10 @@ import ( "os" "path/filepath" - "nocternity.net/go-monitoring/cmd/sslcert" - "nocternity.net/go-monitoring/cmd/zoneserial" - "nocternity.net/go-monitoring/pkg/program" - "nocternity.net/go-monitoring/pkg/version" + "nocternity.net/gomonop/cmd/sslcert" + "nocternity.net/gomonop/cmd/zoneserial" + "nocternity.net/gomonop/pkg/program" + "nocternity.net/gomonop/pkg/version" ) var ( @@ -30,15 +30,19 @@ func main() { if builder, ok := programs[ownName]; ok { program = builder() } else if len(os.Args) < 2 { - exitError("Syntax: %s [arguments]\n %s programs", os.Args[0], os.Args[0]) - } else if os.Args[1] == "programs" { - fmt.Println("Available programs:") + exitError( + ""+ + "Syntax: %s [arguments]\n"+ + " %s --programs|-p\n"+ + " %s --version|-v", + os.Args[0], os.Args[0], os.Args[0]) + } else if os.Args[1] == "--programs" || os.Args[1] == "-p" { for name := range programs { - fmt.Printf(" %s\n", name) + fmt.Println(name) } os.Exit(0) } else if os.Args[1] == "--version" || os.Args[1] == "-v" { - fmt.Printf("%s %s\n", ownName, version.Version()) + fmt.Printf("gomonop %s\n", version.Version()) os.Exit(0) } else if builder, ok := programs[os.Args[1]]; ok { diff --git a/pkg/perfdata/perfdata.go b/pkg/perfdata/perfdata.go index 1456831..9a5ca7c 100644 --- a/pkg/perfdata/perfdata.go +++ b/pkg/perfdata/perfdata.go @@ -1,6 +1,6 @@ // Package `perfdata` provides representations for a monitoring plugin's // performance data. -package perfdata // import nocternity.net/go-monitoring/pkg/perfdata +package perfdata // import nocternity.net/gomonop/pkg/perfdata import ( "fmt" diff --git a/pkg/perfdata/perfdata_test.go b/pkg/perfdata/perfdata_test.go index 473be57..f86bd05 100644 --- a/pkg/perfdata/perfdata_test.go +++ b/pkg/perfdata/perfdata_test.go @@ -1,4 +1,4 @@ -package perfdata // import nocternity.net/go-monitoring/pkg/perfdata +package perfdata // import nocternity.net/gomonop/pkg/perfdata import ( "fmt" diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go index e4206ba..ab4db13 100644 --- a/pkg/plugin/plugin.go +++ b/pkg/plugin/plugin.go @@ -1,6 +1,6 @@ // Package plugin implements a helper that can be used to implement a Nagios, // Centreon, Icinga... service monitoring plugin. -package plugin // import nocternity.net/go-monitoring/pkg/perfdata +package plugin // import nocternity.net/gomonop/pkg/perfdata import ( "container/list" @@ -8,7 +8,7 @@ import ( "os" "strings" - "nocternity.net/go-monitoring/pkg/perfdata" + "nocternity.net/gomonop/pkg/perfdata" ) // Status represents the return status of the monitoring plugin. The diff --git a/pkg/program/program.go b/pkg/program/program.go index 7f2ec06..980c8dd 100644 --- a/pkg/program/program.go +++ b/pkg/program/program.go @@ -1,4 +1,4 @@ -package program // import nocternity.net/go-monitoring/pkg/program +package program // import nocternity.net/gomonop/pkg/program type Program interface { CheckArguments() bool diff --git a/pkg/version/version.go b/pkg/version/version.go index cc49dcf..404db76 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,4 +1,4 @@ -package version // import nocternity.net/go-monitoring/pkg/version +package version // import nocternity.net/gomonop/pkg/version import "fmt"