Subversion Repositories computer_asset_manager_v1

Rev

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

Rev 17 Rev 21
Line 2... Line 2...
2
 
2
 
3
#
3
#
4
# v0.8.1 20160218 RWR
4
# v0.8.1 20160218 RWR
5
# removed print statement to STDOUT (just commented it out)
5
# removed print statement to STDOUT (just commented it out)
6
#
6
#
-
 
7
# v0.8.2 20160407 RWR
-
 
8
# Added checking for missing sysinfo reports
-
 
9
# if a report is not shown in current day, but has been seen in the 
-
 
10
# past five days, an entry is made on the report
7
 
11
 
8
use DBI;
12
use DBI;
9
use Cwd 'abs_path';
13
use Cwd 'abs_path';
10
#use Data::Dumper;
14
#use Data::Dumper;
11
use File::Basename;
15
use File::Basename;
Line 32... Line 36...
32
                  
36
                  
33
my $count = qq/select 
37
my $count = qq/select 
34
                  count(*) 'Count'
38
                  count(*) 'Count'
35
               from sysinfo_report
39
               from sysinfo_report
36
               where sysinfo_report.added_date > date_sub( now(), interval 1 day)/;
40
               where sysinfo_report.added_date > date_sub( now(), interval 1 day)/;
-
 
41
               
-
 
42
my $missing = qq/select
-
 
43
                  device_id ID,
-
 
44
                  device.name name
-
 
45
               from (
-
 
46
                  select 
-
 
47
                     distinct( device_id ) 
-
 
48
                  from 
-
 
49
                     sysinfo_report
-
 
50
                  where 
-
 
51
                     datediff( current_date(),added_date) < 5
-
 
52
                  ) last_five
-
 
53
                  join device using ( device_id )
-
 
54
               where 
-
 
55
                  device.device_id not in (
-
 
56
                     select 
-
 
57
                        distinct( device_id ) 
-
 
58
                     from 
-
 
59
                        sysinfo_report 
-
 
60
                     where 
-
 
61
                        datediff( current_date(),added_date) < 1)/;
37
 
62
 
38
# following are used to find the configuration file
63
# following are used to find the configuration file
39
my $confFileName = "sysinfoRead.conf.yaml";
64
my $confFileName = "sysinfoRead.conf.yaml";
40
my @searchPaths = ( '/etc/camp', '/opt/camp', '/opt/camp/sysinfo', $MY_DIRECTORY );
65
my @searchPaths = ( '/etc/camp', '/opt/camp', '/opt/camp/sysinfo', $MY_DIRECTORY );
41
 
66
 
Line 106... Line 131...
106
$sth->execute();
131
$sth->execute();
107
my $results = $sth->fetchrow_hashref();
132
my $results = $sth->fetchrow_hashref();
108
$message .= "$results->{Count} reports in last 24 hours\n";
133
$message .= "$results->{Count} reports in last 24 hours\n";
109
$sth->finish();
134
$sth->finish();
110
 
135
 
-
 
136
$results = $dbh->selectall_hashref( $missing, 'ID' );
-
 
137
if ( %$results ) {
-
 
138
   $message .= '='x40 . "\nWARNING, no sysinfo reports for the following machines\n" . '='x40 . "\n";
-
 
139
   foreach my $device ( keys %$results ) {
-
 
140
      $message .= sprintf( "%6d\t%s\n", $device, $results->{$device}->{name} );
-
 
141
   }
-
 
142
   $message .= '='x40 . "\n\n";
-
 
143
}
-
 
144
 
111
$results = $dbh->selectall_hashref( $query, 'ID' );
145
$results = $dbh->selectall_hashref( $query, 'ID' );
112
foreach my $id ( keys %$results ) {
146
foreach my $id ( keys %$results ) {
113
   $message .= $results->{$id}->{Date} . "\t" . $results->{$id}->{Client} . "\t" . $results->{$id}->{Device} . "\n";
147
   $message .= $results->{$id}->{Date} . "\t" . $results->{$id}->{Client} . "\t" . $results->{$id}->{Device} . "\n";
114
   $message .= $results->{$id}->{Notes} . "\n\n";
148
   $message .= $results->{$id}->{Notes} . "\n\n";
115
}
149
}
116
$dbh->disconnect();
150
$dbh->disconnect();
-
 
151
 
117
#print $message;
152
#print $message;
118
&sendReport( $$configuration{'sendReport'}, $message );
153
&sendReport( $$configuration{'sendReport'}, $message );
119
 
154
 
120
1;
155
1;