mirror of
https://codeberg.org/mclemens/tsmmonitor2.git
synced 2024-10-02 14:56:03 -04:00
...
This commit is contained in:
parent
8e5e0648a5
commit
d1bb95bdcb
@ -43,78 +43,41 @@
|
|||||||
|
|
||||||
class PollD {
|
class PollD {
|
||||||
|
|
||||||
var $servers;
|
var $servers;
|
||||||
var $queries;
|
var $queries;
|
||||||
var $overviewqueries;
|
var $overviewqueries;
|
||||||
/**
|
var $adodb;
|
||||||
var $db_host;
|
|
||||||
var $db_name;
|
|
||||||
var $db_user;
|
|
||||||
var $db_password;
|
|
||||||
**/
|
|
||||||
var $adodb;
|
|
||||||
|
|
||||||
var $log_timeneeded;
|
var $log_timeneeded;
|
||||||
var $log_unchangedresult;
|
var $log_unchangedresult;
|
||||||
var $log_pollfreqnoreached;
|
var $log_pollfreqnoreached;
|
||||||
var $log_updated;
|
var $log_updated;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function PollD($adodb) {
|
function PollD($adodb) {
|
||||||
|
|
||||||
$this->adodb = $adodb;
|
$this->adodb = $adodb;
|
||||||
|
|
||||||
//$this->setDBParams("localhost", "tsmmonitor", "tsmmonitor", "tsmmonitor");
|
|
||||||
$this->servers = $this->getServers();
|
$this->servers = $this->getServers();
|
||||||
$this->queries = $this->getQueries();
|
$this->queries = $this->getQueries();
|
||||||
$this->overviewqueries = $this->getOverviewQueries();
|
$this->overviewqueries = $this->getOverviewQueries();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fireMySQLQuery - executes a SQL query
|
|
||||||
*
|
|
||||||
* @param string $sql SQL query
|
|
||||||
* @param boolean $direct give back MySQLResultSet directly or Array of Objects
|
|
||||||
* @return MySQLResultSet/Array
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
function fireMySQLQuery($sql, $getreturnval = TRUE){
|
|
||||||
|
|
||||||
$ret = array();
|
|
||||||
|
|
||||||
$db = mysql_connect($this->db_host, $this->db_user, $this->db_password);
|
|
||||||
mysql_select_db($this->db_name, $db);
|
|
||||||
$result = mysql_query($sql, $db);
|
|
||||||
//if (strtolower(substr($sql,0,6)) == "select" && $getreturnval && $result ) {
|
|
||||||
if ($getreturnval && $result ) {
|
|
||||||
while($row = mysql_fetch_object($result))
|
|
||||||
{
|
|
||||||
$ret[] = $row;
|
|
||||||
}
|
|
||||||
mysql_free_result($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
**/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
|
/**
|
||||||
* getQueries - returns an array filled with all configured TSM queries
|
* getQueries - returns an array filled with all configured TSM queries
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getQueries() {
|
function getQueries() {
|
||||||
$queries = array();
|
$queries = array();
|
||||||
$query = "select * from cfg_queries";
|
$query = "select * from cfg_queries";
|
||||||
$querytablerows = $this->adodb->fetchArrayDB($query);
|
$querytablerows = $this->adodb->fetchArrayDB($query);
|
||||||
@ -130,18 +93,18 @@ function getQueries() {
|
|||||||
if ($queryrow->name != "") $queries[$queryrow->name]["header"]["column"] = $cols;
|
if ($queryrow->name != "") $queries[$queryrow->name]["header"]["column"] = $cols;
|
||||||
}
|
}
|
||||||
return $queries;
|
return $queries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getOverviewQueries - returns an array filled with all configured TSM overview queries
|
* getOverviewQueries - returns an array filled with all configured TSM overview queries
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getOverviewQueries() {
|
function getOverviewQueries() {
|
||||||
$queries = array();
|
$queries = array();
|
||||||
$query = "select * from cfg_overviewqueries";
|
$query = "select * from cfg_overviewqueries";
|
||||||
$querytablerows = $this->adodb->fetchArrayDB($query);
|
$querytablerows = $this->adodb->fetchArrayDB($query);
|
||||||
@ -149,16 +112,16 @@ function getOverviewQueries() {
|
|||||||
$queries[$queryrow["name"]] = (array)$queryrow;
|
$queries[$queryrow["name"]] = (array)$queryrow;
|
||||||
}
|
}
|
||||||
return $queries;
|
return $queries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getServers - returns an array containing all defined servers
|
* getServers - returns an array containing all defined servers
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getServers() {
|
function getServers() {
|
||||||
$query = "select * from cfg_servers";
|
$query = "select * from cfg_servers";
|
||||||
$rows = $this->adodb->fetchArrayDB($query);
|
$rows = $this->adodb->fetchArrayDB($query);
|
||||||
$servers = array();
|
$servers = array();
|
||||||
@ -167,13 +130,13 @@ function getServers() {
|
|||||||
}
|
}
|
||||||
return $servers;
|
return $servers;
|
||||||
//return $rows;
|
//return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute - executes a TSM query on a TSM server and returns an array containing SQL insert statements including the results
|
* execute - executes a TSM query on a TSM server and returns an array containing SQL insert statements including the results
|
||||||
*
|
*
|
||||||
* @param string $query TSM query
|
* @param string $query TSM query
|
||||||
@ -184,7 +147,7 @@ function getServers() {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function execute($query = '', $servername = '', $restable = '', $timestamp = '', $overviewname = '') {
|
function execute($query = '', $servername = '', $restable = '', $timestamp = '', $overviewname = '') {
|
||||||
|
|
||||||
$server = $this->servers[$servername];
|
$server = $this->servers[$servername];
|
||||||
$ip = $server["ip"];
|
$ip = $server["ip"];
|
||||||
@ -232,10 +195,10 @@ function execute($query = '', $servername = '', $restable = '', $timestamp = '',
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checkHash - checks with checksum if there's already the same result in the result database. If not, the hash will be stored.
|
* checkHash - checks with checksum if there's already the same result in the result database. If not, the hash will be stored.
|
||||||
*
|
*
|
||||||
* @param string $tablename name of table
|
* @param string $tablename name of table
|
||||||
@ -243,7 +206,7 @@ function execute($query = '', $servername = '', $restable = '', $timestamp = '',
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function checkHash($tablename = '', $hash = ''){
|
function checkHash($tablename = '', $hash = ''){
|
||||||
|
|
||||||
$sql = "select count(*) from log_hashes where TABLENAME='".$tablename."' and HASH='".$hash."'";
|
$sql = "select count(*) from log_hashes where TABLENAME='".$tablename."' and HASH='".$hash."'";
|
||||||
$countobj = $this->adodb->fetchArrayDB($sql);
|
$countobj = $this->adodb->fetchArrayDB($sql);
|
||||||
@ -263,11 +226,11 @@ function checkHash($tablename = '', $hash = ''){
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checkFreq - checks if configured checking frequency is reached
|
* checkFreq - checks if configured checking frequency is reached
|
||||||
*
|
*
|
||||||
* @param string $tablename name of table
|
* @param string $tablename name of table
|
||||||
@ -276,7 +239,7 @@ function checkHash($tablename = '', $hash = ''){
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function checkFreq($tablename, $pollfreq, $timestamp) {
|
function checkFreq($tablename, $pollfreq, $timestamp) {
|
||||||
|
|
||||||
$sql = "select MAX(TimeStamp) from ".$tablename;
|
$sql = "select MAX(TimeStamp) from ".$tablename;
|
||||||
//$res = $this->fireMySQLQuery($sql, TRUE);
|
//$res = $this->fireMySQLQuery($sql, TRUE);
|
||||||
@ -289,17 +252,17 @@ function checkFreq($tablename, $pollfreq, $timestamp) {
|
|||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getSleeptime - searches for the smallest polling frequency and returns the time to sleep
|
* getSleeptime - searches for the smallest polling frequency and returns the time to sleep
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getSleeptime() {
|
function getSleeptime() {
|
||||||
|
|
||||||
$sql = "select MIN(pollfreq) from cfg_queries";
|
$sql = "select MIN(pollfreq) from cfg_queries";
|
||||||
$res = $this->adodb->fetchArrayDB($sql);
|
$res = $this->adodb->fetchArrayDB($sql);
|
||||||
@ -315,10 +278,10 @@ function getSleeptime() {
|
|||||||
|
|
||||||
return min($minoverview,$minqueries)*60;
|
return min($minoverview,$minqueries)*60;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pollQuery - executes a TSM query and stores result in MySQL DB
|
* pollQuery - executes a TSM query and stores result in MySQL DB
|
||||||
*
|
*
|
||||||
* @param array $query
|
* @param array $query
|
||||||
@ -327,7 +290,7 @@ function getSleeptime() {
|
|||||||
* @param string $timestamp
|
* @param string $timestamp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function pollQuery($query = "", $server = "", $ignorePollFreq = FALSE, $timestamp){
|
function pollQuery($query = "", $server = "", $ignorePollFreq = FALSE, $timestamp){
|
||||||
|
|
||||||
$queryname = $query["name"];
|
$queryname = $query["name"];
|
||||||
$tablename = "res_".$queryname."_".$server["servername"];
|
$tablename = "res_".$queryname."_".$server["servername"];
|
||||||
@ -376,10 +339,10 @@ function pollQuery($query = "", $server = "", $ignorePollFreq = FALSE, $timestam
|
|||||||
if (!$ignorePollFreq) echo "no need to update result -> pollfreq not reached!\n";
|
if (!$ignorePollFreq) echo "no need to update result -> pollfreq not reached!\n";
|
||||||
$this->log_pollfreqnoreached++;
|
$this->log_pollfreqnoreached++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pollOverviewQuery - executes a TSM overview query and stores result in MySQL DB
|
* pollOverviewQuery - executes a TSM overview query and stores result in MySQL DB
|
||||||
*
|
*
|
||||||
* @param array $query
|
* @param array $query
|
||||||
@ -388,7 +351,7 @@ function pollQuery($query = "", $server = "", $ignorePollFreq = FALSE, $timestam
|
|||||||
* @param string $timestamp
|
* @param string $timestamp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function pollOverviewQuery($query = "", $server = "", $timestamp){
|
function pollOverviewQuery($query = "", $server = "", $timestamp){
|
||||||
|
|
||||||
$tablename = "res_overview_".$server["servername"];
|
$tablename = "res_overview_".$server["servername"];
|
||||||
echo "---------".$query["name"].": ";
|
echo "---------".$query["name"].": ";
|
||||||
@ -407,12 +370,12 @@ function pollOverviewQuery($query = "", $server = "", $timestamp){
|
|||||||
echo "There was a problem querying the TSM Server ".$server["servername"]."!\n";
|
echo "There was a problem querying the TSM Server ".$server["servername"]."!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cleanupDatabase - cleans up database (single result tables and/or hash entry)
|
* cleanupDatabase - cleans up database (single result tables and/or hash entry)
|
||||||
*
|
*
|
||||||
* @param string $servername
|
* @param string $servername
|
||||||
@ -421,7 +384,7 @@ function pollOverviewQuery($query = "", $server = "", $timestamp){
|
|||||||
* @param string $hashonly do not drop table, just delete entry in log_hashes
|
* @param string $hashonly do not drop table, just delete entry in log_hashes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function cleanupDatabase($servername = "", $queryname = "", $overviewqueryname = "", $hashonly = "yes"){
|
function cleanupDatabase($servername = "", $queryname = "", $overviewqueryname = "", $hashonly = "yes"){
|
||||||
|
|
||||||
if ($servername != "" && $queryname != "" && $overviewqueryname != "") {
|
if ($servername != "" && $queryname != "" && $overviewqueryname != "") {
|
||||||
foreach ($this->servers as $server) {
|
foreach ($this->servers as $server) {
|
||||||
@ -450,12 +413,12 @@ function cleanupDatabase($servername = "", $queryname = "", $overviewqueryname =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setPollDStatus
|
* setPollDStatus
|
||||||
*
|
*
|
||||||
* @param string $status
|
* @param string $status
|
||||||
@ -463,7 +426,7 @@ function cleanupDatabase($servername = "", $queryname = "", $overviewqueryname =
|
|||||||
* @param string $nextrun
|
* @param string $nextrun
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function setPollDStatus($status, $lastrun, $nextrun) {
|
function setPollDStatus($status, $lastrun, $nextrun) {
|
||||||
|
|
||||||
if ($status != "") $status = "`status`='".$status."'";
|
if ($status != "") $status = "`status`='".$status."'";
|
||||||
if ($lastrun != "") $lastrun = ", `lastrun`='".$lastrun."'";
|
if ($lastrun != "") $lastrun = ", `lastrun`='".$lastrun."'";
|
||||||
@ -472,17 +435,17 @@ function setPollDStatus($status, $lastrun, $nextrun) {
|
|||||||
$sql = "update log_polldstat set ".$status." ".$lastrun." ".$nextrun." WHERE `id`='1'";
|
$sql = "update log_polldstat set ".$status." ".$lastrun." ".$nextrun." WHERE `id`='1'";
|
||||||
//$this->fireMySQLQuery($sql, FALSE);
|
//$this->fireMySQLQuery($sql, FALSE);
|
||||||
$this->adodb->execDB($sql);
|
$this->adodb->execDB($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* isEnabled - returns true if PollD is enabled
|
* isEnabled - returns true if PollD is enabled
|
||||||
*
|
*
|
||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function isEnabled() {
|
function isEnabled() {
|
||||||
|
|
||||||
$sql = "select enabled from log_polldstat WHERE `id`='1'";
|
$sql = "select enabled from log_polldstat WHERE `id`='1'";
|
||||||
//$result = $this->fireMySQLQuery($sql, TRUE);
|
//$result = $this->fireMySQLQuery($sql, TRUE);
|
||||||
@ -494,16 +457,16 @@ function isEnabled() {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* controlPollD - enables or disables polld
|
* controlPollD - enables or disables polld
|
||||||
*
|
*
|
||||||
* @param string switch on or off
|
* @param string switch on or off
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function controlPollD($switch = "") {
|
function controlPollD($switch = "") {
|
||||||
|
|
||||||
if ($switch == "on") {
|
if ($switch == "on") {
|
||||||
$val = "1";
|
$val = "1";
|
||||||
@ -520,33 +483,33 @@ function controlPollD($switch = "") {
|
|||||||
$this->adodb->execDB($sql);
|
$this->adodb->execDB($sql);
|
||||||
//$this->adodb->updateDB("log_polldstat", $colarray, 'id');
|
//$this->adodb->updateDB("log_polldstat", $colarray, 'id');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get Status - returns status of PollD
|
* get Status - returns status of PollD
|
||||||
*
|
*
|
||||||
* @returns string
|
* @returns string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getStatus() {
|
function getStatus() {
|
||||||
|
|
||||||
$sql = "select status from log_polldstat WHERE `id`='1'";
|
$sql = "select status from log_polldstat WHERE `id`='1'";
|
||||||
//$result = $this->fireMySQLQuery($sql, TRUE);
|
//$result = $this->fireMySQLQuery($sql, TRUE);
|
||||||
$result = $this->adodb->fetchArrayDB($sql);
|
$result = $this->adodb->fetchArrayDB($sql);
|
||||||
|
|
||||||
return $result[0]->status;
|
return $result[0]["status"];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* poll - the main function that polls the data
|
* poll - the main function that polls the data
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function poll(){
|
function poll(){
|
||||||
|
|
||||||
//$this->controlPollD("off");
|
//$this->controlPollD("off");
|
||||||
|
|
||||||
@ -610,7 +573,7 @@ function poll(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user