#!/opt/vdops/bin/perl # Swatch calls this script when it wants to e-mail somebody. Why use this # instead of Swatch's built-in 'mail=' function? Because this script # mangles the text, stripping off extraneous junk and replacing IP addresses # with hostnames # # This script wants two arguments: the first is the alias to whom the # e-mail will be sent, and the second (and succeeding # arguments) are the words of the message which swatch wants us to send # V Who When What # --------------------------------------------------------------------------- # 1.1.0 skendric 08-26-2010 Upgrade to perl-5.10.1 # 1.0.9 skendric 03-06-2008 Pretty debug output # 1.0.8 skendric 11-21-2007 Add help # 1.0.7 skendric 12-20-2006 Replace strip_html with strip_junk # 1.0.6 skendric 11-06-2006 Strip date and time # 1.0.5 skendric 10-30-2006 Refactor to support Netops structure # 1.0.4 skendric 09-27-2006 Refactor to support SwatchOps-1.09 # 1.0.3 skendric 08-14-2006 Fix subroutine names to support 1.07 # 1.0.2 skendric 04-09-2006 Upgrade to SwatchOps-1.07 # 1.0.1 skendric 04-02-2006 Upgrade to SwatchOps-1.06 # 1.0.0 skendric 04-17-2005 First Version # # Load modules use strict; use warnings; use feature 'say'; use feature 'switch'; use English; use Getopt::Std; use Mail::Send; use FHCRC::Netops::NetopsData 1.1.0; use FHCRC::Netops::SwatchOps 1.1.3; use FHCRC::Netops::Utilities 1.1.2; # Declare global variables # Declare local variables my $line; # The text we plan to send my $recipient; # E-mail alias of recipient my $subject; # Subject line for the message # Define global variables $debug = 0; $program_name = 'mail_em'; $subject = 'Swatch Message'; $usage = 'Usage: mail_em {alias} {message body}'; $version = '1.1.0'; getopts('', \%option); # Make things look pretty say('') if $debug; # Announce beginning say "Beginning $PROGRAM_NAME" if $debug; # Grab arguments $recipient = shift; $line = join $SPACE, @ARGV; chomp $line; unless (defined $recipient) { log_it('Bailing: did not receive recipient'); die; } unless (length $line > 0) { log_it('Bailing: did not receive text'); die; } #### Begin Main Program #### { my $fh; # Mail::Send file handle my $msg; # Mail::Send object # Strip out date, time, and html $line = strip_junk($line); $line = strip_date($line); $line = strip_time($line); # Mangle as needed given ($line) { # Mangle UPS messages when (/snmptrapd.*PowerNet-MIB/) { $line = mangle_apc($line); } # Mangle Exchange messages when (/Microsoft Exchange.*www.microsoft.com/) { $line = mangle_exchange($line); } } # Create Mail::Send object $msg = Mail::Send->new(); $msg->to($recipient); $msg->subject($subject); # Build message body $fh = $msg->open; print $fh $line; # Send message $fh->close; log_it("Sent $recipient: $line"); # Announce ending say "Ending $PROGRAM_NAME" if $debug; } #### End Main Program #### ######################################################################## # Output help ######################################################################## sub HELP_MESSAGE { print <