#!/opt/vdops/bin/perl # Swatch calls this script when it wants to page somebody. # Using this script offers several advantages. First, swatch doesn't # currently allow the use of quotes inside an exec string ... and # we need quotes when we invoke qpage. Second, we can massage the # text of the page. Third, this script offers TOC services (i.e. it # contains code to log messages to the TOC). # # This script wants two arguments: the first is the qpage name (the # recipient) to whom the page 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.6.6 skendric 03-04-2011 Handle empty and undef messagess # 1.6.5 skendric 08-26-2010 Upgrade to perl-5.10.1 # 1.6.4 skendric 08-20-2008 Only log time to apager window # 1.6.3 skendric 03-06-2008 Pretty debug output # 1.6.2 skendric 12-29-2007 Send toclogd date and time with apager # 1.6.1 skendric 12-13-2007 Fixed send_page invocation bug # 1.6.0 skendric 12-04-2007 Add serious switch # 1.5.7 skendric 11-21-2007 Log successful as well as unsuccessful pages # 1.5.6 skendric 06-19-2007 Ignore sops-duty pages # 1.5.5 skendric 04-09-2007 Escape parens heading to TOC's apager frame # 1.5.4 skendric 01-10-2007 Log paging failures # 1.5.3 skendric 12-20-2006 Replace strip_html with strip_junk # 1.5.2 skendric 12-17-2006 Fix bugs in use of strip_xxxx and send_page # 1.5.1 skendric 11-06-2006 Strip date and time # 1.5.0 skendric 10-30-2006 Refactor to support Netops structure # 1.4.2 skendric 09-17-2006 Refactor to support SwatchOps-1.09 # 1.4.1 skendric 04-09-2006 Migrated to SwatchOps-1.07 # 1.4.0 skendric 04-02-2006 Migrated to SwatchOps-1.06 # 1.3.1 skendric 02-01-2006 Convert core section to switch statement # 1.3.0 skendric 04-17-2005 Migrate to SwatchOps.pm # 1.2.1 skendric 04-17-2005 Fiddle with logging duty pages to apager.txt # Generalize convert_ip_addr_to_hostname # 1.2.0 skendric 03-28-2005 Add UPS text mangling # 1.1.7 skendric 03-25-2005 Syntax clean-up # 1.1.6 skendric 11-15-2004 Generalized snmptrapd address conversion # 1.1.5 skendric 07-16-2004 Fixed bug in UPS address conversion # 1.1.4 skendric 04-10-2004 Fixed bug in log_it invocation # 1.1.3 skendric 03-30-2004 Fixed bug in qpage invocation # 1.1.2 phirayam 02-03-2004 Changed path for perl # 1.1.1 skendric 11-09-2002 Fix bug in UPS/ip addr translation # 1.1.0 skendric 11-06-2002 Translate UPS ip addr into hostnames # 1.0.0 skendric 10-15-2002 First Version # # Load modules use strict; use warnings; use feature 'say'; use feature 'switch'; use English; use Getopt::Std; use Regexp::Common; use Sys::Hostname; use FHCRC::Netops::NetopsData 1.1.8; use FHCRC::Netops::SwatchOps 1.1.8; use FHCRC::Netops::Utilities 1.1.9; # Declare local variables my $echo; # Location of the echo binary my $line; # The text we plan to send to pagers my $recipient; # Recipient of page my $tocpipe; # Path to the toclog pipe # Define global variables $debug = 0; $dome = 1; $echo = '/bin/echo'; $tocpipe = '/home/tocops/.tocpipe'; # Specify SNPP host given (hostname) { when (/vishnu/) { $snpp_host = 'danalite' } default { $snpp_host = 'localhost' } } # The basics $program_name = 'page_em'; $usage = 'Usage: page_em [-s yes|no] [-d {integer}] [-h {SNPP host}] {pager id} {message}'; $version = '1.6.6'; getopts('d:h:s:', \%option); $debug = $option{d} if defined $option{d}; $snpp_host = $option{h} if defined $option{h}; given ($option{s}) { when ('yes') { $dome = 1 } when ('no') { $dome = 0 } } $dome = 1 unless $RE{num}{int}->matches($dome); # 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 (defined $line) { log_it('Bailing: did not receive text'); die; } unless (length $line > 0) { log_it('Bailing: text is empty'); die; } # Debug info say "page_em received: $line" if $debug > 0; #### Begin Main Program #### { # 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); $line = strip_time($line); } # Mangle Exchange messages when (/Microsoft Exchange.*www.microsoft.com/) { $line = mangle_exchange($line); $line = strip_time($line); } } # Send page if ($dome) { my (%arg, $diag, $result); %arg = (host => $snpp_host, recipient => [ $recipient ], message => $line); $diag = "to $recipient using $snpp_host and message: $line"; unless ( send_page(\%arg) ) { say "Unable to send page $diag"; log_it("Unable to send page $diag"); } } else { say "Paging is disabled: $recipient $line"; log_it("Paging is disabled: $recipient $line"); } # Log to TOC's apager frame unless ($recipient =~ /sops-duty/) { if ($recipient =~ /duty/i or $recipient =~ /vdops/i) { # $line =~ s/([()])/\\$1/g; system "$echo apager $time $line > $tocpipe"; } } # Announce ending say "Ending $PROGRAM_NAME" if $debug; } #### End Main Program #### ######################################################################## # Output help ######################################################################## sub HELP_MESSAGE { print <