Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions check-ping/README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
# check-ping

## Description

Check ICMP Ping connections with the specified host.

## Synopsis
```

```bash
check-ping -H 127.0.0.1 -n 5 -w 100
```

## Installation

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
```

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
Expand Down
9 changes: 8 additions & 1 deletion check-ping/lib/check-ping.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package checkping

import (
"fmt"
"net"
"os"
"time"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}