Subversion Repositories computer_asset_manager_v1

Rev

Rev 32 | Rev 75 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32 Rev 73
Line 122... Line 122...
122
   open SENDMAIL, "|$commandLine" or die "Could not open [$commandLine]: $!\n";
122
   open SENDMAIL, "|$commandLine" or die "Could not open [$commandLine]: $!\n";
123
   print SENDMAIL $report;
123
   print SENDMAIL $report;
124
   close SENDMAIL;
124
   close SENDMAIL;
125
} # sendReport
125
} # sendReport
126
 
126
 
-
 
127
sub sendViaSendmail {
-
 
128
   my ( $parameters, $report ) = @_;
-
 
129
   my @header;
-
 
130
   push @header, 'To: ' . qq/$$parameters{'mailTo'}/;
-
 
131
   push @header, 'From: ' . qq/$$parameters{'mailFrom'}/;
-
 
132
   push @header, 'Subject: ' . qq/$$parameters{'mailSubject'}/;
-
 
133
   $report = join( "\n", @header ) . "\n\n" . $report . "\n.\n";
-
 
134
   open SENDMAIL, "|sendmail $$parameters{mailTo}" or die "could not open sendmail: $!\n";
-
 
135
   print SENDMAIL $report;
-
 
136
   close SENDMAIL;
-
 
137
} 
-
 
138
 
-
 
139
 
-
 
140
 
-
 
141
 
127
sub individualReport {
142
sub individualReport {
128
   my $data = shift;
143
   my $data = shift;
129
   my @report;
144
   my @report;
130
   
145
   
131
   for my $key ( 'Device ID', 'Run Time', 'Files', 'Size (M)', 'Deleted', 'Skipped', 'Traffic (M)' ) {
146
   for my $key ( 'Device ID', 'Run Time', 'Files', 'Size (M)', 'Deleted', 'Skipped', 'Traffic (M)' ) {
132
      push @report, "$key: " . $$data{$key} unless $key eq 'mailto';
147
      push @report, "$key: " . $$data{$key} unless $key eq 'mailto';
133
   }
148
   }
134
   return join( "\n", @report );
149
   return join( "\n", @report );
135
}
150
}
136
 
151
 
-
 
152
 
-
 
153
 
137
########################################################################
154
########################################################################
138
# Main Program
155
# Main Program
139
########################################################################
156
########################################################################
140
 
157
 
141
# Read anything passed on STDIN to prepend to e-mail
158
# Read anything passed on STDIN to prepend to e-mail
Line 185... Line 202...
185
                  $results->{$id}->{'Traffic (M)'}
202
                  $results->{$id}->{'Traffic (M)'}
186
               );
203
               );
187
   if ( $results->{$id}->{'mailto'} ) {
204
   if ( $results->{$id}->{'mailto'} ) {
188
      $$configuration{'sendReport'}->{'mailTo'} = $results->{$id}->{'mailto'};
205
      $$configuration{'sendReport'}->{'mailTo'} = $results->{$id}->{'mailto'};
189
      $$configuration{'sendReport'}->{'mailSubject'} = 'Backup Report for ' . $results->{$id}->{'Source'};
206
      $$configuration{'sendReport'}->{'mailSubject'} = 'Backup Report for ' . $results->{$id}->{'Source'};
-
 
207
      if ( $$configuration{'sendReport'}{'emailScript'} ) {
190
      &sendReport( $$configuration{'sendReport'}, &individualReport( $results->{$id} ) );
208
         &sendReport( $$configuration{'sendReport'}, &individualReport( $results->{$id} ) );
-
 
209
      } else {
-
 
210
         &sendViaSendmail( $$configuration{'sendReport'}, &individualReport( $results->{$id} ) );
-
 
211
      }
191
   }
212
   }
192
      
213
      
193
}
214
}
194
$dbh->disconnect();
215
$dbh->disconnect();
195
 
216
 
Line 197... Line 218...
197
$$configuration{'sendReport'}->{'mailTo'} = $saveMailTo;
218
$$configuration{'sendReport'}->{'mailTo'} = $saveMailTo;
198
$$configuration{'sendReport'}->{'mailSubject'} = $saveSubject;
219
$$configuration{'sendReport'}->{'mailSubject'} = $saveSubject;
199
 
220
 
200
 
221
 
201
#print $message;
222
#print $message;
-
 
223
if ( $$configuration{'sendReport'}{'emailScript'} ) {
202
&sendReport( $$configuration{'sendReport'}, $message );
224
   &sendReport( $$configuration{'sendReport'}, $message );
-
 
225
} else {
-
 
226
   &sendViaSendmail( $$configuration{'sendReport'}, $message );
203
 
227
}
-
 
228
            
204
1;
229
1;