Subversion Repositories computer_asset_manager_v1

Rev

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

Rev 28 Rev 35
Line 18... Line 18...
18
 * are terminated by two blank lines, not the constant 'sending incremental file
18
 * are terminated by two blank lines, not the constant 'sending incremental file
19
 * list'. Simply modified to terminate on an empty line OR the constant
19
 * list'. Simply modified to terminate on an empty line OR the constant
20
 * 
20
 * 
21
 * Also set it up to only report on one file at a time, ie accept
21
 * Also set it up to only report on one file at a time, ie accept
22
 * only one parameter, and that is assumed to be a file name
22
 * only one parameter, and that is assumed to be a file name
-
 
23
 * 
-
 
24
 * Version 0.2.0 20160826 RWR
-
 
25
 * Fixed problem where file name has YYYYMMDD_HHMMSS_servername_backup.log instead of
-
 
26
 *    YYYYMMDD_servername_backup.log (it now checks for both)
-
 
27
 * Start and end time now accepted as YYYYMMDD_HHMMSS or YYYYMMDDHHMMSS
23
*/
28
*/
24
 
29
 
25
   /*
30
   /*
26
    * This will return error codes
31
    * This will return error codes
27
    * 1 - Invalid Data File Name
32
    * 1 - Invalid Data File Name
Line 30... Line 35...
30
    * 4 - Server Not Found
35
    * 4 - Server Not Found
31
    */
36
    */
32
 
37
 
33
 
38
 
34
require 'library.php';
39
require 'library.php';
35
$VERSION='0.1.0';
40
$VERSION='0.2.0';
36
 
41
 
37
$results = array();
42
$results = array();
38
 
43
 
39
function parseFile( $filename, $path, $maxLineLength = 4096 ) {
44
function parseFile( $filename, $path, $maxLineLength = 4096 ) {
40
   $data = array ( 
45
   $data = array ( 
Line 60... Line 65...
60
 
65
 
61
   $line;
66
   $line;
62
 
67
 
63
   $data['file_name'] = $filename;
68
   $data['file_name'] = $filename;
64
   # get server name from the file name, which should be
69
   # get server name from the file name, which should be
-
 
70
   # date_time_servername.backup.log
-
 
71
   if ( preg_match( '/(\d+)_(\d+)_([a-z0-9_.-]+)\.backup\.log/', $filename, $matches ) ) {
-
 
72
      $data['report_date'] = $matches[1] . $matches[2];
-
 
73
      $data['server_name'] = $matches[3];
-
 
74
   } elseif ( preg_match( '/(\d+)_([a-z0-9_.-]+)\.backup\.log/', $filename, $matches ) ) {
65
   # datetime_servername.backup.log
75
   # datetime_servername.backup.log
66
   if ( preg_match( '/(\d+)_([a-z0-9_.-]+)\.backup\.log/', $filename, $matches ) ) {
-
 
67
      $data['report_date'] = $matches[1];
76
      $data['report_date'] = $matches[1];
68
      $data['server_name'] = $matches[2];
77
      $data['server_name'] = $matches[2];
69
   } else {
78
   } else {
70
      # ensure only three parts returned
79
      # ensure only three parts returned
71
      $data['error'] = "1\tInvalid Data File Name";
80
      $data['error'] = "1\tInvalid Data File Name";
Line 132... Line 141...
132
      }
141
      }
133
      
142
      
134
      // process rsbackup summary
143
      // process rsbackup summary
135
      while (( $line = fgets( $log, $maxLineLength )) !== false ) {
144
      while (( $line = fgets( $log, $maxLineLength )) !== false ) {
136
         $data['notes'] .= $line;
145
         $data['notes'] .= $line;
137
         if ( preg_match( '/^Begin\s+(\d+)/', $line, $matches )   ) {
146
         if ( preg_match( '/^Begin\s+([\d_]+)/', $line, $matches )   ) {
138
            $data['start_time'] = $matches[1];
147
            $data['start_time'] = str_replace( '_', '', $matches[1] );
139
         } elseif ( preg_match( '/Complete\s+(\d+)/', $line, $matches )   ) {
148
         } elseif ( preg_match( '/Complete\s+([\d_]+)/', $line, $matches )   ) {
140
            $data['end_time'] = $matches[1];
149
            $data['end_time'] = str_replace( '_', '', $matches[1] );
141
         } elseif ( preg_match( '/^Status:/', $line, $matches )   ) {
150
         } elseif ( preg_match( '/^Status:/', $line, $matches )   ) {
142
            break;
151
            break;
143
         }
152
         }
144
      }
153
      }
145
      // the rest of it just goes into notes
154
      // the rest of it just goes into notes
Line 160... Line 169...
160
   $results[] = $message;
169
   $results[] = $message;
161
}
170
}
162
 
171
 
163
 
172
 
164
/* 
173
/* 
165
 * checks for a duplicate report, ie one that has already been run.
174
 * checks for a duplicate report, ie one that has already been run.q
166
 * if this computer has a report already for this date/time
175
 * if this computer has a report already for this date/time
167
 */ 
176
 */ 
168
function checkDuplicate( $backups_id, $report_date) {
177
function checkDuplicate( $backups_id, $report_date) {
169
   $sql = "select count(*) from backups_run where backups_id = $backups_id and report_date = $report_date";
178
   $sql = "select count(*) from backups_run where backups_id = $backups_id and report_date = $report_date";
170
   $count = getOneDBValue( $sql );
179
   $count = getOneDBValue( $sql );
Line 248... Line 257...
248
 
257
 
249
 
258
 
250
 
259
 
251
$filename = $argv[1];
260
$filename = $argv[1];
252
$report = parseFile( $filename, $configuration['datapath'] . '/' . $configuration['unprocessed_path'] );
261
$report = parseFile( $filename, $configuration['datapath'] . '/' . $configuration['unprocessed_path'] );
253
// print_r( $report ); print "\n";
262
# print_r( $report ); print "\n";
254
 
263
 
255
if ( isset( $report['error'] ) ) { // we had an error processing the report
264
if ( isset( $report['error'] ) ) { // we had an error processing the report
256
   $result[] = "$filename\t" . $report['error']; 
265
   $result[] = "$filename\t" . $report['error']; 
257
} else {
266
} else {
258
   $result[] = recordReport( $report );
267
   $result[] = recordReport( $report );