Listing 4: Optmod.pl NONEXECUTABLE ######################################################################## # #This listing shows examples of different notifications (e.g., ping, tracert) that you can configure # the module to call and perform. The script writes the results to a log file. The script also # sends email to a designated person; the log file is the message body. # ######################################################################## #Sets up the Time Perl Module to insert a time stamp into the log file. use Time::localtime; #Sets up the log file into the variable. $tslogfile="tslogfile.txt"; #Opens the log file. If the log file does not open, the programs dies. open (LOG, ">>tslogfile.txt")|| die "Cannot open $tslogfile: $!"; #Generates the ping command with the variable from webmonitoringmodulescript.pl # and outputs the results to ouput.txt. $target = join(" ","ping",@ARGV[0],">output.txt"); #Runs the ping command. system($target); #Opens the output file for Ping in order to move the data to the log file. open(OUTPUT, "output.txt"); #Selects the first line in the output file. $line=; #Places the timestamp in the log file. print LOG (ctime()); #Goes through each line in the output file and copies each line to the log file. while ($line ne"") { print LOG ($line); $line=; } #Closes the output file. close (OUTPUT); #Generates the tracert command with the variable from webmonitoringmodulescript.pl # and outputs it the results to ouput.txt. $target = join(" ","tracert",@ARGV[0],">output.txt"); #Runs the tracert command. system ($target); #Opens the output file for tracert in order to move the data to the log file. open(OUTPUT, "output.txt"); #Selects the first line in the output file. $line=; #Goes through each line in the output file and copies each line to the log file. while ($line ne"") { print LOG ($line); $line=; } print LOG ("\n"); #Closes the output and log files. close (OUTPUT); close (LOG); #Sets up the command line to send an email using Blat. # Blat is freeware. # You can download Blat from the Internet. # You must install and configure Blat using an SMTP Server that can send email. ######################################################################## # #CUSTOMIZATION SECTION A # ######################################################################## #If you want more than one person to receive the email, separate each name with a comma # and no spaces. $emailto = "tlandry\@oaot.com, caubley\@oao.com"; $emailsender="tlandry\@oao.com" $emailsubject = "Warning"; #The email's message body is in a file (i.e., the log file). $emailMessage= "tslogfile.txt" ######################################################################## # #END CUSTOMIZATION SECTION A # ######################################################################## #Generates and runs the blat command line. $email = join(" ","blat", $emailmessage, "-s", $emailsubject, "-t", $emailto ,"-f",$emailsender,"-q"); system($email); ######################################################################## # #SCRIPT ENDS HERE # ######################################################################## 13 1