2 ################################################################################
4 # File: NotifyTrigger.pl
5 # Description: This script is a generalized notify trigger. It takes one
6 # parameter, a message file. The format of this file is similar
7 # to an email message. Environment variables will be substituted.
8 # Assumptions: Clearprompt is in the users PATH
9 # Author: Andrew@DeFaria.com
10 # Created: Tue Mar 12 15:42:55 2002
14 # (c) Copyright 2002, Andrew@DeFaria.com, all rights reserved
16 ################################################################################
24 # Add the appropriate path to our modules to @INC array. We use ipconfig to
25 # get the current host's IP address then determine whether we are in the US
26 # or China. Also set our mail server.
27 my @ipconfig = grep (/IP Address/, `ipconfig`);
28 my ($ipaddr) = ($ipconfig[0] =~ /(\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3})/);
30 # US is in the subnets of 192 and 172 while China is in the subnet of 10
31 if ($ipaddr =~ /^192|^172/) {
32 $mailhost="sons-exch02.salira.com";
33 unshift (@INC, "//sons-clearcase/Views/official/Tools/lib");
34 } elsif ($ipaddr =~ /^10/) {
35 $mailhost="sons-exch03.salira.com";
36 unshift (@INC, "//sons-cc/Views/official/Tools/lib");
38 die "Internal Error: Unable to find our modules!\n"
44 # This routine will replace references to environment variables. If an
45 # environment variable is not defined then the string <Unknown> is
48 my $line = shift (@_);
52 while ($line =~ /\$(\w+)/) {
55 if ($ENV{$var} eq "") {
56 $line =~ s/\$$var/\<Unknown\>/;
60 $line =~ s/\$$var/$value/;
75 # First open the message file. If we can't then there's a problem, die!
76 open (MSG, $ARGV[0]) || error "Unable to open message file:\n\n$ARGV[0]\n\n($!)";
80 # Connect to mail server
81 my $smtp = Net::SMTP->new ($mailhost);
83 error "Unable to open connection to mail host: $mailhost" if $smtp == undef;
89 my ($line, $from, $to, @addresses);
91 foreach $line (@lines) {
92 next if $line =~ /^\#/;
93 next if $line =~ /--/;
95 $line = ReplaceText $line;
97 if ($line =~ /^From:\s+/) {
106 if ($line =~ /^To:\s+/) {
110 @addresses = split (/,|;| /);
112 foreach (@addresses) {
119 if ($data_sent eq "F") {
121 $smtp->datasend ($from);
122 $smtp->datasend ($to);
126 if ($from_seen eq "T" && $to_seen eq "T" && $data_sent eq "T") {
127 $smtp->datasend ($line);
129 clearlogmsg "Message file ($ARGV[0]) missing From and/or To!";