From d45b6e708f23342c3e2df1d93e0e7e5a01d09705 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 25 Aug 2010 09:45:24 +0000 Subject: [PATCH] Updated statistics -Added object count to statistics transmit function git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19449 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_stats.inc | 81 ++++++++++++++++++- .../generic/statistics/class_statistics.inc | 30 +++---- 2 files changed, 96 insertions(+), 15 deletions(-) diff --git a/gosa-core/include/class_stats.inc b/gosa-core/include/class_stats.inc index 1523d6d64..6ea22bffc 100644 --- a/gosa-core/include/class_stats.inc +++ b/gosa-core/include/class_stats.inc @@ -282,7 +282,7 @@ class stats * @param int to The timestamp to end the request. * @return array An array containing the requested entries. */ - static function dumpTables($filename) + static function generateStatisticDump($filename) { // Get database connection $TABLE_NAME = stats::$tableName; @@ -332,6 +332,85 @@ class stats rename($path.'/'.$filename, $path.'/'.$filename.".old"); } } + + + static function getLdapObjectCount($config, $statisticConformResult = FALSE) + { + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + + // A list of objectClasses to search for, indexed by their + // object-category + $ocsToSearchFor = array( + "department" => array("gosaDepartment"), + "devices" => array("gotoDevice"), + "fai" => array("FAIobject"), + "gofaxlist" => array("goFaxRBlock","goFaxSBlock"), + "gofonconference" => array("goFonConference"), + "phone" => array("goFonHardware"), + "gofonmacro" => array("goFonMacro"), + "users" => array("gosaAccount"), + "acls" => array("gosaAcl","gosaRole"), + "application" => array("gosaApplication"), + "ogroups" => array("gosaGroupOfNames"), + "roles" => array("organizationalRole"), + "server" => array("goServer"), + "printer" => array("gotoPrinter"), + "terminal" => array("gotoTerminal"), + "workstation" => array("gotoWorkstation"), + "winworkstation" => array("sambaSamAccount"), + "incoming" => array("goHard"), + "component" => array("ieee802Device"), + "mimetypes" => array("gotoMimeType"), + "groups" => array("posixGroup"), + "sudo" => array("sudoRole")); + + // Build up a filter which contains all objectClass combined by OR. + // We will later sum up the results using PHP. + $filter = ""; + $categoryCounter = array(); + foreach($ocsToSearchFor as $category => $ocs){ + foreach($ocs as $oc){ + $filter.= "(objectClass={$oc})"; + } + $categoryCounter[$category] = 0; + } + $filter = "(|{$filter})"; + + // Initiate the ldap query + $res = $ldap->search($filter, array('objectClass')); + if($ldap->success()) { + + // Count number of results per category + while($entry = $ldap->fetch()){ + foreach($ocsToSearchFor as $category => $ocs){ + if(count(array_intersect($ocs, $entry['objectClass']))){ + $categoryCounter[$category] ++; + break; + } + } + } + } + arsort($categoryCounter); + + // Do we have to return the result as SQL INSERT statement? + if($statisticConformResult){ + $uuid = $config->getGOsaUUID(); + $type = 'objectCount'; + $plugin = ''; + $action = ''; + $date = date('Y-m-d'); + $memory_usage = sqlite_escape_string(stats::get_memory_usage()); + $cpu_load = sqlite_escape_string(number_format(stats::get_cpu_load(),4,'.','')); + $sql = array(); + foreach($categoryCounter as $category => $amount){ + $sql[] = array($type, $plugin, $category,$action,$uuid,$date, 0,0,$amount,$memory_usage,$cpu_load,''); + } + return($sql); + }else{ + return($categoryCounter); + } + } } ?> diff --git a/gosa-core/plugins/generic/statistics/class_statistics.inc b/gosa-core/plugins/generic/statistics/class_statistics.inc index 94eebdc5f..b7285e457 100644 --- a/gosa-core/plugins/generic/statistics/class_statistics.inc +++ b/gosa-core/plugins/generic/statistics/class_statistics.inc @@ -20,7 +20,7 @@ class statistics extends plugin var $graph1DatePicker1 = 0; var $graph1DatePicker2 = 0; - // A collection opf timestamps for unsubmitted statistics data. + // A collection of timestamps for unsubmitted statistics data. var $unsbmittedFiles = array(); var $graphs = array(); @@ -39,7 +39,7 @@ class statistics extends plugin $this->staticChart2 = new pieChart2($config); // Init start and stop times for graph 1 - $this->graph1DatePicker1 = date('d.m.Y', time() - 14 * 24 * 60 *60); + $this->graph1DatePicker1 = date('d.m.Y', time() - 28 * 24 * 60 *60); $this->graph1DatePicker2 = date('d.m.Y', time()); // First try to retrieve values via RPC @@ -128,15 +128,6 @@ class statistics extends plugin $smarty->assign('graph1DatePicker1', $this->graph1DatePicker1); $smarty->assign('graph1DatePicker2', $this->graph1DatePicker2); - // Assign list of graphs - $tmp = array(); - foreach($this->graphs as $id => $gClass){ - $tmp[$id] = $gClass->getTitle(); - } - $smarty->assign("selectedGraphType", $this->selectedGraphType); - $smarty->assign("availableGraphs", $tmp); - - // Do not render anything if we are not prepared to send and receive data via rpc. $smarty->assign("rpcConfigured", $this->rpcConfigured); $smarty->assign("validRpcHandle", TRUE); @@ -145,15 +136,25 @@ class statistics extends plugin return($smarty->fetch(get_template_path('statistics.tpl', TRUE))); } + // Assign list of selectable graphs + $tmp = array(); + foreach($this->graphs as $id => $gClass){ + $tmp[$id] = $gClass->getTitle(); + } + $smarty->assign("selectedGraphType", $this->selectedGraphType); + $smarty->assign("availableGraphs", $tmp); + // Send stats if(isset($_POST['transmitStatistics'])){ $this->unsbmittedFiles = $this->getUnsubmittedStatistics(); foreach($this->unsbmittedFiles as $filename => $date){ - $tmp = stats::dumpTables($filename); + $tmp = stats::generateStatisticDump($filename); $dump = array(); foreach($tmp as $entry){ $dump[] = array_values($entry); } + $objectCount = stats::getLdapObjectCount($this->config, TRUE); + $dump = array_merge($dump, $objectCount); $res = $this->rpcHandle->updateInstanceStatus($dump); if(!$this->rpcHandle->success()){ msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG); @@ -166,7 +167,7 @@ class statistics extends plugin } // Transmit daily statistics to GOsa-Server - if(isset($_POST['receiveStatistics']) && $this->rpcConfigured){ + if((isset($_POST['receiveStatistics']) || !count($this->statisticData)) && $this->rpcConfigured){ $start = strtotime($this->graph1DatePicker1); $stop = strtotime($this->graph1DatePicker2); $res = $this->rpcHandle->getInstanceStats($start,$stop); @@ -177,7 +178,8 @@ class statistics extends plugin } $this->rpcHandle_Error = !$this->rpcHandle->success(); } - + + // Update graphs $this->reloadGraphs(); $smarty->assign('staticChart1_ID', $this->staticChart1->getGraphID()); -- 2.30.2