&interface= #### site router interface dlh 138.188.193.233 FastEthernet0/0 dlh 138.188.193.233 Serial0/0 #### use strict; use warnings; use DBI; use HTML::Template; use Log::Log4perl; Log::Log4perl->init("/home/ndb/config/dlh_ndb_log.conf"); my $log = Log::Log4perl->get_logger(); my $template = new HTML::Template(filename=>"home1.tmpl"); my $dbh = DBI->connect('dbi:mysql:ndb','esm','esm') || die "Cannot connect"; #print "\n Connected....."; my @loop_data; my @sites; my @routers; my $query = "select distinct site_name from sites order by site_name"; my $sth = $dbh->prepare($query); $sth->execute; my $query_router = "select distinct router from sites where site_name = ?"; my $sth_router = $dbh->prepare($query_router); my $query_interface = "select interface from sites where site_name = ? and router = ?"; my $sth_interface = $dbh->prepare($query_interface); while(@sites = $sth->fetchrow_array) { my @r_loop_data; $sth_router->bind_param(1,$sites[0]); $sth_router->execute; while(@routers = $sth_router->fetchrow_array) { my @interfaces; $sth_interface->bind_param(1,$sites[0]); $sth_interface->bind_param(2,$routers[0]); $sth_interface->execute; while(my @arr = $sth_interface->fetchrow_array) { my %interface_row = ( interface => $arr[0] ); push(@interfaces, \%interface_row); } my %row; %row = ( router => $routers[0] , interfaces_loop => \@interfaces ); push(@r_loop_data,\%row); } my %site_row = ( site => $sites[0], routers_loop => \@r_loop_data ); push(@loop_data, \%site_row); } $template->param(caption => "ST Sites"); $template->param(sites_loop => \@loop_data); print "Content-Type: text/html\n\n"; print $template->output; $dbh->disconnect or $log->logwarn("Cannot disconnect from the database: $DBI::errstr"); exit 0; ####
|