Example #1
0
 /**
  * Ini system param
  */
 public function init()
 {
     parent::init();
     ini_set('memory_limit', '-1');
     set_time_limit(0);
     $this->_logger = LoggerFactory::getFileLogger('process_sync_db');
 }
 public function run($args)
 {
     $logger = LoggerFactory::getFileLogger('check_processes');
     $logger->log(__METHOD__ . ' Start checkprocesses command.');
     $criteria = new CDbCriteria();
     $criteria->compare('stopped', 0);
     $connections = Listener::model()->findAll($criteria);
     $logger->log(__METHOD__ . ' Found ' . count($connections) . ' connections.');
     foreach ($connections as $connection) {
         $logger->log(__METHOD__ . ' Listener info:', array('process_pid' => $connection->process_pid, 'listener_id' => $connection->listener_id, 'source' => $connection->source));
         if (ProcessPid::isActiveProcess($connection->process_pid) === false) {
             ListenerProcess::addComment($connection->listener_id, 'comment', 'System found out that process is not active any more. Process will be re-run right now.');
             Listener::stopConnection($connection->listener_id, time());
             Listener::runConnection($connection->source, $connection->additional_param, 'auto');
         }
     }
     //        ProcessPid::killProcess(12376);
     $synchronization = new Synchronization();
     if ($synchronization->isProcessed() && ProcessPid::isActiveProcess($synchronization->getTcpServerPid()) === false) {
         $synchronization->startTcpServer();
     }
     if ($synchronization->isProcessed() && ProcessPid::isActiveProcess($synchronization->getTcpClientPid()) === false) {
         $synchronization->startTcpClient();
     }
 }
Example #3
0
 /**
  * Initializes logger at first call.
  * 
  * @return ILogger 
  */
 protected static function getLogger()
 {
     if (is_null(self::$_logger)) {
         self::$_logger = LoggerFactory::getFileLogger('prepare_message');
     }
     return self::$_logger;
 }
 /**
  * @param $msg
  * @param $listener_id
  * @param $rewrite_prev_values
  * @param string $source
  * @param int $station_id
  * @param null $source_info
  * @return int
  * @var $synchronization Synchronization
  */
 public static function addNew($msg, $listener_id, $rewrite_prev_values, $source = '', $station_id = 0, $source_info = null)
 {
     $synchronization = new Synchronization();
     $listener_id_from_master = $synchronization->getListenerId();
     $parseMessage = new ParseMessage(LoggerFactory::getFileLogger('parse_message'), $msg);
     $message_obj = new ListenerLogTemp();
     $message_obj->listener_id = $listener_id;
     $message_obj->station_id_code = $parseMessage->getStationIdCode();
     $message_obj->message = $msg;
     $message_obj->measuring_timestamp = $parseMessage->getMeasuringTimestamp();
     $message_obj->is_processed = 0;
     $message_obj->is_processing = 0;
     if ($listener_id_from_master === $listener_id and $listener_id != 0) {
         $message_obj->from_master = 1;
     } else {
         $message_obj->from_master = 0;
     }
     $message_obj->source = $source;
     $message_obj->source_info = $source_info;
     if ($synchronization->isProcessed()) {
         $message_obj->synchronization_mode = $synchronization->isMaster() ? 'master' : ($synchronization->isSlave() ? 'slave' : 'none');
     } else {
         $message_obj->synchronization_mode = 'none';
     }
     $message_obj->rewrite_prev_values = $rewrite_prev_values;
     $message_obj->save();
     return $message_obj->temp_log_id;
 }
Example #5
0
 private function __construct()
 {
     $this->processedReportsModel = new ScheduleTypeReportProcessed();
     $this->synchronization = new Synchronization();
     $this->_logger = LoggerFactory::getFileLogger('ExchangeODSS');
     TimezoneWork::set('UTC');
 }
Example #6
0
 public function init()
 {
     parent::init();
     ini_set('memory_limit', '-1');
     set_time_limit(0);
     $this->_logger = LoggerFactory::getFileLogger('sms');
     //		$this->_logger = LoggerFactory::getConsoleLogger();
 }
 public function init()
 {
     parent::init();
     ini_set('memory_limit', '-1');
     set_time_limit(0);
     self::$_logger = LoggerFactory::getFileLogger('reports');
     // All reports are generated basing on data in UTC time.
     TimezoneWork::set('UTC');
 }
Example #8
0
 public function init()
 {
     parent::init();
     ini_set('memory_limit', '-1');
     ini_set('display_errors', '1');
     set_time_limit(0);
     error_reporting(E_ALL);
     $this->_logger = LoggerFactory::getFileLogger('poller');
     //		$this->_logger = LoggerFactory::getConsoleLogger(); // For testing
 }
 public function run($args)
 {
     $this->logger = LoggerFactory::getFileLogger('scheduleReports');
     //        $this->logger = LoggerFactory::getConsoleLogger();
     new ScheduleReports($this->logger, $args);
     if (!Yii::app()->mutex->lock('ScheduleTypeReports', 3600)) {
         Yii::app()->end();
     }
     $this->logger = LoggerFactory::getFileLogger('typesReports');
     new ScheduleTypeReports($this->logger, $args);
     Yii::app()->mutex->unlock();
 }
 public function testConnect_NoErrors()
 {
     $logger = LoggerFactory::getFileLogger('tests/LoggerSerialConnectorTest');
     $serial = new PhpSerial($logger);
     $connector = new DataLoggerSerialConnector(new StubLogger(), $serial);
     $connector->setParams(array('port' => 'COM1', 'timeout' => 60, 'flowControl' => 'xon/xoff', 'baudrate' => 9600, 'parity' => 'none', 'stopBits' => 1, 'dataBits' => 8));
     $output = null;
     $result = $connector->readData($output);
     $this->assertTrue($result);
     $this->assertTrue(count($output) > 0);
     $this->assertStringMatchesFormat('@DAWS%s$', $output[0]);
     $errors = $connector->errors();
     $this->assertEquals(0, count($errors));
 }
Example #11
0
 public function run($args)
 {
     if (empty($args[0])) {
         exit;
     }
     $logger = LoggerFactory::getFileLogger('listener/' . $args[0]);
     //        $logger = LoggerFactory::getConsoleLogger();
     $logger->log(__METHOD__ . ' args:' . print_r($args, 1));
     // creates object of ProcessListen class, which duty is listening
     try {
         (new ProcessListen($logger, $args[0], $args[1], $args[2]))->run();
     } catch (Exception $e) {
         It::sendLetter(Yii::app()->params['developer_email'], 'Problem', $e->getMessage());
     }
 }
 /**
  * Ini system param
  */
 public function init()
 {
     parent::init();
     ini_set('memory_limit', '-1');
     set_time_limit(0);
     error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
     $this->_synchronization = new Synchronization();
     $this->_logger = LoggerFactory::getFileLogger('TcpClientCommand');
     //        $this->_logger = LoggerFactory::getConsoleLogger();
     if (Synchronization::setTcpClientPid(getmypid())) {
         $this->_logger->log(__METHOD__ . ' ' . 'process can take pid = ' . getmypid());
     } else {
         $this->_logger->log(__METHOD__ . ' ' . 'process can not take pid.');
     }
 }
 public function testConnect_NoErrors()
 {
     $logger = LoggerFactory::getFileLogger('tests/RealGsmModemSerialConnectorTest');
     $serial = new PhpSerial($logger);
     $connector = new GsmModemSerialConnector(new StubLogger(), $serial);
     $connector->setParams(array('port' => 'COM1', 'timeout' => 5, 'flowControl' => 'rts/cts', 'baudrate' => 9600, 'parity' => 'none', 'stopBits' => 1, 'dataBits' => 8));
     $output = null;
     $result = $connector->readData($output);
     $this->assertTrue($result);
     $errors = $connector->errors();
     $this->assertEquals(0, count($errors));
     $this->assertEquals(2, count($output));
     $this->assertEquals('AT+CMGL="ALL"', $output[0]);
     $this->assertEquals('OK', $output[1]);
 }
 public function __construct($synchronizationObject, $synchronizationRSMObject)
 {
     $this->_logger = LoggerFactory::getFileLogger('SynchronizationSwitcher');
     $this->_synchronization = $synchronizationObject;
     $this->_synchronizationRSM = $synchronizationRSMObject;
     if ($this->_synchronizationRSM->hasServerAnswer()) {
         if ($this->_synchronization->isFixedSwitchVariant()) {
             $this->_fixedSwitchLogic();
         }
         if ($this->_synchronization->isFlexibilitySwitchVariant()) {
             $this->_flexibilitySwitchLogic();
         }
     } else {
         $this->_synchronization->setInMaster();
     }
 }
 public static function create($handler_id, $logger = null)
 {
     $client_code = Yii::app()->params['client_code'];
     $class = "{$handler_id}WeatherTypeReport";
     $client_class = "{$client_code}{$handler_id}WeatherTypeReport";
     if (class_exists($client_class)) {
         if (is_null($logger)) {
             $logger = LoggerFactory::getFileLogger($client_class);
         }
         return new $client_class($logger);
     }
     if (!class_exists($class)) {
         return false;
     }
     if (is_null($logger)) {
         $logger = LoggerFactory::getFileLogger('typesReports');
     }
     return new $class($logger);
 }
 public function run($args)
 {
     ini_set('display_errors', 1);
     $this->_logger = LoggerFactory::getFileLogger('SendMessageFromFile');
     //$this->_logger = LoggerFactory::getConsoleLogger();
     $this->_logger->log(__METHOD__, array('args' => $args));
     if (count($args) < 3) {
         $this->_logger->log(__METHOD__ . ' Too few params.');
         echo 'Expected 3 parameters: [IP ADDRESS: XXX.XXX.XXX.XXX], [PORT: XXXXX], [FILENAME: XXXXXX]';
         exit;
     }
     $this->remote_server_ip = $args[0];
     $this->remote_server_port = $args[1];
     $this->file_name = __DIR__ . '/../../www/files/temp/' . $args[2];
     $this->_logger->log(__METHOD__ . ' ' . __DIR__);
     $this->_logger->log(__METHOD__ . 'filename ' . $this->file_name);
     $this->readFile();
     $this->sendMessage();
 }
Example #17
0
 public function run($args)
 {
     if (Yii::app()->mutex->lock('prepare', 300)) {
         ini_set('memory_limit', '-1');
         set_time_limit(0);
         error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
         $this->synchronization = new Synchronization();
         $this->_logger = LoggerFactory::getFileLogger('process_message');
         //            $this->_logger = LoggerFactory::getConsoleLogger();
         if ($this->synchronization->isProcessed()) {
             $this->_logger->log(__METHOD__ . ' synchronization in process');
             $this->run_process();
         } else {
             $this->_logger->log(__METHOD__ . ' synchronization stopped');
             $this->run_process_base();
         }
         Yii::app()->mutex->unlock();
     }
 }
Example #18
0
 public function test_AtCommand()
 {
     $logger = LoggerFactory::getFileLogger('tests/PhpSerialTest');
     $connector = new PhpSerial($logger);
     $connector->deviceSet('COM1');
     $connector->confBaudRate(9600);
     $connector->confParity('none');
     $connector->confFlowControl('rts/cts');
     $connector->confCharacterLength(8);
     $connector->confStopBits(1);
     $connector->deviceOpen('r+b');
     stream_set_timeout($connector->_dHandle, 2);
     $connector->sendMessage("AT\r\n");
     $result = $connector->readPort();
     $connector->deviceClose();
     $result = explode("\r\n", $result);
     $this->assertEquals(4, count($result));
     $this->assertEquals('AT', $result[0]);
     $this->assertEmpty($result[1]);
     $this->assertEquals('OK', $result[2]);
     $this->assertEmpty($result[3]);
 }
 public function init()
 {
     parent::init();
     ini_set('memory_limit', '-1');
     set_time_limit(0);
     error_reporting(E_ALL & ~E_WARNING);
     date_default_timezone_set('UTC');
     /**
      * For flexibility system
      */
     $this->founded_in = date('YmdHis');
     /**
      * Logger
      */
     $this->logger = LoggerFactory::getFileLogger('SyncStatusCommand');
     //        $this->logger = LoggerFactory::getConsoleLogger();
     /**
      * Settings
      */
     $this->settings = new Synchronization();
     /**
      * Check pid
      */
     if ($this->settings->getSynsStatusCommandPid() && ProcessPid::isActiveProcess($this->settings->getSynsStatusCommandPid())) {
         exit;
     } else {
         $this->settings->setSynsStatusCommandPid(getmypid());
     }
     /**
      * Connector
      */
     $server = ['ip' => $this->settings->server_ip, 'port' => $this->settings->server_port];
     $client = ['ip' => $this->settings->remote_server_ip, 'port' => $this->settings->remote_server_port];
     $this->connector = new UDPConnector($this->logger, $server, $client);
     /**
      * Message
      */
     $this->message_features = [SyncStatusHandler::MESSAGE_TYPE => 'S', SyncStatusHandler::MESSAGE_FROM => $this->settings->getIdentificator(), SyncStatusHandler::FOUNDED_IN => $this->founded_in];
 }
Example #20
0
 public static function create($handler_id, $logger = null)
 {
     $class = "{$handler_id}SensorHandler";
     $res = Yii::import('application.helpers.SensorHandler.' . $class);
     if (!$res) {
         if (!is_null($logger)) {
             $logger->log(__METHOD__ . ' Can\'t import application.helpers.SensorHandler.' . $class . ' class');
         }
         return false;
     }
     if (!class_exists($class)) {
         if (!is_null($logger)) {
             $logger->log(__METHOD__ . ' Class ' . $class . ' is not exists.');
         }
         return false;
     }
     if (is_null($logger)) {
         $logger = LoggerFactory::getFileLogger('sensor_handler');
     }
     $logger->log(__METHOD__, array('class' => $class));
     return new $class($logger);
 }
 public function __construct($scheduleProcessedIdArray = array(), $logger = null)
 {
     if (!is_null($logger)) {
         $this->_logger = $logger;
     } else {
         $this->_logger = LoggerFactory::getFileLogger('email_report');
     }
     $this->_logger->log(__METHOD__ . ' schedule_processed_ids: ' . print_r($scheduleProcessedIdArray, 1));
     if (count($scheduleProcessedIdArray) == 0) {
         return false;
     }
     $this->scheduleProcessedReports = ScheduleReportProcessed::model()->with('listenerLog', 'ScheduleReportToStation.realStation')->findAllByPk($scheduleProcessedIdArray);
     $this->schedule_report = $this->scheduleProcessedReports[0]->ScheduleReportToStation->schedule_report;
     if (!$this->schedule_report->send_email_together) {
         return false;
     }
     $this->destinations = $this->scheduleProcessedReports[0]->ScheduleReportToStation->schedule_report->destinations;
     if ($this->schedule_report->send_like_attach) {
         $this->_sendLikeAttach();
     } else {
         $this->_sendInMessageBody();
     }
 }
 /**
  * @var $stationForm configForm
  * **/
 public function run($args)
 {
     //        error_reporting(null);
     ini_set('display_errors', 1);
     $this->_logger = LoggerFactory::getFileLogger('GenerateMessageCommand');
     //        $this->_logger = LoggerFactory::getConsoleLogger();
     $this->_logger->log('start');
     //       $args:
     //       $args[0] AWS01
     //       $args[1] "sensors:TS1;TS2;"
     $station_id_code = false;
     if (preg_match('/^([A-Z,a-z,0-9]{4,5})$/', $args[0], $matchesStations)) {
         $station_id_code = $matchesStations[1];
     } else {
         $this->_logger->log(' Station ID can contain only Letters (A-Z) and Figures (1-9), and must be of 4(rain) or 5(AWS) chars length.');
     }
     $sensor_id_codes = array();
     if (isset($args[1])) {
         if (preg_match("/^sensors:([A-Za-z1-9;]+)/", $args[1], $matchesSensors)) {
             $sensor_id_code = explode(';', $matchesSensors[1]);
             $sensor_id_codes = array_values($sensor_id_code);
             $sensor_id_codes_count = count($sensor_id_codes);
             for ($i = 0; $i < $sensor_id_codes_count; $i++) {
                 if (!preg_match('/^([A-Z,a-z]{2})([1-9]{1})$/', $sensor_id_codes[$i], $matches)) {
                     unset($sensor_id_codes[$i]);
                     $this->_logger->log('Sensor ID should contain two letters and 1 digit. Ex.: TP1');
                 }
             }
             $sensor_id_codes = array_values($sensor_id_codes);
         }
     }
     $station = Station::getStationByCode($station_id_code, array('sensors.handler', 'sensors.features.metric'));
     //            $sql = "SELECT `t1`.`station_sensor_id`, `t1`.`sensor_id_code`,  `t2`.`handler_id_code`, `t3`.`feature_code`, `t4`.`code` AS `metric_code`
     //                            FROM `".StationSensor::model()->tableName()."` `t1`
     //                            LEFT JOIN `".SensorDBHandler::model()->tableName()."`      `t2` ON `t2`.`handler_id` = `t1`.`handler_id`
     //                            LEFT JOIN `".StationSensorFeature::model()->tableName()."` `t3` ON `t3`.`sensor_id`  = `t1`.`station_sensor_id`
     //                            LEFT JOIN `".RefbookMetric::model()->tableName()."`        `t4` ON `t4`.`metric_id`  = `t3`.`metric_id`
     //                            WHERE `t1`.`station_id` = '".$station_id."' AND `t1`.`station_sensor_id` IN (".implode(',',$sensor_id).")";
     //            $res = Yii::app()->db->createCommand($sql)->queryAll();
     if ($station) {
         TimezoneWork::set($station->timezone_id);
         $sensors = array();
         foreach ($station->sensors as $key => $sensor) {
             if (in_array($sensor->sensor_id_code, $sensor_id_codes) || count($sensor_id_codes) == 0) {
                 if (!isset($sensors[$sensor->station_sensor_id])) {
                     $sensors[$sensor->station_sensor_id] = array('station_sensor_id' => $sensor->station_sensor_id, 'sensor_id_code' => $sensor->sensor_id_code, 'handler_id_code' => $sensor->handler->handler_id_code);
                 }
                 foreach ($sensor->features as $feature) {
                     if (is_object($feature->metric)) {
                         $sensors[$sensor->station_sensor_id]['features'][$feature->feature_code] = $feature->metric->code;
                     }
                 }
             }
         }
         $i = time();
         $messages[$i]['timestamp'] = $i;
         $this->_logger->log(__METHOD__ . ': sensors ' . print_r($sensors['sensor_id_code'], 1));
         foreach ($messages as $key => $value) {
             if ($station->station_type === 'rain') {
                 $messages[$key]['parts'][] = 'D';
                 $messages[$key]['parts'][] = $station->station_id_code;
                 $messages[$key]['parts'][] = date('ymd', $key);
                 $messages[$key]['parts'][] = date('Hi', $key);
                 $messages[$key]['parts'][] = str_pad(rand(100, 135), 3, "0", STR_PAD_LEFT);
                 $messages[$key]['parts'][] = '00';
             } else {
                 $messages[$key]['parts'][] = 'D';
                 $messages[$key]['parts'][] = $station->station_id_code;
                 $messages[$key]['parts'][] = date('ymd', $key);
                 $messages[$key]['parts'][] = date('Hi', $key);
                 $messages[$key]['parts'][] = '00';
             }
             $sensors_values = array();
             if ($sensors) {
                 foreach ($sensors as $k1 => $v1) {
                     $handler = SensorHandler::create($v1['handler_id_code']);
                     $random_value = $handler->getRandomValue($v1['features']);
                     $sensors_values[] = $v1['sensor_id_code'] . $random_value;
                 }
                 shuffle($sensors_values);
                 foreach ($sensors_values as $k1 => $v1) {
                     $messages[$key]['parts'][] = $v1;
                 }
             }
             $crc = It::prepareCRC(implode('', $messages[$key]['parts']));
             $messages[$key]['parts'][] = $crc;
             array_push($messages[$key]['parts'], '$');
             array_unshift($messages[$key]['parts'], '@');
         }
         $messages_display = array();
         $messages_copy = array();
         foreach ($messages as $key => $value) {
             $messages_display[] = implode(' ', $value['parts']);
             $messages_copy[] = implode('', $value['parts']);
         }
         $this->_logger->log(__METHOD__ . ': $messages_copy ' . print_r($messages_copy, 1));
         foreach ($messages_copy as $msg) {
             ListenerLogTemp::addNew($msg, 0, 1, 'import', 0);
         }
     } else {
         $this->_logger->log(__METHOD__ . ': has no stations like ' . $args[0]);
     }
 }
Example #23
0
 public function getAllDataInType($stationType, $start_time = false, $end_time = false)
 {
     $criteria = new CDbCriteria();
     $criteria->addCondition("`listener`.`station_type` = '" . $stationType . "'");
     $criteria->alias = 'listener';
     if ($start_time != false) {
         $criteria->addCondition("`listener`.`measuring_timestamp` >= '" . $start_time . "'");
     }
     if ($end_time != false) {
         $criteria->addCondition("`listener`.`measuring_timestamp` < '" . $end_time . "'");
     }
     $criteria->order = '`listener`.`created` DESC ';
     $log = LoggerFactory::getFileLogger('listenerModel');
     $log->log(__METHOD__ . print_r($criteria, 1));
     $criteria->with = array('Station' => array('select' => 'station_id, station_id_code, station_type'), 'sensor_data' => array('select' => 'sensor_feature_value, sensor_id, sensor_data_id, sensor_feature_id, metric_id'), 'Station', 'sensor_data.sensor_feature.metric', 'sensor_data.Sensor');
     $logger = LoggerFactory::getFileLogger('getAllDataInType');
     // $criteria->limit = '2';
     $result_short = $this->findAll($criteria);
     $result_long = $this->long()->findAll($criteria);
     //        $logger->log(__METHOD__.' $result_short '. print_r($result_short,1));
     //        $logger->log(__METHOD__.' $result_long '. print_r($result_long,1));
     $logger->log(__METHOD__ . ' $criteria: ' . print_r($criteria, 1));
     $logger->log(__METHOD__ . ' $result_short COUNT' . count($result_short));
     $logger->log(__METHOD__ . ' $result_long COUNT' . count($result_long));
     if (count($result_short) && count($result_long)) {
         $short_ids = array();
         foreach ($result_short as $item) {
             $short_ids[] = $item->log_id;
         }
         $result_long_temp = array();
         foreach ($result_long as $item) {
             if (!in_array($item->log_id, $short_ids)) {
                 $result_long_temp[] = $item;
             }
         }
         foreach ($result_long_temp as $item) {
             $result_short[] = $item;
         }
         $logger->log(__METHOD__ . ' result  COUNT' . count($result_short));
         return $result_short;
     } elseif (is_array($result_short)) {
         return $result_short;
     } elseif (is_array($result_short)) {
         return $result_long;
     } else {
         return null;
     }
 }
Example #24
0
 public static function sendLetter($recipient, $subject, $body, $attachments = array())
 {
     $settings = Settings::model()->findByPk(1);
     ini_set('sendmail_from', $settings->mail__sender_address);
     //        if ($settings->mail__use_fake_sendmail)
     //		{
     //            ini_set('sendmail_path', Yii::app()->params['sendmail_fake_params']['Sendmail']);
     //        }
     $mailer = Yii::createComponent('application.extensions.mailer.EMailer');
     $mailer->Mailer = Yii::app()->params['sendmail_fake_params']['Mailer'];
     if ($settings->mail__use_fake_sendmail) {
         $mailer->Sendmail = Yii::app()->params['sendmail_fake_params']['Sendmail'];
     }
     $mailer->From = $settings->mail__sender_address;
     $mailer->FromName = $settings->mail__sender_name;
     $mailer->AddAddress($recipient);
     $mailer->isHTML(true);
     $mailer->Subject = $subject;
     $mailer->Body = $body;
     $mailer->CharSet = 'UTF-8';
     if ($attachments) {
         foreach ($attachments as $key => $attachment) {
             $mailer->AddAttachment($attachment['file_path'], $attachment['file_name']);
         }
     }
     $result = $mailer->Send();
     if (!$result) {
         $logger = LoggerFactory::getFileLogger('mail');
         $logger->log(__METHOD__ . 'Mail send error', array('errorInfo' => $mailer->ErrorInfo));
         unset($logger);
     }
     return $result;
 }