in reply to Need help writing a basic network monitor.

Still keeping it fairly simple, how about something like this:
#!/usr/bin/perl -w use strict; use Net::Ping; my $test_host = 'www.google.com'; my $sleepy_time = 30; print "Network Monitor started at ", scalar localtime, ". (Testing $test_host every $sleepy_time seconds)\n"; my $p = Net::Ping->new(); while (1) { sleep $sleepy_time; next if $p->ping($test_host); print "$test_host appears to be down at ", scalar localtime, "\n"; }

If you wanted to do this properly, then there are plenty of (open source) off-the-shelf Network Monitoring Systems available. Big Brother is one that I have used and would recommend.

Cheers,
Darren :)

Replies are listed 'Best First'.
Re^2: Need help writing a basic network monitor.
by svenXY (Deacon) on Sep 16, 2006 at 08:14 UTC
    Hi McDarren++,
    we use Nagios. Uses loads of plugin scripts for the different test. The plugins are small standalone scripts or programs. I use perl massively to write plugins for Nagios.
    Furthermore, we use some perl scripts to generate the Nagios config files from a machine database that we maintain.
    Regards,
    svenXY
      "we use Nagios."

      I've heard a lot of good stuff about Nagios, but I've never used it myself. I've been using BB for almost 6 years now, and it pretty much does everything I need.

      "I use perl massively to write plugins for Nagios."

      Same here with regards BB. At the previous company I worked for, we were running about a dozen customised tests - all written in Perl :)
      Where I am now, most of the servers we monitor are windoze boxen. I would have liked to have written our customised tests in Perl, but it wasn't really practical. It would have meant either installing ActivePerl on about 300 machines, or doing something with PAR. We've actually resorted to (ugh!) VBScript at the moment - which is (sortof) working okay, except for some of the incredibly ridiculous hoops you have to jump though to do the most basic things with VBScript - such as parsing a bit of text ;) So I would still like to migrate everything to Perl if I get the chance :)

      "Furthermore, we use some perl scripts to generate the Nagios config files from a machine database that we maintain."

      Yup, again we do the same with BB. In fact, we've gone a step further and completely dispensed with the standard BB display interface, and built one of our own using Perl/CGI. A bit more about that is here.

      Cheers, Darren :)

        Hi,

        I also use Nagios at the company and I also do Windows box test with it without problems and out of the box, because what you really do is testing services that run on a machine. But the windows boxes can be count with the hands. :-)

        I think the way to extending it (scripts) is very useful, because this way you can even write testers for special net services you could have developed.

        Initial configuration could be a little annoying, but I think it's worth. I also like the idea to have a central server where all the network/supervise tools are installed, and not having daemons on the machines that give me some feedback.

        By the side, Nagios with the Nuvola theme looks very nice :-D

        Regards,

        fmerges at irc.freenode.net