Exemplo n.º 1
0
 private function updateRemovedLogicalVolumes(EtvaNode $etva_node, $server_lvs)
 {
     $etva_server = $this->etva_server;
     $etva_cluster = $etva_node->getEtvaCluster();
     foreach ($server_lvs as $logicalvol) {
         // if logical volume is shared
         if ($logicalvol->getStorageType() != EtvaLogicalvolume::STORAGE_TYPE_LOCAL_MAP) {
             $lvdevice = $logicalvol->getLvdevice();
             // remove device in each node
             $etva_cluster->soapSend('device_remove', array('device' => $lvdevice), $etva_node);
         }
     }
     $lv_va = new EtvaLogicalvolume_VA();
     $lv_va->send_update($etva_node);
 }
Exemplo n.º 2
0
 public function executeJsonReloadLogicalVolumes(sfWebRequest $request)
 {
     //adding cluster id filter
     $elements = array();
     // get node id from cluster context
     $etva_node = EtvaNodePeer::getOrElectNode($request);
     if (!$etva_node) {
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaNodePeer::_ERR_NOTFOUND_ID_, array('%id%' => $nid));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $node_log = Etva::getLogMessage(array('id' => $nid), EtvaNodePeer::_ERR_NOTFOUND_ID_);
         //notify system log
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $node_log, 'priority' => EtvaEventLogger::ERR)));
         // if is a CLI soap request return json encoded data
         if (sfConfig::get('sf_environment') == 'soap') {
             return json_encode($error);
         }
         // if is browser request return text renderer
         $error = $this->setJsonError($error);
         return $this->renderText($error);
     }
     $lv_va = new EtvaLogicalvolume_VA();
     $lv_errors = $lv_va->send_update($etva_node, true);
     //notify system log
     $message = Etva::getLogMessage(array(), EtvaLogicalvolumePeer::_OK_SOAPREFRESH_);
     $msg_i18n = sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_OK_SOAPREFRESH_, array());
     sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message)));
     // return array
     $result = array('success' => true, 'agent' => $etva_node->getName(), 'response' => $msg_i18n);
     $return = json_encode($result);
     if (sfConfig::get('sf_environment') == 'soap') {
         return $return;
     }
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($return);
 }
Exemplo n.º 3
0
 public function register(EtvaNode $etva_node, $vg_info = null)
 {
     $etva_cluster = $etva_node->getEtvaCluster();
     // check if volumegroup is shared
     $shared = $this->etva_vg->getStorageType() != EtvaVolumegroup::STORAGE_TYPE_LOCAL_MAP;
     // force to load volume groups
     $bulk_responses = array();
     if ($shared) {
         $bulk_responses = $etva_cluster->soapSend(self::GET_SYNC_VOLUMEGROUPS, array('force' => 1));
     } else {
         $node_id = $etva_node->getId();
         $bulk_responses[$node_id] = $etva_node->soapSend(self::GET_SYNC_VOLUMEGROUPS, array('force' => 1));
     }
     $vg_info_sync = $this->getVolumegroupInfo($etva_node, $bulk_responses);
     // merge vg info
     if ($vg_info_sync) {
         $vg_info = $vg_info ? array_merge($vg_info_sync, $vg_info) : $vg_info_sync;
     }
     // set vg info if needed
     if ($vg_info) {
         $this->etva_vg->initData($vg_info);
     }
     // for none local storage devices
     if ($shared) {
         // check if all nodes see that
         $check_res = $this->check_all_see_it($etva_node, $bulk_responses);
         if (!$check_res['success']) {
             return array('success' => false, 'errors' => $check_res['errors'], 'debug' => 'check_all_see_it');
         }
     }
     $etva_volgroup = $this->etva_vg;
     // set cluster
     $etva_cluster = $etva_node->getEtvaCluster();
     $etva_volgroup->setEtvaCluster($etva_cluster);
     // save it
     $etva_volgroup->save();
     // create relation node_volumegorup
     $etva_node_volgroup = new EtvaNodeVolumegroup();
     $etva_node_volgroup->setEtvaVolumegroup($etva_volgroup);
     $etva_node_volgroup->setEtvaNode($etva_node);
     $etva_node_volgroup->save();
     if ($vg_info) {
         /*
          * associate pvs with vg and update info
          */
         $pvs = isset($vg_info[EtvaVolumegroup::PHYSICALVOLUMES_MAP]) ? (array) $vg_info[EtvaVolumegroup::PHYSICALVOLUMES_MAP] : array();
         foreach ($pvs as $pv => $pvInfo) {
             $pv_info = (array) $pvInfo;
             $pv_type = $pv_info[EtvaPhysicalvolume::STORAGE_TYPE_MAP];
             $pv_uuid = isset($pv_info[EtvaPhysicalvolume::UUID_MAP]) ? $pv_info[EtvaPhysicalvolume::UUID_MAP] : '';
             $pv_device = $pv_info[EtvaPhysicalvolume::DEVICE_MAP];
             //error_log(sprintf("node name=%s id=%d device=%s uuid=%s type=%s",$etva_node->getName(),$etva_node->getId(),$pv_device,$pv_uuid,$pv_type));
             //get physical volume based on node, type, uuid and device
             $etva_physical = EtvaPhysicalvolumePeer::retrieveByNodeTypeUUIDDevice($etva_node->getId(), $pv_type, $pv_uuid, $pv_device);
             if (!$etva_physical) {
                 $etva_physical = new EtvaPhysicalvolume();
             }
             $etva_physical->setEtvaCluster($etva_cluster);
             $etva_physical->initData($pv_info);
             $etva_physical->save();
             $etva_node_physical = EtvaNodePhysicalvolumePeer::retrieveByPK($etva_node->getId(), $etva_physical->getId());
             if (!$etva_node_physical) {
                 $etva_node_physical = new EtvaNodePhysicalvolume();
             }
             $etva_node_physical->setEtvaPhysicalvolume($etva_physical);
             $etva_node_physical->setEtvaNode($etva_node);
             $etva_node_physical->setDevice($pv_device);
             $etva_node_physical->save();
             $etva_volgroup_physical = EtvaVolumePhysicalPeer::retrieveByPK($etva_volgroup->getId(), $etva_physical->getId());
             if (!$etva_volgroup_physical) {
                 $etva_volgroup_physical = new EtvaVolumePhysical();
             }
             $etva_volgroup_physical->setEtvaPhysicalvolume($etva_physical);
             $etva_volgroup_physical->setEtvaVolumegroup($etva_volgroup);
             $etva_volgroup_physical->save();
         }
     }
     // for no local storage type
     $errors = $this->sync_update($bulk_responses);
     if (!empty($errors)) {
         return array('success' => false, 'errors' => $errors);
     }
     // update logical volumes
     $lv_va = new EtvaLogicalvolume_VA();
     $lv_errors = $lv_va->send_update($etva_node, true, $shared);
     if (!empty($lv_errors)) {
         return array('success' => false, 'errors' => $lv_errors);
     }
     return array('success' => true);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true));
     parent::execute($arguments, $options);
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add your code here
     // Update nodes logical volumes
     $this->log('[INFO] Update nodes logical volumes info...' . "\n");
     $list_nodes = EtvaNodeQuery::create()->find();
     foreach ($list_nodes as $node) {
         $lv_va = new EtvaLogicalvolume_VA();
         $lv_errors = $lv_va->send_update($node, false, false);
     }
     // Check servers with snapshots
     $this->log('[INFO] Checking Servers with snapshots...' . "\n");
     $errors_arr = array();
     $list_servers = EtvaServerQuery::create()->find();
     foreach ($list_servers as $server) {
         $server_lvs = $server->getEtvaLogicalvolumes();
         foreach ($server_lvs as $lv) {
             if ($lv->getPerUsageSnapshots() >= EtvaLogicalvolume::PER_USAGESNAPSHOTS_CRITICAL) {
                 $this->log('[ERROR] Logical volume \'' . $lv->getLvdevice() . '\' of server \'' . $server->getName() . '\' is in CRITICAL with ' . sprintf('%g%%', round($lv->getPerUsageSnapshots() * 100)) . ' of usage by snapshots ');
                 array_push($errors_arr, array('server_name' => $server->getName(), 'lvdevice' => $lv->getLvdevice(), 'per_usage_snapshots' => $lv->getPerUsageSnapshots(), 'status_id' => EtvaServer::USAGESNAPSHOTS_STATUS_CRITICAL, 'status_str' => EtvaServer::USAGESNAPSHOTS_STATUS_CRITICAL_STR));
             } else {
                 if ($lv->getPerUsageSnapshots() >= EtvaLogicalvolume::PER_USAGESNAPSHOTS_WARNING) {
                     $this->log('[ERROR] Logical volume \'' . $lv->getLvdevice() . '\' of server \'' . $server->getName() . '\' is in WARNING with ' . sprintf('%g%%', round($lv->getPerUsageSnapshots() * 100)) . ' of usage by snapshots ');
                     array_push($errors_arr, array('server_name' => $server->getName(), 'lvdevice' => $lv->getLvdevice(), 'per_usage_snapshots' => $lv->getPerUsageSnapshots(), 'status_id' => EtvaServer::USAGESNAPSHOTS_STATUS_WARNING, 'status_str' => EtvaServer::USAGESNAPSHOTS_STATUS_WARNING_STR));
                 } else {
                     $this->log('[INFO] Logical volume \'' . $lv->getLvdevice() . '\' of server \'' . $server->getName() . '\' is in NORMAL with ' . sprintf('%g%%', round($lv->getPerUsageSnapshots() * 100)) . ' of usage by snapshots ');
                     #array_push($errors_arr, array('server_name'=>$server->getName(),'lvdevice'=>$lv->getLvdevice(),'per_usage_snapshots'=>$lv->getPerUsageSnapshots(),'status_id'=>EtvaServer::USAGESNAPSHOTS_STATUS_CRITICAL,'status_str'=>EtvaServer::USAGESNAPSHOTS_STATUS_CRITICAL_STR));
                 }
             }
         }
     }
     if (!empty($errors_arr)) {
         $message = "";
         foreach ($errors_arr as $err) {
             if ($server_name != $err['server_name']) {
                 $server_name = $err['server_name'];
                 $message = $message . "Server '{$server_name}':\r\n";
             }
             $message = $message . " Logical volume '" . $err['lvdevice'] . "' in state '" . $err['status_str'] . "' with " . sprintf('%g%%', round($err['per_usage_snapshots'] * 100)) . " usage of snapshots.\r\n";
         }
         $from = EtvaSettingPeer::retrieveByPK(EtvaSettingPeer::_ALERT_EMAIL_FROM_)->getValue();
         if (!$from) {
             $from = '*****@*****.**';
         }
         $to = EtvaSettingPeer::retrieveByPK(EtvaSettingPeer::_ALERT_EMAIL_)->getValue();
         if (!$to) {
             $to = '*****@*****.**';
         }
         $subject_prefix = EtvaSettingPeer::retrieveByPK(EtvaSettingPeer::_ALERT_SUBJECT_PREFIX_)->getValue();
         if (!$subject_prefix) {
             $subject_prefix = 'Nuxis -';
         }
         #$to = "*****@*****.**";
         $subject = $subject_prefix . " " . "Servers snapshots usage report";
         $headers = "From: {$from}\r\n";
         mail($to, $subject, $message, $headers);
         $this->log("[INFO] Email with report sent to {$to}");
     } else {
         $this->log("[INFO] No errors to report");
     }
 }