On Mon, 23 Jun 2003, Max Baker wrote:
> Has anyone written a DHCP monitor? If not, I'll be throwing one > together. > I wrote one a while back. I've posted it to the list before, but there have been some minor changes, so I'll post it again. If the maintainer of the contrib archive would like to include it there, he may do so. Here are the comments I posted along with it last time it came up, with minor updates for the current version: On Mon, 10 Feb 2003, Diallo Moussa wrote: > So i heard that i could use Mon. But with i didn't find a script to > check a DHCP service.... I wrote a script for monitoring DHCP servers. I'm attaching it to this message. It uses the Net::DHCP::Watch perl module, which you can get from CPAN, to send DHCP INFORM messages to each server given on the command line. A few things to note are: It uses ifconfig to determine the monitoring host's IP address and Ethernet address. If you aren't running on a Linux machine, you may wish to change that. And if the monitoring host isn't listed in the DHCP server's configuration, I don't know what will happen. With ISC's DHCPD, during periods of high load the dhcp server may not respond within the 30 second timeout. We found that this happened often enough that just using an 'alertafter' option in our mon config wasn't enough. So the script will try each server 3 times before declaring it dead. Since Net::DHCP::Watch just does an INFORM transaction, this won't detect a case where a pool of dynamic addresses is fully utilized. Actually detecting that would require significantly more work. -David Nolan Network Software Developer Carnegie Mellon University Computing Services
#!/usr/bin/perl -w # verify that a DHCP server is operating. # # usage: dhcp.monitor [host ...] # # Uses Net::DHCP::Watch to send a DHCP inform message to each of the servers # listed on the command line, and then waits up to 30 seconds for a response. # # Copyright (c) 2000-2002 Carnegie Mellon University. All rights reserved. # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. The name "Carnegie Mellon University" must not be used to endorse or # promote products derived from this software without prior written # permission. For permission or any legal details, please contact: # Office of Technology Transfer # Carnegie Mellon University # 5000 Forbes Avenue # Pittsburgh, PA 15213-3890 # (412) 268-4387, fax: (412) 268-7395 # [EMAIL PROTECTED] # # 4. Redistributions of any form whatsoever must retain the following # acknowledgment: "This product includes software developed by Computing # Services at Carnegie Mellon University (http://www.cmu.edu/computing/)." # # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS # SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, # IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, # INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. use Net::DHCP::Watch; $Client = qx[ /sbin/ifconfig eth0 | /bin/sed 's/:/ /' | /bin/grep "inet addr" | /bin/awk '{print \$3}' ]; chomp($Client); $Ether = qx[ /sbin/ifconfig eth0 | /bin/grep HWaddr | /bin/awk '{print \$5}']; chomp($Ether); foreach $host (@ARGV) { eval { my $dhcpw = new Net::DHCP::Watch({ client => $Client, server => $host, ether => $Ether, timeout => 30, }); my $success = 0; foreach (1..3) { $dhcpw->watch(); my $s = $dhcpw->status(); if ($s->{Ok}) { $success = 1; last; } $dhcpw->unwatch(); } if (!$success) { push @failures, $host; push @longerr, "$host: DHCP INFORM request failed"; } }; if ($EVAL_ERROR && ($EVAL_ERROR =~ /Timeout/ )) { push @failures, $host; push @longerr, "$host: Request timed out."; } elsif ($EVAL_ERROR) { push @longerr, "$host: $EVAL_ERROR"; push @failures, $host; } } if ([EMAIL PROTECTED]) { exit 0; } print join(" ", @failures),"\n"; print join("\n", @longerr), "\n"; exit scalar @failures;
_______________________________________________ mon mailing list [EMAIL PROTECTED] http://linux.kernel.org/mailman/listinfo/mon