#!/usr/bin/perl =pod =head1 NAME $RCSfile: checkdns,v $ Check DNS by attempting to call gethostbyname of a well known host. =head1 VERSION =over =item Author Andrew DeFaria =item Revision $Revision: 1.6 $ =item Created: Wed Aug 30 21:03:14 CDT 2006 =item Modified: $Date: 2011/04/15 15:05:16 $ =back =head1 SYNOPSIS Usage: checkdns [-u|sage] [-v|erbose] [-d|ebug] [-s|leep ] [-l|ogpath ] Where: -u|sage Print this usage -v|erbose: Verbose mode -de|bug: Emit debug information -h|ost: Host to check (Default: google.com) -s|leep : Set sleep period to minutes (Default: 15 minutes) -l|ogpath : Put the log file in (Default: /var/log) -da|emon: Whether to go into daemon most (Default: yes) =head1 DESCRIPTION This script will look at the security logfile for attempted breakins and then use whois to report them to the upstream provider. =cut use strict; use warnings; use Getopt::Long; use FindBin; use lib "$FindBin::Bin/../lib"; use Logger; use Utils; use Display; my $VERSION = '$Revision: 1.6 $'; ($VERSION) = ($VERSION =~ /\$Revision: (.*) /); $0 = $FindBin::Script; my ($log, $initial_sleep); my %opts = ( host => 'google.com', sleep => 15, logpath => '/var/log', usage => sub { Usage }, verbose => sub { set_verbose }, debug => sub { set_debug }, daemon => 1, ); sub CheckDNS { my ($host) = @_; $? = 0; my @ipaddrs = gethostbyname $host; if (!@ipaddrs) { debug "Host: $host (ipaddrs empty)"; # Cut down sleep time to monitor this outage more closely but do not go # below once a minute. if ($opts{sleep} > 1) { $opts{sleep} -= $opts{sleep} / 2; } else { $opts{sleep} = 1; } # if return 1; } # if # Successful lookup - set $sleep to $initial_sleep $opts{sleep} = $initial_sleep; return; } # CheckDNS sub Shutdown { my $msg; my $errors = $log->errors; $log->msg("$errors errors encountered since starting") if $errors; $log->msg('Caught interrupt - shutting down'); exit $errors; } # Interrupt # Main GetOptions ( \%opts, 'usage', 'verbose', 'debug', 'host=s', 'sleep=i', 'logpath=s', 'daemon!', ) or Usage 'Invalid parameter'; $initial_sleep = $opts{sleep}; $SIG {INT} = $SIG {TERM} = \&Shutdown; # Call sethostent so that gethostbyname is fresh everytime sethostent (0); $log = Logger->new ( path => $opts{logpath}, timestamped => 'yes', append => 'yes', ); $log->msg ( "Started $FindBin::Script $VERSION logging to $opts{logpath}/$FindBin::Script.log" ); if ($opts{sleep} > 1) { $log->msg ("Polling DNS on host $opts{host} every $opts{sleep} minutes"); } else { $log->msg ("Polling DNS on host $opts{host} every minute"); } # if $opts{daemon} = 0 if get_debug; EnterDaemonMode if $opts{daemon}; while () { my $status = CheckDNS $opts{host}; if ($status) { $log->err ("Unable to resolve IP address for $opts{host}"); } else { $log->msg ("Successfully resolved $opts{host}"); } # if sleep $opts{sleep} * 60; } # while =pod =head1 CONFIGURATION AND ENVIRONMENT DEBUG: If set then $debug is set to this level. VERBOSE: If set then $verbose is set to this level. TRACE: If set then $trace is set to this level. =head1 DEPENDENCIES =head2 Perl Modules L L =head2 ClearSCM Perl Modules =begin man Display Logger Utils =end man =begin html
Display
Logger
Utils
=end html =head1 BUGS AND LIMITATIONS There are no known bugs in this script Please report problems to Andrew DeFaria . =head1 LICENSE AND COPYRIGHT Copyright (c) 2004, ClearSCM, Inc. All rights reserved. =cut