Skip to content

Commit

Permalink
Option for auto enable in elastic search
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Sep 13, 2018
1 parent 2772a9d commit ee7e092
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions design/elasticsearchtheme/tpl/elasticsearch/options.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
</div>
<hr>
<h4>Failover</h4>

<div class="form-group">
<label><input type="checkbox" value="on" name="auto_enable" <?php isset($es_options['auto_enable']) && ($es_options['auto_enable'] == true) ? print 'checked="checked"' : ''?> /> Enable elastic search automatically.</label><br/>
</div>

<div class="form-group">
<label><input type="checkbox" value="on" name="disable_es" <?php isset($es_options['disable_es']) && ($es_options['disable_es'] == true) ? print 'checked="checked"' : ''?> /> Disable Elastic Search. Systems set's this automatically if cronjob detects that Elastic Search is down for whatever reason.</label><br/>
</div>
Expand Down
41 changes: 40 additions & 1 deletion modules/lhcron/check_health.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
}
}

9 changes: 9 additions & 0 deletions modules/lhelasticsearch/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
'disable_es' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'boolean'
),
'auto_enable' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'boolean'
),
'indexType' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'string'
),
Expand All @@ -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 {
Expand Down

0 comments on commit ee7e092

Please sign in to comment.