If you would like to monitor your mission-critical routers and servers around the clock, one of the best ways is to build a ping server. In a recent From the Trenches column, “How a Linux solution saved this company $35K,” TechRepublic member Ed Carp told us how he used a Linux ping server to monitor his infrastructure and alert his pager if there were problems, which helped avert disaster when one of his WAN links went down.

A number of TechRepublic members wrote us asking if Carp would share his script, and he has graciously agreed to do so. In this article, we will show you the script that Carp developed, how he has improved the script, and provide copies of his script and associates files for you to download and build your own ping server.

Monitoring and messaging
In the original ping server configuration, Carp’s script would ping a list of hosts from a flat file. If one of those hosts was down, the ping server would send an e-mail alert to his pager.

Carp has modified the original script to add a feature that allows information from the pinged host to be captured and saved.

“Instead of using a flat file, I’m using a database table. So now the script detects state change,” Carp said. “So if the state is different than what is in the database, [it] sends the message out,” Carp said.

In the materials he is sharing with us, Carp uses a database table in MySQL, a powerful, but free, database program that comes with many distributions of Linux.

Another refinement in this script is that it forces the ping script to repeat a changed state in the host through three cycles before it sends its notification.

“I was sort of surprised how many people were interested in the shell script. Just to write a script to ping a host is pretty trivial,” Carp said of the reaction to the first Trenches article. “The tough part is saving the state between invocations.

“If you ping a host and it’s down, and you run this thing out every 60 seconds, the next time you run it you don’t want to send a page out. You just want to send it out once. So you have to have some mechanism for saving the state so it will know it has already sent the page out. That’s why I use the database.”

The database automatically assigns an alias name to each host so that the status message it sends will fit in a pager window. The status message gives the host alias name, its IP address, and if the change in state is up or down. Because everyone always asks when the host went down, the database keeps track of the time of the status change, he said.

Improvements and more improvements
Carp improved his ping server for a client in Dallas who wanted to be able to see the status of any of his servers at any time and not simply to be notified of a change of state.

Carp now works for a company called Squished Mosquito and he has developed a server-side scripting language called Escapade that he used to fulfill his client’s request. Like Linux and MySQL, the Escapade scripting engine is available for free.

“I use Escapade to pull the data out of the table, wrap HTML around it, and throw it up in a browser,” he said. “It’s color-coded so if your ping times are outside a certain range, it will show up in red. Green for anything below 10 milliseconds or so, the yellow for anything below 50 milliseconds, and then anything greater was red.”

The client was an engineering firm and it wanted to see the different ping speeds to see when the network was being stressed.

We’ve included an Escapade script page and an Escapade instructions file in our ping script download.

Grab this download!

Never be unaware one of the hosts on your network has gone down again! Download Ed Carp’s ping server script, including instructions on how to install it and set up your MySQL database, and you will never be caught off guard again.