コード例 #1
0
 /**
  * Checks connection to elasticsearch. Type of status check can be set via configuration
  * setting 'status_test'. Available status tests are: 'ping' (default), 'info',
  * 'cluster_health', 'cluster_stats' and 'nodes_stats'.
  *
  * @return Status of the connection to the configured elasticsearch
  */
 public function getStatus()
 {
     if ($this->config->has('fake_status')) {
         return new Status($this, $this->config->get('fake_status'));
     }
     // many endpoints are available and suitable for status checks:
     // - GET /
     // - GET _cluster/health?level=indices
     // - GET _cluster/stats
     // - GET _nodes/stats
     // - https://www.elastic.co/guide/en/elasticsearch/guide/2.x/_cat_api.html
     // Here only some are implemented as an example.
     $test = $this->config->get('status_test', 'ping');
     try {
         switch ($test) {
             case 'info':
                 return Status::working($this, $this->getConnection()->info());
             case 'cluster_health':
                 return Status::working($this, $this->getConnection()->cluster()->health());
             case 'cluster_stats':
                 return Status::working($this, $this->getConnection()->cluster()->stats());
             case 'nodes_stats':
                 return Status::working($this, $this->getConnection()->nodes()->stats());
             case 'ping':
             default:
                 if ($this->getConnection()->ping()) {
                     return Status::working($this, ['message' => 'Pinging elasticsearch succeeded.']);
                 }
                 return Status::failing($this, ['message' => 'Pinging elasticsearch failed.']);
         }
     } catch (Exception $e) {
         error_log('[' . static::CLASS . '] Error on "' . $test . '": ' . $e->getTraceAsString());
         return Status::failing($this, ['message' => 'Error on "' . $test . '": ' . $e->getMessage()]);
     }
 }
コード例 #2
0
ファイル: ArrayConnector.php プロジェクト: honeybee/honeybee
 /**
  * Depending on the type of client and how the connection works this method
  * may return UNKNOWN Status or create an actual connection and check whether
  * it works as expected. Status checks should strive to be fast though.
  *
  * Whether to do actual status checks of the underlying connection is entirely
  * up to the connector.
  *
  * @return Status of this connector
  */
 public function getStatus()
 {
     if ($this->config->has('fake_status')) {
         return new Status($this, $this->config->get('fake_status'));
     }
     if ($this->connect() instanceof Map) {
         return Status::working($this);
     }
     return Status::failing($this);
 }
コード例 #3
0
ファイル: StatusTest.php プロジェクト: honeybee/honeybee
 public function testFakeWorkingStatusConnectorSucceeds()
 {
     $connector = new TestConnector('working', new ArrayConfig([]));
     $status = new Status($connector, Status::WORKING);
     $this->assertTrue($status->isWorking());
     $this->assertSame(Status::WORKING, $status->getStatus());
     $this->assertSame('working', $status->getConnectionName());
     $status = Status::working($connector);
     $this->assertTrue($status->isWorking());
     $this->assertSame(Status::WORKING, $status->getStatus());
     $this->assertSame('working', $status->getConnectionName());
 }
コード例 #4
0
ファイル: NullConnector.php プロジェクト: honeybee/honeybee
 /**
  * @return Status of this connector
  */
 public function getStatus()
 {
     if ($this->config->has('fake_status')) {
         return new Status($this, $this->config->get('fake_status'));
     }
     try {
         $this->getConnection();
         return Status::working($this);
     } catch (Exception $e) {
         error_log('[' . static::CLASS . '] Null mailer connection failed: ' . $e->getTraceAsString());
         return Status::failing($this, ['message' => 'Exception on creating the mailer: ' . $e->getMessage()]);
     }
 }
コード例 #5
0
 /**
  * Tries to access a (maybe non-existant) file path to see whether the connection works
  * correctly. Configure the 'status_test_path' to check for an actual existant file path.
  *
  * @return Status of the configured filesystem connector
  */
 public function getStatus()
 {
     if ($this->config->has('fake_status')) {
         return new Status($this, $this->config->get('fake_status'));
     }
     try {
         if ($this->config->has('status_test')) {
             if ($this->getConnection()->has($this->config->get('status_test'))) {
                 return Status::working($this, ['message' => 'Expected file path exists.']);
             }
             return Status::failing($this, ['message' => 'Expected file path does not exist.']);
         }
         $this->getConnection()->has('some-probably-non-existant-filepath');
         return Status::working($this);
     } catch (Exception $e) {
         error_log('[' . static::CLASS . '] Error on file path existance check: ' . $e->getTraceAsString());
         return Status::failing($this, ['message' => 'Exception on file path existance check: ' . $e->getMessage()]);
     }
 }
コード例 #6
0
ファイル: Connector.php プロジェクト: honeybee/honeybee
 /**
  * Depending on the type of client and how the connection works this method
  * may return UNKNOWN Status or create an actual connection and check whether
  * it works as expected. Status checks should strive to be fast though.
  *
  * Whether to do actual status checks of the underlying connection is entirely
  * up to the connector.
  *
  * @return Status of this connector
  */
 public function getStatus()
 {
     if ($this->config->has('fake_status')) {
         return new Status($this, $this->config->get('fake_status'));
     }
     return Status::unknown($this);
 }
コード例 #7
0
ファイル: GuzzleConnector.php プロジェクト: honeybee/honeybee
 /**
  * Checks connection via HTTP(s).
  *
  * @return Status of the connection to the configured host
  */
 public function getStatus()
 {
     if ($this->config->has('fake_status')) {
         return new Status($this, $this->config->get('fake_status'));
     }
     if (!$this->config->has('status_test')) {
         return Status::unknown($this, ['message' => 'No status_test path specified']);
     }
     $path = $this->config->get('status_test');
     try {
         $info = [];
         $verbose = $this->config->get('status_verbose', true);
         $response = $this->getConnection()->get($path, ['on_stats' => function (TransferStats $stats) use(&$info, $verbose) {
             if (!$verbose) {
                 return;
             }
             $info['effective_uri'] = (string) $stats->getEffectiveUri();
             $info['transfer_time'] = $stats->getTransferTime();
             $info = array_merge($info, $stats->getHandlerStats());
             if ($stats->hasResponse()) {
                 $info['status_code'] = $stats->getResponse()->getStatusCode();
             } else {
                 $error_data = $stats->getHandlerErrorData();
                 if (is_array($error_data) || is_string($error_data)) {
                     $info['handler_error_data'] = $error_data;
                 }
             }
         }]);
         $status_code = $response->getStatusCode();
         if ($status_code >= 200 && $status_code < 300) {
             $msg['message'] = 'GET succeeded: ' . $path;
             if (!empty($info)) {
                 $msg['info'] = $info;
             }
             return Status::working($this, $msg);
         }
         return Status::failing($this, ['message' => 'GET failed: ' . $path, 'headers' => $response->getHeaders(), 'info' => $info]);
     } catch (Exception $e) {
         error_log('[' . static::CLASS . '] Error on "' . $path . '": ' . $e->getTraceAsString());
         return Status::failing($this, ['message' => 'Error on "' . $path . '": ' . $e->getMessage()]);
     }
 }