From 24f3dfbac85a43124c237f2c78c832c5b3ffed43 Mon Sep 17 00:00:00 2001 From: kga Date: Wed, 13 Aug 2025 23:12:05 +0900 Subject: [PATCH 1/2] implement status-as option to check-ping --- check-ping/README.md | 1 + check-ping/lib/check-ping.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/check-ping/README.md b/check-ping/README.md index 6515e260..0cc7807c 100644 --- a/check-ping/README.md +++ b/check-ping/README.md @@ -44,6 +44,7 @@ command = ["check-ping", "-H", "127.0.0.1", "-n", "5", "-w", "100"] -H, --host= check target IP Address -n, --count= sending (and receiving) count ping packets (default: 1) -w, --wait-time= wait time, Max RTT(ms) (default: 1000) + --status-as= Overwrite status=to-status, support multiple comma separetes. ``` ## For more information diff --git a/check-ping/lib/check-ping.go b/check-ping/lib/check-ping.go index 7c8056aa..44c74bfb 100644 --- a/check-ping/lib/check-ping.go +++ b/check-ping/lib/check-ping.go @@ -1,6 +1,7 @@ package checkping import ( + "fmt" "net" "os" "time" @@ -14,6 +15,7 @@ var opts struct { Host string `long:"host" short:"H" description:"check target IP Address"` Count int `long:"count" short:"n" default:"1" description:"sending (and receiving) count ping packets"` WaitTime int `long:"wait-time" short:"w" default:"1000" description:"wait time, Max RTT(ms)"` + StatusAs string `long:"status-as" description:"Overwrite status=to-status, support multiple comma separetes."` } func run(args []string) *checkers.Checker { @@ -70,5 +72,10 @@ func isIPv6(host string) bool { func Do() { ckr := run(os.Args[1:]) ckr.Name = "Ping" - ckr.Exit() + maps, err := checkers.ParseStatusMap(opts.StatusAs) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + ckr.ExitStatusAs(maps) } From f496610ddbf01e9fdf35095be24d50c001bda568 Mon Sep 17 00:00:00 2001 From: kga Date: Wed, 13 Aug 2025 23:13:36 +0900 Subject: [PATCH 2/2] format README --- check-ping/README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/check-ping/README.md b/check-ping/README.md index 0cc7807c..631c4a08 100644 --- a/check-ping/README.md +++ b/check-ping/README.md @@ -1,10 +1,12 @@ # check-ping ## Description + Check ICMP Ping connections with the specified host. ## Synopsis -``` + +```bash check-ping -H 127.0.0.1 -n 5 -w 100 ``` @@ -12,7 +14,7 @@ check-ping -H 127.0.0.1 -n 5 -w 100 First, build this program. -``` +```bash go get github.com/mackerelio/go-check-plugins cd $(go env GOPATH)/src/github.com/mackerelio/go-check-plugins/check-ping go install @@ -20,27 +22,26 @@ go install Or you can use this program by installing the official Mackerel package. See [Using the official check plugin pack for check monitoring - Mackerel Docs](https://mackerel.io/docs/entry/howto/mackerel-check-plugins). - Next, you can execute this program :-) -``` +```bash check-ping -H 127.0.0.1 -n 5 -w 100 ``` - ## Setting for mackerel-agent -If there are no problems in the execution result, add a setting in mackerel-agent.conf . +If there are no problems in the execution result, add a setting in mackerel-agent.conf. -``` +```toml [plugin.checks.check-ping-sample] command = ["check-ping", "-H", "127.0.0.1", "-n", "5", "-w", "100"] ``` ## Usage + ### Options -``` +```text -H, --host= check target IP Address -n, --count= sending (and receiving) count ping packets (default: 1) -w, --wait-time= wait time, Max RTT(ms) (default: 1000)