Skip to content

Commit 8bdf188

Browse files
authored
Merge pull request #927 from mackerelio/check-ping-status-as
implement status-as option to check-ping
2 parents 8101506 + f496610 commit 8bdf188

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

check-ping/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
11
# check-ping
22

33
## Description
4+
45
Check ICMP Ping connections with the specified host.
56

67
## Synopsis
7-
```
8+
9+
```bash
810
check-ping -H 127.0.0.1 -n 5 -w 100
911
```
1012

1113
## Installation
1214

1315
First, build this program.
1416

15-
```
17+
```bash
1618
go get github.com/mackerelio/go-check-plugins
1719
cd $(go env GOPATH)/src/github.com/mackerelio/go-check-plugins/check-ping
1820
go install
1921
```
2022

2123
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).
2224

23-
2425
Next, you can execute this program :-)
2526

26-
```
27+
```bash
2728
check-ping -H 127.0.0.1 -n 5 -w 100
2829
```
2930

30-
3131
## Setting for mackerel-agent
3232

33-
If there are no problems in the execution result, add a setting in mackerel-agent.conf .
33+
If there are no problems in the execution result, add a setting in mackerel-agent.conf.
3434

35-
```
35+
```toml
3636
[plugin.checks.check-ping-sample]
3737
command = ["check-ping", "-H", "127.0.0.1", "-n", "5", "-w", "100"]
3838
```
3939

4040
## Usage
41+
4142
### Options
4243

43-
```
44+
```text
4445
-H, --host= check target IP Address
4546
-n, --count= sending (and receiving) count ping packets (default: 1)
4647
-w, --wait-time= wait time, Max RTT(ms) (default: 1000)
48+
--status-as= Overwrite status=to-status, support multiple comma separetes.
4749
```
4850

4951
## For more information

check-ping/lib/check-ping.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package checkping
22

33
import (
4+
"fmt"
45
"net"
56
"os"
67
"time"
@@ -14,6 +15,7 @@ var opts struct {
1415
Host string `long:"host" short:"H" description:"check target IP Address"`
1516
Count int `long:"count" short:"n" default:"1" description:"sending (and receiving) count ping packets"`
1617
WaitTime int `long:"wait-time" short:"w" default:"1000" description:"wait time, Max RTT(ms)"`
18+
StatusAs string `long:"status-as" description:"Overwrite status=to-status, support multiple comma separetes."`
1719
}
1820

1921
func run(args []string) *checkers.Checker {
@@ -70,5 +72,10 @@ func isIPv6(host string) bool {
7072
func Do() {
7173
ckr := run(os.Args[1:])
7274
ckr.Name = "Ping"
73-
ckr.Exit()
75+
maps, err := checkers.ParseStatusMap(opts.StatusAs)
76+
if err != nil {
77+
fmt.Println(err)
78+
os.Exit(1)
79+
}
80+
ckr.ExitStatusAs(maps)
7481
}

0 commit comments

Comments
 (0)