implemented GUI control for debug mode (in admin backend)

some GUI improvements
some bugfixes
This commit is contained in:
Michael Clemens 2009-05-15 11:54:36 +00:00
parent 5d24954cea
commit 6506cd4bc0
6 changed files with 96 additions and 71 deletions

View File

@ -77,6 +77,7 @@ if (isset($_SESSION["logindata"]["user"]) && isset($_SESSION["logindata"]["pass"
// show settings page
} else if ($tsmmonitor->GETVars['qq'] == "settings") {
$tmonpolld = new PollD($adodb);
$tmonpolld->adodb->setDebug($_SESSION["debug"]);
// If start/stop button was pressed
if ($_POST["PollDControl"] != "") {
@ -89,55 +90,69 @@ if (isset($_SESSION["logindata"]["user"]) && isset($_SESSION["logindata"]["pass"
if ($tmonpolld->isEnabled()=="1") {
$polldenabled = "enabled and ".$tmonpolld->getStatus();
$cellcolor = "green";
//$cellcolor = "green";
} else {
$polldenabled = "disabled";
$cellcolor = "red";
//$cellcolor = "red";
}
echo "<b>PollD Control</b><br>";
echo "<form action=".$_SERVER['PHP_SELF']."?q=".$tsmmonitor->GETVars['qq']."&m=".$tsmmonitor->GETVars['menu']." method='post'>";
echo "<table class='zebra'>";
echo "<tr><th>Start/Stop</th><th>Status</th></tr>";
echo "<tr class='d0'><td>";
echo "<input type='submit' class='button' name='PollDControl' value='Start' onclick='submit();'>";
echo "<input type='submit' class='button' name='PollDControl' value='Stop' onclick='submit();'>";
echo "</td></td><td bgcolor=".$cellcolor.">PollD is ".$polldenabled."</td></tr>";
echo "<tr><th>Configuration</th><th>Action</th><th>Status</th></tr>";
echo "<tr class='d0'>";
echo " <td>PollD Control</td>";
echo " <td>";
echo " <input type='submit' class='button' name='PollDControl' value='Start' onclick='submit();'>";
echo " <input type='submit' class='button' name='PollDControl' value='Stop' onclick='submit();'>";
echo " </td>";
echo " <td bgcolor=".$cellcolor.">PollD is ".$polldenabled."</td>";
echo "</tr>";
echo "<tr class='d1'>";
echo " <td>Debug Mode</td>";
echo " <td>";
echo " <input type='submit' class='button' name='DebugMode' value='On' onclick='submit();'>";
echo " <input type='submit' class='button' name='DebugMode' value='Off' onclick='submit();'>";
echo " </td>";
echo " <td>".$_SESSION["debug"]."</td>";
echo "</tr>";
echo "<tr class='d0'>";
echo " <td>PollD Control</td>";
echo " <td>";
echo " <table border=0>";
echo " <tr><td>";
echo " <select name='cleandbserver' size=1 class='button'>";
echo " <option value='all'>- all servers -</options>";
while(list($servername,$serveritems) = each($tsmmonitor->configarray["serverlist"])) {
echo '<option value="'.$servername.'"> '.$servername.' ('.$serveritems["description"].')</option>';
}
echo " </select>";
echo " </td><td>";
echo " <select name='cleandbquery' size=1 class='button'>";
echo ' <option value="all">- all queries -</options>';
while(list($queryname,$queryitems) = each($tsmmonitor->queryarray)) {
echo '<option value="'.$queryname.'"> '.$queryname.'</option>';
}
echo " </select>";
echo " </td><td>";
echo " <select name='cleandbovqueires' size=1 class='button'>";
echo ' <option value="yes">yes</options>';
echo ' <option value="no">no</options>';
echo " </select>";
echo " </td><td>";
echo " <select name='cleandbtime' size=1 class='button'>";
$times = array("1 month" => "30", "2 months" => "60", "3 months" => "90", "6 months" => "180", "1 year" => "360");
while(list($label,$value) = each($times)) {
echo '<option value="'.$value.'"> '.$label.'</option>';
}
echo " </select>";
echo " </td><td>";
echo " <input type='submit' class='button' name='cleanaction' value='Clean Up' onclick='submit();'>";
echo " </td></tr>";
echo " </table>";
echo " </td>";
echo " <td></td>";
echo "</tr>";
echo "</table>";
echo "<br><br>";
echo "<b>Cleanup Database</b><br>";
echo "<table class='zebra'>";
echo "<tr><th>Server</th><th>Query</th><th>Overview Query</th><th>Keep</th><th></th></tr>";
echo "<tr class='d0'><td>";
echo "<select name='cleandbserver' size=1 class='button'>";
echo '<option value="all">- all servers -</options>';
while(list($servername,$serveritems) = each($tsmmonitor->configarray["serverlist"])) {
echo '<option value="'.$servername.'"> '.$servername.' ('.$serveritems["description"].')</option>';
}
echo "</select>";
echo "</td><td>";
echo "<select name='cleandbquery' size=1 class='button'>";
echo '<option value="all">- all queries -</options>';
while(list($queryname,$queryitems) = each($tsmmonitor->queryarray)) {
echo '<option value="'.$queryname.'"> '.$queryname.'</option>';
}
echo "</select>";
echo "</td><td>";
echo "<select name='cleandbovqueires' size=1 class='button'>";
echo '<option value="yes">yes</options>';
echo '<option value="no">no</options>';
echo "</select>";
echo "</td><td>";
echo "<select name='cleandbtime' size=1 class='button'>";
$times = array("1 month" => "30", "2 months" => "60", "3 months" => "90", "6 months" => "180", "1 year" => "360");
while(list($label,$value) = each($times)) {
echo '<option value="'.$value.'"> '.$label.'</option>';
}
echo "</select>";
echo "<td><input type='submit' class='button' name='cleanaction' value='Clean Up' onclick='submit();'></td></tr>";
echo "</table>";
echo "<br><br>";
echo "</form>";
} else {

View File

@ -81,10 +81,14 @@ class ADOdb {
/**
* setDebug - enables or disabled debug mode
*
* @param boolean $debug
* @param string $debug On or Off
*/
function setDebug($debug) {
$this->debug = $debug;
if ($debug == "On") {
$this->debug = TRUE;
} else {
$this->debug = FALSE;
}
}
@ -116,7 +120,8 @@ class ADOdb {
return($recordSet);
} else {
echo "<p style='font-size: 16px; font-weight: bold; color: red;'>Database Error (".$this->conn->ErrorNo().")</p>\n<p>".$this->conn->ErrorMsg()."</p>";
exit;
//exit;
return "";
}
}

View File

@ -29,6 +29,8 @@
if ($_POST["css"] != "") $_SESSION['stylesheet'] = $_POST["css"];
if ($_POST["tabletype"] != "") $_SESSION["tabletype"] = $_POST["tabletype"];
if ($_POST["DebugMode"] != "") $_SESSION["debug"] = $_POST["DebugMode"];
$adodb->setDebug($_SESSION["debug"]);
?>
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">

View File

@ -179,10 +179,10 @@ class PollD {
if ($restable == "res_querysession_TSMSRV1") echo $read."\n";
$read = ereg_replace("\t","\",\"",$read);
if ($restable == "res_querysession_TSMSRV1") echo $read."\n";
if ($timestamp != '') {
if ($overviewname == '') {
$out[] = 'INSERT IGNORE INTO '.$restable.' values ("'.$timestamp.'", "'.$read.'")';
} else {
$out[] = 'INSERT INTO '.$restable.' (name, result) values ("'.$overviewname.'", "'.$read.'") ON DUPLICATE KEY update result="'.$read.'"';
$out[] = 'INSERT INTO '.$restable.' (timestamp, name, result) values ("'.$timestamp.'", "'.$overviewname.'", "'.$read.'") ON DUPLICATE KEY update result="'.$read.'"';
}
} else { // result is empty and it's ok
$out[0] = 'INSERT IGNORE INTO '.$restable.' (timestamp) values ("'.$timestamp.'")';
@ -352,9 +352,9 @@ class PollD {
$tablename = "res_overview_".$server["servername"];
echo "---------".$query["name"].": ";
//$ctsql = "CREATE TABLE IF NOT EXISTS ".$tablename." LIKE smp_overview";
$ctsql = "CREATE TABLE IF NOT EXISTS ".$tablename." ( `name` varchar(35) collate utf8_unicode_ci NOT NULL, `result` varchar(255) collate utf8_unicode_ci NOT NULL, UNIQUE KEY `name` (`name`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$ctsql = "CREATE TABLE IF NOT EXISTS ".$tablename." ( `timestamp` int(11) collate utf8_unicode_ci NOT NULL, `name` varchar(35) collate utf8_unicode_ci NOT NULL, `result` varchar(255) collate utf8_unicode_ci NOT NULL, UNIQUE KEY `name` (`name`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$this->adodb->execDB($ctsql);
$result = $this->execute($query["query"], $server["servername"], $tablename, '', $query["name"]);
$result = $this->execute($query["query"], $server["servername"], $tablename, $timestamp, $query["name"]);
if ($result != "") {
foreach ($result["sql"] as $insertquery) {
$this->adodb->execDB($insertquery);

View File

@ -64,6 +64,8 @@ class TSMMonitor {
$this->adodb = $adodb;
//$this->adodb->setDebug($_SESSION["debug"]);
session_name("tsmmonitordev");
session_start();
@ -134,6 +136,7 @@ class TSMMonitor {
if ($_POST["Poll"] == "Poll Now!") {
$timestamp = time();
$tmonpolld = new PollD($this->adodb);
$tmonpolld->adodb->setDebug($_SESSION["debug"]);
$tmonpolld->pollQuery($tmonpolld->queries[$this->GETVars['qq']], $tmonpolld->servers[$this->GETVars['server']], TRUE, $timestamp);
$_SESSION['timemachine']['date'] = $timestamp;
$_SESSION['timemachine']['time'] = $timestamp;
@ -315,10 +318,11 @@ class TSMMonitor {
$this->queryarray = $this->configarray["queryarray"];
$ret = "";
$qq = $this->GETVars['qq'];
if ($this->queryarray[$this->GETVars['qq']]["polltype"]=="snapshot") {
if ($this->queryarray[$qq]["polltype"]=="snapshot") {
$ret .= "<div class='sidebarinfo'><b>Time Machine</b><br><br><div id='datechooser'>";
$ret .= "<form name='calform' action='".$_SERVER['PHP_SELF']."?q=".$this->GETVars['qq']."&m=".$this->GETVars['menu']."&s=".$this->GETVars['server']."' method='post'>";
$ret .= "<form name='calform' action='".$_SERVER['PHP_SELF']."?q=".$qq."&m=".$this->GETVars['menu']."&s=".$this->GETVars['server']."' method='post'>";
$ret .= "<input id='dateinput' class='textfield' name='dateinput' type='text' style='width: 100px' value='".strftime("%Y/%m/%d", $_SESSION['timemachine']['date'])."'>";
$ret .= "<br>";
$ret .= "<select name='timestamps' class='button' size=1 style='width: 103px' onchange='submit()'>";
@ -341,22 +345,19 @@ class TSMMonitor {
$ret .= "<input type='submit' name='Poll' value='Poll Now!' onclick='submit();' class='button'>";
$ret .= "</form> </div><br></DIV>";
} else if ($this->queryarray[$this->GETVars['qq']]["polltype"]=="update" || $this->queryarray[$this->GETVars['qq']]["polltype"]=="append") {
$LastTimestamp = $this->GetLastSnapshot();
if ($LastTimestamp!="") {
$ret .= "<div class='sidebarinfo'><b>Time Machine</b><br><br><div id='datechooser'>";
$ret .= "<br>";
$ret .= "Last updated: ".strftime('%H:%M:%S', $LastTimestamp);
$ret .= "<br>";
$ret .= "<br>";
$ret .= "<input type='submit' name='Poll' value='Poll Now!' onclick='submit();' class='button'>";
$ret .= "</form> </div><br></DIV>";
}
} else if ($this->queryarray[$qq]["polltype"]=="update" || $this->queryarray[$qq]["polltype"]=="append" || $qq == "index") {
$ret .= "<div class='sidebarinfo'><b>Time Machine</b><br><br><div id='datechooser'>";
$ret .= "<form name='calform' action='".$_SERVER['PHP_SELF']."?q=".$qq."&m=".$this->GETVars['menu']."&s=".$this->GETVars['server']."' method='post'>";
$ret .= "<br>";
if ($qq == "index") $qq = "overview";
$LastTimestamp = $this->getLastSnapshot($qq);
if ($LastTimestamp!="") $ret .= "Last updated: ".strftime('%H:%M:%S', $LastTimestamp);
$ret .= "<br>";
$ret .= "<br>";
$ret .= "<input type='submit' name='Poll' value='Poll Now!' onclick='submit();' class='button'>";
$ret .= "</form> </div><br></DIV>";
}
return $ret;
}
@ -456,7 +457,7 @@ class TSMMonitor {
$ret = "";
$ret .= "<div class='sidebarinfo'>";
$ret .= "<b>Stylesheet Switcher</b><br><br>";
$ret .= "<form action=".$_SERVER['PHP_SELF']."?q=".$tsmmonitor->GETVars['qq']."&m=".$tsmmonitor->GETVars['menu']."&s=".$tsmmonitor->GETVars['server']." method='post'>\n";
$ret .= "<form action=".$_SERVER['PHP_SELF']."?q=".$this->GETVars['qq']."&m=".$this->GETVars['menu']."&s=".$this->GETVars['server']." method='post'>\n";
$ret .= "<select name='css' size=1 onChange='submit();' class='button'>\n";
if ($handle = opendir('css')) {
while (false !== ($file = readdir($handle))) {
@ -651,17 +652,18 @@ class TSMMonitor {
/**
* getLastSnapshot - returns the last inserted timestamp of a query result
*
* @param string qq name of query
* @return string
*/
function getLastSnapshot() {
function getLastSnapshot($qq) {
$server = $this->GETVars['server'];
$ret = array();
$qtable = $this->configarray["queryarray"][$this->GETVars['qq']]["name"];
//$qtable = $this->configarray["queryarray"][$this->GETVars['qq']]["name"];
$sql = "SELECT MAX(TimeStamp) from res_".$qtable."_".$server;
$sql = "SELECT MAX(TimeStamp) from res_".$qq."_".$server;
$ret = $this->adodb->fetchArrayDB($sql);
$ret = (array)$ret[0];

View File

@ -24,8 +24,9 @@
*
* tmonpolld.php, TSM Monitor
*
* This file is the TSM Monitor Polling Daemon. It executes queries against TSM
* and inserts them into TMS Monitor's MySQL Database
* This file instantiates PollD and executes the polling process.
* Start it like this: 'nohup php tmonpolld.php &'
*
*
* @author Michael Clemens
* @version 1.0