Disclaimer: If you are new to Go this is not a good place to learn best practices, the code is not very idiomatic and there's probably a few bad ideas.
pingd is the ping engine used by the ping.gg monitoring service. It allows to simultaneously ping hundreds of IPs and can manage which hosts are being pinged during runtime.
The system is meant to be composed (or embedded) by you and requires up to 3 compatible functions to:
- load an initial set of hosts to monitor
- receive commands to start and stop monitoring a given host
- publish host UP or host DOWN events
These functions must be the following types respectively.
type Loader func(chan<- Host) type Receiver func(chan<- Host, chan<- Host) type Notifier func(<-chan Host)
There are some implementations of these functions available under pingd/io.
NOTE: Before you run anything, remember that ICMP echo (ping) requires root privileges for raw socket access. If you don't want to sudo every time consider using setuid
To create your own private ping.gg alternative:
# get the example export GOPATH=$PWD go get github.com/pinggg/pingd/examples/httpmail # start pinging 184.108.40.206 and 220.127.116.11 and email you if they go down sudo bin/httpmail -firstname.lastname@example.org 18.104.22.168 22.214.171.124 # add a new host while running curl localhost:7700/126.96.36.199 # stop pinging 188.8.131.52 curl -XDELETE localhost:7700/184.108.40.206
Keep in mind that this is just an example which assumes that there is a local mail server running on port 25. Take a look at the sendMail function and adapt it to your needs. For example, to send the emails via Gmail.
You can add your own functions to have pingd interact with the world. For example, switching on some red light with the help of a Raspberry Pi.