Skip to content

Commit

Permalink
Merge pull request #227 from na4ma4/fix/makefiles-dep
Browse files Browse the repository at this point in the history
fix linter warnings and paths from test/ to testdata/
  • Loading branch information
na4ma4 authored Dec 5, 2023
2 parents 3ad05d7 + 81ebf11 commit 76959a7
Show file tree
Hide file tree
Showing 29 changed files with 581 additions and 679 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on:
pull_request:
push:
branches:
- '*'
- '**'
tags:
- 'v*'
- '**'

jobs:
unit-test:
Expand All @@ -15,7 +15,7 @@ jobs:

goreleaser:
name: "Goreleaser"
if: startsWith(github.ref, 'refs/tags/v')
if: startsWith(github.ref, 'refs/tags/')
needs:
- unit-test
uses: na4ma4/actions/.github/workflows/goreleaser.yml@main
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.makefiles
/artifacts
/.vscode
test/test.cmd
testdata/test.cmd
/dist
20 changes: 12 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# This code is licensed under the terms of the MIT license https://opensource.org/license/mit
# Copyright (c) 2021 Marat Reymers
#
# Initially imported from https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322

## Golden config for golangci-lint v1.54.2
## Golden config for golangci-lint v1.55.2
#
# This is the best config for golangci-lint based on my experience and opinion.
# It is very strict, but not extremely strict.
# Feel free to adapt and change it for your needs.
#
# Imported from https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322
# Modified for na4ma4 repositories.
#

run:
# Timeout for analysis, e.g. 30s, 5m.
Expand Down Expand Up @@ -122,6 +124,7 @@ linters-settings:
- os.WriteFile
- prometheus.ExponentialBuckets.*
- prometheus.LinearBuckets
- cobra.MinimumNArgs

gomodguard:
blocked:
Expand Down Expand Up @@ -215,6 +218,7 @@ linters:
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
- gochecknoglobals # checks that no global variables exist
- gochecknoinits # checks that no init functions are present in Go code
- gochecksumtype # checks exhaustiveness on Go "sum types"
- gocognit # computes and checks the cognitive complexity of functions
- goconst # finds repeated strings that could be replaced by a constant
- gocritic # provides diagnostics that check for bugs, performance and style issues
Expand All @@ -239,15 +243,19 @@ linters:
- nolintlint # reports ill-formed or insufficient nolint directives
- nonamedreturns # reports all named returns
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
- perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative
- predeclared # finds code that shadows one of Go's predeclared identifiers
- promlinter # checks Prometheus metrics naming via promlint
- protogetter # reports direct reads from proto message fields when getters should be used
- reassign # checks that package variables are not reassigned
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
- rowserrcheck # checks whether Err of rows is checked successfully
- sloglint # ensure consistent code style when using log/slog
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
- stylecheck # is a replacement for golint
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
- testableexamples # checks if examples are testable (have an expected output)
- testifylint # checks usage of github.com/stretchr/testify
- testpackage # makes you use a separate _test package
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # removes unnecessary type conversions
Expand All @@ -263,6 +271,7 @@ linters:
#- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega
#- godox # detects FIXME, TODO and other comment keywords
#- goheader # checks is file header matches to pattern
#- inamedparam # [great idea, but too strict, need to ignore a lot of cases by default] reports interfaces with unnamed method parameters
#- interfacebloat # checks the number of methods inside an interface
#- ireturn # accept interfaces, return concrete types
#- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
Expand Down Expand Up @@ -326,8 +335,3 @@ issues:
- gosec
- noctx
- wrapcheck
# Allow dot imports for ginkgo and gomega
- source: ginkgo|gomega
linters:
- revive
text: "should not use dot imports"
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GENERATED_FILES += artifacts/certs/client-key.pem
GENERATED_FILES += artifacts/certs/cert.pem
GENERATED_FILES += artifacts/certs/key.pem

GO_TEST_REQ += test/test.cmd
GO_TEST_REQ += testdata/test.cmd

-include .makefiles/Makefile
-include .makefiles/pkg/protobuf/v2/Makefile
Expand Down Expand Up @@ -72,7 +72,7 @@ artifacts/protobuf/args/go.jq: artifacts/protobuf/args/go
# Test
######################

test/test.cmd:
testdata/test.cmd:
ln -s /dev/null "$(@)"


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This can be run on any host with network access to the `rscad` server.
This should be run on the server to check, it runs the checks in the config file and sends them to `rscad` on schedule.

Copy [rsca.service](systemd/client/rsca.service) to `/etc/systemd/system/rsca.service`.
Copy [rsca.toml](test/rsca.toml) to `/etc/nagios/rsca.toml`.
Copy [rsca.toml](testdata/rsca.toml) to `/etc/nagios/rsca.toml`.

### rscad service

Expand Down
8 changes: 4 additions & 4 deletions api/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ func (x *Member) isMatchWildcardSuffix(query string) bool {
//
// Query strings can start or end in a * or % to indicate wildcard matching.
func (x *Member) IsMatch(query string) bool {
if strings.EqualFold(query, x.Id) || strings.EqualFold(query, x.Name) {
if strings.EqualFold(query, x.GetId()) || strings.EqualFold(query, x.GetName()) {
return true
}

if x.isMatchWildcardSuffix(query) {
if strings.HasPrefix(x.Name, query[:len(query)-1]) {
if strings.HasPrefix(x.GetName(), query[:len(query)-1]) {
return true
}
}

if x.isMatchWildcardPrefix(query) {
if strings.HasSuffix(x.Name, query[1:]) {
if strings.HasSuffix(x.GetName(), query[1:]) {
return true
}
}

if x.isMatchWildcardPrefix(query) && x.isMatchWildcardSuffix(query) {
if strings.Contains(x.Name, query[1:len(query)-1]) {
if strings.Contains(x.GetName(), query[1:len(query)-1]) {
return true
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ func (c *Client) RunEvents(
}
case in, ok := <-c.inbox:
if ok {
if in != nil && in.Message != nil {
switch msg := in.Message.(type) {
if in != nil && in.GetMessage() != nil {
switch msg := in.GetMessage().(type) {
case *api.Message_PingMessage:
go func() {
c.outbox <- common.GeneratePingMessage(c.logger, c.hostname, in, msg)
Expand Down
18 changes: 9 additions & 9 deletions cmd/rsc/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ func init() {
}

func fillInAPIMember(in *api.Member) {
if in.Service == nil {
if in.GetService() == nil {
in.Service = []string{}
} else {
sort.Strings(in.Service)
sort.Strings(in.GetService())
}

if in.Capability == nil {
if in.GetCapability() == nil {
in.Capability = []string{}
} else {
sort.Strings(in.Capability)
sort.Strings(in.GetCapability())
}

if in.Tag == nil {
if in.GetTag() == nil {
in.Tag = []string{}
} else {
sort.Strings(in.Tag)
sort.Strings(in.GetTag())
}

in.LastSeenAgo = time.Since(in.LastSeen.AsTime()).String()
in.Latency = in.PingLatency.AsDuration().String()
in.LastSeenAgo = time.Since(in.GetLastSeen().AsTime()).String()
in.Latency = in.GetPingLatency().AsDuration().String()
}

//nolint:gomnd // ignore padding count.
func printHostList(tmpl *template.Template, forceHeaderAbsent bool, hostList []*api.Member) {
sort.Slice(hostList, func(i, j int) bool { return hostList[i].Name < hostList[j].Name })
sort.Slice(hostList, func(i, j int) bool { return hostList[i].GetName() < hostList[j].GetName() })

w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)

Expand Down
43 changes: 20 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ go 1.20

require (
github.com/asdine/storm/v3 v3.2.1
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.4.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/na4ma4/config v1.0.1
github.com/na4ma4/go-certprovider v0.2.0
github.com/na4ma4/go-timestring v0.3.0
github.com/na4ma4/permbits v0.3.0
github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.30.0
github.com/prometheus/client_golang v1.17.0
github.com/shirou/gopsutil/v3 v3.23.10
github.com/shirou/gopsutil/v3 v3.23.11
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
go.uber.org/multierr v1.11.0
Expand All @@ -28,40 +27,38 @@ require (
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lufia/plan9stats v0.0.0-20230110061619-bbe2e5e100de // indirect
github.com/lufia/plan9stats v0.0.0-20231016141302-07b5767bb0ed // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/gomega v1.30.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 76959a7

Please sign in to comment.