mirror of
https://codeberg.org/mclemens/tsmmonitor2.git
synced 2024-09-29 19:06:11 -04:00
- Added STDOUT logging for PollD_MP if no logfile is configured.
- Added new exception handling and logging for ADODB.
This commit is contained in:
parent
8882989945
commit
97afaa73a6
@ -1143,7 +1143,7 @@ function _adodb_backtrace($printOrArr=true,$levels=9999,$skippy=0,$ishtml=null)
|
|||||||
$s .= "\n";
|
$s .= "\n";
|
||||||
}
|
}
|
||||||
if ($html) $s .= '</pre>';
|
if ($html) $s .= '</pre>';
|
||||||
if ($printOrArr) print $s;
|
// if ($printOrArr) print $s;
|
||||||
|
|
||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ class ADOdb {
|
|||||||
|
|
||||||
var $conn;
|
var $conn;
|
||||||
var $debug;
|
var $debug;
|
||||||
|
var $logfile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor - establishes a DB connection via ADODB
|
* constructor - establishes a DB connection via ADODB
|
||||||
@ -55,9 +56,10 @@ class ADOdb {
|
|||||||
* @param string $retr the number attempts for the DB connection before a failure is reported
|
* @param string $retr the number attempts for the DB connection before a failure is reported
|
||||||
* @return 0
|
* @return 0
|
||||||
*/
|
*/
|
||||||
function ADOdb($host, $port = "3306", $user, $pass, $db_name, $db_type, $retr = 20, $debug = FALSE) {
|
function ADOdb($host, $port = "3306", $user, $pass, $db_name, $db_type, $retr = 20, $debug = FALSE, $logfile = FALSE) {
|
||||||
|
|
||||||
$this->debug = $debug;
|
$this->debug = $debug;
|
||||||
|
if ($logfile != FALSE) $this->logfile = $logfile;
|
||||||
|
|
||||||
$try = 0;
|
$try = 0;
|
||||||
$hostport = $host . ":" . $port;
|
$hostport = $host . ":" . $port;
|
||||||
@ -93,6 +95,50 @@ class ADOdb {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setLogfile - set logfile path and name
|
||||||
|
*
|
||||||
|
* @param string $logfile Logfile path and name
|
||||||
|
*/
|
||||||
|
function setLogfile($logfile) {
|
||||||
|
if ($logfile != "") {
|
||||||
|
$this->logfile = $logfile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writeMSG
|
||||||
|
*
|
||||||
|
* @param mixed $msg
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function writeMSG($msg) {
|
||||||
|
|
||||||
|
if ($this->logfile != "") {
|
||||||
|
if ($loghandle = fopen($this->logfile, 'a')) {
|
||||||
|
$starttime = microtime();
|
||||||
|
do {
|
||||||
|
$lock = flock($loghandle, LOCK_EX);
|
||||||
|
if (!$lock) usleep(round(rand(0, 100) * 1000));
|
||||||
|
} while (!$lock && ((microtime() - $starttime) < 1000));
|
||||||
|
|
||||||
|
if ($lock) {
|
||||||
|
fwrite($loghandle, $msg);
|
||||||
|
}
|
||||||
|
fclose($loghandle);
|
||||||
|
} else {
|
||||||
|
echo "ERROR: Cannot open logfile: '".$logfile."' for writing. Falling back to STDOUT.\n";
|
||||||
|
echo $msg;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo $msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* closeDB - close an open DB connection
|
* closeDB - close an open DB connection
|
||||||
*
|
*
|
||||||
@ -115,13 +161,15 @@ class ADOdb {
|
|||||||
$this->conn->debug = $this->debug;
|
$this->conn->debug = $this->debug;
|
||||||
$sql = $this->sanitizeSQL($sql);
|
$sql = $this->sanitizeSQL($sql);
|
||||||
|
|
||||||
|
try {
|
||||||
$recordSet = &$this->conn->Execute($sql);
|
$recordSet = &$this->conn->Execute($sql);
|
||||||
|
} catch (exception $e) {
|
||||||
|
$this->writeMSG(adodb_backtrace($e->gettrace()));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if (($recordSet) || ($this->conn->ErrorNo() == 0)) {
|
if (($recordSet) || ($this->conn->ErrorNo() == 0)) {
|
||||||
return($recordSet);
|
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;
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +184,6 @@ class ADOdb {
|
|||||||
* @return string Content of the cell as a single variable
|
* @return string Content of the cell as a single variable
|
||||||
*/
|
*/
|
||||||
function fetchCellDB($sql, $column_name) {
|
function fetchCellDB($sql, $column_name) {
|
||||||
//$this->conn->debug = true;
|
|
||||||
$this->conn->debug = $this->debug;
|
$this->conn->debug = $this->debug;
|
||||||
$sql = $this->sanitizeSQL($sql);
|
$sql = $this->sanitizeSQL($sql);
|
||||||
|
|
||||||
@ -145,7 +192,12 @@ class ADOdb {
|
|||||||
} else {
|
} else {
|
||||||
$this->conn->SetFetchMode(ADODB_FETCH_NUM);
|
$this->conn->SetFetchMode(ADODB_FETCH_NUM);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
$recordSet = $this->conn->Execute($sql);
|
$recordSet = $this->conn->Execute($sql);
|
||||||
|
} catch (exception $e) {
|
||||||
|
$this->writeMSG(adodb_backtrace($e->gettrace()));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if (($recordSet) || ($this->conn->ErrorNo() == 0)) {
|
if (($recordSet) || ($this->conn->ErrorNo() == 0)) {
|
||||||
if (!$recordSet->EOF) {
|
if (!$recordSet->EOF) {
|
||||||
@ -158,9 +210,6 @@ class ADOdb {
|
|||||||
|
|
||||||
return($column);
|
return($column);
|
||||||
}
|
}
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,12 +222,16 @@ class ADOdb {
|
|||||||
* @return array First row of results as an associative array
|
* @return array First row of results as an associative array
|
||||||
*/
|
*/
|
||||||
function fetchRowDB($sql) {
|
function fetchRowDB($sql) {
|
||||||
//$this->conn->debug = true;
|
|
||||||
$this->conn->debug = $this->debug;
|
$this->conn->debug = $this->debug;
|
||||||
$sql = $this->sanitizeSQL($sql);
|
$sql = $this->sanitizeSQL($sql);
|
||||||
|
|
||||||
$this->conn->SetFetchMode(ADODB_FETCH_ASSOC);
|
$this->conn->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||||
|
try {
|
||||||
$recordSet = $this->conn->Execute($sql);
|
$recordSet = $this->conn->Execute($sql);
|
||||||
|
} catch (exception $e) {
|
||||||
|
$this->writeMSG(adodb_backtrace($e->gettrace()));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if (($recordSet) || ($this->conn->ErrorNo() == 0)) {
|
if (($recordSet) || ($this->conn->ErrorNo() == 0)) {
|
||||||
if (!$recordSet->EOF) {
|
if (!$recordSet->EOF) {
|
||||||
@ -187,9 +240,6 @@ class ADOdb {
|
|||||||
|
|
||||||
return($recordFields);
|
return($recordFields);
|
||||||
}
|
}
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,13 +252,17 @@ class ADOdb {
|
|||||||
* @return array All results in an associative array
|
* @return array All results in an associative array
|
||||||
*/
|
*/
|
||||||
function fetchArrayDB($sql) {
|
function fetchArrayDB($sql) {
|
||||||
//$this->conn->debug = true;
|
|
||||||
$this->conn->debug = $this->debug;
|
$this->conn->debug = $this->debug;
|
||||||
$sql = $this->sanitizeSQL($sql);
|
$sql = $this->sanitizeSQL($sql);
|
||||||
|
|
||||||
$recordArray = array();
|
$recordArray = array();
|
||||||
$this->conn->SetFetchMode(ADODB_FETCH_ASSOC);
|
$this->conn->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||||
$recordSet = &$this->conn->Execute($sql);
|
try {
|
||||||
|
$recordSet = $this->conn->Execute($sql);
|
||||||
|
} catch (exception $e) {
|
||||||
|
$this->writeMSG(adodb_backtrace($e->gettrace()));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if (($recordSet) || ($this->conn->ErrorNo() == 0)) {
|
if (($recordSet) || ($this->conn->ErrorNo() == 0)) {
|
||||||
while ((!$recordSet->EOF) && ($recordSet)) {
|
while ((!$recordSet->EOF) && ($recordSet)) {
|
||||||
@ -217,9 +271,6 @@ class ADOdb {
|
|||||||
}
|
}
|
||||||
$recordSet->close();
|
$recordSet->close();
|
||||||
return($recordArray);
|
return($recordArray);
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,9 +288,13 @@ class ADOdb {
|
|||||||
* @return string Auto-increment ID if insert was performed
|
* @return string Auto-increment ID if insert was performed
|
||||||
*/
|
*/
|
||||||
function updateDB($table, $cells, $keys, $autoquote = TRUE) {
|
function updateDB($table, $cells, $keys, $autoquote = TRUE) {
|
||||||
//$this->conn->debug = true;
|
|
||||||
$this->conn->debug = $this->debug;
|
$this->conn->debug = $this->debug;
|
||||||
|
try {
|
||||||
$this->conn->Replace($table, $cells, $keys, $autoquote);
|
$this->conn->Replace($table, $cells, $keys, $autoquote);
|
||||||
|
} catch (exception $e) {
|
||||||
|
$this->writeMSG(adodb_backtrace($e->gettrace()));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->conn->Insert_ID();
|
return $this->conn->Insert_ID();
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ header("Pragma: no-cache");
|
|||||||
//error_reporting(E_ALL);
|
//error_reporting(E_ALL);
|
||||||
|
|
||||||
// ** Include generic code and external libraries ** //
|
// ** Include generic code and external libraries ** //
|
||||||
|
include ($config["library_path"] . "/adodb5/adodb-exceptions.inc.php");
|
||||||
include ($config["library_path"] . "/adodb5/adodb.inc.php");
|
include ($config["library_path"] . "/adodb5/adodb.inc.php");
|
||||||
include_once($config["include_path"] . "/adodb.php");
|
include_once($config["include_path"] . "/adodb.php");
|
||||||
include_once($config["include_path"] . "/tsmmonitor.php");
|
include_once($config["include_path"] . "/tsmmonitor.php");
|
||||||
@ -94,11 +95,11 @@ include_once($config["include_path"] . "/polld.php");
|
|||||||
$adodb = new ADOdb($config["db_host"], $config["db_port"], $config["db_user"], $config["db_password"], $config["db_name"], $config["db_type"]);
|
$adodb = new ADOdb($config["db_host"], $config["db_port"], $config["db_user"], $config["db_password"], $config["db_name"], $config["db_type"]);
|
||||||
|
|
||||||
// ** instantiate TSMMonitor Class ** //
|
// ** instantiate TSMMonitor Class ** //
|
||||||
$tsmmonitor = new TSMMonitor($adodb);
|
if (isset($_SERVER['HTTP_USER_AGENT'])) $tsmmonitor = new TSMMonitor($adodb);
|
||||||
|
|
||||||
// check to see if this is a new installation
|
// check to see if this is a new installation
|
||||||
$version = $adodb->fetchCellDB("SELECT confval FROM cfg_config WHERE confkey='version'", '');
|
$version = $adodb->fetchCellDB("SELECT confval FROM cfg_config WHERE confkey='version'", '');
|
||||||
if ($version != $config["tsm_monitor_version"] && basename($_SERVER['REQUEST_URI']) != 'install.php') {
|
if (isset($_SERVER['HTTP_USER_AGENT']) && $version != $config["tsm_monitor_version"] && basename($_SERVER['REQUEST_URI']) != 'install.php') {
|
||||||
header("Location: install.php");
|
header("Location: install.php");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,8 @@ class PollD {
|
|||||||
$this->loghandle = fopen($logfile[0]["confval"], 'at');
|
$this->loghandle = fopen($logfile[0]["confval"], 'at');
|
||||||
if (!$this->loghandle) {
|
if (!$this->loghandle) {
|
||||||
echo "ERROR: Cannot open logfile: '".$logfile[0]["confval"]."' for writing. Falling back to STDOUT.\n";
|
echo "ERROR: Cannot open logfile: '".$logfile[0]["confval"]."' for writing. Falling back to STDOUT.\n";
|
||||||
|
} else {
|
||||||
|
$this->adodb->setLogfile($logfile[0]["confval"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql = "select confval from cfg_config WHERE `confkey`='path_dsmadmc'";
|
$sql = "select confval from cfg_config WHERE `confkey`='path_dsmadmc'";
|
||||||
@ -803,6 +805,7 @@ class PollD_MP {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->debuglevel >= $ilevel) {
|
if ($this->debuglevel >= $ilevel) {
|
||||||
|
if ($this->logfile != "") {
|
||||||
if ($loghandle = fopen($this->logfile, 'a')) {
|
if ($loghandle = fopen($this->logfile, 'a')) {
|
||||||
$starttime = microtime();
|
$starttime = microtime();
|
||||||
do {
|
do {
|
||||||
@ -818,6 +821,9 @@ class PollD_MP {
|
|||||||
echo "ERROR: Cannot open logfile: '".$logfile."' for writing. Falling back to STDOUT.\n";
|
echo "ERROR: Cannot open logfile: '".$logfile."' for writing. Falling back to STDOUT.\n";
|
||||||
echo $level.": ".$msg;
|
echo $level.": ".$msg;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
echo $level.": ".$msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1302,7 +1308,7 @@ class PollD_MP {
|
|||||||
if ($this->isEnabled()) {
|
if ($this->isEnabled()) {
|
||||||
// Main loop for dispatcher
|
// Main loop for dispatcher
|
||||||
while(true) {
|
while(true) {
|
||||||
$this->adodb = new ADOdb($this->cfg["db_host"], $this->cfg["db_port"], $this->cfg["db_user"], $this->cfg["db_password"], $this->cfg["db_name"], $this->cfg["db_type"]);
|
$this->adodb = new ADOdb($this->cfg["db_host"], $this->cfg["db_port"], $this->cfg["db_user"], $this->cfg["db_password"], $this->cfg["db_name"], $this->cfg["db_type"], "", "", $this->logfile);
|
||||||
$this->updateJoblist($this->adodb);
|
$this->updateJoblist($this->adodb);
|
||||||
$query = "SELECT * FROM job_list";
|
$query = "SELECT * FROM job_list";
|
||||||
$jobs = $this->adodb->fetchArrayDB($query);
|
$jobs = $this->adodb->fetchArrayDB($query);
|
||||||
@ -1352,7 +1358,7 @@ class PollD_MP {
|
|||||||
$this->child_pid = posix_getpid();
|
$this->child_pid = posix_getpid();
|
||||||
$timestamp = time();
|
$timestamp = time();
|
||||||
$this->writeMSG("Worker(".$this->child_pid.") ".sprintf('%-16s', $server)." Timestamp for this run is $timestamp.\n", INFO);
|
$this->writeMSG("Worker(".$this->child_pid.") ".sprintf('%-16s', $server)." Timestamp for this run is $timestamp.\n", INFO);
|
||||||
$this->adodb = new ADOdb($this->cfg["db_host"], $this->cfg["db_port"], $this->cfg["db_user"], $this->cfg["db_password"], $this->cfg["db_name"], $this->cfg["db_type"]);
|
$this->adodb = new ADOdb($this->cfg["db_host"], $this->cfg["db_port"], $this->cfg["db_user"], $this->cfg["db_password"], $this->cfg["db_name"], $this->cfg["db_type"], "", "", $this->logfile);
|
||||||
$this->setPollDStatus($server, "running", $this->child_pid, $timestamp, "");
|
$this->setPollDStatus($server, "running", $this->child_pid, $timestamp, "");
|
||||||
|
|
||||||
// Process job
|
// Process job
|
||||||
|
Loading…
Reference in New Issue
Block a user