From ee7e09288393b01c0a33aafc8bbb1193efe75efd Mon Sep 17 00:00:00 2001 From: Remigijus Kiminas Date: Thu, 13 Sep 2018 04:38:05 -0400 Subject: [PATCH] Option for auto enable in elastic search --- .../tpl/elasticsearch/options.tpl.php | 5 +++ modules/lhcron/check_health.php | 41 ++++++++++++++++++- modules/lhelasticsearch/options.php | 9 ++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/design/elasticsearchtheme/tpl/elasticsearch/options.tpl.php b/design/elasticsearchtheme/tpl/elasticsearch/options.tpl.php index 13c9f50..b0da5e6 100644 --- a/design/elasticsearchtheme/tpl/elasticsearch/options.tpl.php +++ b/design/elasticsearchtheme/tpl/elasticsearch/options.tpl.php @@ -39,6 +39,11 @@

Failover

+ +
+
+
+

diff --git a/modules/lhcron/check_health.php b/modules/lhcron/check_health.php index d30c300..70e6c53 100644 --- a/modules/lhcron/check_health.php +++ b/modules/lhcron/check_health.php @@ -43,6 +43,45 @@ } } else { - echo "Elastic Search is still dead, no status change!"; + if (isset($dataOptions['auto_enable']) && $dataOptions['auto_enable'] == 1) { + try { + print_r(erLhcoreClassElasticClient::getHandler()->Cluster()->health(array('client' => array('timeout' => 80, 'connect_timeout' => 80)))); + + $dataOptions['disable_es'] = 0; + $dataOptions['fail_reason'] = 'Elastic Search Was automatically enabled!'; + + $esOptions->explain = ''; + $esOptions->type = 0; + $esOptions->hidden = 1; + $esOptions->identifier = 'elasticsearch_options'; + $esOptions->value = serialize($dataOptions); + $esOptions->saveThis(); + + echo "Elastic Search was automatically enabled!\n"; + + if (isset($dataOptions['report_email_es']) && !empty($dataOptions)) + { + $mail = new PHPMailer(); + $mail->CharSet = "UTF-8"; + $mail->FromName = 'Live Helper Chat Elastic Search'; + $mail->Subject = 'Elastic Search was enabled, live detected'; + $mail->Body = "Elastic Search was automatically enabled!"; + + $emailRecipient = explode(',',$dataOptions['report_email_es']); + + foreach ($emailRecipient as $receiver) { + $mail->AddAddress( trim($receiver) ); + } + + erLhcoreClassChatMail::setupSMTP($mail); + $mail->Send(); + } + + } catch (Exception $e) { + echo "Elastic Search is still dead, no status change!"; + } + } else { + echo "Elastic Search is still dead, no status change!"; + } } diff --git a/modules/lhelasticsearch/options.php b/modules/lhelasticsearch/options.php index ceb386e..5b88ec9 100644 --- a/modules/lhelasticsearch/options.php +++ b/modules/lhelasticsearch/options.php @@ -26,6 +26,9 @@ 'disable_es' => new ezcInputFormDefinitionElement( ezcInputFormDefinitionElement::OPTIONAL, 'boolean' ), + 'auto_enable' => new ezcInputFormDefinitionElement( + ezcInputFormDefinitionElement::OPTIONAL, 'boolean' + ), 'indexType' => new ezcInputFormDefinitionElement( ezcInputFormDefinitionElement::OPTIONAL, 'string' ), @@ -50,6 +53,12 @@ $data['disable_es'] = 0; } + if ( $form->hasValidData( 'auto_enable' ) && $form->auto_enable == true ) { + $data['auto_enable'] = 1; + } else { + $data['auto_enable'] = 0; + } + if ( $form->hasValidData( 'use_es_prev_chats' ) && $form->use_es_prev_chats == true ) { $data['use_es_prev_chats'] = 1; } else {