refactor: reorganize project in order to include automation #1

Merged
Emmanuel BENOîT merged 19 commits from :master into master 2024-07-19 22:01:35 +02:00
12 changed files with 61 additions and 47 deletions
Showing only changes of commit 9a1144d112 - Show all commits

View file

@ -23,7 +23,7 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Build plugins
- name: Build plugins for all architectures
run: |
make build-cross

View file

@ -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

View file

@ -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
--------
@ -49,3 +46,16 @@ supports the following command-line flags:
server.
* `-p port`/`--rs-port port`: the port to use on the reference server
(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`.

View file

@ -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"
)

View file

@ -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"

2
go.mod
View file

@ -1,4 +1,4 @@
module nocternity.net/go-monitoring
module nocternity.net/gomonop
go 1.22

22
main.go
View file

@ -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 <program> [arguments]\n %s programs", os.Args[0], os.Args[0])
} else if os.Args[1] == "programs" {
fmt.Println("Available programs:")
exitError(
""+
"Syntax: %s <program> [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 {

View file

@ -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"

View file

@ -1,4 +1,4 @@
package perfdata // import nocternity.net/go-monitoring/pkg/perfdata
package perfdata // import nocternity.net/gomonop/pkg/perfdata
import (
"fmt"

View file

@ -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

View file

@ -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

View file

@ -1,4 +1,4 @@
package version // import nocternity.net/go-monitoring/pkg/version
package version // import nocternity.net/gomonop/pkg/version
import "fmt"