Subversion Repositories computer_asset_manager_v1

Rev

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

Rev 8 Rev 9
Line 1... Line 1...
1
#! /usr/bin/perl -w
1
#! /usr/bin/perl -w
2
 
2
 
-
 
3
# v0.2 20160205 RWR
-
 
4
# Removed echoing the results from parse_sysinfo for all normally processed
-
 
5
# reports. Only if a report is invalid, duped, or waiting on user input
-
 
6
# is anything from parse_sysinfo echoed.
-
 
7
#
-
 
8
# v0.3 20160205 RWR
-
 
9
# Removed most of the reporting, and put it in script sendReport.pl
-
 
10
# which is called from here.
-
 
11
 
3
use IO::Interactive qw(is_interactive interactive busy);
12
use IO::Interactive qw(is_interactive interactive busy);
4
use YAML::XS;
13
use YAML::XS;
5
use Cwd 'abs_path';
14
use Cwd 'abs_path';
6
#use Data::Dumper;
15
#use Data::Dumper;
7
 
16
 
8
use File::Basename;
17
use File::Basename;
9
 
18
 
-
 
19
my $VERSION = '0.8';
10
my $MY_DIRECTORY = abs_path(dirname(__FILE__) );
20
my $MY_DIRECTORY = abs_path(dirname(__FILE__) );
11
 
21
 
12
my $CRON= ! is_interactive(); # determine if we are in interactive shell
22
my $CRON= ! is_interactive(); # determine if we are in interactive shell
13
 
23
 
14
# control the flow of the program. $CHECKMAIL is pretty clear.
24
# control the flow of the program. $CHECKMAIL is pretty clear.
Line 109... Line 119...
109
$UNPROCESSED=$DATADIR . '/' . $$config{'unprocessed_path'};
119
$UNPROCESSED=$DATADIR . '/' . $$config{'unprocessed_path'};
110
 
120
 
111
# check that the executables exist before continuing
121
# check that the executables exist before continuing
112
$getMailScript = "$MY_DIRECTORY/" . $$config{'getMailScript'};
122
$getMailScript = "$MY_DIRECTORY/" . $$config{'getMailScript'};
113
$processMailScript = "$MY_DIRECTORY/" . $$config{'processMailScript'};
123
$processMailScript = "$MY_DIRECTORY/" . $$config{'processMailScript'};
-
 
124
$reportScript = "$MY_DIRECTORY/" . $$config{'reportScript'};
-
 
125
 
114
die "Could not find the getMailScript [$getMailScript] in $MY_DIRECTORY\n" unless -e $getMailScript;
126
die "Could not find the getMailScript [$getMailScript] in $MY_DIRECTORY\n" unless -e $getMailScript;
115
die "Could not find the processMailScript [$processMailScript] in $MY_DIRECTORY\n" unless -e $processMailScript;
127
die "Could not find the processMailScript [$processMailScript] in $MY_DIRECTORY\n" unless -e $processMailScript;
-
 
128
die "Could not find the reportScript [$reportScript] in $MY_DIRECTORY\n" unless -e $reportScript;
-
 
129
 
116
 
130
 
117
# fetch all messages pending from e-mail accounts
131
# fetch all messages pending from e-mail accounts
118
`php $getMailScript` if $CHECKMAIL;
132
`php $getMailScript` if $CHECKMAIL;
119
 
133
 
120
# get a list of all messages waiting to be processed
134
# get a list of all messages waiting to be processed
Line 124... Line 138...
124
 
138
 
125
my $count = 0;
139
my $count = 0;
126
 
140
 
127
foreach my $thisFile ( sort @files ) {
141
foreach my $thisFile ( sort @files ) {
128
   if ( $PROCESS ) {
142
   if ( $PROCESS ) {
129
      $results .=  `php $processMailScript <'$thisFile'`;
143
      $tempResults .=  `php $processMailScript <'$thisFile'`;
130
      if ( $? == -1 ) {
144
      if ( $? == -1 ) {
131
         $exitCode = -1;
145
         $exitCode = -1;
132
         die "Parsing failed: $!\n";
146
         die "Parsing failed: $!\n";
133
      } else {
147
      } else {
134
         $exitCode = $? >> 8;
148
         $exitCode = $? >> 8;
Line 137... Line 151...
137
     $results .= "Not processing file $thisFile";
151
     $results .= "Not processing file $thisFile";
138
     $exitCode = 0;
152
     $exitCode = 0;
139
   }
153
   }
140
   if ( $exitCode == 0 ) {
154
   if ( $exitCode == 0 ) {
141
      $filesProcessed{ 'valid' }++;
155
      $filesProcessed{ 'valid' }++;
-
 
156
      $tempResults = '';
142
      &storeFile( $thisFile ) if $MOVEFILES;
157
      &storeFile( $thisFile ) if $MOVEFILES;
143
   } elsif ( $exitCode == 1 ) {
158
   } elsif ( $exitCode == 1 ) {
144
      $filesProcessed{ 'Invalid Format' }++;
159
      $filesProcessed{ 'Invalid Format' }++;
145
      &storeFile( $thisFile, 'InvalidFormat' ) if $MOVEFILES;
160
      &storeFile( $thisFile, 'InvalidFormat' ) if $MOVEFILES;
146
   } elsif ( $exitCode == 2 || $exitCode == 3 ) {
161
   } elsif ( $exitCode == 2 || $exitCode == 3 ) {
Line 154... Line 169...
154
   } else {
169
   } else {
155
      # at this point, we only have reports waiting for manual CAMP
170
      # at this point, we only have reports waiting for manual CAMP
156
      # updates, so just leave them where they are
171
      # updates, so just leave them where they are
157
      $filesProcessed{ 'Waiting CAMP Updates' }++;
172
      $filesProcessed{ 'Waiting CAMP Updates' }++;
158
   }
173
   }
-
 
174
   $results .= $tempResults;
159
  last if ++$count >= $MAXTOPROCESS;
175
  last if ++$count >= $MAXTOPROCESS;
160
  print STDERR "\r$count" unless $CRON;
176
  print STDERR "\r$count" unless $CRON;
161
}
177
}
162
 
178
 
163
my $emailString;
179
my $emailString;
Line 169... Line 185...
169
}
185
}
170
$emailString .=  "$count\tTotal Files Processed\n";
186
$emailString .=  "$count\tTotal Files Processed\n";
171
$emailString .=  "--------------------------------\n\n";
187
$emailString .=  "--------------------------------\n\n";
172
$emailString .=  $results;
188
$emailString .=  $results;
173
 
189
 
-
 
190
open SEND, "|$reportScript" or die "Could not find sendReport.pl: $!\n";
-
 
191
print SEND $emailString;
-
 
192
close SEND;
-
 
193
 
174
&sendReport( $$config{'sendReport'}, $emailString );
194
# &sendReport( $$config{'sendReport'}, $emailString );
175
 
195
 
176
1;
196
1;