spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / perl / tutorial / 6

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Monitoring Ports with Moniker

Abstract

If you're responsible for administering Internet services like HTTP, POP, and SMTP, one of your daily tasks probably consists of testing these services to make sure they're running. Alternatively, you can simply wait for a user to call and complain that mail isn't working. After all, users are often more than willing to notify you by phone or in person when a service is not working. Still, a little pro-active monitoring is a good thing as long as it doesn't require much effort. Sicking a Perl script on the problem will also reduce the amount of time you spend listening to user babble, which will allow you to focus on the more important things in life; like playing Quake for instance.

I whipped up a little script for the job (less than 100 lines) that allows me to monitor ports on various servers. It's a command line script with a couple switches (port and host) with an alternative switch that allows you to specify an email address to send an alert to if the service test fails. You can automate the process by running it as a cron job (*nix), or with at (Scheduler on NT).

Required Modules

For Moniker to work on your system, you should have a recent version of Perl installed, 5.003 or better. You will also need the following modules installed:

  • Mail::Sendmail
  • Net::Telnet
To install Mail::Sendmail:
  • on *nix: perl -MCPAN -e "install Mail::Sendmail"
  • on NT/Win95: ppm install --location=http://alma.ch/perl/ppm Mail-Sendmail
To install Net::Telnet
  • on *nix: perl -MCPAN -e "install Net::Telnet"
  • on NT/Win95: ppm install Net-Telnet

Syntax

The usage for moniker is quite simple:

moniker -h host -s service [-e email]
-h Hostname or IP address of the machine you want to test
-s Name of the service you want to test. Currently, these are ftp, ssh, telnet, www, pop, nntp, imap, and smtp
-e Email to send alert to if the test fails

So, to test the Web Mother of Perl Web server, the syntax would be:

moniker -h www.motherofperl.com -s www
And if I wanted an email notification in the event of a failed test, the syntax would be:
moniker -h www.motherofperl.com -s www -e eisen@internet.com
Next, let's take a look at the code. It's short but sweet.

moniker.pl Get source
This script allows one to monitor Internet services.


home / experts / perl / tutorial / 6

http://www.internet.com

Produced by Jonathan Eisenzopf and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags


Created: August 4, 1999
Revised: August 4, 1999

URL: http://www.webreference.com/perl/tutorial/6/