Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/local/perl -w use strict; use warnings; use diagnostics; use Net::SMTP; use File::Tail; our $logfile=("/pix/pix.log"); # PIX Log File our $criticallog=("/pix/critical_log"); # Critical Message Log File our $datestamp; # Global Time Variables our $timestamp; our $readline; # File::Tail Working Variable our $maxlogsize=("10000000"); # Max Log Size (bytes) our $emailpriority; # E-Mail Priority for Paging our $messagebody; # Text Of E-Mail Alert our $size; # Current Log File Size # main { # Process PIX Log File in infinite loop of tail checking # Start 'Tailing' the log file for changes my $workingfile=File::Tail->new(name=>$logfile, maxinterval=>30, adjustafter=>5, maxbuf=>16384); # Evaluation Loop - NOTE: Activates only on changes to logfile while (defined($readline=$workingfile->read)) { # Sets evaluation parsing to look for ACTIVE and Down # ACTIVE - triggered on firewall failover # Down - triggered on interface shutdown or failure if (($readline=~/ACTIVE/) || ($readline=~/Down/)) { TimeStamping ($datestamp,$timestamp); $messagebody=("$readline"); $emailpriority=("2"); EMailAlert ($datestamp,$timestamp, $messagebody,$emailpriority); CriticalLogging ($datestamp,$timestamp,$readline); } # Evaluate the log size against established maximum (my $dev,my $ino,my $mode,my $nlink,my $uid,my $gid, my $rdev,$size,my $atime,my $mtime,my $ctime, my $blksize,my $blocks)=stat($logfile); if ($size>$maxlogsize) { LogRollover ($size); $workingfile=File::Tail->new(name=>$logfile, maxinterval=>30, adjustafter=>5, maxbuf=>16384); } # Signal handlers for an attempted clean exit $SIG{INT}=\&CleanExit; $SIG{QUIT}=\&CleanExit; $SIG{ABRT}=\&CleanExit; $SIG{TERM}=\&CleanExit; } } exit; sub TimeStamping { # Dynamically assigns a human readable date/time variable for stamp +ing (my $sec, my $min, my $hour, my $day, my $mon, my $year) =localtime(time); $year=sprintf("%04d",($year+1900)); # Year correction $mon=sprintf("%02d",($mon+1)); # Month correction $day=sprintf("%02d",$day); $hour=sprintf("%02d",$hour); $min=sprintf("%02d",$min); $sec=sprintf("%02d",$sec); $datestamp=("$year-$mon-$day"); # Friendly file date $timestamp=("$hour:$min:$sec"); # Friendly file time } sub LogRollover { # Rollover of logs to an archived datestamped file TimeStamping ($datestamp,$timestamp); my $archivename=("pix.$datestamp.$timestamp.archive"); rename "/pix/pix.log","/pix/pix.$datestamp.$timestamp.archive"; system "/etc/init.d/syslog restart"; # Restart Syslogd $messagebody=("Log at: $size/n Archived to: $archivename"); $emailpriority=("1"); # Low Priority EMailAlert ($messagebody,$emailpriority); } sub EMailAlert { # E-Mail or Page the Administrator of critical alerts and failures # SMTP Relay Server Information my $smtp=Net::SMTP->new('mail.<somedomain>.com' , Hello => '<somedomain>.com' , Timeout => 60, , Debug => 0, ); $smtp->mail( "" ); # Evaluate priority for alphanumeric paging if ($emailpriority=="2") { $smtp->to("<phonenumber>\@<some>"); } $smtp->to("<administrator-type>\@<somedomain>.com"); $smtp->data(); $smtp->datasend("From: PIX Syslog Parser\n"); $smtp->datasend("Subject: PIX Alert Notification\n"); $smtp->datasend("To: Network Administrator\n"); $smtp->datasend("BCC: \n"); $smtp->datasend("\n"); $smtp->datasend("Alert: $datestamp $timestamp\n"); $smtp->datasend("\n"); $smtp->datasend("$messagebody\n"); $smtp->datasend("\n"); $smtp->dataend(); $smtp->quit(); $emailpriority=("1"); } sub CriticalLogging { # Writes critical notifications to seperate log file open (CRITICALLOGFILE, ">>$criticallog") or die "Unable to write critical notification to file\n"; print CRITICALLOGFILE "$datestamp $timestamp\n"; print CRITICALLOGFILE "$readline\n"; close (CRITICALLOGFILE); } sub CleanExit { # Subroutine for a clean exit from script close (CRITICALLOGFILE); close ($logfile); print ("Terminating Script\n"); exit; }

In reply to PIX Syslog Parser by salsa

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (8)
    As of 2017-09-25 16:22 GMT
    Find Nodes?
      Voting Booth?
      During the recent solar eclipse, I:

      Results (282 votes). Check out past polls.