[icinga-checkins] icinga.org: icinga-vagrant/master: icinga2x-elastic: Fix kibana setup ( wait for ES starting up)

git at icinga.org git at icinga.org
Mon Nov 28 23:30:41 CET 2016


Module: icinga-vagrant
Branch: master
Commit: b85760cadfcb1067e11965bbb2649bb33ae107fd
URL:    https://git.icinga.org/?p=icinga-vagrant.git;a=commit;h=b85760cadfcb1067e11965bbb2649bb33ae107fd

Author: Michael Friedrich <michael.friedrich at icinga.com>
Date:   Mon Nov 28 22:50:03 2016 +0100

icinga2x-elastic: Fix kibana setup (wait for ES starting up)

---

 README.md                                         |    2 +-
 icinga2x-elastic/files/usr/local/bin/kibana-setup |   24 +++++++++++++++++++++
 icinga2x-elastic/manifests/default.pp             |   20 ++++++++++-------
 3 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 966dd59..e568e6d 100644
--- a/README.md
+++ b/README.md
@@ -349,7 +349,7 @@ Specific projects:
   ----------------------|-------------------------------|-------------------------------
   graylog2-puppet	| modules/graylog2		| https://github.com/Graylog2/graylog2-puppet.git
   puppet-elasticsearch	| modules/elasticsearch		| https://github.com/elasticsearch/puppet-elasticsearch.git
-  puppet-logstash       | modules/logstash              | https://github.com/elastic/puppet-logstash.git
+  puppet-logstash       | modules/logstash              | https://github.com/elastic/puppet-logstash.git - 5.x branch
   puppet-kibana4        | modules/kibana4               | https://github.com/lesaux/puppet-kibana4.git
   puppet-kibana5	| modules/kibana5		| https://github.com/Nextdoor/puppet-kibana5
   puppet-filebeat       | modules/filebeat		| https://github.com/pcfens/puppet-filebeat.git
diff --git a/icinga2x-elastic/files/usr/local/bin/kibana-setup b/icinga2x-elastic/files/usr/local/bin/kibana-setup
new file mode 100755
index 0000000..3213dc6
--- /dev/null
+++ b/icinga2x-elastic/files/usr/local/bin/kibana-setup
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+ES_URL="http://localhost:9200"
+ES_INDEX_URL="$ES_URL/.kibana/index-pattern/filebeat"
+ES_DEFAULT_INDEX_URL="$ES_URL/.kibana/config/5.0.1" #TODO on package update
+TIMEOUT=300
+
+START=$(date +%s)
+
+echo -e "Checking whether Elasticsearch is listening at $ES_URL"
+until $(curl --output /dev/null --silent $ES_URL); do
+  NOW=$(date +%s)
+  REAL_TIMEOUT=$(( START + TIMEOUT ))
+  if [[ "$NOW" -gt "$REAL_TIMEOUT" ]]; then
+    echo "Cannot reach Elasticsearch at $ES_URL. Timeout reached."
+    exit 1
+  fi
+  printf '.'
+  sleep 1
+done
+
+curl -XPUT $ES_INDEX_URL -d '{ "title":"filebeat", "timeFieldName":"@timestamp" }'
+
+curl -XPUT $ES_DEFAULT_INDEX_URL -d '{ "defaultIndex":"filebeat" }'
diff --git a/icinga2x-elastic/manifests/default.pp b/icinga2x-elastic/manifests/default.pp
index 02b5bf3..624de95 100644
--- a/icinga2x-elastic/manifests/default.pp
+++ b/icinga2x-elastic/manifests/default.pp
@@ -248,7 +248,7 @@ elasticsearch::instance { 'elastic-es':
 class { 'logstash':
   manage_repo  => true,
   repo_version => '5.x',
-  java_install => false,
+  #java_install => false,
 }->
 class { 'kibana5':
   version => '5.0.1-1', # version and revision are required for now
@@ -277,16 +277,20 @@ class { 'filebeat':
     'level' => 'debug' #TODO reset after finishing the box
   }
 }->
-exec { 'filebeat-kibana-index': # filebeat defines the index 'filebeat', but the dashboards provide "filebeat-*". create our own. https://www.elastic.co/guide/en/beats/filebeat/current/elasticsearch-output.html
-  path => '/bin:/usr/bin:/sbin:/usr/sbin',
-  command => "curl -XPUT 'http://localhost:9200/.kibana/index-pattern/filebeat' -d '{ \"title\":\"filebeat\", \"timeFieldName\":\"@timestamp\" }'"
-}->
-exec { 'filebeat-kibana-defaultindex':
+file { 'kibana-setup':
+  name => '/usr/local/bin/kibana-setup',
+  owner => root,
+  group => root,
+  mode => '0755',
+  source => "puppet:////vagrant/files/usr/local/bin/kibana-setup",
+}
+->
+exec { 'finish-kibana-setup':
   path => '/bin:/usr/bin:/sbin:/usr/sbin',
-  command => "curl -XPUT 'http://localhost:9200/.kibana/config/5.0.1' -d '{ \"defaultIndex\": \"filebeat\" }'"
+  command => "/usr/local/bin/kibana-setup",
+  timeout => 3600
 }
 
-
 filebeat::prospector { 'syslogs':
   paths => [
     '/var/log/messages'



More information about the icinga-checkins mailing list