Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
arrilot committed May 27, 2019
2 parents 82a4054 + bb7e7ea commit 077c6d2
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/Checks/Custom/ElasticSearchConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Arrilot\BitrixSystemCheck\Checks\Custom;

use Arrilot\BitrixSystemCheck\Checks\Check;

/**
* Class ElasticSearchConnection
* @package System\SystemCheck\Checks
*/
class ElasticSearchConnection extends Check
{
/**
* @var string
*/
protected $host;

/**
* @var int
*/
protected $port;

/**
* ElasticSearchConnection constructor.
* @param string $host
* @param int $port
*/
public function __construct($host = 'localhost', $port = 9200)
{
$this->host = $host;
$this->port = $port;
}

/**
* @return string
*/
public function name()
{
return "Проверка доступности соединения с ElasticSearch...";
}

/**
* @return boolean
*/
public function run()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://{$this->host}:{$this->port}");
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10000);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
if (!$result) {
$this->logError('Отсутствует соединение с ElasticSearch (' . curl_error($ch) . ')');
curl_close($ch);
return false;
}
curl_close($ch);

return true;
}
}

0 comments on commit 077c6d2

Please sign in to comment.