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);
 }
 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");
 }
 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");
     }
 }