public function GetVolumeList() { $volumes = ''; $volumes_list = array(); $query = ""; //MKO Aggiunto per calcolo TTL $time = time(); $dtF = new DateTime("@0"); //END MKO foreach (Pools_Model::getPools($this->db_link) as $pool) { switch ($this->db_driver) { case 'sqlite': case 'mysql': //MKO Aggiunto per firstwritten per calcolo TTL $query = "SELECT Media.voluseduration, Media.inchanger, Media.slot, Media.firstwritten, Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention\n\t\t\t\t\t\t\t\t\tFROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE Media.poolid = '" . $pool['poolid'] . "' ORDER BY Media.volumename"; break; case 'pgsql': $query = "SELECT media.voluseduration, media.inchanger, media.slot, media.firstwritten, media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention\n\t\t\t\t\t\t\t\t\tFROM media LEFT JOIN pool ON media.poolid = pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE media.poolid = '" . $pool['poolid'] . "' ORDER BY media.volumename"; //END MKO break; } // end switch $volumes = CDBUtils::runQuery($query, $this->db_link); if (!array_key_exists($pool['name'], $volumes_list)) { $volumes_list[$pool['name']] = array(); } foreach ($volumes->fetchAll() as $volume) { if ($volume['lastwritten'] != "0000-00-00 00:00:00") { // Calculate expiration date if the volume is Full if ($volume['volstatus'] == 'Full') { $expire_date = strtotime($volume['lastwritten']) + $volume['volretention']; $volume['expire'] = strftime("%Y-%m-%d", $expire_date); } else { $volume['expire'] = 'N/A'; } //MKO Calcolo Append Life $timediff = $time - strtotime($volume['firstwritten']); if ($volume['volstatus'] == 'Append') { $remaining = $volume['voluseduration'] - $timediff; if ($remaining < 0) { $remaining = 0; } $dtT = new DateTime("@{$remaining}"); $volume['volstatus'] = $volume['volstatus'] . ' (' . $dtF->diff($dtT)->format('%ad %Hh %im %ss') . ')'; } //MKO Calcolo TTL $ttl = $volume['volretention'] - $timediff; $dtT = new DateTime("@{$ttl}"); $ttl > 0 ? $volume['ttl'] = $dtF->diff($dtT)->format('%ad %Hh %im %ss') : ($volume['ttl'] = 'Expired'); //MKO In Changer $volume['inchanger'] ? $volume['changer'] = 'Slot: ' . $volume['slot'] : ($volume['changer'] = 'No'); // Media used bytes in a human format $volume['volbytes'] = CUtils::Get_Human_Size($volume['volbytes']); } else { $volume['lastwritten'] = "N/A"; $volume['expire'] = "N/A"; $volume['volbytes'] = "0 KB"; } $volume['volretention'] = $volume['volretention'] / 60 / 60 / 24 . 'd'; // Add the media in pool array array_push($volumes_list[$pool['name']], $volume); } // end foreach volumes } // end foreach pools return $volumes_list; }
$graph->SetData($jobs_status_data, 'pie'); $graph->setPieLegendColors(array('gray', 'green', 'blue', 'red', 'orange')); // Graph rendering $view->assign('graph_jobs', $graph->Render()); unset($graph); // ============================================================== // Volumes per pool widget // ============================================================== $vols_by_pool = array(); $graph = new CGraph("dashboard-graph02.jpg"); $max_pools = '9'; $table_pool = 'Pool'; $limit = ''; $sum_vols = ''; // Count defined pools in catalog $pools_count = Pools_Model::count($dbSql->db_link); // Display 9 biggest pools and rest of volumes in 10th one display as Other if ($pools_count > $max_pools) { if (CDB::getDriverName() == 'pgsql') { $limit = $max_pools . 'OFFSET ' . ($pools_count - $max_pools); } else { $limit = $max_pools . ',' . ($pools_count - $max_pools); } $query = array('table' => $table_pool, 'fields' => array('SUM(numvols) AS sum_vols'), 'limit' => $limit, 'groupby' => 'name'); $result = CDBUtils::runQuery(CDBQuery::get_Select($query), $dbSql->db_link); $sum_vols = $result->fetch(); } else { $limit = $pools_count; } // Check database driver for pool table name if (CDB::getDriverName() == 'pgsql') {
public function GetVolumeList() { $pools = array(); $query = ""; foreach (Pools_Model::getPools($this->db_link) as $pool) { $pool_name = $pool['name']; switch ($this->db_driver) { case 'sqlite': case 'mysql': $query = "SELECT Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention, Media.slot\n\t\t\t\t\t\t\t\t\tFROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE Media.poolid = '" . $pool['poolid'] . "' ORDER BY Media.volumename"; break; case 'pgsql': $query = "SELECT media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention, media.slot\n\t\t\t\t\t\t\t\t\tFROM media LEFT JOIN pool ON media.poolid = pool.poolid\n\t\t\t\t\t\t\t\t\tWHERE media.poolid = '" . $pool['poolid'] . "' ORDER BY media.volumename"; break; } // end switch $volumes = CDBUtils::runQuery($query, $this->db_link); // If we have at least 1 volume in this pool, create sub array for the pool if (!array_key_exists($pool_name, $pools)) { $pools[$pool_name] = array(); $pools[$pool_name]['volumes'] = array(); } foreach ($volumes->fetchAll() as $volume) { // Set volume default values $volume['expire'] = 'n/a'; // Set value for unused volumes if (empty($volume['lastwritten'])) { $volume['lastwritten'] = 'n/a'; } // Media used bytes in a human format $volume['volbytes'] = CUtils::Get_Human_Size($volume['volbytes']); // If volume have alreday been used if ($volume['lastwritten'] != "0000-00-00 00:00:00") { // Calculate expiration date only if the volume is Full if ($volume['volstatus'] == 'Full') { $expire_date = strtotime($volume['lastwritten']) + $volume['volretention']; $volume['expire'] = strftime("%Y-%m-%d", $expire_date); } } // Push the volume array to the $pool array array_push($pools[$pool_name]['volumes'], $volume); } // end foreach volumes // Calulate used bytes for each pool $sql = "SELECT SUM(Media.volbytes) FROM Media WHERE Media.PoolId = '" . $pool['poolid'] . "'"; $result = CDBUtils::runQuery($sql, $this->db_link); $result = $result->fetchAll(); $pools[$pool_name]['total_used_bytes'] = CUtils::Get_Human_Size($result[0]['sum']); } // end foreach pools return $pools; }