diff --git a/check-ping/README.md b/check-ping/README.md index 6515e260..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,30 +22,30 @@ 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) + --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) }