Subversion Repositories computer_asset_manager_v1

Rev

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

Rev 23 Rev 24
Line 24... Line 24...
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 = 10000;
29
my $MAXTOPROCESS = 1000;
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 = "backupRead.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 );
35
 
35
 
36
 
36
 
37
sub loadConfig {
37
sub loadConfig {
38
   my ( $confFileName, @searchPaths ) = @_;
38
   my ( $confFileName, @searchPaths ) = @_;
Line 61... Line 61...
61
   use File::Basename;
61
   use File::Basename;
62
   my $file = shift;
62
   my $file = shift;
63
   my $targetDirectory = shift;
63
   my $targetDirectory = shift;
64
   unless ( $targetDirectory ) {
64
   unless ( $targetDirectory ) {
65
      my ($name,$path) = fileparse($file);
65
      my ($name,$path) = fileparse($file);
66
      my ( $date,$time,$client,$server,$serial) = split( '_', $name );
66
      my ( $date,$server,$serial) = split( '_', $name );
-
 
67
      my $year = substr( $date,0,4);
67
      my ( $year, $month, $day ) = split( '-', $date );
68
      my $month = substr( $date, 4, 2);
-
 
69
      my $day = substr( $date, 6,2);
68
      $targetDirectory = "/$year/$month";
70
      $targetDirectory = "/$year/$month";
69
   }
71
   }
70
   $targetDirectory = "$DATADIR/$targetDirectory";
72
   $targetDirectory = "$DATADIR/$targetDirectory";
71
   `mkdir -p '$targetDirectory'` unless -d $targetDirectory;
73
   `mkdir -p '$targetDirectory'` unless -d $targetDirectory;
72
   `mv '$file' '$targetDirectory'`;
74
   `mv '$file' '$targetDirectory'`;
Line 92... Line 94...
92
 
94
 
93
 
95
 
94
# fetch all messages pending from e-mail accounts
96
# fetch all messages pending from e-mail accounts
95
`php $getMailScript` if $CHECKMAIL;
97
`php $getMailScript` if $CHECKMAIL;
96
 
98
 
-
 
99
# see if anything is gzipped and, if so, gunzip it
-
 
100
`gunzip -f $UNPROCESSED\/*.gz`;
-
 
101
 
97
# get a list of all messages waiting to be processed
102
# get a list of all messages waiting to be processed
98
opendir ( my $dh, $UNPROCESSED ) or die "Could not open $UNPROCESSED for read: $!";
103
opendir ( my $dh, $UNPROCESSED ) or die "Could not open $UNPROCESSED for read: $!";
-
 
104
@files = sort grep { ! /^\./ && -f "$UNPROCESSED/$_" } readdir( $dh );
99
@files = map{ "$UNPROCESSED\/$_" } sort grep { ! /^\./ && -f "$UNPROCESSED/$_" } readdir( $dh );
105
#@files = map{ "$UNPROCESSED\/$_" } sort grep { ! /^\./ && -f "$UNPROCESSED/$_" } readdir( $dh );
100
closedir $dh;
106
closedir $dh;
101
 
107
 
102
my $count = 0;
108
my $count = 0;
103
 
109
 
-
 
110
#0 - Ok
-
 
111
#1 - Invalid Data File Name
-
 
112
#2 - Could not open the file
-
 
113
#3 - Duplicate Report
-
 
114
#4 - Server not found in database
-
 
115
 
-
 
116
my $file;
-
 
117
my $exitMessage;
-
 
118
my $exitCode;
-
 
119
 
-
 
120
 
104
foreach my $thisFile ( sort @files ) {
121
foreach my $thisFile ( sort @files ) {
105
   if ( $PROCESS ) {
122
   if ( $PROCESS ) {
106
      $tempResults .=  `php $processMailScript <'$thisFile'`;
123
      $tempResults .=  `php $processMailScript '$thisFile'`;
107
      if ( $? == -1 ) {
-
 
108
         $exitCode = -1;
-
 
109
         die "Parsing failed: $!\n";
-
 
110
      } else {
-
 
111
         $exitCode = $? >> 8;
124
      ($file,$exitCode,$exitMessage) = split( "\t", $tempResults );
112
      }
-
 
113
   } else {
125
   } else {
114
     $results .= "$thisFile moving without processing\n";
126
     $results .= "$thisFile moving without processing\n";
115
     $exitCode = 0;
127
     $exitCode = 0;
116
   }
128
   }
-
 
129
   $tempResults = $exitMessage;
117
   if ( $exitCode == 0 ) {
130
   if ( $exitCode == 0 ) {
118
      $filesProcessed{ 'valid' }++;
131
      $filesProcessed{ 'valid' }++;
119
      $tempResults = '';
132
      $tempResults = '';
120
      &storeFile( $thisFile ) if $MOVEFILES;
133
      &storeFile( "$UNPROCESSED\/$thisFile" ) if $MOVEFILES;
121
   } elsif ( $exitCode == 1 ) {
134
   } elsif ( $exitCode == 1 ) {
122
      $filesProcessed{ 'Invalid Format' }++;
135
      $filesProcessed{ 'Invalid Data File Name' }++;
123
      &storeFile( $thisFile, 'InvalidFormat' ) if $MOVEFILES;
136
      &storeFile( "$UNPROCESSED\/$thisFile", 'InvalidFormat' ) if $MOVEFILES;
-
 
137
   } elsif ( $exitCode == 2 ) {
-
 
138
      $filesProcessed{ 'Could not open file' }++;
-
 
139
   } elsif ( $exitCode == 3 ) {
-
 
140
      $filesProcessed{ 'Duplicate Report' }++;
-
 
141
      &storeFile( "$UNPROCESSED\/$thisFile", 'Duplicate' ) if $MOVEFILES;
-
 
142
   } elsif ( $exitCode == 4 ) {
-
 
143
      $filesProcessed{ 'Server not found in Database' }++;
124
   } else {
144
   } else {
125
      $filesProcessed{ 'Unknown File Error' }++;
145
      $filesProcessed{ 'Unknown File Error' }++;
126
   }
146
   }
127
   $results .= $tempResults;
147
   $results .= $tempResults;
128
  last if ++$count >= $MAXTOPROCESS;
148
  last if ++$count >= $MAXTOPROCESS;
129
  print STDERR "\r$count" unless $CRON;
149
  print STDERR "\r$count" unless $CRON;
130
}
150
}
131
 
151
 
-
 
152
exit 1;
-
 
153
 
132
my $emailString;
154
my $emailString;
133
print "\n" unless $CRON; 
155
print "\n" unless $CRON; 
134
$count= 0;
156
$count= 0;
135
foreach my $key ( sort keys %filesProcessed ) {
157
foreach my $key ( sort keys %filesProcessed ) {
136
   $count += $filesProcessed{$key};
158
   $count += $filesProcessed{$key};