diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fc51337..d0ad1de 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -14,6 +14,12 @@ updates: - "andyone" reviewers: - "andyone" + groups: + all: + applies-to: version-updates + update-types: + - "minor" + - "patch" - package-ecosystem: "github-actions" directory: "/" diff --git a/.github/images/card.svg b/.github/images/card.svg new file mode 100644 index 0000000..92488c4 --- /dev/null +++ b/.github/images/card.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/.github/images/godoc.svg b/.github/images/godoc.svg new file mode 100644 index 0000000..f994fd0 --- /dev/null +++ b/.github/images/godoc.svg @@ -0,0 +1 @@ +go: referencegoreference \ No newline at end of file diff --git a/.github/images/license.svg b/.github/images/license.svg new file mode 100644 index 0000000..8990e77 --- /dev/null +++ b/.github/images/license.svg @@ -0,0 +1 @@ +license: Apache-2.0licenseApache-2.0 \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b67dfb6..1e25be5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,49 +5,52 @@ on: branches: [master, develop] pull_request: branches: [master] + workflow_dispatch: + inputs: + force_run: + description: 'Force workflow run' + required: true + type: choice + options: [yes, no] permissions: actions: read contents: read statuses: write +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: Go: name: Go runs-on: ubuntu-latest - env: - SRC_DIR: src/github.com/${{ github.repository }} - strategy: matrix: - go: [ '1.17.x', '1.18.x' ] + go: [ '1.21.x', '1.22.x' ] steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - - name: Checkout - uses: actions/checkout@v3 - with: - path: ${{env.SRC_DIR}} - - name: Download dependencies - working-directory: ${{env.SRC_DIR}} run: make deps - name: Run tests - working-directory: ${{env.SRC_DIR}} run: go test -covermode=count -coverprofile=cover.out - name: Send coverage data - uses: essentialkaos/goveralls-action@v1 + uses: essentialkaos/goveralls-action@v2 env: COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - path: ${{env.SRC_DIR}} profile: cover.out parallel: true flag-name: linux-${{ matrix.go }} @@ -60,7 +63,7 @@ jobs: steps: - name: Finish parallel tests - uses: essentialkaos/goveralls-action@v1 + uses: essentialkaos/goveralls-action@v2 env: COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -72,23 +75,30 @@ jobs: needs: Go - env: - SRC_DIR: src/github.com/${{ github.repository }} - GO111MODULE: auto - steps: - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: '1.17.x' - - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 with: - path: ${{env.SRC_DIR}} + go-version: '1.21.x' - name: Check Golang sources with Aligo - uses: essentialkaos/aligo-action@v1 + uses: essentialkaos/aligo-action@v2 with: - path: ${{env.SRC_DIR}} files: . + + Typos: + name: Typos + runs-on: ubuntu-latest + + needs: Go + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check spelling + continue-on-error: true + uses: crate-ci/typos@master diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index bf5ecc9..bfc4df5 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -20,14 +20,14 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 2 - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: go - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000..55aead8 --- /dev/null +++ b/.typos.toml @@ -0,0 +1,2 @@ +[files] +extend-exclude = ["go.sum"] diff --git a/Makefile b/Makefile index 76fadc4..f369230 100644 --- a/Makefile +++ b/Makefile @@ -1,51 +1,104 @@ ################################################################################ -# This Makefile generated by GoMakeGen 1.6.0 using next command: +# This Makefile generated by GoMakeGen 3.0.2 using next command: # gomakegen --mod . # # More info: https://kaos.sh/gomakegen ################################################################################ -export GO111MODULE=on +ifdef VERBOSE ## Print verbose information (Flag) +VERBOSE_FLAG = -v +endif -.DEFAULT_GOAL := help -.PHONY = fmt vet deps deps-test test mod-init mod-update mod-download mod-vendor help +COMPAT ?= 1.19 +MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD) ################################################################################ -deps: mod-update ## Download dependencies +.DEFAULT_GOAL := help +.PHONY = fmt vet deps update test init vendor mod-init mod-update mod-download mod-vendor help -deps-test: deps ## Download dependencies for tests +################################################################################ -test: ## Run tests - go test -covermode=count ./. +init: mod-init ## Initialize new module -mod-init: ## Initialize new module - go mod init - go mod tidy +deps: mod-download ## Download dependencies -mod-update: ## Update modules to their latest versions - go get -u - go mod tidy +update: mod-update ## Update dependencies to the latest versions -mod-download: ## Download modules to local cache - go mod download +vendor: mod-vendor ## Make vendored copy of dependencies -mod-vendor: ## Make vendored copy of dependencies - go mod vendor +test: ## Run tests + @echo "Starting tests…" +ifdef COVERAGE_FILE ## Save coverage data into file (String) + @go test $(VERBOSE_FLAG) -covermode=count -coverprofile=$(COVERAGE_FILE) ./. +else + @go test $(VERBOSE_FLAG) -covermode=count ./. +endif + +mod-init: + @echo "[1/2] Modules initialization…" +ifdef MODULE_PATH ## Module path for initialization (String) + @go mod init $(MODULE_PATH) +else + @go mod init +endif + + @echo "[2/2] Dependencies cleanup…" +ifdef COMPAT ## Compatible Go version (String) + @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT) +else + @go mod tidy $(VERBOSE_FLAG) +endif + +mod-update: + @echo "[1/4] Updating dependencies…" +ifdef UPDATE_ALL ## Update all dependencies (Flag) + @go get -u $(VERBOSE_FLAG) all +else + @go get -u $(VERBOSE_FLAG) ./... +endif + + @echo "[2/4] Stripping toolchain info…" + @grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || : + + @echo "[3/4] Dependencies cleanup…" +ifdef COMPAT + @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) +else + @go mod tidy $(VERBOSE_FLAG) +endif + + @echo "[4/4] Updating vendored dependencies…" + @test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : + +mod-download: + @echo "Downloading dependencies…" + @go mod download + +mod-vendor: + @echo "Vendoring dependencies…" + @rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : fmt: ## Format source code with gofmt - find . -name "*.go" -exec gofmt -s -w {} \; + @echo "Formatting sources…" + @find . -name "*.go" -exec gofmt -s -w {} \; -vet: ## Runs go vet over sources - go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... +vet: ## Runs 'go vet' over sources + @echo "Running 'go vet' over sources…" + @go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... help: ## Show this info - @echo -e '\n\033[1mSupported targets:\033[0m\n' + @echo -e '\n\033[1mTargets:\033[0m\n' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ - | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-14s\033[0m %s\n", $$1, $$2}' + | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-6s\033[0m %s\n", $$1, $$2}' + @echo -e '\n\033[1mVariables:\033[0m\n' + @grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \ + | sed 's/ifdef //' \ + | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-13s\033[0m %s\n", $$1, $$2}' @echo -e '' - @echo -e '\033[90mGenerated by GoMakeGen 1.6.0\033[0m\n' + @echo -e '\033[90mGenerated by GoMakeGen 3.0.2\033[0m\n' ################################################################################ diff --git a/README.md b/README.md index 0d15e8d..df09fd4 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,20 @@ -

+

- PkgGoDev - GoReportCard + GitHub Actions CI Status GitHub Actions CodeQL Status Coverage Status Codebeat badge - +

-

Installation • Usage example • zabbix-jmx-get • Build Status • License

+

Usage example • zabbix-jmx-get • CI Status • License


`zabbix-jmx` is a Go package for retrieving and parsing data from Zabbix Java Gateway. -### Installation - -Make sure you have a working Go 1.17+ workspace (_[instructions](https://golang.org/doc/install)_), then: - -``` -go get -d github.com/essentialkaos/go-zabbix-jmx -``` - -For update to the latest stable release, do: - -``` -go get -d -u github.com/essentialkaos/go-zabbix-jmx -``` - ### Usage example ```go @@ -76,7 +61,7 @@ We also provide a command-line tool `zabbix-jmx-get` for retrieving data from Za From sources: ``` -go install github.com/essentialkaos/go-zabbix-jmx/cmd/zabbix-jmx-get +go install github.com/essentialkaos/go-zabbix-jmx/cmd/zabbix-jmx-get@latest ``` Prebuilt binaries: @@ -109,7 +94,7 @@ $ zabbix-jmx-get -h 127.0.0.1 -p 10052 -H kfk-node1.domain.com -P 9093 'jmx["kaf ``` -### Build Status +### CI Status | Branch | Status | |--------|--------| diff --git a/beans.go b/beans.go index eda8203..fdeb4ce 100644 --- a/beans.go +++ b/beans.go @@ -2,7 +2,7 @@ package jmx // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2022 ESSENTIAL KAOS // +// Copyright (c) 2023 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cmd/zabbix-jmx-get/zabbix-jmx-get.go b/cmd/zabbix-jmx-get/zabbix-jmx-get.go index 352c5ae..e75331a 100644 --- a/cmd/zabbix-jmx-get/zabbix-jmx-get.go +++ b/cmd/zabbix-jmx-get/zabbix-jmx-get.go @@ -2,7 +2,7 @@ package main // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2022 ESSENTIAL KAOS // +// Copyright (c) 2023 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // @@ -208,7 +208,7 @@ func printError(f string, a ...interface{}) { fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...) } -// printErrorAndExit print error mesage and exit with exit code 1 +// printErrorAndExit print error message and exit with exit code 1 func printErrorAndExit(f string, a ...interface{}) { printError(f, a...) os.Exit(1) diff --git a/example_test.go b/example_test.go index d78ae0d..d975fc1 100644 --- a/example_test.go +++ b/example_test.go @@ -2,7 +2,7 @@ package jmx // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2022 ESSENTIAL KAOS // +// Copyright (c) 2023 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/go.mod b/go.mod index e7c7125..dc62d49 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,14 @@ module github.com/essentialkaos/go-zabbix-jmx -go 1.17 +go 1.18 require ( - github.com/essentialkaos/check v1.3.0 - github.com/essentialkaos/ek/v12 v12.44.1 + github.com/essentialkaos/check v1.4.0 + github.com/essentialkaos/ek/v12 v12.127.0 ) require ( - github.com/kr/pretty v0.3.0 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect - github.com/rogpeppe/go-internal v1.8.1 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect ) diff --git a/go.sum b/go.sum index 19fb6d6..8597bda 100644 --- a/go.sum +++ b/go.sum @@ -1,29 +1,13 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/essentialkaos/check v1.2.1/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8= -github.com/essentialkaos/check v1.3.0 h1:ria+8o22RCLdt2D/1SHQsEH5Mmy5S+iWHaGHrrbPUc0= -github.com/essentialkaos/check v1.3.0/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8= -github.com/essentialkaos/ek/v12 v12.44.1 h1:x9Zk5TVsnCWOR1cmHS81mDrgAGLa1o8VQLdmWg9GoqE= -github.com/essentialkaos/ek/v12 v12.44.1/go.mod h1:uQUkpvaZHWR9aI8GfknZqOG5FC+G2PYJLFyMw9fdjbo= -github.com/essentialkaos/go-linenoise/v3 v3.3.5/go.mod h1:g4X3LhT83XT4h7xwrCLclAdMkJvS9qWBQTGNdS6y4vo= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= +github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0= +github.com/essentialkaos/ek/v12 v12.127.0 h1:fU5A+QbIZ7NTq1K5jGVwAWwuLtBUhsIKuRWYT78hE+Q= +github.com/essentialkaos/ek/v12 v12.127.0/go.mod h1:71IJ7m82hgjrvWnhL+z0vIhguxz47/rfVma5/CeI5Fw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= -github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= -golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= diff --git a/protocol.go b/protocol.go index 37c7d1b..3cb9671 100644 --- a/protocol.go +++ b/protocol.go @@ -2,7 +2,7 @@ package jmx // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2022 ESSENTIAL KAOS // +// Copyright (c) 2023 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/zabbix.go b/zabbix.go index a1f21ea..3c8f051 100644 --- a/zabbix.go +++ b/zabbix.go @@ -3,7 +3,7 @@ package jmx // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2022 ESSENTIAL KAOS // +// Copyright (c) 2023 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // @@ -141,7 +141,7 @@ func convertRequest(r *Request) *jmxRequest { } } -// connectToServer makes connetion to Zabbix server +// connectToServer makes connection to Zabbix server func connectToServer(c *Client) (*net.TCPConn, error) { if c.ConnectTimeout > 0 && c.dialer.Timeout != c.ConnectTimeout { c.dialer.Timeout = c.ConnectTimeout @@ -156,7 +156,7 @@ func connectToServer(c *Client) (*net.TCPConn, error) { return conn.(*net.TCPConn), nil } -// readFromConnection reads data fron connection +// readFromConnection reads data from connection func readFromConnection(conn *net.TCPConn, buf []byte, timeout time.Duration) error { if timeout > 0 { conn.SetReadDeadline(time.Now().Add(timeout)) diff --git a/zabbix_test.go b/zabbix_test.go index 79ac7b9..2b92dcf 100644 --- a/zabbix_test.go +++ b/zabbix_test.go @@ -2,7 +2,7 @@ package jmx // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2022 ESSENTIAL KAOS // +// Copyright (c) 2023 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// //