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 // show settings page
} else if ($tsmmonitor->GETVars['qq'] == "settings") { } else if ($tsmmonitor->GETVars['qq'] == "settings") {
$tmonpolld = new PollD($adodb); $tmonpolld = new PollD($adodb);
$tmonpolld->adodb->setDebug($_SESSION["debug"]);
// If start/stop button was pressed // If start/stop button was pressed
if ($_POST["PollDControl"] != "") { if ($_POST["PollDControl"] != "") {
@ -89,29 +90,38 @@ if (isset($_SESSION["logindata"]["user"]) && isset($_SESSION["logindata"]["pass"
if ($tmonpolld->isEnabled()=="1") { if ($tmonpolld->isEnabled()=="1") {
$polldenabled = "enabled and ".$tmonpolld->getStatus(); $polldenabled = "enabled and ".$tmonpolld->getStatus();
$cellcolor = "green"; //$cellcolor = "green";
} else { } else {
$polldenabled = "disabled"; $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 "<form action=".$_SERVER['PHP_SELF']."?q=".$tsmmonitor->GETVars['qq']."&m=".$tsmmonitor->GETVars['menu']." method='post'>";
echo "<table class='zebra'>"; echo "<table class='zebra'>";
echo "<tr><th>Start/Stop</th><th>Status</th></tr>"; echo "<tr><th>Configuration</th><th>Action</th><th>Status</th></tr>";
echo "<tr class='d0'><td>"; 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='Start' onclick='submit();'>";
echo " <input type='submit' class='button' name='PollDControl' value='Stop' 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 " </td>";
echo "</table>"; echo " <td bgcolor=".$cellcolor.">PollD is ".$polldenabled."</td>";
echo "<br><br>"; echo "</tr>";
echo "<b>Cleanup Database</b><br>"; echo "<tr class='d1'>";
echo "<table class='zebra'>"; echo " <td>Debug Mode</td>";
echo "<tr><th>Server</th><th>Query</th><th>Overview Query</th><th>Keep</th><th></th></tr>"; echo " <td>";
echo "<tr class='d0'><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 " <select name='cleandbserver' size=1 class='button'>";
echo '<option value="all">- all servers -</options>'; echo " <option value='all'>- all servers -</options>";
while(list($servername,$serveritems) = each($tsmmonitor->configarray["serverlist"])) { while(list($servername,$serveritems) = each($tsmmonitor->configarray["serverlist"])) {
echo '<option value="'.$servername.'"> '.$servername.' ('.$serveritems["description"].')</option>'; echo '<option value="'.$servername.'"> '.$servername.' ('.$serveritems["description"].')</option>';
} }
@ -135,9 +145,14 @@ if (isset($_SESSION["logindata"]["user"]) && isset($_SESSION["logindata"]["pass"
echo '<option value="'.$value.'"> '.$label.'</option>'; echo '<option value="'.$value.'"> '.$label.'</option>';
} }
echo " </select>"; echo " </select>";
echo "<td><input type='submit' class='button' name='cleanaction' value='Clean Up' onclick='submit();'></td></tr>"; 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 "</table>";
echo "<br><br>";
echo "</form>"; echo "</form>";
} else { } else {

View File

@ -81,10 +81,14 @@ class ADOdb {
/** /**
* setDebug - enables or disabled debug mode * setDebug - enables or disabled debug mode
* *
* @param boolean $debug * @param string $debug On or Off
*/ */
function setDebug($debug) { function setDebug($debug) {
$this->debug = $debug; if ($debug == "On") {
$this->debug = TRUE;
} else {
$this->debug = FALSE;
}
} }
@ -116,7 +120,8 @@ class ADOdb {
return($recordSet); return($recordSet);
} else { } else {
echo "<p style='font-size: 16px; font-weight: bold; color: red;'>Database Error (".$this->conn->ErrorNo().")</p>\n<p>".$this->conn->ErrorMsg()."</p>"; 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["css"] != "") $_SESSION['stylesheet'] = $_POST["css"];
if ($_POST["tabletype"] != "") $_SESSION["tabletype"] = $_POST["tabletype"]; 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\"> <!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"; if ($restable == "res_querysession_TSMSRV1") echo $read."\n";
$read = ereg_replace("\t","\",\"",$read); $read = ereg_replace("\t","\",\"",$read);
if ($restable == "res_querysession_TSMSRV1") echo $read."\n"; if ($restable == "res_querysession_TSMSRV1") echo $read."\n";
if ($timestamp != '') { if ($overviewname == '') {
$out[] = 'INSERT IGNORE INTO '.$restable.' values ("'.$timestamp.'", "'.$read.'")'; $out[] = 'INSERT IGNORE INTO '.$restable.' values ("'.$timestamp.'", "'.$read.'")';
} else { } 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 } else { // result is empty and it's ok
$out[0] = 'INSERT IGNORE INTO '.$restable.' (timestamp) values ("'.$timestamp.'")'; $out[0] = 'INSERT IGNORE INTO '.$restable.' (timestamp) values ("'.$timestamp.'")';
@ -352,9 +352,9 @@ class PollD {
$tablename = "res_overview_".$server["servername"]; $tablename = "res_overview_".$server["servername"];
echo "---------".$query["name"].": "; echo "---------".$query["name"].": ";
//$ctsql = "CREATE TABLE IF NOT EXISTS ".$tablename." LIKE smp_overview"; //$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); $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 != "") { if ($result != "") {
foreach ($result["sql"] as $insertquery) { foreach ($result["sql"] as $insertquery) {
$this->adodb->execDB($insertquery); $this->adodb->execDB($insertquery);

View File

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

View File

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