Rev 68 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#!/usr/bin/env perl
use strict;
use warnings;
#
# v0.8.1 20160218 RWR
# removed print statement to STDOUT (just commented it out)
#
# v0.8.2 20160407 RWR
# Added checking for missing sysinfo reports
# if a report is not shown in current day, but has been seen in the
# past five days, an entry is made on the report
use DBI;
use Cwd 'abs_path';
#use Data::Dumper;
use File::Basename;
use YAML::XS;
my $VERSION = '0.8.1';
my $MY_DIRECTORY = abs_path(dirname(__FILE__) );
my $query = qq/select
hyper.name DOM0,
virt.name DOMU
from
device hyper join device virt
join device_type on (virt.device_type_id = device_type.device_type_id)
where
device_type.show_as_system = "Y"
and hyper.device_id = virt.part_of
and hyper.removed_date is null
and virt.removed_date is null
order by
hyper.name,
virt.name/;
# following are used to find the configuration file
my $confFileName = "sysinfoRead.conf.yaml";
my @searchPaths = ( '/etc/camp', '/opt/camp', '/opt/camp/sysinfo', $MY_DIRECTORY );
sub loadConfig {
my ( $confFileName, @searchPaths ) = @_;
my $configuration;
for ( my $i = 0; $i < @searchPaths; $i++ ) {
my $filename = $searchPaths[$i] . '/' . $confFileName;
if ( -e $filename ) {
#print "Found $filename\n";
open CONF, "<$filename" or warn "Could not read $filename: $!\n";
$configuration = Load( join( '', <CONF> ) );
close CONF;
last; # exit out of the loop; we don't try to load it more than once
} # if
} # foreach
return $configuration;
} # sub loadConfig
my $configuration = &loadConfig( $confFileName, @searchPaths );
die "Could not find configuration file $confFileName in " . join( ', ', @searchPaths) . "\n" unless $configuration;
my $dbh = DBI->connect('DBI:mysql:' . $$configuration{'database'}{'database'},
$$configuration{'database'}{'databaseUsername'},
$$configuration{'database'}{'databasePassword'} )
|| die "Could not connect to database: $DBI::errstr";
my $sth = $dbh->prepare( $query );
$sth->execute();
open REPORT, ">$$configuration{'domuOutput'}" or die "Could not open $$configuration{'domuOutput'} for DOMU Report: $!\n";
print REPORT "DOM0\tDOMU\n";
while ( my $row = $sth->fetchrow_hashref() ) {
print REPORT $row->{"DOM0"} . "\t" . $row->{"DOMU"} . "\n";
}
close REPORT;
`chown www-data:www-data $$configuration{"domuOutput"}`;
1;