#!/usr/bin/perl #this script will pregenerate the graph page for all the platforms in the given db instance #note this script was developed from processGraphs.pl and shares most of the same code use strict; use DBI; use XML::LibXML; use LWP::UserAgent; #load database and path info my ($env,$unit_conversion) = @ARGV; my $xp_env = XML::LibXML->new->parse_file("../environment_xenia_$env.xml"); my $xp_graph = XML::LibXML->new->parse_file("environment_xenia_graph.xml"); my $db_host = $xp_env->findvalue('//db/host'); my $db_name = $xp_env->findvalue('//db/name'); my $db_user = $xp_env->findvalue('//db/user'); my $db_passwd = $xp_env->findvalue('//db/passwd'); my $dir_tmp = $xp_env->findvalue('//path/dir_tmp'); my $dir_base = $xp_env->findvalue('//path/dir_base'); my $http_base = $xp_env->findvalue('//path/http_base'); my $http_xenia_graph = $xp_env->findvalue('//path/http_xenia_graph'); #establish database connection my ($dbh,$sth,$sql,$sth_2,$sth_3); if ($db_host eq '') { $dbh = DBI->connect ("dbi:Pg:dbname=$db_name", "$db_user", "$db_passwd"); } #remove host reference if local else { $dbh = DBI->connect ("dbi:Pg:dbname=$db_name;host=$db_host", "$db_user", "$db_passwd"); } if ( !defined $dbh ) {die "Cannot connect to database!\n";} #get platforms for this xenia instance $sql = qq{ select row_id,platform_handle from platform }; #print "sql:".$sql."\n"; $sth = $dbh->prepare( $sql ); $sth->execute(); if ($sth->rows == 0) { print "no data\n"; &exit_no_data; } while ( my ($platform_id,$platform_handle) = $sth->fetchrow() ) { print "platform_id:$platform_id\n"; my $unit_suffix; if ($unit_conversion eq 'en') { $unit_suffix = '_en'; } my $file_to; #php_graph my $php_graph = "graph$unit_suffix.php"; $file_to = $dir_base."platform/$platform_handle/html/$php_graph"; open (PHP_GRAPH,">$file_to"); my $html_content .= <<"END_OF_FILE";
\n";
END_OF_FILE
} #while $sensor_id
$html_content .= <<"END_OF_FILE";
?>
END_OF_FILE
print PHP_GRAPH $html_content;
close (PHP_GRAPH);
} #while $platform_id
exit 0;
sub exit_no_data {
$sth->finish;
$dbh->disconnect();
exit 0;
}