internet_box_logger 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ # Use this file to easily define all of your cron jobs.
2
+ #
3
+ # It's helpful, but not entirely necessary to understand cron before proceeding.
4
+ # http://en.wikipedia.org/wiki/Cron
5
+
6
+ # Example:
7
+ #
8
+ # set :output, "/path/to/my/cron_log.log"
9
+ #
10
+ # every 2.hours do
11
+ # command "/usr/bin/some_great_command"
12
+ # runner "MyModel.some_method"
13
+ # rake "some:great:rake:task"
14
+ # end
15
+ #
16
+ # every 4.days do
17
+ # runner "AnotherModel.prune_old_records"
18
+ # end
19
+
20
+ # Learn more: http://github.com/javan/whenever
21
+
22
+ # Default interval
23
+ # To actually set the default interval, use cron_interval in your application config
24
+ require 'active_support/all'
25
+
26
+ @interval ||= 1
27
+
28
+ this_gem_path = File.expand_path('../..', __FILE__)
29
+ set :path, this_gem_path
30
+ set :output, "#{this_gem_path}/log/cron.log"
31
+
32
+ job_type :ruby_script, 'cd :path && bundle exec ruby bin/:task :output'
33
+
34
+ every @interval.to_i.minute do
35
+ ruby_script 'internet_box_logger'
36
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'internet_box_logger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'internet_box_logger'
8
+ spec.version = InternetBoxLogger::VERSION
9
+ spec.authors = ['Laurent B']
10
+ spec.email = ['lbnetid+gh@gmail.com']
11
+ spec.summary = %q{Monitor your internet box.}
12
+ spec.description = %q{Logs information gathered from your internet box and stores into ElasticSearch for display into Kibana.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'pry'
25
+
26
+ spec.add_dependency 'activesupport'
27
+ spec.add_dependency 'whenever'
28
+ spec.add_dependency 'easy_app_helper'
29
+ spec.add_dependency 'elasticsearch'
30
+
31
+ end
@@ -0,0 +1,61 @@
1
+ module InternetBoxLogger
2
+ module ElasticSearch
3
+
4
+ module Server
5
+
6
+ def self.[]
7
+ EasyAppHelper.config[:elastic_servers] || EasyAppHelper.config[:default_elastic_search]['elastic_servers']
8
+ end
9
+
10
+ def self.local_path
11
+ EasyAppHelper.config[:elastic_binary] || EasyAppHelper.config[:default_elastic_search]['elastic_binary']
12
+ end
13
+
14
+ def self.local?
15
+ !remote?
16
+ end
17
+
18
+ def self.manageable?
19
+ !(remote? || local_path.nil? )
20
+ end
21
+
22
+ def self.remote?
23
+ # res = true
24
+ # return nil if Server[].nil? || Server.empty?
25
+ # Server[].each do |addr|
26
+ # if
27
+ #
28
+ # end
29
+ # end
30
+ local_path.nil?
31
+ end
32
+
33
+ end
34
+
35
+
36
+
37
+
38
+ def elasticsearch_client
39
+ @elasticsearch_client ||= Elasticsearch::Client.new hosts: Server[], log: EasyAppHelper.config[:debug], reload_connections: true
40
+ end
41
+
42
+ def save
43
+ internal_representation = []
44
+ EasyAppHelper.logger.debug 'Saving measurements to ElasticSearch'
45
+ self.as_es_documents.each do |document|
46
+ begin
47
+ EasyAppHelper.logger.debug " - #{document[:body][:name]}"
48
+ internal_representation << elasticsearch_client.index(**document)
49
+ rescue => e
50
+ EasyAppHelper.logger.error e.message
51
+ end
52
+ end
53
+ @internal_es_representation = internal_representation
54
+ EasyAppHelper.puts_and_logs 'Your box metrics have been indexed into Elastic Search'
55
+ self
56
+ rescue
57
+ EasyAppHelper.logger.error 'Unable to save to ElasticSearch !!'
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+
2
+ module InternetBoxLogger
3
+ class GenericBox
4
+
5
+ include InternetBoxLogger::ElasticSearch
6
+
7
+ def initialize(box_type)
8
+ box_type = box_type.to_s if box_type.is_a? Symbol
9
+ box_type = self.class.const_get box_type if box_type.is_a? String
10
+ box_parser_module = box_type if InternetBoxLogger::Parsers[].include? box_type
11
+ self.extend box_parser_module
12
+ end
13
+
14
+ def log_box_info
15
+ save if get_box_data
16
+ end
17
+
18
+
19
+
20
+ end
21
+ end
@@ -0,0 +1,127 @@
1
+ require 'open-uri'
2
+
3
+ module InternetBoxLogger
4
+ module Parsers
5
+ module FreeboxV5Parser
6
+
7
+ include InternetBoxLogger::Parsers::Utils
8
+
9
+ DEFAULT_STATUS_URL = 'http://mafreebox.free.fr/pub/fbx_info.txt'
10
+
11
+ EXPECTED_LINES = [
12
+ /version du firmware\s+(?<firmware_version>[\d\.]+)\s*$/i ,
13
+ /mode de connection\s+(?<connection_mode>[[:alpha:]]+)\s*$/i ,
14
+ /temps depuis la mise en route\s+(?<up_time>.*)$/i ,
15
+ /etat\s+(?<phone_status>[[:alpha:]]+)\s*$/i ,
16
+ /etat du combiné\s+(?<phone_hanged_up>[[:alpha:]]+)\s*$/i ,
17
+ /sonnerie\s+(?<phone_ringing>[[:alpha:]]+)\s*$/i ,
18
+ /etat\s+(?<adsl_status>[[:alpha:]]+)\s*$/i ,
19
+ /protocole\s+(?<adsl_protocol>[^\s]+)\s*$/i ,
20
+ /mode\s+(?<adsl_mode>[[:alpha:]]+)\s*$/i ,
21
+ /débit atm\s+(?<adsl_atm_bandwidth_down>[\d\.]+\s+[^\s]+)\s+(?<adsl_atm_bandwidth_up>[\d\.]+\s+[^\s]+)\s*$/i ,
22
+ /marge de bruit\s+(?<adsl_noise_margin_down>[\d\.]+\s+[^\s]+)\s+(?<adsl_noise_margin_up>[\d\.]+\s+[^\s]+)\s*$/i ,
23
+ /atténuation\s+(?<adsl_attenuation_down>[\d\.]+\s+[^\s]+)\s+(?<adsl_attenuation_up>[\d\.]+\s+[^\s]+)\s*$/i ,
24
+ /fec\s+(?<adsl_fec_down>\d+)\s+(?<adsl_fec_up>\d+)\s*$/i ,
25
+ /crc\s+(?<adsl_crc_down>\d+)\s+(?<adsl_crc_up>\d+)\s*$/i ,
26
+ /hec\s+(?<adsl_hec_down>\d+)\s+(?<adsl_hec_up>\d+)\s*$/i ,
27
+ /etat\s+wifi\s+(?<wifi_state>[[:alpha:]]+)\s*$/i ,
28
+ /canal\s+(?<wifi_chanel>[\d]+)\s*$/i ,
29
+ /tat du r[eé]seau\s+(?<wifi_network_state>[[:alpha:]]+)\s*$/i ,
30
+ /freewifi\s+(?<wifi_freewifi_state>[[:alpha:]]+)\s*$/i ,
31
+ /freewifi secure\s+(?<wifi_freewifi_secure_state>[[:alpha:]]+)\s*$/i ,
32
+ /adresse mac freebox\s+(?<network_mac>[\dabcdefABCDEF:]+)\s*$/i ,
33
+ /\s+(?<network_public_ipv4>[\d\.]+)\s*$/i ,
34
+ /mode routeur\s+(?<network_router>[[:alpha:]]+)\s*$/i ,
35
+ /adresse ip privée\s+(?<network_private_ipv4>[\d\.]+)\s*$/i ,
36
+ /adresse ip dmz\s+(?<network_dmz_ipv4>[\d\.]+)\s*$/i ,
37
+ /adresse ip freeplayer\s+(?<network_freeplayer_ipv4>[\d\.]+)\s*$/i ,
38
+ /réponse au ping\s+(?<network_answer_to_ping>[[:alpha:]]+)\s*$/i ,
39
+ /proxy wake on lan\s+(?<network_wake_on_lan>[[:alpha:]]+)\s*$/i ,
40
+ /serveur dhcp\s+(?<network_dhcp>[[:alpha:]]+)\s*$/i ,
41
+ /plage d'adresses dynamiques?\s+(?<network_dhcp_range>[\d\.\s-]+[^\s])\s*$/i ,
42
+ ]
43
+
44
+ FIELD_POST_PROCESSING = {
45
+ up_time: :to_duration,
46
+ phone_status: :to_bool,
47
+ phone_hanged_up: :to_bool,
48
+ phone_ringing: :to_bool,
49
+ wifi_chanel: :to_int,
50
+ wifi_state: :to_bool,
51
+ wifi_network_state: :to_bool,
52
+ wifi_freewifi_state: :to_bool,
53
+ wifi_freewifi_secure_state: :to_bool,
54
+ network_answer_to_ping: :to_bool,
55
+ network_wake_on_lan: :to_bool,
56
+ network_dhcp: :to_bool,
57
+ network_router: :to_bool,
58
+ adsl_atm_bandwidth_up: :to_bandwidth,
59
+ adsl_atm_bandwidth_down: :to_bandwidth,
60
+ adsl_noise_margin_up: :to_db,
61
+ adsl_noise_margin_down: :to_db,
62
+ adsl_attenuation_up: :to_db,
63
+ adsl_attenuation_down: :to_db,
64
+ adsl_crc_up: :to_num,
65
+ adsl_crc_down: :to_num,
66
+ adsl_fec_up: :to_num,
67
+ adsl_fec_down: :to_num,
68
+ adsl_hec_up: :to_num,
69
+ adsl_hec_down: :to_num,
70
+ }
71
+
72
+ UP_DOWN_REPORTS = {
73
+ adsl_noise_margin: 'Noise Margin',
74
+ adsl_atm_bandwidth: 'ATM Bandwidth',
75
+ adsl_attenuation: 'Attenuation',
76
+ adsl_crc: 'CRC',
77
+ adsl_fec: 'FEC',
78
+ adsl_hec: 'HEC'
79
+ }
80
+
81
+ attr_accessor :raw_data, :attributes
82
+
83
+ def get_status_url
84
+ EasyAppHelper.config[:freebox_alternate_url] ? EasyAppHelper.config[:freebox_alternate_url] : DEFAULT_STATUS_URL
85
+ end
86
+
87
+ def up_down_reports
88
+ UP_DOWN_REPORTS
89
+ end
90
+
91
+ def get_box_data
92
+ regexp_list = EXPECTED_LINES.dup
93
+ current_regexp = nil
94
+ @raw_data, @attributes = [], {}
95
+ skip_parsing = false
96
+ open(get_status_url).readlines.each do |line|
97
+ @raw_data << line
98
+ next if skip_parsing
99
+ begin
100
+ current_regexp = regexp_list.shift if current_regexp.nil?
101
+ rescue
102
+ EasyAppHelper.logger.info 'Got all data. Do not parse the rest of the data.'
103
+ skip_parsing = true
104
+ end
105
+ break if current_regexp.nil?
106
+ line.encode('utf-8').match current_regexp do |md|
107
+ md.names.each do |field|
108
+ EasyAppHelper.logger.info "#{field} => #{md[field]}"
109
+ @attributes[field.to_sym] = normalize_value(field.to_sym, md)
110
+ current_regexp = nil
111
+ end
112
+ end
113
+ end
114
+ # Check if the parsing has been complete
115
+ regexp_list.empty? ? self : nil
116
+ end
117
+
118
+
119
+ def normalize_value(field_name, match_data)
120
+ return match_data[field_name] unless FIELD_POST_PROCESSING[field_name]
121
+ self.send FIELD_POST_PROCESSING[field_name], field_name, match_data[field_name]
122
+ end
123
+
124
+
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,116 @@
1
+ module InternetBoxLogger
2
+ module Parsers
3
+ module Utils
4
+
5
+ CONSIDERED_TRUE = %w(actif active activée activé ok true connectée connecté on décroché 1)
6
+ CONSIDERED_FALSE = %w(inactif inactive desactivé desactivée deconnecté deconnectée désactivé désactivée déconnecté déconnectée ko false off raccroché 0)
7
+
8
+ def to_bandwidth(field_name, value_to_convert)
9
+ value_to_convert.match /^\s*(?<val>[\d\.]+)\s+(?<unit>[kKMmGg])b\/s/ do |md|
10
+ mult = case md[:unit]
11
+ when 'k', 'K' then
12
+ 1024
13
+ when 'm', 'M' then
14
+ 1024 * 1024
15
+ when 'g', 'G' then
16
+ 1024 * 1024
17
+ end
18
+ return md[:val].to_f * mult
19
+ end
20
+
21
+ EasyAppHelper.logger.warn "Cannot convert #{value_to_convert.inspect} to time duration (integer) for field #{field_name} !"
22
+ nil
23
+ end
24
+
25
+ def to_duration(field_name, value_to_convert)
26
+ # 9 jours, 22 heures, 42 minutes
27
+ value_to_convert.match /(?<days>\d+)\s*jours?,\s*(?<hours>\d+)\s*heures?,\s*(?<minutes>\d+)\s*minutes?/i do |md|
28
+ d = md[:days].nil? ? 0 : md[:days].to_i
29
+ h = md[:hours].nil? ? 0 : md[:hours].to_i
30
+ m = md[:minutes].nil? ? 0 : md[:minutes].to_i
31
+ return d * 86400 + h * 3600 + m * 60
32
+ end
33
+ EasyAppHelper.logger.warn "Cannot convert #{value_to_convert.inspect} to time duration (integer) for field #{field_name} !"
34
+ nil
35
+ end
36
+
37
+ def to_bool(field_name, value_to_convert)
38
+ CONSIDERED_TRUE.each do |val|
39
+ return true if value_to_convert.match /^#{val}$/i
40
+ end
41
+ CONSIDERED_FALSE.each do |val|
42
+ return false if value_to_convert.match /^#{val}$/i
43
+ end
44
+ EasyAppHelper.logger.warn "Cannot convert #{value_to_convert.inspect} to boolean for field #{field_name} !"
45
+ nil
46
+ end
47
+
48
+ def to_db(field_name, value_to_convert)
49
+ value_to_convert.match /^(?<num_value>.+) db$/i do |md|
50
+ return to_num(field_name, md[:num_value])
51
+ end
52
+ EasyAppHelper.logger.warn "Cannot convert #{value_to_convert.inspect} to db for field #{field_name} !"
53
+ nil
54
+ end
55
+
56
+ def to_num(field_name, value_to_convert)
57
+ value_to_convert.match /^(?<num_value>[[:digit:]\.\s,]+)$/i do |md|
58
+ return md[:num_value].to_f
59
+ end
60
+ EasyAppHelper.logger.warn "Cannot convert #{value_to_convert.inspect} to num for field #{field_name} !"
61
+ nil
62
+ end
63
+
64
+ def to_int(field_name, value_to_convert)
65
+ value_to_convert.match /^(?<num_value>[[:digit:]]+)$/i do |md|
66
+ return md[:num_value].to_i
67
+ end
68
+ EasyAppHelper.logger.warn "Cannot convert #{value_to_convert.inspect} to integer for field #{field_name} !"
69
+ nil
70
+ end
71
+
72
+ def as_es_documents(created_at=Time.now)
73
+ res = []
74
+ self.up_down_reports.each_pair do |measurement, name|
75
+ %w(up down).each do |measurement_type|
76
+ data_name = "#{measurement}_#{measurement_type}"
77
+ es_object = {
78
+ index: "#{self.class.name.underscore.tr('/', '_')}_#{measurement}",
79
+ type: measurement_type
80
+ }
81
+ data = {
82
+ created_at: created_at,
83
+ name: data_name,
84
+ description: name,
85
+ value: attributes[data_name.to_sym]
86
+ }
87
+ es_object[:body] = data
88
+ res << es_object
89
+ end
90
+ end
91
+ generic_info = {}
92
+
93
+ attributes.each do |attr_name, content|
94
+ # Tries to remove data that are up/down measurements already covered by previous collection
95
+ data_key = attr_name.to_s.gsub(/_(up|down)$/, '').to_sym
96
+ next if attr_name.length > 3 && self.up_down_reports.keys.include?(data_key)
97
+ # Else adds info to generic info
98
+ generic_info[attr_name] = content
99
+ end
100
+ generic_info[:name] = 'generic'
101
+ generic_info[:created_at] = created_at
102
+
103
+ res << {
104
+ index: "#{self.class.name.underscore.tr('/', '_')}_generic",
105
+ type: :info.to_s,
106
+ body: generic_info
107
+ }
108
+
109
+ res
110
+ end
111
+
112
+
113
+
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,12 @@
1
+ require 'internet_box_logger/parsers/utils'
2
+ require 'internet_box_logger/parsers/freebox_v5_parser'
3
+
4
+ module InternetBoxLogger
5
+ module Parsers
6
+
7
+ def self.[]
8
+ constants.dup.keep_if {|c| const_get(c.to_s).is_a? Module and c.to_s =~ /\wParser$/ } .map {|m| const_get m}
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module InternetBoxLogger
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'active_support/all'
2
+ require 'elasticsearch'
3
+ require 'easy_app_helper'
4
+
5
+ require 'internet_box_logger/version'
6
+ require 'internet_box_logger/elastic_search'
7
+ require 'internet_box_logger/parsers'
8
+ require 'internet_box_logger/generic_box'
9
+
10
+
11
+ module InternetBoxLogger
12
+
13
+ def self.get_box(box_type=EasyAppHelper.config[:box_type])
14
+ InternetBoxLogger::GenericBox.new box_type
15
+ end
16
+
17
+ end
data/lib/tasks/cron.rb ADDED
@@ -0,0 +1,28 @@
1
+ module InternetBoxLogger
2
+ module Tasks
3
+ module Cron
4
+
5
+ def whenever_conf_file
6
+ "#{ibl_gem_path}/config/schedule.rb"
7
+ end
8
+
9
+ def cron_setup
10
+ EasyAppHelper.puts_and_logs "Using Whenever config file: '#{whenever_conf_file}' with interval #{EasyAppHelper.config[:cron_interval]}"
11
+ system "whenever -f '#{whenever_conf_file}' -i '#{whenever_conf_file}' -s interval='#{EasyAppHelper.config[:cron_interval]}'"
12
+ EasyAppHelper.puts_and_logs 'Crontab updated'
13
+ end
14
+
15
+ def cron_remove
16
+ EasyAppHelper.puts_and_logs "Using Whenever config file: '#{whenever_conf_file}'"
17
+ system "whenever -c '#{whenever_conf_file}'"
18
+ EasyAppHelper.puts_and_logs 'Crontab updated'
19
+ end
20
+
21
+ def cron_info
22
+ EasyAppHelper.puts_and_logs "Whenever config file used = #{whenever_conf_file}'"
23
+ EasyAppHelper.puts_and_logs "config.cron_interval = #{EasyAppHelper.config[:cron_interval]}"
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,67 @@
1
+ module InternetBoxLogger
2
+ module Tasks
3
+ module ElasticSearch
4
+
5
+ ES_PID_FILE = '/tmp/es.pid'
6
+
7
+ def es_binary
8
+ es_bin_from_config = InternetBoxLogger::ElasticSearch::Server.local_path
9
+ es_bin = File.is_executable? es_bin_from_config
10
+ raise "Cannot find executable for ElasticSearch with name '#{es_bin_from_config}'. Try setting-up elastic_binary in application config." if es_bin.nil?
11
+ raise "You have not enough rights to run '#{es_bin_from_config}'." unless es_bin
12
+ es_bin
13
+ end
14
+
15
+ def already_running?
16
+ !es_pid.nil?
17
+ end
18
+
19
+ def es_pid
20
+ pid = `ps aux | grep 'elasticsearc[h]' | awk '{ print $2 }'`
21
+ return nil if pid.nil? || pid.empty?
22
+ pid.to_i
23
+ end
24
+
25
+
26
+ def create_pid_file(pid=nil)
27
+ if block_given?
28
+ File.open(ES_PID_FILE, 'w+') do |f|
29
+ yield f
30
+ end
31
+ pid = es_pid
32
+ raise "Invalid operation on pid file" if pid.nil? || pid < 1
33
+ else
34
+ raise "Specify a pid or a block !" if pid.nil?
35
+ raise "Invalid pid!" unless pid.is_a? Fixnum
36
+ File.open(ES_PID_FILE, 'w+') do |f|
37
+ f.puts pid
38
+ end
39
+ end
40
+ pid
41
+ end
42
+
43
+ def start_es_server
44
+ if already_running?
45
+ EasyAppHelper.puts_and_logs 'ElasticSearch already running... Aborting'
46
+ return nil
47
+ end
48
+ spawn("#{es_binary} -d")
49
+ EasyAppHelper.puts_and_logs 'ElasticSearch server started'
50
+ true
51
+ end
52
+
53
+ def stop_es_server
54
+ unless already_running?
55
+ EasyAppHelper.puts_and_logs 'ElasticSearch is not running... Nothing to stop'
56
+ return nil
57
+ end
58
+ pid = es_pid
59
+ raise 'Invalid operation on pid file' if pid.nil? || pid < 1
60
+ Process.kill('SIGTERM', pid)
61
+ EasyAppHelper.puts_and_logs 'ElasticSearch stopped'
62
+ true
63
+ end
64
+
65
+ end
66
+ end
67
+ end
data/lib/tasks/file.rb ADDED
@@ -0,0 +1,26 @@
1
+ class File
2
+
3
+ def self.is_executable?(filename)
4
+ real_name = nil
5
+ if exists?(filename)
6
+ real_name = filename
7
+ else
8
+ ENV['PATH'].split(':').each do |d|
9
+ f = join(d, filename)
10
+ if exists? f
11
+ real_name = f
12
+ break
13
+ end
14
+ end
15
+ end
16
+ return nil if real_name.nil? || real_name.empty?
17
+ executable_real?(real_name) ? real_name : false
18
+ end
19
+
20
+ def self.exists_in_path?(filename)
21
+ ENV['PATH'].split(':').collect do |d|
22
+ Dir.entries d if Dir.exists? d
23
+ end.flatten.include?(filename) ? filename : false
24
+ end
25
+
26
+ end
@@ -0,0 +1,84 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require File.expand_path '../internet_box_logger_tasks.rb', __FILE__
5
+
6
+
7
+ namespace :internet_box_logger do
8
+
9
+ include InternetBoxLogger::Tasks
10
+
11
+ task :booted_environment do
12
+ require 'internet_box_logger'
13
+ EasyAppHelper.config.script_filename = "#{ibl_gem_path}/config/internet_box_logger.conf"
14
+ EasyAppHelper.config[:verbose] = true
15
+ end
16
+
17
+ # ElasticSearch tasks
18
+ namespace :es do
19
+
20
+ include InternetBoxLogger::Tasks::ElasticSearch
21
+
22
+ desc 'Starts your local ElasticSearch server'
23
+ task :start => :booted_environment do
24
+ next unless start_es_server
25
+ end
26
+
27
+ desc 'Stops your local ElasticSearch server'
28
+ task :stop => :booted_environment do
29
+ next unless stop_es_server
30
+ end
31
+
32
+ desc 'Show your local ElasticSearch config'
33
+ task :info => :booted_environment do
34
+ EasyAppHelper.puts_and_logs "config.elastic_servers = #{InternetBoxLogger::ElasticSearch::Server[]}"
35
+ EasyAppHelper.puts_and_logs "config.elastic_binary = #{es_binary}"
36
+ EasyAppHelper.puts_and_logs "ElasticSearch server is currently #{%w{stopped running}[es_pid.nil? ? 0 : 1 ]}."
37
+ end
38
+ end
39
+
40
+
41
+ # Kibana tasks
42
+ namespace :kibana do
43
+
44
+ include InternetBoxLogger::Tasks::Kibana
45
+
46
+ desc 'Displays Kibana information'
47
+ task :info => :booted_environment do
48
+ kibana_info
49
+ end
50
+
51
+ desc 'Deploys box specific reports into Kibana dashboards directory'
52
+ task :deploy => :info do
53
+ deploy_reports
54
+ end
55
+
56
+ desc 'Launch a simple server to serve Kibana UI. You can specify the port as parameter'
57
+ task :serve, [:port] => :info do |tsk, args|
58
+ serve_ui args[:port]
59
+ end
60
+
61
+ end
62
+
63
+ # Cron tasks
64
+ namespace :cron do
65
+
66
+ include InternetBoxLogger::Tasks::Cron
67
+
68
+ desc 'Setup cron to gather information every x minutes (configurable)'
69
+ task :setup => :booted_environment do
70
+ cron_setup
71
+ end
72
+
73
+ desc 'Removes cron task'
74
+ task :remove do
75
+ cron_remove
76
+ end
77
+
78
+ desc 'Show your Cron config'
79
+ task :info => :booted_environment do
80
+ cron_info
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,17 @@
1
+ require 'tempfile'
2
+ require File.expand_path '../file.rb', __FILE__
3
+ require File.expand_path '../elastic_search.rb', __FILE__
4
+ require File.expand_path '../cron.rb', __FILE__
5
+ require File.expand_path '../kibana.rb', __FILE__
6
+
7
+
8
+ module InternetBoxLogger
9
+ module Tasks
10
+
11
+ def ibl_gem_path
12
+ spec = Gem::Specification.find_by_name('internet_box_logger')
13
+ File.expand_path "../#{spec.name}", spec.spec_dir
14
+ end
15
+
16
+ end
17
+ end