use Tk;
use strict;
use DBI;
# Main Window
my $mw = new MainWindow;
my $but1 = $mw -> Button(-text => "view cpu",-width=>300,
-command =>\&push_button);
$but1 -> pack();
my $but2 = $mw -> Button(-text => "view memory",-width=>300);
$but2 -> pack();
my $but3 = $mw -> Button(-text => "view disk",-width=>300);
$but3 -> pack();
my $but3 = $mw -> Button(-text => "view Event",-width=>300);
$but3 -> pack();
my $but4 = $mw -> Button(-text => "cleart",-width=>300,-command =>\&clear_button);
$but4 -> pack();
#Text Area
my $txt = $mw -> Text(-width=>300, -height=>100) -> pack();
MainLoop;
#This is executed when the button is pressed
sub push_button {
# system("cls");
my $dbName = 'dwh5';
my $dbUser = 'test';
my $dbUserPass = 'test';
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database " ;
my $hostSql = qq{select trim(HOST),trim(FILESYSTEM),trim(TYPE),trim(SIZE#),trim(USED),trim(AVAIL),trim(USE),trim(MOUNTED),to_char(SYSDATE\,'yyyy-mm-dd:Hh24:Mm:Ss') from cpu_info};
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
my $selStmt = $dbh->prepare($hostSql);
$selStmt->bind_columns(undef, \$a1, \$a2, \$a3,\$a4,\$a5,\$a6,\$a7,\$a8,\$a9);
$selStmt->execute();
while( $selStmt->fetch() ){
#print "$table_name\t\t $tablespace_name\t\t$status\n";
$txt -> insert("end","$a1\t$a2\t$a3\t$a4\t$a5\t$a6\t$a7\t$a8\t$a9"."\n");
}
$selStmt->finish;
$dbh->disconnect;
}
sub clear_button {
system("cls");
}