mirror of
https://codeberg.org/mclemens/tsmmonitor2.git
synced 2024-11-17 14:56:00 -05:00
implemented debug levels and try/catch blocks into polld
This commit is contained in:
parent
45983ec077
commit
2bd9496e47
@ -46,6 +46,7 @@ class PollD {
|
|||||||
var $queries;
|
var $queries;
|
||||||
var $overviewqueries;
|
var $overviewqueries;
|
||||||
var $adodb;
|
var $adodb;
|
||||||
|
var $debuglevel; // VERBOSE=4, INFO=3, WARN=2, ERROR=1, OFF=0
|
||||||
|
|
||||||
var $log_timeneeded;
|
var $log_timeneeded;
|
||||||
var $log_unchangedresult;
|
var $log_unchangedresult;
|
||||||
@ -53,8 +54,6 @@ class PollD {
|
|||||||
var $log_updated;
|
var $log_updated;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PollD
|
* PollD
|
||||||
*
|
*
|
||||||
@ -64,13 +63,78 @@ class PollD {
|
|||||||
*/
|
*/
|
||||||
function PollD($adodb) {
|
function PollD($adodb) {
|
||||||
|
|
||||||
|
$this->setDebuglevel("INFO");
|
||||||
$this->adodb = $adodb;
|
$this->adodb = $adodb;
|
||||||
$this->servers = $this->getServers();
|
$this->servers = $this->getServers();
|
||||||
$this->queries = $this->getQueries();
|
$this->queries = $this->getQueries();
|
||||||
$this->overviewqueries = $this->getOverviewQueries();
|
$this->overviewqueries = $this->getOverviewQueries();
|
||||||
|
//$this->controlPollD("off");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writeMSG
|
||||||
|
*
|
||||||
|
* @param mixed $msg
|
||||||
|
* @param mixed $level VERBOSE, INFO, WARN, ERROR, OFF
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function writeMSG($msg, $level) {
|
||||||
|
|
||||||
|
switch ($level) {
|
||||||
|
case ("OFF"):
|
||||||
|
$ilevel = 0;
|
||||||
|
break;
|
||||||
|
case ("ERROR"):
|
||||||
|
$ilevel = 1;
|
||||||
|
break;
|
||||||
|
case ("WARN"):
|
||||||
|
$ilevel = 2;
|
||||||
|
break;
|
||||||
|
case ("INFO"):
|
||||||
|
$ilevel = 3;
|
||||||
|
break;
|
||||||
|
case ("VERBOSE"):
|
||||||
|
$ilevel = 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->debuglevel >= $ilevel) {
|
||||||
|
echo $level.": ".$msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setDebuglevel
|
||||||
|
*
|
||||||
|
* @param mixed $debuglevel VERBOSE, INFO, WARN, ERROR, OFF
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function setDebuglevel($debuglevel) {
|
||||||
|
|
||||||
|
switch ($debuglevel) {
|
||||||
|
case ("OFF"):
|
||||||
|
$this->debuglevel = 0;
|
||||||
|
break;
|
||||||
|
case ("ERROR"):
|
||||||
|
$this->debuglevel = 1;
|
||||||
|
break;
|
||||||
|
case ("WARN"):
|
||||||
|
$this->debuglevel = 2;
|
||||||
|
break;
|
||||||
|
case ("INFO"):
|
||||||
|
$this->debuglevel = 3;
|
||||||
|
break;
|
||||||
|
case ("VERBOSE"):
|
||||||
|
$this->debuglevel = 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,9 +237,7 @@ class PollD {
|
|||||||
if ($read != ' ' && $read != '' && !$stop) {
|
if ($read != ' ' && $read != '' && !$stop) {
|
||||||
if ($blank == "") {
|
if ($blank == "") {
|
||||||
$read = preg_replace('/[\n]+/', '', $read);
|
$read = preg_replace('/[\n]+/', '', $read);
|
||||||
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 ($overviewname == '') {
|
if ($overviewname == '') {
|
||||||
$out[] = 'INSERT IGNORE INTO '.$restable.' values ("'.$timestamp.'", "'.$read.'")';
|
$out[] = 'INSERT IGNORE INTO '.$restable.' values ("'.$timestamp.'", "'.$read.'")';
|
||||||
} else {
|
} else {
|
||||||
@ -284,21 +346,23 @@ class PollD {
|
|||||||
* @param boolean $ignorePollFreq
|
* @param boolean $ignorePollFreq
|
||||||
* @param string $timestamp
|
* @param string $timestamp
|
||||||
*/
|
*/
|
||||||
function pollQuery($query = "", $server = "", $ignorePollFreq = FALSE, $timestamp){
|
function pollQuery($query = "", $server = "", $ignorePollFreq = TRUE, $timestamp){
|
||||||
|
|
||||||
$queryname = $query["name"];
|
$queryname = $query["name"];
|
||||||
$tablename = "res_".$queryname."_".$server["servername"];
|
$tablename = "res_".$queryname."_".$server["servername"];
|
||||||
if (!$ignorePollFreq) echo "---------".$queryname.": ";
|
if (!$ignorePollFreq) {
|
||||||
|
$this->writeMSG("---------".$queryname.": ", "INFO");
|
||||||
|
}
|
||||||
// create table if not exists
|
// create table if not exists
|
||||||
$showsql = "SHOW TABLES LIKE '".$tablename."'";
|
$showsql = "SHOW TABLES LIKE '".$tablename."'";
|
||||||
$res = $this->adodb->fetchArrayDB($showsql);
|
$res = $this->adodb->fetchArrayDB($showsql);
|
||||||
if (!isset($res[0])) {
|
if (!isset($res[0])) {
|
||||||
$fieldsql = "select fields from cfg_queries where name='".$queryname."'";
|
$fieldsql = "select fields from cfg_queries where name='".$queryname."'";
|
||||||
$fields = $this->adodb->fetchArrayDB($fieldsql);
|
$fields = $this->adodb->fetchArrayDB($fieldsql);
|
||||||
var_dump($fields);
|
|
||||||
$ctsql = "CREATE TABLE `".$tablename."` (".$fields[0]['fields'].") DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
|
$ctsql = "CREATE TABLE `".$tablename."` (".$fields[0]['fields'].") DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
|
||||||
if (!$ignorePollFreq) echo "created table ".$tablename." and ";
|
if (!$ignorePollFreq) {
|
||||||
//$ctsql = "CREATE TABLE IF NOT EXISTS ".$tablename." LIKE smp_".$query["name"];
|
$this->writeMSG("created table ".$tablename." and ", "INFO");
|
||||||
|
}
|
||||||
$this->adodb->execDB($ctsql);
|
$this->adodb->execDB($ctsql);
|
||||||
}
|
}
|
||||||
// execute query and store result in mysql db
|
// execute query and store result in mysql db
|
||||||
@ -306,31 +370,38 @@ class PollD {
|
|||||||
try {
|
try {
|
||||||
$result = $this->execute($query["tsmquery"], $server["servername"], $tablename, $timestamp);
|
$result = $this->execute($query["tsmquery"], $server["servername"], $tablename, $timestamp);
|
||||||
} catch (exception $e) {
|
} catch (exception $e) {
|
||||||
$result = "";
|
$this->writeMSG("Problem while querying from TSM Server!", "ERROR");
|
||||||
print_r($e);
|
|
||||||
}
|
}
|
||||||
if ($result != "") {
|
if ($result != "") {
|
||||||
if (!$this->checkHash($tablename, $result["md5"])) {
|
if (!$this->checkHash($tablename, $result["md5"])) {
|
||||||
if ($query["polltype"]=="update") {
|
if ($query["polltype"]=="update") {
|
||||||
$dropsql = "truncate table ".$tablename;
|
$dropsql = "truncate table ".$tablename;
|
||||||
|
try {
|
||||||
$this->adodb->execDB($dropsql);
|
$this->adodb->execDB($dropsql);
|
||||||
if (!$ignorePollFreq) echo " TRUNCATED TABLE and ";
|
} catch (exception $e) {
|
||||||
|
$this->writeMSG("Error while truncating table (".$dropsql.")", "ERROR");
|
||||||
|
}
|
||||||
|
$this->writeMSG(" TRUNCATED TABLE and ", "INFO");
|
||||||
}
|
}
|
||||||
foreach ($result["sql"] as $insertquery) {
|
foreach ($result["sql"] as $insertquery) {
|
||||||
if ($queryname == "querysession") echo "\n\n".$insertquery."\n\n";
|
try {
|
||||||
$this->adodb->execDB($insertquery);
|
$this->adodb->execDB($insertquery);
|
||||||
|
//echo $insertquery;
|
||||||
|
} catch (exception $e) {
|
||||||
|
$this->writeMSG("Error while inserting into table (".$insertquery.")", "ERROR");
|
||||||
}
|
}
|
||||||
if (!$ignorePollFreq) echo "inserted new rows into ".$tablename."\n";
|
}
|
||||||
|
$this->writeMSG("inserted new rows into ".$tablename."\n", "INFO");
|
||||||
$this->log_updated++;
|
$this->log_updated++;
|
||||||
} else {
|
} else {
|
||||||
if (!$ignorePollFreq) echo "no need to update result -> result is the same as last time\n";
|
$this->writeMSG("no need to update result -> result is the same as last time\n", "INFO");
|
||||||
$this->log_unchangedresult++;
|
$this->log_unchangedresult++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo "There was a problem querying the TSM Server ".$server["servername"]."!\n";
|
$this->writeMSG("There was a problem querying the TSM Server ".$server["servername"]."!\n", "ERROR");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!$ignorePollFreq) echo "no need to update result -> pollfreq not reached!\n";
|
$this->writeMSG("no need to update result -> pollfreq not reached!\n", "INFO");
|
||||||
$this->log_pollfreqnoreached++;
|
$this->log_pollfreqnoreached++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,7 +418,7 @@ class PollD {
|
|||||||
function pollOverviewQuery($query = "", $server = "", $timestamp){
|
function pollOverviewQuery($query = "", $server = "", $timestamp){
|
||||||
|
|
||||||
$tablename = "res_overview_".$server["servername"];
|
$tablename = "res_overview_".$server["servername"];
|
||||||
echo "---------".$query["name"].": ";
|
$this->writeMSG("---------".$query["name"].": ", "INFO");
|
||||||
//$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." ( `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";
|
$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);
|
||||||
@ -355,10 +426,10 @@ class PollD {
|
|||||||
if ($result != "") {
|
if ($result != "") {
|
||||||
foreach ($result["sql"] as $insertquery) {
|
foreach ($result["sql"] as $insertquery) {
|
||||||
$this->adodb->execDB($insertquery);
|
$this->adodb->execDB($insertquery);
|
||||||
echo "inserted row\n";
|
$this->writeMSG("inserted row\n", "INFO");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo "There was a problem querying the TSM Server ".$server["servername"]."!\n";
|
$this->writeMSG("There was a problem querying the TSM Server ".$server["servername"]."!\n", "ERROR");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -488,12 +559,11 @@ class PollD {
|
|||||||
*/
|
*/
|
||||||
function poll(){
|
function poll(){
|
||||||
|
|
||||||
$this->controlPollD("off");
|
|
||||||
|
|
||||||
$sleeptime = $this->getSleeptime();
|
$sleeptime = $this->getSleeptime();
|
||||||
|
|
||||||
|
|
||||||
echo "Sleeptime will be ".$sleeptime." seconds\n";
|
$this->writeMSG("Sleeptime will be ".$sleeptime." seconds\n", "WARN");
|
||||||
|
|
||||||
|
|
||||||
// infinite loop
|
// infinite loop
|
||||||
@ -503,8 +573,7 @@ class PollD {
|
|||||||
|
|
||||||
$timestamp = time();
|
$timestamp = time();
|
||||||
|
|
||||||
echo "running!\n";
|
$this->writeMSG("running!\ntimestamp for this run is ".$timestamp."\n", "WARN");
|
||||||
echo "timestamp for this run is ".$timestamp."\n";
|
|
||||||
|
|
||||||
$this->setPollDStatus("running", "", "");
|
$this->setPollDStatus("running", "", "");
|
||||||
|
|
||||||
@ -515,12 +584,12 @@ class PollD {
|
|||||||
$this->log_pollfreqnoreached = 0;
|
$this->log_pollfreqnoreached = 0;
|
||||||
$this->log_updated = 0;
|
$this->log_updated = 0;
|
||||||
// go through all queries defined in xml file
|
// go through all queries defined in xml file
|
||||||
echo "---querying server ".$server["servername"]."\n";
|
$this->writeMSG("---querying server ".$server["servername"]."\n", "WARN");
|
||||||
echo "------querying normal queries\n";
|
$this->writeMSG("------querying normal queries\n", "WARN");
|
||||||
foreach ($this->queries as $query) {
|
foreach ($this->queries as $query) {
|
||||||
$this->pollQuery($query, $server, FALSE, $timestamp);
|
$this->pollQuery($query, $server, FALSE, $timestamp);
|
||||||
}
|
}
|
||||||
echo "------querying overview queries\n";
|
$this->writeMSG("------querying overview queries\n", "WARN");
|
||||||
foreach ($this->overviewqueries as $query) {
|
foreach ($this->overviewqueries as $query) {
|
||||||
$this->pollOverviewQuery($query, $server, $timestamp);
|
$this->pollOverviewQuery($query, $server, $timestamp);
|
||||||
}
|
}
|
||||||
@ -530,11 +599,11 @@ class PollD {
|
|||||||
$init = "no";
|
$init = "no";
|
||||||
|
|
||||||
|
|
||||||
echo "needed ".(time()-$timestamp)." seconds for this run.\n";
|
$this->writeMSG("needed ".(time()-$timestamp)." seconds for this run.\n", "INFO");
|
||||||
//$tempsleeptime = $sleeptime-(time()-$timestamp);
|
//$tempsleeptime = $sleeptime-(time()-$timestamp);
|
||||||
$tempsleeptime = 900 -(time()-$timestamp);
|
$tempsleeptime = 900 -(time()-$timestamp);
|
||||||
echo "sleeping for ".$tempsleeptime." seconds...\n";
|
$this->writeMSG("sleeping for ".$tempsleeptime." seconds...\n", "WARN");
|
||||||
echo "next run will be at ".strftime("%H:%M:%S", (time()+$tempsleeptime))."\n\n";
|
$this->writeMSG("next run will be at ".strftime("%H:%M:%S", (time()+$tempsleeptime))."\n\n", "WARN");
|
||||||
|
|
||||||
$this->setPollDStatus("sleeping", $timestamp, (time()+$tempsleeptime));
|
$this->setPollDStatus("sleeping", $timestamp, (time()+$tempsleeptime));
|
||||||
|
|
||||||
@ -543,7 +612,7 @@ class PollD {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
echo "PollD is disabled. Sleeping for 5 minutes...\n";
|
$this->writeMSG("PollD is disabled. Sleeping for 5 minutes...\n", "ERROR");
|
||||||
sleep (3);
|
sleep (3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -102,9 +102,13 @@ class TSMMonitor {
|
|||||||
$this->configarray = $_SESSION['configarray'];
|
$this->configarray = $_SESSION['configarray'];
|
||||||
|
|
||||||
// timeout
|
// timeout
|
||||||
if( !ini_get('safe_mode') && ini_get('max_execution_time') != $this->configarray["settings"]["timeout"]) {
|
if( !ini_get('safe_mode')) {
|
||||||
|
if (ini_get('max_execution_time') != $this->configarray["settings"]["timeout"]) {
|
||||||
ini_set('max_execution_time', $this->configarray["settings"]["timeout"]);
|
ini_set('max_execution_time', $this->configarray["settings"]["timeout"]);
|
||||||
}
|
}
|
||||||
|
//ini_set('session.gc_maxlifetime', 10);
|
||||||
|
//ini_set('session.gc_divisor', 1);
|
||||||
|
}
|
||||||
|
|
||||||
// set defaults if vars are empty
|
// set defaults if vars are empty
|
||||||
if ($this->GETVars["menu"] == "") { $this->GETVars["menu"]="main"; }
|
if ($this->GETVars["menu"] == "") { $this->GETVars["menu"]="main"; }
|
||||||
|
@ -37,6 +37,8 @@ include_once("../includes/global.php");
|
|||||||
|
|
||||||
|
|
||||||
$tmonpolld = new PollD($adodb);
|
$tmonpolld = new PollD($adodb);
|
||||||
|
$tmonpolld->setDebuglevel("WARN");
|
||||||
|
$tmonpolld->controlPollD("on");
|
||||||
$tmonpolld->poll();
|
$tmonpolld->poll();
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user