Prowl: check server status (using ping)

Yesterday I’ve start using Prowl, as I heard good comments about it. And one of the things I want it to check, are my server statuses. I made a quick script using bash and crontab to check every 10 min if it replies on ping. Per server, I created “host.domain.tld.sh” (e.g. zero.rootspirit.com.sh), and added this in the file:

#!/bin/bash
KEY=YourApiKey
HOST=zero.rootspirit.com
ping -c 1 $HOST   &>/dev/null
if [ $? -ne 0 ] ; then
curl -k -s "https://prowl.weks.net/publicapi/add?apikey=$KEY&application=Server%20Connectivity%20Failure&event=&description=$HOST&priority=2"
fi

Of course, change KEY to your API key, HOST to the IP or DNS of the server it should ping. Also, make sure, that when pinging on your host where you’ll run the bash script on, a non-existing domain actually returns:

ping: unknown host ezfzigjagaqg.reg

instead of

PING ezfzigjagaqg.reg.rootspirit.com (85.12.6.130) 56(84) bytes of data.

(Should depend on the search line in /etc/resolv.conf) As I’m pinging about 6 servers I created the file “checkServers.sh” with this content:

#!/bin/bash

`/home/yeri/prowl/zero.rootspirit.com.sh &>/dev/null`
`/home/yeri/prowl/one.rootspirit.com.sh &>/dev/null`
`/home/yeri/prowl/two.rootspirit.com.sh &>/dev/null`
`/home/yeri/prowl/four.rootspirit.com.sh &>/dev/null`
`/home/yeri/prowl/vm0.rootspirit.com.sh &>/dev/null`
`/home/yeri/prowl/vm1.rootspirit.com.sh &>/dev/null`

Make sure to chmod +x *.sh, to make it executable, and edit crontab and add something like that:

*/10	*	*	*	*	/home/yeri/prowl/checkServers.sh &>/dev/null

Don’t forget to test it whether it works or not (try non-existing domain(s), and run the script again).


Posted by

in

, , ,

Comments

4 responses to “Prowl: check server status (using ping)”

  1. bla avatar
    bla

    Nice post,
    small typo: “host.domain.ltd.sh”, you ppb meant host.domain.TLD.sh”
    yoo

  2. SUNWfrk avatar

    Nice post,

    thanks for bringing this nice app to my attention!

  3. Yeri Tiete avatar
    Yeri Tiete

    Improved checkServers.sh (as I’m check a lot of servers):

    all server_files.sh in “servers” directory

    Content of checkServers.sh:

    #!/bin/bash

    for i in `ls servers`;
    do
    echo ” >> $i”
    ./servers/$i
    done

    yeri@Wei ~/prowl $ ls
    checkServers.sh servers
    yeri@Wei ~/prowl $ ls servers/
    deng.sh had1.sh jiang.sh kryptonite.sh miia-exch2010.sh miia-ts.sh qiang.sh shi.sh yong.sh
    gon.sh had2.sh koi.sh mao.sh miia-file2008.sh nuxe.sh relay.sh wei.sh

Leave a Reply…