Example #1
0
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'])->getConnection();
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', 'dev', true));
     if ($options['server'] !== null) {
         EtvaSettingPeer::updateSetting(EtvaSettingPeer::_SMTP_SERVER_, $options['server']);
     }
     if ($options['port'] !== null) {
         EtvaSettingPeer::updateSetting(EtvaSettingPeer::_SMTP_PORT_, $options['port']);
     }
     if ($options['security-type'] !== null) {
         EtvaSettingPeer::updateSetting(EtvaSettingPeer::_SMTP_SECURITY_, $options['security-type']);
     }
     if ($options['use-auth'] !== null) {
         EtvaSettingPeer::updateSetting(EtvaSettingPeer::_SMTP_USE_AUTH_, $options['use-auth']);
     }
     if ($options['username'] !== null) {
         EtvaSettingPeer::updateSetting(EtvaSettingPeer::_SMTP_USERNAME_, $options['username']);
     }
     if ($options['password'] !== null) {
         EtvaSettingPeer::updateSetting(EtvaSettingPeer::_SMTP_KEY_, $options['password']);
     }
     return;
 }
Example #2
0
 public function executeJsonGetSMTPConf($request)
 {
     error_log(sfConfig::get("app_remote_smtpserver"));
     $c = new Criteria();
     $settings = EtvaSettingPeer::doSelect($c);
     foreach ($settings as $set) {
         switch ($set->getParam()) {
             case EtvaSettingPeer::_SMTP_SERVER_:
                 $addr = $set->getValue();
                 break;
             case EtvaSettingPeer::_SMTP_PORT_:
                 $port = $set->getValue();
                 break;
             case EtvaSettingPeer::_SMTP_USE_AUTH_:
                 $useauth = $set->getValue();
                 break;
             case EtvaSettingPeer::_SMTP_USERNAME_:
                 $username = $set->getValue();
                 break;
             case EtvaSettingPeer::_SMTP_KEY_:
                 $key = $set->getValue();
                 break;
             case EtvaSettingPeer::_SMTP_SECURITY_:
                 $security = $set->getValue();
                 break;
         }
     }
     $final = array('addr' => $addr, 'port' => $port, 'useauth' => $useauth, 'username' => $username, 'key' => $key, 'security' => $security);
     $result = $final;
     $result = json_encode($final);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($result);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', 'dev', true));
     parent::execute($arguments, $options);
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add your code here
     $this->log('[INFO] Flushing old data...' . "\n");
     $eventlog_flush = EtvaSettingPeer::retrieveByPK('eventlog_flush');
     $flush_range = $eventlog_flush->getValue();
     $con->beginTransaction();
     $affected = 0;
     try {
         $offset_date = date("c", time() - $flush_range * 24 * 60 * 60);
         /*
          * get event records that have creation date outdated
          */
         $c = new Criteria();
         $c->add(EtvaEventPeer::CREATED_AT, $offset_date, Criteria::LESS_THAN);
         $affected = EtvaEventPeer::doDelete($c, $con);
         $con->commit();
         $message = sprintf('Events Log - %d Record(s) deleted after %d day offset', $affected, $flush_range);
         $context->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message)));
         $this->log('[INFO] ' . $message);
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     $logger = new sfFileLogger($context->getEventDispatcher(), array('file' => sfConfig::get("sf_log_dir") . '/cron_status.log'));
     // log the message!
     $logger->log("[INFO] The events flush task ran!", 6);
 }
Example #4
0
 public function updateSetting($param, $value)
 {
     $c = new Criteria();
     $c->add(EtvaSettingPeer::PARAM, $param);
     $obj = EtvaSettingPeer::doSelectOne($c);
     if ($obj === null) {
         $obj = new EtvaSetting();
         $obj->setParam($param);
     }
     $obj->setValue($value);
     $obj->save();
 }
 protected function sendReport()
 {
     $message = $this->report;
     $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 -';
     }
     $subject = $subject_prefix . " " . "Backup Server report";
     $headers = "From: {$from}\r\n";
     mail($to, $subject, $message, $headers);
     $this->log("[INFO] The report was sent to '{$to}' with following subject '{$subject}'.\n");
 }
Example #6
0
 public function executeJsonImport(sfWebRequest $request)
 {
     $nid = $request->getParameter('nid');
     $import_data = json_decode($request->getParameter('import'), true);
     $server = $import_data;
     $vnc_keymap = EtvaSettingPeer::retrieveByPk('vnc_keymap');
     $server['vnc_keymap'] = $vnc_keymap->getValue();
     $server['uuid'] = EtvaServerPeer::generateUUID();
     $server['name'] = $import_data['name'];
     $server['vm_type'] = $import_data['vm_type'];
     $server['ip'] = '000.000.000.000';
     $server['boot'] = 'filesystem';
     $import_data['uuid'] = $server['uuid'];
     $import_data['vnc_keymap'] = $server['vnc_keymap'];
     // import validation check
     $result = $this->jsonImportCheck($request);
     if (!$result['success']) {
         // if is a CLI soap request return json encoded data
         if (sfConfig::get('sf_environment') == 'soap') {
             return json_encode($result);
         }
         // if is browser request return text renderer
         $error = $this->setJsonError($result);
         return $this->renderText($error);
     }
     if (!($etva_node = EtvaNodePeer::retrieveByPK($nid))) {
         $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);
         //notify event log
         $node_log = Etva::getLogMessage(array('id' => $nid), EtvaNodePeer::_ERR_NOTFOUND_ID_);
         $message = Etva::getLogMessage(array('info' => $node_log), OvfEnvelope_VA::_ERR_IMPORT_);
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, '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);
     }
     $disks = $import_data['disks'];
     $collVgs = array();
     foreach ($disks as $id => $info) {
         $vg = $info['vg'];
         $lv = $info['lv'];
         if ($etva_lv = $etva_node->retrieveLogicalvolumeByLv($lv)) {
             $msg_type = $is_DiskFile ? EtvaLogicalvolumePeer::_ERR_DISK_EXIST_ : EtvaLogicalvolumePeer::_ERR_LV_EXIST_;
             $msg = Etva::getLogMessage(array('name' => $lv), $msg_type);
             $msg_i18n = $this->getContext()->getI18N()->__($msg_type, array('%name%' => $lv));
             $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n);
             //notify system log
             $message = Etva::getLogMessage(array('name' => $lv, 'info' => $msg), OvfEnvelope_VA::_ERR_IMPORT_);
             $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, '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);
         }
         if (!($etva_vg = $etva_node->retrieveVolumegroupByVg($vg))) {
             $msg = Etva::getLogMessage(array('name' => $vg), EtvaVolumegroupPeer::_ERR_NOTFOUND_);
             $msg_i18n = $this->getContext()->getI18N()->__(EtvaVolumegroupPeer::_ERR_NOTFOUND_, array('%name%' => $vg));
             $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n);
             //notify system log
             $message = Etva::getLogMessage(array('name' => $lv, 'info' => $msg), OvfEnvelope_VA::_ERR_IMPORT_);
             $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, '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);
         }
         // fix lv path
         $is_DiskFile = $vg == sfConfig::get('app_volgroup_disk_flag') ? 1 : 0;
         $import_data['disks'][$id]['lv'] = $is_DiskFile ? $etva_node->getStoragedir() . '/' . $lv : $lv;
         $collVgs[$vg] = $etva_vg;
     }
     $networks = $import_data['networks'];
     $networks_va = $import_data['networks'];
     $collNetworks = array();
     $i = 0;
     // check if networks are available
     foreach ($networks as $network) {
         if ($etva_vlan = EtvaVlanPeer::retrieveByPk($network['vlan_id'])) {
             $import_data['networks'][$i]['network'] = $etva_vlan->getName();
             $import_data['networks'][$i]['macaddr'] = $network['mac'];
         }
         $etva_mac = EtvaMacPeer::retrieveByMac($network['mac']);
         /*
          * TODO improve this to add Mac Address to the pool
          */
         if (!$etva_mac || !$etva_vlan) {
             $msg = Etva::getLogMessage(array(), EtvaNetworkPeer::_ERR_);
             $msg_i18n = $this->getContext()->getI18N()->__(EtvaNetworkPeer::_ERR_, array());
             if (!$etva_mac) {
                 $msg = Etva::getLogMessage(array('%mac%' => $network['mac']), EtvaMacPeer::_ERR_INVALID_MAC_);
                 $msg_i18n = $this->getContext()->getI18N()->__(EtvaMacPeer::_ERR_INVALID_MAC_, array('%mac%' => $network['mac']));
             }
             $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n);
             //notify event log
             $message = Etva::getLogMessage(array('name' => $server['name'], 'info' => $msg), OvfEnvelope_VA::_ERR_IMPORT_);
             $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, '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);
         }
         if ($etva_mac->getInUse()) {
             $msg = Etva::getLogMessage(array('%name%' => $etva_mac->getMac()), EtvaMacPeer::_ERR_ASSIGNED_);
             $msg_i18n = $this->getContext()->getI18N()->__(EtvaMacPeer::_ERR_ASSIGNED_, array('%name%' => $etva_mac->getMac()));
             $error = array('success' => false, 'agent' => $etva_node->getName(), 'info' => $msg_i18n, 'error' => $msg_i18n);
             //notify event log
             $message = Etva::getLogMessage(array('name' => $server['name'], 'info' => $msg), OvfEnvelope_VA::_ERR_IMPORT_);
             $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, '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);
         }
         $etva_network = new EtvaNetwork();
         $etva_network->fromArray($network, BasePeer::TYPE_FIELDNAME);
         $collNetworks[] = $etva_network;
         $i++;
     }
     $env = new OvfEnvelope_VA();
     $env->fromArray($import_data);
     /* get server copy VA server representation */
     $params = $env->_VA();
     $method = 'vm_ovf_import_may_fork';
     $response = $etva_node->soapSend($method, $params);
     if (!$response['success']) {
         $error_decoded = $response['error'];
         $result = $response;
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_CREATE_, array('%name%' => $server['name'], '%info%' => $error_decoded));
         $result['error'] = $msg_i18n;
         //notify event log
         $message = Etva::getLogMessage(array('name' => $server['name'], 'info' => $response['info']), EtvaServerPeer::_ERR_CREATE_);
         $this->dispatcher->notify(new sfEvent($response['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         if (sfConfig::get('sf_environment') == 'soap') {
             return json_encode($result);
         }
         $return = $this->setJsonError($result);
         return $this->renderText($return);
     }
     $response_decoded = (array) $response['response'];
     $returned_object = (array) $response_decoded['_obj_'];
     $returned_lvs = (array) $returned_object['LVS'];
     $collLvs = array();
     foreach ($returned_lvs as $disk) {
         $disk_array = (array) $disk;
         $vg_info = (array) $disk_array[EtvaLogicalvolume::VOLUMEGROUP_MAP];
         $vg = $vg_info[EtvaVolumegroup::VG_MAP];
         $fake_lv_response = array('success' => true, 'response' => array('_obj_' => $disk_array));
         // create logical volume
         $etva_lv = new EtvaLogicalvolume();
         $etva_lv->setEtvaVolumegroup($collVgs[$vg]);
         $lv_va = new EtvaLogicalvolume_VA($etva_lv);
         $lv_response = $lv_va->processResponse($etva_node, $fake_lv_response, 'lvcreate');
         if (!$lv_response['success']) {
             $return = $this->setJsonError($lv_response);
             return $this->renderText($return);
         }
         $collLvs[] = $etva_lv;
     }
     $etva_server = new EtvaServer();
     $etva_server->fromArray($server, BasePeer::TYPE_FIELDNAME);
     $user_groups = $this->getUser()->getGroups();
     $server_sfgroup = array_shift($user_groups);
     //if user has group then put one of them otherwise put DEFAULT GROUP ID
     if ($server_sfgroup) {
         $etva_server->setsfGuardGroup($server_sfgroup);
     } else {
         $etva_server->setsfGuardGroup(sfGuardGroupPeer::getDefaultGroup());
     }
     foreach ($collNetworks as $coll) {
         $etva_server->addEtvaNetwork($coll);
     }
     $i = 0;
     foreach ($collLvs as $coll) {
         $server_disk = new EtvaServerLogical();
         $server_disk->setEtvaLogicalvolume($coll);
         $server_disk->setBootDisk($i);
         $etva_server->addEtvaServerLogical($server_disk);
         $i++;
     }
     //update some data from agent response
     $vm = (array) $returned_object['VM'];
     $etva_server->initData($vm);
     //$etva_server->setEtvaNode($etva_node);
     $etva_server->setEtvaCluster($etva_node->getEtvaCluster());
     try {
         $etva_server->save();
     } catch (Exception $e) {
         $msg = $e->getMessage();
         $result = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg, 'info' => $msg);
         $return = $this->setJsonError($result);
         return $this->renderText($return);
     }
     // assign To etva_node
     $etva_server->assignTo($etva_node);
     $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_OK_CREATE_, array('%name%' => $server['name']));
     $message = Etva::getLogMessage(array('name' => $server['name']), EtvaServerPeer::_OK_CREATE_);
     $this->dispatcher->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message)));
     $result = array('success' => true, 'agent' => $response['agent'], 'insert_id' => $etva_server->getId(), 'response' => $msg_i18n);
     $return = json_encode($result);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     // if is browser request return text renderer
     return $this->renderText($return);
 }
Example #7
0
 public function saveSettings($sn, $user, $pwd, $desc)
 {
     $this->serial_number = $sn;
     $pk = 'serial_number';
     $sn_setting = EtvaSettingPeer::retrieveByPk($pk);
     if (!$sn_setting) {
         $sn_setting = new EtvaSetting();
     }
     $sn_setting->setParam($pk);
     $sn_setting->setValue($this->serial_number);
     $sn_setting->save();
     $this->username = $user;
     $pk = 'username';
     $user_setting = EtvaSettingPeer::retrieveByPk($pk);
     if (!$user_setting) {
         $user_setting = new EtvaSetting();
     }
     $user_setting->setParam($pk);
     $user_setting->setValue($this->username);
     $user_setting->save();
     $this->password = $pwd;
     $pk = 'password';
     $pwd_setting = EtvaSettingPeer::retrieveByPk($pk);
     if (!$pwd_setting) {
         $pwd_setting = new EtvaSetting();
     }
     $pwd_setting->setParam($pk);
     $pwd_setting->setValue($this->password);
     $pwd_setting->save();
     $this->description = $desc;
     $pk = 'description';
     $desc_setting = EtvaSettingPeer::retrieveByPk($pk);
     if (!$desc_setting) {
         $desc_setting = new EtvaSetting();
     }
     $desc_setting->setParam($pk);
     $desc_setting->setValue($this->description);
     $desc_setting->save();
 }
Example #8
0
 /**
  * Perform update on table setting
  *
  * @param      string $param parameter name to perform operation
  * @param      string $value value for the $param
  *     
  */
 public function executeJsonUpdateSetting(sfWebRequest $request)
 {
     $isAjax = $request->isXmlHttpRequest();
     if (!$isAjax) {
         return $this->redirect('@homepage');
     }
     if (!$request->isMethod('post') && !$request->isMethod('put')) {
         $info = array('success' => false, 'error' => 'Wrong parameters');
         $error = $this->setJsonError($info);
         return $this->renderText($error);
     }
     $param = $request->getParameter('param');
     if (!($etva_setting = EtvaSettingPeer::retrieveByPk($param))) {
         $error_msg = sprintf('Object etva_setting does not exist (%s).', $param);
         $info = array('success' => false, 'error' => $error_msg);
         $error = $this->setJsonError($info);
         return $this->renderText($error);
     }
     $etva_setting->setValue($request->getParameter('value'));
     $param = $request->getParameter('param');
     switch ($param) {
         case 'vnc_keymap':
             if ($etva_setting->saveVNCkeymap()) {
                 //notify system log
                 $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $etva_setting->getValue()), EtvaSettingPeer::_OK_VNCKEYMAP_CHANGE_))));
             } else {
                 //notify system log
                 $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $request->getParameter('value')), EtvaSettingPeer::_ERR_VNCKEYMAP_CHANGE_), 'priority' => EtvaEventLogger::ERR)));
             }
             break;
         default:
             $etva_setting->save();
             break;
     }
     $result = array('success' => true, 'agent' => sfConfig::get('config_acronym'), 'info' => sfConfig::get('config_acronym'));
     $result = json_encode($result);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($result);
 }
Example #9
0
 private function sendDiagnosticEmail()
 {
     // generate tarball with logs
     //        $smtpServer = sfConfig::get("app_remote_log_smtpserver");
     $filepath = sfConfig::get("app_remote_log_file");
     $scriptfile = sfConfig::get("app_remote_log_mailscript");
     $email = sfConfig::get("app_remote_log_toemail");
     $security_type = EtvaSettingPeer::retrieveByParam(EtvaSettingPeer::_SMTP_SECURITY_)->getValue();
     $smtpServer = EtvaSettingPeer::retrieveByParam(EtvaSettingPeer::_SMTP_SERVER_)->getValue();
     $port = EtvaSettingPeer::retrieveByParam(EtvaSettingPeer::_SMTP_PORT_)->getValue();
     $useauth = EtvaSettingPeer::retrieveByParam(EtvaSettingPeer::_SMTP_USE_AUTH_)->getValue();
     if ($useauth == '1') {
         $username = EtvaSettingPeer::retrieveByParam(EtvaSettingPeer::_SMTP_USERNAME_)->getValue();
         $key = EtvaSettingPeer::retrieveByParam(EtvaSettingPeer::_SMTP_KEY_)->getValue();
     }
     error_log("[SMTPSERVER] {$smtpServer}");
     error_log("[COMMAND] perl {$scriptfile} {$filepath} {$smtpServer} {$port} {$email} {$security_type} {$useauth} {$username} {$key}");
     $command = "perl {$scriptfile} {$filepath} {$smtpServer} {$port} {$email} {$security_type} {$useauth} {$username} {$key}";
     $path = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . "utils";
     ob_start();
     passthru('echo ' . $command . ' | sudo /usr/bin/php -f ' . $path . DIRECTORY_SEPARATOR . 'sudoexec.php', $retval);
     $content_grabbed = ob_get_contents();
     ob_end_clean();
     //exec($command, $output, $retval);
     //$output = shell_exec("perl $scriptfile $email $smtpServer $filepath");
     //error_log(print_r($output, true));
     if ($retval == 0) {
         //         $msg = array('success'=>true);
         //           return $this->renderText(json_encode($msg));
         return true;
     } else {
         //            $msg = "Cannot send email: \n";
         //            $msg .= implode("\n", $output);
         error_log("[ERROR] Couldn't send diagnostic by email" . print_r($content_grabbed, true));
         //            $info = array('success'=>false,'error'=>$msg, 'info'=>$msg);
         //            $error = $this->setJsonError($info);
         //            return $this->renderText($error);
         return false;
     }
 }
 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");
     }
 }
Example #11
0
 public function buildServer($method)
 {
     $etva_server = $this->etva_server;
     if ($method == self::SERVER_CREATE) {
         $etva_server->setUuid(EtvaServerPeer::generateUUID());
         $vnc_keymap = EtvaSettingPeer::retrieveByPk('vnc_keymap');
         $etva_server->setVncKeymap($vnc_keymap->getValue());
         $user_groups = sfContext::getInstance()->getUser()->getGroups();
         $server_sfgroup = array_shift($user_groups);
         //if user has group then put one of them otherwise put DEFAULT GROUP ID
         if ($server_sfgroup) {
             $etva_server->setsfGuardGroup($server_sfgroup);
         } else {
             $etva_server->setsfGuardGroup(sfGuardGroupPeer::getDefaultGroup());
         }
     }
     foreach ($this->collNetworks as $coll) {
         $etva_server->addEtvaNetwork($coll);
     }
     foreach ($this->collDisks as $coll) {
         $etva_server->addEtvaServerLogical($coll);
     }
     if (isset($this->collDevices)) {
         $str = json_encode($this->collDevices);
         $etva_server->setDevices($str);
     }
 }
Example #12
0
 /**
  * perform operations on server vnc_keymap
  *
  *
  * request object is like this;
  * <code>
  * $request['id'] = $id; //server ID
  * $request['method'] = update | null //operation to perform (update). Default will list value
  * $request['vnc_keymap'] = $vnc_keymap
  * $request['vnc_keymap_default'] = 0 | 1
  * </code>
  *
  * @param sfWebRequest $request A request object
  * @return string json string representation of array('success'=>true,'data'=>$data)
  *
  */
 public function executeJsonKeymap(sfWebRequest $request)
 {
     $id = $request->getParameter('id');
     $method = $request->getParameter('method');
     $keymap = $request->getParameter('vnc_keymap');
     $default_keymap = $request->getParameter('vnc_keymap_default');
     if (!($etva_server = EtvaServerPeer::retrieveByPK($id))) {
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_, array('%id%' => $id));
         $error = array('success' => false, 'error' => $msg_i18n);
         //notify event log
         $server_log = Etva::getLogMessage(array('id' => $id), EtvaServerPeer::_ERR_NOTFOUND_ID_);
         $message = Etva::getLogMessage(array('name' => $keymap, 'server' => '', 'info' => $server_log), EtvaServerPeer::_ERR_VNCKEYMAP_CHANGE_);
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         // if is browser request return text renderer
         $error = $this->setJsonError($error);
         return $this->renderText($error);
     }
     $server = $etva_server->getName();
     $server_uuid = $etva_server->getUuid();
     $etva_node = $etva_server->getEtvaNode();
     switch ($method) {
         case 'update':
             $params = array('uuid' => $server_uuid, 'vnc_keymap' => $keymap);
             $response = $etva_node->soapSend('set_vnc_options', $params);
             if (!$response['success']) {
                 $result = $response;
                 //notify system log
                 $message = Etva::getLogMessage(array('name' => $keymap, 'info' => $response['info'], 'server' => $etva_server->getName()), EtvaServerPeer::_ERR_VNCKEYMAP_CHANGE_);
                 $this->dispatcher->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
                 $return = $this->setJsonError($result);
                 return $this->renderText($return);
             }
             $etva_server->setVncKeymapDefault($default_keymap);
             $etva_server->setVnckeymap($keymap);
             $etva_server->save();
             //notify system log
             $message = Etva::getLogMessage(array('name' => $keymap, 'server' => $etva_server->getName()), EtvaServerPeer::_OK_VNCKEYMAP_CHANGE_);
             $this->dispatcher->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message)));
             $response_decoded = (array) $response['response'];
             $returned_status = $response_decoded['_okmsg_'];
             $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_OK_VNCKEYMAP_CHANGE_, array('%name%' => $keymap, '%server%' => $etva_server->getName()));
             $msg = $response;
             $msg['response'] = $msg_i18n;
             break;
         default:
             $vnc_keymap = EtvaSettingPeer::retrieveByPk('vnc_keymap');
             $keymap_val = $vnc_keymap->getValue();
             $data = array('vnc_keymap' => $etva_server->getVnckeymap(), 'vnc_keymap_default' => $etva_server->getVncKeymapDefault(), 'keymap_default' => $keymap_val);
             $msg = array('success' => true, 'data' => $data);
             break;
     }
     $result = json_encode($msg);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($result);
 }
Example #13
0
 /**
  * Perform update on table setting
  *
  * @param      string $param parameter name to perform operation
  * @param      string $value value for the $param
  *
  */
 public function executeJsonUpdateSetting(sfWebRequest $request)
 {
     $isAjax = $request->isXmlHttpRequest();
     if (!$isAjax) {
         return $this->redirect('@homepage');
     }
     $settings = $request->getParameter('settings');
     $settings_decoded = json_decode($settings, true);
     $force = $request->getParameter('force');
     $networks = $request->getParameter('networks');
     $network_decoded = json_decode($networks, true);
     if ($networks) {
         $etva_data = Etva::getEtvaModelFile();
         $etvamodel = $etva_data['model'];
         /*
          * get nodes....and call node agent script
          */
         $remote_errors = array();
         $change_networks = 0;
         $cm_networks = new SystemNetworkUtil();
         $interfaces_devices = sfConfig::get('app_device_interfaces');
         $devices = $interfaces_devices[$etvamodel];
         $cm_networks->loadCMNetworks($devices);
         $sys_networks = $cm_networks->getNetworks();
         if ($etvamodel == 'standard') {
             $local = $network_decoded['lan'];
             $remote = $network_decoded['cm_management'];
             $cm_ip = $remote['ip'];
             $local_net = new SystemNetwork();
             $local_net->fromArray($local);
             $remote_net = new SystemNetwork();
             $remote_net->fromArray($remote);
             $sys_lan_if = $devices['lan'];
             $sys_manag_if = $devices['cm_management'];
             $sys_lan_net = $sys_networks[$sys_lan_if];
             $sys_manag_net = $sys_networks[$sys_manag_if];
             if (!$local_net->equals($sys_lan_net) || !$remote_net->equals($sys_manag_net)) {
                 $change_networks = 1;
             }
         } else {
             $local = $network_decoded['cm_management'];
             $remote = array();
             $cm_ip = $local['ip'];
             $local_net = new SystemNetwork();
             $local_net->fromArray($local);
             $sys_manag_if = $devices['cm_management'];
             $sys_manag_net = $sys_networks[$sys_manag_if];
             if (!$local_net->equals($sys_manag_net)) {
                 $change_networks = 1;
             }
         }
         if ($change_networks) {
             $criteria = new Criteria();
             $etva_nodes = EtvaNodePeer::doSelect($criteria);
             if (!$force) {
                 // check for nodes state if not force
                 foreach ($etva_nodes as $etva_node) {
                     $node_state = $etva_node->getState();
                     if (!$node_state) {
                         $remote_errors[] = Etva::getLogMessage(array('agent' => $etva_node->getName(), 'msg' => 'Down'), Etva::_AGENT_MSG_);
                     }
                     /*
                      * check if servers has an MA and are down...send error
                      */
                     $etva_servers = $etva_node->getEtvaServers();
                     foreach ($etva_servers as $etva_server) {
                         $server_ma = $etva_server->getAgentTmpl();
                         $server_state = $etva_server->getState();
                         if (!$server_state && $server_ma) {
                             $remote_errors[] = Etva::getLogMessage(array('agent' => $etva_server->getName(), 'msg' => 'Down'), Etva::_AGENT_MSG_);
                         }
                     }
                 }
                 //end foreach
             }
             if ($remote_errors && !$force) {
                 $msg = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => 'check_nodes', 'info' => implode('<br>', $remote_errors), 'error' => implode(' ', $remote_errors));
                 $error = $this->setJsonError($msg);
                 return $this->renderText($error);
             }
             if ($etvamodel != 'standard') {
                 // only if not standard version
                 /*
                  * 
                  * check ISO DIR in use
                  *
                  */
                 $isosdir = sfConfig::get("config_isos_dir");
                 $criteria = new Criteria();
                 $criteria->add(EtvaServerPeer::LOCATION, "%{$isosdir}%", Criteria::LIKE);
                 $criteria->add(EtvaServerPeer::VM_STATE, 'running');
                 $servers_running_iso = EtvaServerPeer::doSelect($criteria);
                 foreach ($servers_running_iso as $server) {
                     $remote_errors[] = $this->getContext()->getI18N()->__(EtvaServerPeer::_CDROM_INUSE_, array('%name%' => $server->getName()));
                 }
                 if ($remote_errors) {
                     $message = Etva::getLogMessage(array('info' => ETVA::_CDROM_INUSE_), ETVA::_ERR_ISODIR_INUSE_);
                     $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
                     $i18n_br_sep = implode('<br>', $remote_errors);
                     $i18n_sp_sep = implode(' ', $remote_errors);
                     //$iso_br_msg = Etva::getLogMessage(array('info'=>'<br>'.$br_sep), ETVA::_ERR_ISODIR_INUSE_);
                     $i18n_iso_br_msg = $this->getContext()->getI18N()->__(ETVA::_ERR_ISODIR_INUSE_, array('%info%' => '<br>' . $i18n_br_sep));
                     //$iso_sp_msg = Etva::getLogMessage(array('info'=>$sp_sep), ETVA::_ERR_ISODIR_INUSE_);
                     $i18n_iso_sp_msg = $this->getContext()->getI18N()->__(ETVA::_ERR_ISODIR_INUSE_, array('%info%' => $i18n_sp_sep));
                     $msg = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'info' => $i18n_iso_br_msg, 'error' => $i18n_iso_sp_msg);
                     $error = $this->setJsonError($msg);
                     return $this->renderText($error);
                 }
                 /*
                  * if all ok so far.....send nodes umount ISO DIR
                  */
                 foreach ($etva_nodes as $etva_node) {
                     $node_va = new EtvaNode_VA($etva_node);
                     $response = array('success' => true);
                     if ($force && $etva_node->getState()) {
                         $response = $node_va->send_umount_isosdir();
                     }
                     $success = $response['success'];
                     if (!$success) {
                         $node_msg = Etva::getLogMessage(array('name' => $response['agent'], 'info' => $response['error']), EtvaNodePeer::_ERR_ISODIR_UMOUNT_);
                         $remote_errors[] = $node_msg;
                         $message = Etva::getLogMessage(array('info' => $node_msg), EtvaSettingPeer::_ERR_SETTING_REMOTE_CONNECTIVITY_SAVE_);
                         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
                     }
                 }
                 if (!empty($remote_errors)) {
                     $msg = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'info' => implode('<br>', $remote_errors), 'error' => implode(' ', $remote_errors));
                     $error = $this->setJsonError($msg);
                     return $this->renderText($error);
                 }
             }
             /*
              * update using local script
              */
             $local_updated = $this->localUpdate($local);
             if (!$local_updated) {
                 $intf = $local['if'];
                 $msg_i18n = $this->getContext()->getI18N()->__(SystemNetwork::_ERR_NOTFOUND_INTF_, array('%name%' => $intf, '%info%' => ''));
                 $info = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n);
                 $error = $this->setJsonError($info);
                 return $this->renderText($error);
             }
             if (empty($remote_errors)) {
                 foreach ($etva_nodes as $etva_node) {
                     // send update to nodes if force
                     $etva_node->setSoapTimeout(5);
                     $remote_updated = $this->remoteUpdate($etva_node, $remote, $cm_ip);
                     if ($remote_updated !== true) {
                         if ($remote_updated === false) {
                             $intf = $remote['intf'];
                             $msg_i18n = $this->getContext()->getI18N()->__(SystemNetwork::_ERR_NOTFOUND_INTF_, array('%name%' => $intf, '%info%' => ''));
                             $remote_errors[] = $msg_i18n;
                             //$error = array('success'=>false,'agent'=>sfConfig::get('config_acronym'),'error'=>$msg_i18n);
                         } else {
                             $agent_msg = Etva::getLogMessage(array('agent' => $remote_updated['agent'], 'msg' => $remote_updated['error']), Etva::_AGENT_MSG_);
                             $message = Etva::getLogMessage(array('info' => $agent_msg), EtvaSettingPeer::_ERR_SETTING_REMOTE_CONNECTIVITY_SAVE_);
                             $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
                             $remote_errors[] = $agent_msg;
                         }
                     }
                     /*
                      * update MA if any...
                      *
                      */
                     $etva_servers = $etva_node->getEtvaServers();
                     foreach ($etva_servers as $etva_server) {
                         $server_ma = $etva_server->getAgentTmpl();
                         $server_state = $etva_server->getState();
                         if ($server_state && $server_ma) {
                             $aux_ip = $etva_server->getIp();
                             $etva_server->setSoapTimeout(5);
                             $remote_updated = $this->remoteUpdate($etva_server, $remote, $cm_ip);
                             if ($remote_updated === false) {
                                 $intf = $remote['intf'];
                                 $msg_i18n = $this->getContext()->getI18N()->__(SystemNetwork::_ERR_NOTFOUND_INTF_, array('%name%' => $intf, '%info%' => ''));
                                 $remote_errors[] = $msg_i18n;
                                 //$error = array('success'=>false,'agent'=>sfConfig::get('config_acronym'),'error'=>$msg_i18n);
                             } else {
                                 $agent_msg = Etva::getLogMessage(array('agent' => $remote_updated['agent'], 'msg' => $remote_updated['error']), Etva::_AGENT_MSG_);
                                 $message = Etva::getLogMessage(array('info' => $agent_msg), EtvaSettingPeer::_ERR_SETTING_REMOTE_CONNECTIVITY_SAVE_);
                                 $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
                                 $remote_errors[] = $agent_msg;
                             }
                         }
                     }
                 }
             }
             if (!empty($remote_errors)) {
                 $msg = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'info' => implode('<br>', $remote_errors), 'error' => implode(' ', $remote_errors));
                 $error = $this->setJsonError($msg);
                 return $this->renderText($error);
             }
         }
         // end if changed networks
     }
     foreach ($settings_decoded as $data) {
         $param = $data['param'];
         $value = $data['value'];
         if (!($etva_setting = EtvaSettingPeer::retrieveByPk($param))) {
             $msg_i18n = $this->getContext()->getI18N()->__(EtvaSettingPeer::_ERR_NOTFOUND_PARAM_, array('%id%' => $param));
             $info = array('success' => false, 'error' => $msg_i18n);
             $error = $this->setJsonError($info);
             return $this->renderText($error);
         }
         $etva_setting->setValue($value);
         switch ($param) {
             case 'vnc_keymap':
                 if ($etva_setting->saveVNCkeymap()) {
                     //notify system log
                     $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $etva_setting->getValue()), EtvaSettingPeer::_OK_VNCKEYMAP_CHANGE_))));
                 } else {
                     //notify system log
                     $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $value), EtvaSettingPeer::_ERR_VNCKEYMAP_CHANGE_), 'priority' => EtvaEventLogger::ERR)));
                 }
                 break;
             default:
                 try {
                     $etva_setting->save();
                     //notify system log
                     $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $etva_setting->getParam(), 'value' => $etva_setting->getValue()), EtvaSettingPeer::_OK_SETTING_CHANGE_))));
                 } catch (Exception $e) {
                     //notify system log
                     $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $value), EtvaSettingPeer::_ERR_SETTING_CHANGE_), 'priority' => EtvaEventLogger::ERR)));
                 }
                 break;
         }
     }
     // end foreach
     $msg_i18n = $this->getContext()->getI18N()->__(EtvaSettingPeer::_OK_SETTING_CONNECTIVITY_SAVE_);
     $message = EtvaSettingPeer::_OK_SETTING_CONNECTIVITY_SAVE_;
     $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message)));
     $info = array('success' => true, 'agent' => sfConfig::get('config_acronym'), 'response' => $msg_i18n);
     return $this->renderText(json_encode($info));
 }