#!/usr/bin/perl
# Perl script to send email alerts from HP OV events
# Invoked via notification option
# Version 2.8
# To use enter the following:
#perl <scriptname> <MessageID> <SourceNode> <SourceNodeType> <DateCreated> <TimeCreated>
#<DateReceived> <TimeReceived> <Application> <MessageGroup> <Object> <Severity> <Operators>
#<MessageText> <Instructions> <CMA>
#Place a text file called mailList.txt in the same location as the script and put all the destination e-mail #addresses in a comma delimited from in it.
my $message_id = $ARGV[0];
my $source_node = $ARGV[1];
my $source_node_type = $ARGV[2];
my $date_created = $ARGV[3];
my $time_created = $ARGV[4];
my $date_received = $ARGV[5];
my $time_received = $ARGV[6];
my $application = $ARGV[7];
my $message_group = $ARGV[8];
my $object = $ARGV[9];
my $severity = $ARGV[10];
my $operators = $ARGV[11];
my $message_text = $ARGV[12];
my $instruction = $ARGV[13];
my $cma = $ARGV[14];
my $supp_dup_msgs = $ARGV[15];
use Net::SMTP;
use strict;
use Text::Wrap;
# Wrap the message_text into something more palatable
my $wrap_text = wrap("\t", "", "$message_text\n");
# Configure the mail server IP/name here
my $MAILHOST = '192.168.0.0'; #Insert your SMTP server here
my @addresses = ();
open MAILLIST,"mailList.txt";
while(<MAILLIST>) {
chomp;
push @addresses,$_;
}
# Configure a name to appear in the 'From' field of the email msg here
my $FROM = '[email protected]';
my $msg = ("Header\n
\n
$source_node had a $severity error on $date_created at $time_created.\n
The Error message is:\n
\n
$wrap_text\n
\n
Footer");
for $address (@addresses) {
# connect to the smtp server
my $smtp = Net::SMTP->new($MAILHOST, Timeout => 10) or die "Unable to connect to mail host :
$MAILHOST - $!\n";
$smtp->mail($address);
$smtp->to($address);
$smtp->data();
$smtp->datasend("From: $FROM\n");
$smtp->datasend("To: $address\n");
$smtp->datasend("Subject: $source_node has a $severity error.\n");
$smtp->datasend("\n$msg \n\n");
$smtp->datasend;
$smtp->dataend();
$smtp->quit;
open(MYOUTFILE, ">>/var/opt/OV/maillog.log");
print MYOUTFILE "Timestamp: " $source_node “ “ $date_created “ “ $time_created “ “ $message_text “\n”;
close(MYOUTFILE);
}