#!/usr/bin/perl -w use strict; use DBI; use CGI; use Config::IniHash; my $q = new CGI; my $uri = $ENV{'REQUEST_URI'}; $uri =~ s/\?.*//; print $q->header(); print $q->start_html(-title => "Puppet Status"); print $q->h1("Puppet Status Monitoring"); print $q->hr; my $incfg = ReadINI ("/etc/puppet/puppet.conf"); my %cfg; foreach my $k ( keys %{$incfg->{'puppetmasterd'}} ) { my $v = $incfg->{'puppetmasterd'}->{$k}; $k =~ s/^\s*//; $cfg{$k} = $v; } my $dbuser = $cfg{"dbuser"}; my $dbadapter = $cfg{"dbadapter"}; my $dbpass = $cfg{"dbpassword"}; my $dbname = $cfg{"dbname"}; unless ($dbuser and $dbadapter and $dbpass and $dbname) { print "Could not find all required database parameters in puppet.conf"; goto DONE; } my $dbh = DBI->connect("dbi:$dbadapter:$dbname", $dbuser, $dbpass); if (not $dbh){ print "Could not not connect to database using supplied parameters"; goto DONE; } my $hostid = $q->param('hostid'); if (not $hostid) { $hostid = '0'; } $hostid =~ /(\d+)/; $hostid = $1; if($hostid){ my $hostq = "select id, name, greatest(hosts.last_compile, hosts.last_freshcheck) as recent from hosts where id = ?"; $hostq = $dbh->prepare($hostq); $hostq->execute($hostid); if($hostq->rows == 0){ print "Could not find host $hostid\n"; goto DONE; } my $info = $hostq->fetchall_arrayref()->[0]; $hostq->finish; print $q->h1("Facter database for host " . $info->[1]); print "

Last Update: ", $info->[2], "

\n"; my $factq = "select fact_names.name, fact_values.value from fact_names, fact_values where fact_values.fact_name_id = fact_names.id and fact_values.host_id = ? order by fact_names.name"; $factq = $dbh->prepare($factq); $factq->execute($hostid); print "\n"; foreach my $rw ( @{$factq->fetchall_arrayref()} ){ print "\n"; } print "
FactValue
", $rw->[0], "", $rw->[1], "
\n"; $factq->finish; }else{ my $listq ="select id, name, greatest(hosts.last_compile, hosts.last_freshcheck) as recent from hosts order by name"; $listq = $dbh->prepare($listq); $listq->execute; print "\n"; foreach my $rw ( @{$listq->fetchall_arrayref()} ) { print "\n"; } print "
HostLast Checkin
", "", $rw->[1], "", $rw->[2], "
\n"; $listq->finish; } DONE: print $q->hr; print $q->end_html; $dbh->disconnect;