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