Subversion Repositories computer_asset_manager_v1

Rev

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

Rev 24 Rev 25
Line 18... Line 18...
18
my $CRON= ! is_interactive(); # determine if we are in interactive shell
18
my $CRON= ! is_interactive(); # determine if we are in interactive shell
19
 
19
 
20
# control the flow of the program. $CHECKMAIL is pretty clear.
20
# control the flow of the program. $CHECKMAIL is pretty clear.
21
# if $PROCESS is false and $MOVEFILES is true, the files will be moved
21
# if $PROCESS is false and $MOVEFILES is true, the files will be moved
22
# but not processed (ie, they were processed some other way)
22
# but not processed (ie, they were processed some other way)
23
my $CHECKMAIL=1; #controls whether we will check the mail or not
23
my $CHECKMAIL=0; #controls whether we will check the mail or not
24
my $PROCESS=1; # controls whether we will process the files
24
my $PROCESS=1; # controls whether we will process the files
25
my $MOVEFILES=1; # controls whether we will move the files successfully processed
25
my $MOVEFILES=1; # controls whether we will move the files successfully processed
26
 
26
 
27
my $DATADIR; # will hold the reports directory
27
my $DATADIR; # will hold the reports directory
28
my $UNPROCESSED; # will hold the location for unprocessed reports
28
my $UNPROCESSED; # will hold the location for unprocessed reports
29
my $MAXTOPROCESS = 1000;
29
my $MAXTOPROCESS = 10000;
30
my %filesProcessed;
30
my %filesProcessed;
31
 
31
 
32
# following are used to find the configuration file
32
# following are used to find the configuration file
33
my $confFileName = 'rsbackupRead.conf.yaml';
33
my $confFileName = 'rsbackupRead.conf.yaml';
34
my @searchPaths = ( '/etc/camp', '/opt/camp', '/opt/camp/sysinfo', $MY_DIRECTORY );
34
my @searchPaths = ( '/etc/camp', '/opt/camp', '/opt/camp/sysinfo', $MY_DIRECTORY );
Line 115... Line 115...
115
 
115
 
116
my $file;
116
my $file;
117
my $exitMessage;
117
my $exitMessage;
118
my $exitCode;
118
my $exitCode;
119
 
119
 
-
 
120
# The script $processMailScript returns three fields as a tab delimited
-
 
121
# string -- Filename, Exit Code (integer), Exit Message
-
 
122
# The Exit Codes are
-
 
123
#  0 - Processed Normally
-
 
124
#  1 - Invalid Data File Name
-
 
125
#  2 - Could not open the file
-
 
126
#  3 - Duplicate Report
-
 
127
#  4 - Server Not Found
120
 
128
 
121
foreach my $thisFile ( sort @files ) {
129
foreach my $thisFile ( sort @files ) {
122
   if ( $PROCESS ) {
130
   if ( $PROCESS ) {
123
      $tempResults .=  `php $processMailScript '$thisFile'`;
131
      $temp =  `php $processMailScript '$thisFile'`;
124
      ($file,$exitCode,$exitMessage) = split( "\t", $tempResults );
132
      ($file,$exitCode,$exitMessage) = split( "\t", $temp );
125
   } else {
133
   } else {
126
     $results .= "$thisFile moving without processing\n";
134
     $tempResults .= "$thisFile moving without processing\n";
127
     $exitCode = 0;
135
     $exitCode = 0;
128
   }
136
   }
129
   $tempResults = $exitMessage;
137
   $tempResults = "$thisFile\t$exitMessage\n";
130
   if ( $exitCode == 0 ) {
138
   if ( $exitCode == 0 ) {
131
      $filesProcessed{ 'valid' }++;
139
      $filesProcessed{ 'valid' }++;
132
      $tempResults = '';
140
      $tempResults = ''; # do not give messages for files which are Ok
133
      &storeFile( "$UNPROCESSED\/$thisFile" ) if $MOVEFILES;
141
      &storeFile( "$UNPROCESSED\/$thisFile" ) if $MOVEFILES;
134
   } elsif ( $exitCode == 1 ) {
142
   } elsif ( $exitCode == 1 ) {
135
      $filesProcessed{ 'Invalid Data File Name' }++;
143
      $filesProcessed{ 'Invalid Data File Name' }++;
136
      &storeFile( "$UNPROCESSED\/$thisFile", 'InvalidFormat' ) if $MOVEFILES;
144
      &storeFile( "$UNPROCESSED\/$thisFile", 'InvalidFileName' ) if $MOVEFILES;
137
   } elsif ( $exitCode == 2 ) {
145
   } elsif ( $exitCode == 2 ) {
138
      $filesProcessed{ 'Could not open file' }++;
146
      $filesProcessed{ 'Could not open file' }++;
139
   } elsif ( $exitCode == 3 ) {
147
   } elsif ( $exitCode == 3 ) {
140
      $filesProcessed{ 'Duplicate Report' }++;
148
      $filesProcessed{ 'Duplicate Report' }++;
141
      &storeFile( "$UNPROCESSED\/$thisFile", 'Duplicate' ) if $MOVEFILES;
149
      &storeFile( "$UNPROCESSED\/$thisFile", 'Duplicate' ) if $MOVEFILES;
142
   } elsif ( $exitCode == 4 ) {
150
   } elsif ( $exitCode == 4 ) {
143
      $filesProcessed{ 'Server not found in Database' }++;
151
      $filesProcessed{ 'Server not found in Database' }++;
-
 
152
      &storeFile( "$UNPROCESSED\/$thisFile", 'ServerNotFound' ) if $MOVEFILES;
144
   } else {
153
   } else {
145
      $filesProcessed{ 'Unknown File Error' }++;
154
      $filesProcessed{ 'Unknown File Error' }++;
146
   }
155
   }
147
   $results .= $tempResults;
156
   $results .= $tempResults;
148
  last if ++$count >= $MAXTOPROCESS;
157
  last if ++$count >= $MAXTOPROCESS;
149
  print STDERR "\r$count" unless $CRON;
158
  print STDERR "\r$count" unless $CRON;
150
}
159
}
151
 
160
 
152
exit 1;
-
 
153
 
-
 
154
my $emailString;
161
my $emailString;
155
print "\n" unless $CRON; 
162
print "\n" unless $CRON; 
156
$count= 0;
163
$count= 0;
157
foreach my $key ( sort keys %filesProcessed ) {
164
foreach my $key ( sort keys %filesProcessed ) {
158
   $count += $filesProcessed{$key};
165
   $count += $filesProcessed{$key};
Line 160... Line 167...
160
}
167
}
161
$emailString .=  "$count\tTotal Files Processed\n";
168
$emailString .=  "$count\tTotal Files Processed\n";
162
$emailString .=  "--------------------------------\n\n";
169
$emailString .=  "--------------------------------\n\n";
163
$emailString .=  $results;
170
$emailString .=  $results;
164
 
171
 
165
open SEND, "|$reportScript" or die "Could not find sendReport.pl: $!\n";
172
open SEND, "|$reportScript" or die "Could not find $reportScript: $!\n";
166
print SEND $emailString;
173
print SEND $emailString;
167
close SEND;
174
close SEND;
168
 
175
 
169
1;
176
1;