Subversion Repositories computer_asset_manager_v1

Rev

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

Rev 23 Rev 25
Line 5... Line 5...
5
#use Data::Dumper;
5
#use Data::Dumper;
6
use File::Basename;
6
use File::Basename;
7
use YAML::XS;
7
use YAML::XS;
8
 
8
 
9
 
9
 
-
 
10
 
10
my $VERSION = '0.8';
11
my $VERSION = '0.8';
11
my $MY_DIRECTORY = abs_path(dirname(__FILE__) );
12
my $MY_DIRECTORY = abs_path(dirname(__FILE__) );
12
my $message; # the message to send
13
my $message; # the message to send
13
my $query = qq/select
14
my $query = qq|select 
14
                  sysinfo_report.sysinfo_report_id 'ID', 
15
                  backups_run.backups_run_id 'ID',
15
                  sysinfo_report.report_date 'Date',
16
                  device.device_id 'Device ID',
16
                  client.name 'Client',
17
                  device.name 'Source',
-
 
18
                  timediff( backups_run.end_time,backups_run.start_time ) 'Run Time',
-
 
19
                  backups_run.transferred_count 'Files',
-
 
20
                  round(backups_run.transferred_size/1024/1024,2) 'Size (M)',
17
                  device.name 'Device',
21
                  backups_run.files_deleted 'Deleted',
18
                  sysinfo_report.notes 'Notes'
22
                  backups_run.skipped 'Skipped',
-
 
23
                  round( backups_run.data_sent/1024/1024,2) 'Traffic (M)'
19
               from 
24
               from
20
                  sysinfo_report 
25
                  backups_run
21
                  join device using (device_id) 
26
                  join backups using (backups_id)
22
                  join site site using (site_id) 
27
                  join device using (device_id)
23
                  join client using (client_id) 
-
 
24
               where 
28
               where
25
                  sysinfo_report.added_date > date_sub( now(), interval 1 day)
29
                  report_date > date_sub( now(), interval 1 day)
26
                  and sysinfo_report.notes is not null/;
30
               |;
-
 
31
 
27
                  
32
                  
-
 
33
                  
-
 
34
my $count = qq/select count(*) 'Count' 
-
 
35
               from backups_run 
-
 
36
               where added_date > date_sub( now(), interval 1 day)/;
-
 
37
 
28
my $count = qq/select 
38
my $missing = qq/select 
-
 
39
                  device.device_id ID,
-
 
40
                  device.name name
-
 
41
               from
-
 
42
                  ( 
-
 
43
                     select distinct( backups_id ) 
-
 
44
                     from 
-
 
45
                        backups_run 
-
 
46
                     where 
-
 
47
                        (datediff( current_date(),added_date) < 5 ) 
-
 
48
                  ) last_five
29
                  count(*) 'Count'
49
                  left join
-
 
50
                  (
-
 
51
                     select 
-
 
52
                        distinct( backups_id ) 
30
               from sysinfo_report
53
                     from 
-
 
54
                        backups_run
-
 
55
                     where 
31
               where sysinfo_report.added_date > date_sub( now(), interval 1 day)/;
56
                        datediff( current_date(),added_date) < 1
-
 
57
                  ) today using (backups_id)
-
 
58
                  join 
-
 
59
                     backups using (backups_id)
-
 
60
                  join 
-
 
61
                     device using (device_id)
-
 
62
               where 
-
 
63
                  today.backups_id is null
-
 
64
                  /;
-
 
65
 
32
 
66
 
33
# following are used to find the configuration file
67
# following are used to find the configuration file
34
my $confFileName = "sysinfoRead.conf.yaml";
68
my $confFileName = "rsbackupRead.conf.yaml";
35
my @searchPaths = ( '/etc/camp', '/opt/camp', '/opt/camp/sysinfo', $MY_DIRECTORY );
69
my @searchPaths = ( '/etc/camp', '/opt/camp', '/opt/camp/sysinfo', $MY_DIRECTORY );
36
 
70
 
37
 
71
 
38
sub loadConfig {
72
sub loadConfig {
39
   my ( $confFileName, @searchPaths ) = @_;
73
   my ( $confFileName, @searchPaths ) = @_;
Line 101... Line 135...
101
$sth->execute();
135
$sth->execute();
102
my $results = $sth->fetchrow_hashref();
136
my $results = $sth->fetchrow_hashref();
103
$message .= "$results->{Count} reports in last 24 hours\n";
137
$message .= "$results->{Count} reports in last 24 hours\n";
104
$sth->finish();
138
$sth->finish();
105
 
139
 
-
 
140
$results = $dbh->selectall_hashref( $missing, 'ID' );
-
 
141
if ( %$results ) {
-
 
142
   $message .= '='x40 . "\nWARNING, no backup reports for the following machines\n" . '='x40 . "\n";
-
 
143
   foreach my $device ( keys %$results ) {
-
 
144
      $message .= sprintf( "%6d\t%s\n", $device, $results->{$device}->{name} );
-
 
145
   }
-
 
146
   $message .= '='x40 . "\n\n";
-
 
147
}
-
 
148
 
106
$results = $dbh->selectall_hashref( $query, 'ID' );
149
$results = $dbh->selectall_hashref( $query, 'ID' );
-
 
150
$message .= 'Device  Device Name                               Run Time  Files Size (M) Delete   Skip     xfer' . "\n" . '='x40 . "\n";
107
foreach my $id ( keys %$results ) {
151
foreach my $id ( keys %$results ) {
108
   $message .= $results->{$id}->{Date} . "\t" . $results->{$id}->{Client} . "\t" . $results->{$id}->{Device} . "\n";
152
   $message .= sprintf( "%7u %-40s %9s %6u %8.2f %6u %6u %8.2f\n",
109
   $message .= $results->{$id}->{Notes} . "\n\n";
153
                  $results->{$id}->{'Device ID'} , 
-
 
154
                  $results->{$id}->{'Source'} , 
-
 
155
                  $results->{$id}->{'Run Time'} ,
-
 
156
                  $results->{$id}->{'Files'} ,
-
 
157
                  $results->{$id}->{'Size (M)'} ,
-
 
158
                  $results->{$id}->{'Deleted'} ,
-
 
159
                  $results->{$id}->{'Skipped'} ,
-
 
160
                  $results->{$id}->{'Traffic (M)'}
-
 
161
               );
110
}
162
}
111
$dbh->disconnect();
163
$dbh->disconnect();
112
print $message;
164
print $message;
113
&sendReport( $$configuration{'sendReport'}, $message );
165
&sendReport( $$configuration{'sendReport'}, $message );
114
 
166