예제 #1
0
 /**
  * @return ApiKey|False
  */
 public function get_api_key()
 {
     if (!$this->_api_key) {
         $this->_api_key = ApiKey::search()->where('key', $this->key)->execOne();
     }
     return $this->_api_key;
 }
예제 #2
0
 /**
  * @return Array[ApiKey]
  */
 public function get_api_keys()
 {
     if (!$this->_api_keys) {
         $this->_api_keys = ApiKey::search()->where('application_id', $this->application_id)->exec();
     }
     return $this->_api_keys;
 }
예제 #3
0
 public static function handle_packet($buf)
 {
     try {
         /* @var $event Datagram */
         list($event, $passed_key) = Eventsd::rehydrate($buf);
     } catch (DatagramHydrationException $e) {
         $reply = json_encode(array('Status' => 'FAIL', 'Checksum' => crc32($buf), 'FailureMessage' => "Hydration Failure"));
         return $reply;
     }
     if (!isset($passed_key)) {
         $reply = json_encode(array('Status' => 'FAIL', 'Checksum' => crc32($buf), 'FailureMessage' => "ApiKey not passed."));
         return $reply;
     }
     $api_key = \Eventsd\Models\ApiKey::search()->where('key', $passed_key)->execOne();
     if (!$api_key instanceof \Eventsd\Models\ApiKey) {
         $reply = json_encode(array('Status' => 'FAIL', 'Checksum' => crc32($buf), 'FailureMessage' => "ApiKey validation bad."));
         return $reply;
     }
     $user = $api_key->get_user();
     if (!$user instanceof \Eventsd\Models\User) {
         $reply = json_encode(array('Status' => 'FAIL', 'Checksum' => crc32($buf), 'FailureMessage' => "User validation bad."));
         return $reply;
     }
     $occ = new \Eventsd\Models\Occurrence();
     $occ->event = $event->event;
     $occ->local_time = date("Y-m-d H:i:s");
     $occ->remote_time = $event->time;
     $occ->user_id = $user->user_id;
     $occ->application_id = $api_key->application_id;
     $occ->value = $event->value;
     $occ->hostname = $event->host;
     //$occ->remote_ip = $remote_ip;
     //$occ->redis();
     $occ->save();
     $occ->push();
     foreach (self::$callbacks as $callback) {
         $callback($occ);
     }
     return false;
     // If all went well...
     $reply = json_encode(array('Status' => 'OKAY', 'Checksum' => crc32($buf)));
     return $reply;
 }