From 6d858a982ae72bc9d38d59336d7688812a87936b Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 6 Apr 2011 09:12:31 +1000 Subject: [PATCH] WIP sofar --- application/classes/database/tsm.php | 3 +- application/classes/database/tsm/result.php | 17 ++-- .../classes/model/auth/userdefault.php | 3 +- application/classes/model/node.php | 90 +++++++++++++++++++ application/classes/orm.php | 8 +- application/classes/ormtsm.php | 88 ++++++++++++++++++ application/config/config.php | 1 + application/media/css/default.css | 1 + 8 files changed, 202 insertions(+), 9 deletions(-) create mode 100644 application/classes/model/node.php create mode 100644 application/classes/ormtsm.php diff --git a/application/classes/database/tsm.php b/application/classes/database/tsm.php index 65b7eeb..7de495c 100644 --- a/application/classes/database/tsm.php +++ b/application/classes/database/tsm.php @@ -83,8 +83,9 @@ class Database_TSM extends Database { else { // Create a connection and force it to be a new link - $this->_connection = sprintf('%s -id=%s -password=%s -displ=list -dataonly=YES %s %s', + $this->_connection = sprintf('%s %s -id=%s -password=%s -displ=list -dataonly=YES %s %s', Kohana::config('config.client'), + Kohana::config('config.stanza') ? '-server='.Kohana::config('config.stanza') : '', $username, $password, Kohana::config('config.client_errorlogname') ? sprintf('-errorlogname=%s',Kohana::config('config.client_errorlogname')) : '', diff --git a/application/classes/database/tsm/result.php b/application/classes/database/tsm/result.php index 80891af..e6909fb 100644 --- a/application/classes/database/tsm/result.php +++ b/application/classes/database/tsm/result.php @@ -59,9 +59,6 @@ class Database_TSM_Result extends Database_Result { if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row)) return FALSE; - // Increment internal row for optimization assuming rows are fetched in order - $this->_internal_row++; - if ($this->_as_object === TRUE) { // Return an stdClass @@ -72,14 +69,24 @@ class Database_TSM_Result extends Database_Result { // Return an object of given class name $o = new $this->_as_object; - return $o->_load_values($this->_rows[$this->_current_row++]); + return $o->_load_values($this->_rows[$this->_current_row]); } else { // Return an array of the row - return $this->_rows[$this->_current_row++]; + return $this->_rows[$this->_current_row]; } } + /** + * Get a row value from the query + * + * TSM returns all columns in upper case + */ + public function get($name, $default = NULL) { + $name = strtoupper($name); + + return parent::get($name,$default); + } } // End Database_TSM_Result ?> diff --git a/application/classes/model/auth/userdefault.php b/application/classes/model/auth/userdefault.php index 37cbcf8..8257921 100644 --- a/application/classes/model/auth/userdefault.php +++ b/application/classes/model/auth/userdefault.php @@ -9,7 +9,8 @@ * @license http://dev.leenooks.net/license.html */ class Model_Auth_UserDefault extends Model_Auth_User { - protected $_table_names_plural = false; + protected $_table_names_plural = FALSE; + protected $_disable_wild_select = TRUE; // Validation rules protected $_rules = array( diff --git a/application/classes/model/node.php b/application/classes/model/node.php new file mode 100644 index 0000000..0cc05c5 --- /dev/null +++ b/application/classes/model/node.php @@ -0,0 +1,90 @@ +array('ORMTSM::date'=>array('d-M-Y')), + 'PWSET_TIME'=>array('ORMTSM::date'=>array('d-M-Y')), + 'LASTACC_TIME'=>array('ORMTSM::date'=>array('d-M-Y')), + 'LASTSESS_SENT'=>array('number_format'=>array(0)), + 'LASTSESS_RECVD'=>array('number_format'=>array(0)), + 'LASTSESS_DURATION'=>array('number_format'=>array(2)), + 'LASTSESS_IDLEWAIT'=>array('number_format'=>array(2)), + 'LASTSESS_COMMWAIT'=>array('number_format'=>array(2)), + 'LASTSESS_MEDIAWAIT'=>array('number_format'=>array(2)), + ); + + protected $_sorting = array( + 'NODE_NAME'=>'ASC', + ); + + public function tsmclientversion() { + return sprintf('%s.%s.%s.%s',$this->CLIENT_VERSION,$this->CLIENT_RELEASE,$this->CLIENT_LEVEL,$this->CLIENT_SUBLEVEL); + } + + // @todo This needs to return the global configuration. + public function passexp() { + if ($this->PASSEXP) + return 'TBA'; + else + return _('No Set'); + } + + public function lasttransferpercent() { + return number_format(100-($this->LASTSESS_IDLEWAIT+$this->LASTSESS_COMMWAIT+$this->LASTSESS_MEDIAWAIT),2); + } + + public function lasttransfertime() { + return number_format($this->LASTSESS_DURATION*($this->lasttransferpercent()/100),2); + } + + public function lastsendperformance() { + if ($this->lasttransfertime()) + return number_format($this->LASTSESS_SENT/$this->lasttransfertime()/1024/1024,2); + else + return _('N/A'); + } + + public function lastreceiveperformance() { + if ($this->lasttransfertime()) + return number_format($this->LASTSESS_RECVD/$this->lasttransfertime()/1024/1024,2); + else + return _('N/A'); + } + + public function lastsendaggperformance() { + return number_format($this->LASTSESS_SENT/$this->LASTSESS_DURATION/1024/1024,2); + } + + public function lastreceiveaggperformance() { + return number_format($this->LASTSESS_RECVD/$this->LASTSESS_DURATION/1024/1024,2); + } + + // @todo This should return the system setting (cloptset), if the node setting is not configured. + public function txngroupmax() { + return $this->display('TXNGROUPMAX'); + } + + /** + * Get all the nodes by OS + */ + public function byos() { + $a = $this->select('count(*) AS node_name,platform_name') + ->group_by('platform_name') + ->order_by('platform_name'); + + return $a->find_all(); + } +} +?> diff --git a/application/classes/orm.php b/application/classes/orm.php index a365572..c17c260 100644 --- a/application/classes/orm.php +++ b/application/classes/orm.php @@ -17,9 +17,13 @@ class ORM extends Kohana_ORM { public function find($id = NULL) { // Since TSM doesnt support LIMIT, we'll use find_all() but return the first record foreach ($this->find_all() as $object) { - $this->_load_values($object->_object); + // In TSM Primary Keys are in upper case + if (is_null($id) OR $object->{$object->_primary_key} == strtoupper($id)) + $this->_load_values($object->_object); - return; + // If we have found our item return + if ($this->_loaded) + return; } } diff --git a/application/classes/ormtsm.php b/application/classes/ormtsm.php new file mode 100644 index 0000000..e29bdc5 --- /dev/null +++ b/application/classes/ormtsm.php @@ -0,0 +1,88 @@ +.* + protected $_disable_wild_select = TRUE; + + // Enable the formating of columns + protected $_object_formated = array(); + protected $_formated = FALSE; + protected $_formats = array(); + + /** + * Format fields for display purposes + * + * @param string column name + * @return mixed + */ + protected function _format() { + $format = Validate::factory($this->_object); + + foreach ($this->_formats as $column => $formats) + $format->filters($column,$formats); + + if ($format->check()) + foreach ($format as $column => $value) + $this->_object_formated[$column] = $value; + + $this->_formated = TRUE; + } + + /** + * Return a formated columns, as per the model definition + */ + public function display($column) { + // Trigger a load of the record. + $value = $this->__get($column); + + // If some of our fields need to be formated for display purposes. + if ($this->_loaded AND ! $this->_formated AND $this->_formats) + $this->_format(); + + if (isset($this->_object_formated[$column])) + return $this->_object_formated[$column]; + else + return $value; + } + + public static function date($date,$format) { + return date($format,strtotime($date)); + } + + /** + * This function will enhance the [Validate::filter], since it always passes + * the value as the first argument and sometimes functions need that to not + * be the first argument. + * + * Currently this implements: + * [date()][date-ref] + * + * [date-ref]: http://www.php.net/date + * + * This function will throw an exception if called without a function + * defined. + * + * @param mixed $val Value to be processed + * @param string $func Name of function to call + * @param string $arg Other arguments for the function + */ + final public static function _filters($val,$func,$arg) { + switch ($func) { + case 'date': + return date($arg,$val); + default: + throw new Exception(sprintf(_('Unknown function: %s (%s,%s)'),$func,$arg,$val)); + } + } +} +?> diff --git a/application/config/config.php b/application/config/config.php index 0a55a76..33e5e58 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -13,6 +13,7 @@ return array( 'cache_type' => 'file', 'client' => '/opt/tivoli/tsm/client/ba/bin/dsmadmc', + 'stanza' => '', 'client_errorlogname' => '/tmp/pta-tsm-errorlog.log', 'date_format' => 'd-m-Y', 'email_admin_only'=> array( diff --git a/application/media/css/default.css b/application/media/css/default.css index 6de390a..1592830 100644 --- a/application/media/css/default.css +++ b/application/media/css/default.css @@ -1,5 +1,6 @@ /* Default Template CSS */ +table.box-full { border: 1px solid #AAAACC; margin-right: auto; width: 100%; } table.box-left { border: 1px solid #AAAACC; margin-right: auto; } table.box-center { border: 1px solid #AAAACC; margin-left: auto; margin-right: auto; } tr.head { font-weight: bold; }