From e11fe3918e4daa9277755c93bc928ec6df9b46a0 Mon Sep 17 00:00:00 2001 From: yseto Date: Wed, 13 Sep 2023 20:57:42 +0900 Subject: [PATCH 1/3] support overwrite status --- check-tcp/lib/check-tcp.go | 9 ++++++++- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/check-tcp/lib/check-tcp.go b/check-tcp/lib/check-tcp.go index d70efa1b..81a3e699 100644 --- a/check-tcp/lib/check-tcp.go +++ b/check-tcp/lib/check-tcp.go @@ -36,6 +36,7 @@ type exchange struct { SSL bool `short:"S" long:"ssl" description:"Use SSL for the connection."` UnixSock string `short:"U" long:"unix-sock" description:"Unix Domain Socket"` NoCheckCertificate bool `long:"no-check-certificate" description:"Do not check certificate"` + StatusAs string `long:"status-as" description:"Overwrite status=to-status, support multiple comma separetes."` expectReg *regexp.Regexp } @@ -45,12 +46,18 @@ func Do() { if err != nil { os.Exit(1) } + maps, err := checkers.ParseStatusMap(opts.StatusAs) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + ckr := opts.run() ckr.Name = "TCP" if opts.Service != "" { ckr.Name = opts.Service } - ckr.Exit() + ckr.ExitStatusAs(maps) } func parseArgs(args []string) (*tcpOpts, error) { diff --git a/go.mod b/go.mod index f1089e4b..9b6a951d 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/jessevdk/go-flags v1.5.0 github.com/jmoiron/sqlx v1.3.5 github.com/lib/pq v1.10.7 - github.com/mackerelio/checkers v0.0.4 + github.com/mackerelio/checkers v0.2.0 github.com/mackerelio/go-osstat v0.2.4 github.com/mackerelio/golib v1.2.1 github.com/mattn/go-encoding v0.0.2 diff --git a/go.sum b/go.sum index 6aa323e3..b2fa1602 100644 --- a/go.sum +++ b/go.sum @@ -89,8 +89,8 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= -github.com/mackerelio/checkers v0.0.4 h1:dLxl3szIA1uW/+pFefamBPaFT9MCKkdH3uQND7c64bk= -github.com/mackerelio/checkers v0.0.4/go.mod h1:VEf9gFHvpvH7Zvcwjuj7x3ozQg5w3En6ww9UcWoWHeE= +github.com/mackerelio/checkers v0.2.0 h1:YBOQjpU2Qno66eUrUEH6DjWn+Wna5BXCKMdekz50XWs= +github.com/mackerelio/checkers v0.2.0/go.mod h1:CW3k/5bvHhxDrfKgWvMvNH0R51zco141ZVxlI7o/KAc= github.com/mackerelio/go-osstat v0.2.4 h1:qxGbdPkFo65PXOb/F/nhDKpF2nGmGaCFDLXoZjJTtUs= github.com/mackerelio/go-osstat v0.2.4/go.mod h1:Zy+qzGdZs3A9cuIqmgbJvwbmLQH9dJvtio5ZjJTbdlQ= github.com/mackerelio/golib v1.2.1 h1:SDcDn6Jw3p9bi1N0bg1Z/ilG5qcBB23qL8xNwrU0gg4= From fe3ea328b84c8d7c52b493c46f53006597c07250 Mon Sep 17 00:00:00 2001 From: yseto Date: Tue, 17 Oct 2023 10:22:27 +0900 Subject: [PATCH 2/3] Go 1.20 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9b6a951d..c905dab9 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/mackerelio/go-check-plugins -go 1.18 +go 1.20 require ( github.com/StackExchange/wmi v1.2.1 From 31eeb20096b452c50f67463f3b9bbc71c6c72320 Mon Sep 17 00:00:00 2001 From: yseto Date: Wed, 18 Oct 2023 11:52:21 +0900 Subject: [PATCH 3/3] update README --- check-tcp/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/check-tcp/README.md b/check-tcp/README.md index 0024da5b..6e8d4530 100644 --- a/check-tcp/README.md +++ b/check-tcp/README.md @@ -51,6 +51,7 @@ command = ["check-tcp", "-H", "localhost", "-p", "4224", "-w", "3", "-c", "5"] -S, --ssl Use SSL for the connection. -U, --unix-sock= Unix Domain Socket --no-check-certificate Do not check certificate + --status-as= Overwrite status=to-status, support multiple comma separetes. -t, --timeout= Seconds before connection times out (default: 10) -m, --maxbytes= Close connection once more than this number of bytes are received -d, --delay= Seconds to wait between sending string and polling for response