As the previous thread, I too want to use Mr Bowden's perl script. However, I don't care much for the Unix "Epoch" timestamp that it imposes. So...can anyone help with the re-writing of the script to take the time arg out? The simple solution is to put the generic HP OV var for the time ($X) in the message part....but I'm sure we can all do a better job than that...
Thanks team.
Here's the crux part of the script:
###################################################
my ($node, $alert, $time, @email_addresses) = @ARGV;
# check that we have the miminum fields which we require
if (! ($node && $alert && $time) ) {
die "You must supply a value for the node, alert message and time !\nNode = $node\nMessage = $alert\nTime = $time\n\n";
}
$time = localtime($time); # convert to readable format
my $msg = ("$time : $node : $alert\n"
;
# connect to the smtp server
my $smtp = Net::SMTP->new($MAILHOST, Timeout => 10) or die "Unable to connect to mail host : $MAILHOST - $!\n";
# add email addresses configured in @EMAIL_TO to any email addresses
# passed in args from command line
@email_addresses = (@email_addresses, @EMAIL_TO);
foreach my $address (@email_addresses) {
$smtp->mail($address);
$smtp->to($address);
$smtp->data();
$smtp->datasend("From: $FROM\n"
;
$smtp->datasend("To: $address\n"
;
$smtp->datasend("Subject: $alert : $node\n"
;
$smtp->datasend("\n$msg \n\n"
;
$smtp->datasend;
$smtp->dataend();
}
$smtp->quit;
################################################################
Thanks team.
Here's the crux part of the script:
###################################################
my ($node, $alert, $time, @email_addresses) = @ARGV;
# check that we have the miminum fields which we require
if (! ($node && $alert && $time) ) {
die "You must supply a value for the node, alert message and time !\nNode = $node\nMessage = $alert\nTime = $time\n\n";
}
$time = localtime($time); # convert to readable format
my $msg = ("$time : $node : $alert\n"
# connect to the smtp server
my $smtp = Net::SMTP->new($MAILHOST, Timeout => 10) or die "Unable to connect to mail host : $MAILHOST - $!\n";
# add email addresses configured in @EMAIL_TO to any email addresses
# passed in args from command line
@email_addresses = (@email_addresses, @EMAIL_TO);
foreach my $address (@email_addresses) {
$smtp->mail($address);
$smtp->to($address);
$smtp->data();
$smtp->datasend("From: $FROM\n"
$smtp->datasend("To: $address\n"
$smtp->datasend("Subject: $alert : $node\n"
$smtp->datasend("\n$msg \n\n"
$smtp->datasend;
$smtp->dataend();
}
$smtp->quit;
################################################################