Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elastic search support #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Check/ElasticSearchCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Liip\MonitorBundle\Check;

use Laminas\Diagnostics\Check\CheckCollectionInterface;
use Laminas\Diagnostics\Check\ElasticSearch;

/**
* @author Son Bui <[email protected]>
*/
class ElasticSearchCollection implements CheckCollectionInterface
{
private $checks = [];

public function __construct(array $configs)
{
foreach ($configs as $name => $config) {
if (isset($config['dsn'])) {
$config = \array_merge($config, \parse_url($config['dsn']));
}

$elasticSearchUrl = sprintf('%s://%s:%s', $config['scheme'], $config['host'], $config['port']);
$check = new ElasticSearch($elasticSearchUrl);
$check->setLabel(\sprintf('Elastic Search "%s"', $name));

$this->checks[\sprintf('elastic_search_%s', $name)] = $check;
}
}

/**
* @return array|\Traversable
*/
public function getChecks()
{
return $this->checks;
}
}
16 changes: 16 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ private function createGroupsNode(): NodeDefinition
->end()
->end()
->end()
->arrayNode('elastic_search')
->info('Validate that an Elasticsearch service is running')
->useAttributeAsKey('name')
->beforeNormalization()
->ifString()
->then(function ($v) { return ['dsn' => $v]; })
->end()
->prototype('array')
->children()
->scalarNode('scheme')->defaultValue('http')->end()
->scalarNode('host')->defaultValue('localhost')->end()
->integerNode('port')->defaultValue(9200)->end()
->scalarNode('dsn')->defaultNull()->end()
->end()
->end()
->end()
->arrayNode('http_service')
->info('Attempt connection to given HTTP host and (optionally) check status code and page content')
->useAttributeAsKey('name')
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/LiipMonitorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private function setParameters(ContainerBuilder $container, $checkName, $group,
case 'memcache':
case 'memcached':
case 'redis':
case 'elastic_search':
case 'rabbit_mq':
case 'stream_wrapper_exists':
case 'file_ini':
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,17 @@ liip_monitor:
# or
dsn: redis://localhost:6379

# Validate that an Elasticsearch service is running
elastic_search:

# Prototype
name:
scheme: http
host: localhost
port: 9200
# or
dsn: http://localhost:9200

# Attempt connection to given HTTP host and (optionally) check status code and page content
http_service:

Expand Down
13 changes: 13 additions & 0 deletions Resources/config/checks/elastic_search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="liip_monitor.check.elastic_search" public="true" class="Liip\MonitorBundle\Check\ElasticSearchCollection">
<argument>%%liip_monitor.check.elastic_search%%</argument>
<tag name="liip_monitor.check_collection" />
</service>
</services>
</container>