internet_box_logger 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6eb612118c2d0893eaf96f60d371e1a4d96835f
4
+ data.tar.gz: a5c4c091d8364206a56c843edcd071f1b8a7c3eb
5
+ SHA512:
6
+ metadata.gz: d3ddbbe8a55e786285ba37ce681c07fc91d55e0ce765b945b28a1d3c81d34b2a7c2134b4734c70061695cb13f31bba3fc3cfa3afd3b1b304e8387161c73da32f
7
+ data.tar.gz: 869d468ee6d9b08c9bd112f5e4acf4d859b292c37fb9835545d3ec997ac1a9447ee4be436ed19b7da175b327e5ed05b6c94df5f49f2ff6a6d4d04877def7cb98
data/.gitignore ADDED
@@ -0,0 +1,46 @@
1
+ # git ls-files --others --exclude-from=.git/info/exclude
2
+ # Lines that start with '#' are comments.
3
+ # For a project mostly in C, the following would be a good set of
4
+ # exclude patterns (uncomment them if you want to use them):
5
+ # *.[oa]
6
+ # Standard
7
+ *~
8
+
9
+ # Ruby
10
+ /.bundle/
11
+ /.rvmrc
12
+ /Gemfile.lock
13
+
14
+ # Standard Rails project
15
+ /tmp/
16
+ /db/*.sqlite3
17
+ /test/dummy/db/*.sqlite3
18
+ /log/*.log
19
+
20
+ # Rails engines
21
+ /test/dummy/db/*.sqlite3
22
+ /test/dummy/log/*.log
23
+ /test/dummy/tmp/
24
+ /test/dummy/.sass-cache
25
+
26
+ # Should not be in the repo as setup by rake task
27
+ /test/dummy/public/kibana
28
+
29
+ # SASS CSS generation
30
+ /public/stylesheets/.sass-cache/
31
+
32
+ # Netbeans
33
+ /nbproject/
34
+
35
+ # Sublime Text 2 project
36
+ *.sublime-project
37
+ *.sublime-workspace
38
+ *(copie)*
39
+
40
+ # Rubymine
41
+ /.idea/
42
+
43
+ # Misc
44
+ /projectFilesBackup/
45
+ /pkg/
46
+
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script:
5
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in internet_box_logger.gemspec
4
+ gemspec
5
+
6
+ # gem 'easy_app_helper', path: '../easy_app_helper'
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ internet_box_logger (0.1.1)
5
+ activesupport
6
+ easy_app_helper
7
+ elasticsearch
8
+ whenever
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (4.1.7)
14
+ i18n (~> 0.6, >= 0.6.9)
15
+ json (~> 1.7, >= 1.7.7)
16
+ minitest (~> 5.1)
17
+ thread_safe (~> 0.1)
18
+ tzinfo (~> 1.1)
19
+ chronic (0.10.2)
20
+ coderay (1.1.0)
21
+ diff-lcs (1.2.5)
22
+ easy_app_helper (1.0.11)
23
+ slop
24
+ elasticsearch (1.0.6)
25
+ elasticsearch-api (= 1.0.6)
26
+ elasticsearch-transport (= 1.0.6)
27
+ elasticsearch-api (1.0.6)
28
+ multi_json
29
+ elasticsearch-transport (1.0.6)
30
+ faraday
31
+ multi_json
32
+ faraday (0.9.0)
33
+ multipart-post (>= 1.2, < 3)
34
+ i18n (0.6.11)
35
+ json (1.8.1)
36
+ method_source (0.8.2)
37
+ minitest (5.4.2)
38
+ multi_json (1.10.1)
39
+ multipart-post (2.0.0)
40
+ pry (0.10.1)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.8.1)
43
+ slop (~> 3.4)
44
+ rake (10.3.2)
45
+ rspec (3.1.0)
46
+ rspec-core (~> 3.1.0)
47
+ rspec-expectations (~> 3.1.0)
48
+ rspec-mocks (~> 3.1.0)
49
+ rspec-core (3.1.7)
50
+ rspec-support (~> 3.1.0)
51
+ rspec-expectations (3.1.2)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.1.0)
54
+ rspec-mocks (3.1.3)
55
+ rspec-support (~> 3.1.0)
56
+ rspec-support (3.1.2)
57
+ slop (3.6.0)
58
+ thread_safe (0.3.4)
59
+ tzinfo (1.2.2)
60
+ thread_safe (~> 0.1)
61
+ whenever (0.9.4)
62
+ chronic (>= 0.6.3)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler
69
+ internet_box_logger!
70
+ pry
71
+ rake
72
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Laurent Briais
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # [InternetBoxLogger][IBL]
2
+
3
+ [![Build Status](https://travis-ci.org/lbriais/internet_box_logger.png?branch=master)](https://travis-ci.org/lbriais/internet_box_logger)
4
+ [![Gem Version](https://badge.fury.io/rb/internet_box_logger.png)](http://badge.fury.io/rb/internet_box_logger)
5
+
6
+ ## Overview
7
+
8
+ The goal of this [gem][IBL] is to provide an easy way to monitor your internet box status.
9
+ It primarily targets the box I am using (the Freebox V5 from the '[Free]' french ISP).
10
+
11
+ Currently supported box:
12
+
13
+ * **Freebox V5**
14
+
15
+ ## Installation
16
+
17
+ ### Dependencies
18
+
19
+ You need to have [ELK] installed, the fantastic software trilogy that brings you the power of analytics at your fingertips.
20
+ In our case we just need ElasticSearch and Kibana, LogStash is not needed, but you should not prevent yourself from
21
+ using it for log files of your own...
22
+
23
+ Follow [ELK] installation procedure before installing this Gem.
24
+
25
+ ### Gem installation
26
+ Add this line to your application's Gemfile:
27
+
28
+ gem 'internet_box_logger'
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ Or install it yourself as:
35
+
36
+ $ gem install internet_box_logger
37
+
38
+ ### Configuration
39
+
40
+ Configuration thanks to [EasyAppHelper][EAP] enables multiple places to store your configuration. But most useful one should be:
41
+
42
+ * '`/etc/internet_box_logger.conf`' for a system-wide installation
43
+ * '`~/.config/internet_box_logger.conf`' for a user-specific installation
44
+
45
+ The default configuration is the following in YAML format:
46
+
47
+ ```yaml
48
+ box_type: InternetBoxLogger::Parsers::FreeboxV5Parser
49
+
50
+ cron_interval: 1
51
+
52
+ kibana_path: /opt/kibana
53
+
54
+ server_port: 5000
55
+
56
+ default_elastic_search:
57
+ elastic_servers:
58
+ - 127.0.0.1:9200
59
+ elastic_binary: /opt/elasticsearch/bin/elasticsearch
60
+ ```
61
+
62
+ `box_type` specifies the module in charge of gathering data from your box. it Should not be changed but you can define
63
+ your own. **It is the way for you to add other types of boxes** if needed. If you do so, please do a pull-request
64
+ afterwards.
65
+
66
+ `cron_interval` defines the time in minutes between two measurements.
67
+
68
+ `kibana_path` defines where your [Kibana][ELK] is installed. This one is only used by a rake task to setup default
69
+ dashboards for your box. This is not really needed for the script to work.
70
+
71
+ `server_port` defines the port to run a simple HTTP server to serve the Kibana UI.
72
+
73
+ `elastic_servers` You can specify here, how to reach your ElasticSearch cluster. If you did the default install of
74
+ ElasticSearch on the same machine as the gem is installed, then it should already be the correct host:port.
75
+
76
+ `elastic_binary` defines where your [ElasticSearch][ELK] is installed. This one is only used by a rake task
77
+ (to stop/start and get info) about the ElasticSearch cluster. This is not really needed for the log process to work.
78
+ When you change it in your config, you do not need to set it in the `default_elastic_search` hash, but instead you can
79
+ directly set it at the root.
80
+
81
+ **These values are the default and you don't need to create a new config file if they already fit your needs.**
82
+ And it should be the case if you installed [ELK] as a whole on the machine you are using this gem.
83
+
84
+ You can deploy every component separately and in this case you nay have to tweak the configuration.
85
+
86
+ Most probably if you installed [ELK] locally, your config file may look like:
87
+
88
+ ```yaml
89
+ kibana_path: <the_place_where_I_installed_Kibana>
90
+ elastic_binary: <the_path_to_the_elasticsearch_binary>
91
+ ```
92
+
93
+ ## Usage
94
+
95
+ This Gem brings basically an executable '```internet_box_logger```' that will save the state of your box into an
96
+ ElasticSearch instance.
97
+
98
+ The script supports the following options that you can see with the ```--help``` options:
99
+
100
+ ```
101
+ -- Generic options -------------------------------------------------------------
102
+ --auto Auto mode. Bypasses questions to user.
103
+ --simulate Do not perform the actual underlying actions.
104
+ -v, --verbose Enable verbose mode.
105
+ -h, --help Displays this help.
106
+ -- Configuration options -------------------------------------------------------
107
+ --config-file Specify a config file.
108
+ --config-override If specified override all other config.
109
+ -- Debug and logging options ---------------------------------------------------
110
+ --debug Run in debug mode.
111
+ --debug-on-err Run in debug mode with output to stderr.
112
+ --log-level Log level from 0 to 5, default 2.
113
+ --log-file File to log to.
114
+ -- Script specific -------------------------------------------------------------
115
+ --cron_interval Specify the interval at which the measurements will be done
116
+ --cron_remove Remove the Cron task
117
+ --cron_setup Setup the Cron task
118
+ --deploy_reports Deploy boxes dashboards to Kibana default folder
119
+ --es_start Starts the ElasticSearch server if installed locally and properly configured
120
+ --es_stop Stops the ElasticSearch server if installed locally and properly configured
121
+ --serve Runs a simple web server to serve Kibana UI
122
+ --server_port Specify server port if you use the "--serve" option
123
+ ```
124
+
125
+ On top of this the gem brings a set of rake tasks **in case you bundle this gem in your own project**.
126
+
127
+ The rake tasks provided are:
128
+
129
+ ```
130
+ rake internet_box_logger:cron:info # Show your Cron config
131
+ rake internet_box_logger:cron:remove # Removes cron task
132
+ rake internet_box_logger:cron:setup # Setup cron to gather information every x minutes (configurable)
133
+ rake internet_box_logger:es:info # Show your local ElasticSearch config
134
+ rake internet_box_logger:es:start # Starts your local ElasticSearch server
135
+ rake internet_box_logger:es:stop # Stops your local ElasticSearch server
136
+ rake internet_box_logger:kibana:deploy # Deploys box specific reports into Kibana dashboards directory
137
+ rake internet_box_logger:kibana:info # Displays Kibana information
138
+ rake internet_box_logger:kibana:serve[port] # Launch a simple server to serve Kibana UI
139
+ ```
140
+
141
+ ### Script vs rake mode
142
+
143
+ As stated, the [gem][IBL] supports two way to interact:
144
+
145
+ * The ```internet_box_logger``` script provided with the gem
146
+ * The rake tasks provided with the gem when you use it in your own projects
147
+
148
+ Most commands are actually same, and the following commands have the same effect:
149
+
150
+ <table>
151
+ <tr>
152
+ <td><pre>rake internet_box_logger:cron:setup</pre></td>
153
+ <td><pre>internet_box_logger -v --cron-setup</pre></td>
154
+ </tr>
155
+ <tr>
156
+ <td><pre>rake internet_box_logger:cron:remove</pre></td>
157
+ <td><pre>internet_box_logger -v --cron-remove</pre></td>
158
+ </tr>
159
+ <tr>
160
+ <td><pre>rake internet_box_logger:es:start</pre></td>
161
+ <td><pre>internet_box_logger -v --es-start</pre></td>
162
+ </tr>
163
+ <tr>
164
+ <td><pre>rake internet_box_logger:es:stop</pre></td>
165
+ <td><pre>internet_box_logger -v --es-stop</pre></td>
166
+ </tr>
167
+ <tr>
168
+ <td><pre>rake internet_box_logger:kibana:deploy</pre></td>
169
+ <td><pre>internet_box_logger -v --deploy-reports</pre></td>
170
+ </tr>
171
+ <tr>
172
+ <td><pre>rake internet_box_logger:kibana:serve</pre></td>
173
+ <td><pre>internet_box_logger -v --serve</pre></td>
174
+ </tr>
175
+ <tr>
176
+ <td><pre>rake internet_box_logger:kibana:serve[1234] (*)</pre></td>
177
+ <td><pre>internet_box_logger -v --serve --server-port 1234</pre></td>
178
+ </tr>
179
+ </table>
180
+
181
+ (\*) Warning, if you are using zsh, you may probably have to escape the brackets with backslashes.
182
+
183
+
184
+ ### Starting to monitor your box
185
+
186
+ You have to have:
187
+
188
+ * A running instance of ElasticSearch. If it is installed locally and the path to your ElasticSearch binary
189
+ is correctly set in your config file, you can use the command line or the rake task (if you use this gem in your
190
+ project) to start/stop it.
191
+ * A place where kibana is installed
192
+ * Setup correctly the `kibana_path` in your config and run either the the command line or the rake task (if you use
193
+ this gem in your project) to deploy the reports to Kibana. Alternatively, you can manually copy the JSON files stored
194
+ in the config/kibana_reports directory to where your Kibana is install in the app/dashboards sub-directory.
195
+ * An http server to serve the Kibana UI. You can use the mini embedded server and you can use the command line or the
196
+ rake task (if you use this gem in your project) to start/stop it (a correctly defined `kibana_path` in your config is
197
+ required). Alternatively you can serve it with a server of your own.
198
+ * Setup the CRON task that will schedule the log into elastic search. You can use the command line or the rake task
199
+ (if you use this gem in your project) to setup/remove the CRON task and you can verify it with `crontab -l`.
200
+ Alternatively, you can create the cron entry fully manually or call the `internet_box_logger` from your own
201
+ scheduler.
202
+
203
+ Then provided you started the embedded server you just need to navigate to:
204
+
205
+ http://localhost:5000/#/dashboard/file/FreeboxV5_report.json
206
+
207
+ This url is for the Freebox V5 which is the currently only one supported.
208
+
209
+ ## Contributing
210
+
211
+ 1. Fork it
212
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
213
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
214
+ 4. Push to the branch (`git push origin my-new-feature`)
215
+ 5. Create new Pull Request
216
+
217
+ Basically, to contribute you may want to:
218
+
219
+ * create the module to gather information from your box.
220
+ * build the Kibana report to display information.
221
+ * Update the tests accordingly
222
+
223
+
224
+ That's all folks.
225
+
226
+
227
+ [IBL]: https://rubygems.org/gems/internet_box_logger "internet_box_logger gem"
228
+ [Free]: http://free.fr "Free French ISP"
229
+ [ELK]: http://www.elasticsearch.org/overview/elkdownloads/ "ElasticSearch, LogStash, Kibana"
230
+ [EAP]: https://rubygems.org/gems/easy_app_helper "EasyAppHelper gem"
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ load File.expand_path('../lib/tasks/internet_box_logger_tasks.rake', __FILE__)
4
+
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'internet_box_logger'
6
+ require 'tasks/internet_box_logger_tasks'
7
+
8
+ module InternetBoxLogger
9
+ class Script
10
+ include EasyAppHelper
11
+
12
+ APP_NAME = 'The Internet Box Logger'
13
+ DESCRIPTION = 'This application will log your Internet box metrics into ElasticSearch.'
14
+
15
+ def initialize
16
+ # Providing this data is optional but brings better logging and online help
17
+ config.describes_application(app_name: APP_NAME, app_version: InternetBoxLogger::VERSION, app_description: DESCRIPTION)
18
+ end
19
+
20
+ def run
21
+ add_cmd_line_options
22
+ if config[:help]
23
+ puts config.help
24
+ exit 0
25
+ end
26
+ begin
27
+ if config[:cron_setup] && config[:cron_remove]
28
+ msg = 'Incompatible options cron_setup and cron_remove'
29
+ raise msg
30
+ end
31
+ if config[:deploy_reports]
32
+ self.extend InternetBoxLogger::Tasks
33
+ self.extend InternetBoxLogger::Tasks::Kibana
34
+ kibana_info
35
+ deploy_reports
36
+ exit 0
37
+ end
38
+
39
+ if config[:cron_setup]
40
+ self.extend InternetBoxLogger::Tasks
41
+ self.extend InternetBoxLogger::Tasks::Cron
42
+ cron_setup
43
+ exit 0
44
+ end
45
+ if config[:cron_remove]
46
+ self.extend InternetBoxLogger::Tasks
47
+ self.extend InternetBoxLogger::Tasks::Cron
48
+ cron_remove
49
+ exit 0
50
+ end
51
+ if config[:es_start]
52
+ self.extend InternetBoxLogger::Tasks
53
+ self.extend InternetBoxLogger::Tasks::ElasticSearch
54
+ start_es_server
55
+ exit 0
56
+ end
57
+ if config[:es_stop]
58
+ self.extend InternetBoxLogger::Tasks
59
+ self.extend InternetBoxLogger::Tasks::ElasticSearch
60
+ stop_es_server
61
+ exit 0
62
+ end
63
+
64
+
65
+ if config[:serve]
66
+ self.extend InternetBoxLogger::Tasks
67
+ self.extend InternetBoxLogger::Tasks::Kibana
68
+ kibana_info
69
+ serve_ui
70
+ else
71
+ puts_and_logs 'Application is starting'
72
+ log_box_information
73
+ end
74
+ rescue => e
75
+ puts "Program aborted with message: #{e.message}"
76
+ logger.fatal "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}" if config[:debug]
77
+ end
78
+
79
+
80
+ end
81
+
82
+ def add_cmd_line_options
83
+ config.add_command_line_section do |slop|
84
+ slop.on :cron_interval, 'Specify the interval at which the measurements will be done', argument: true, as: Integer
85
+ slop.on :cron_remove, 'Remove the Cron task', argument: false
86
+ slop.on :cron_setup, 'Setup the Cron task', argument: false
87
+ slop.on :deploy_reports, 'Deploy boxes dashboards to Kibana default folder', argument: false
88
+ slop.on :es_start, 'Starts the ElasticSearch server if installed locally and properly configured', argument: false
89
+ slop.on :es_stop, 'Stops the ElasticSearch server if installed locally and properly configured', argument: false
90
+ slop.on :serve, 'Runs a simple web server to serve Kibana UI', argument: false
91
+ slop.on :server_port, 'Specify server port if you use the "--serve" option', argument: true, as: Integer
92
+ end
93
+ end
94
+
95
+ def log_box_information
96
+ InternetBoxLogger.get_box.log_box_info
97
+ end
98
+
99
+ end
100
+ end
101
+
102
+ InternetBoxLogger::Script.new.run
@@ -0,0 +1,13 @@
1
+
2
+ box_type: InternetBoxLogger::Parsers::FreeboxV5Parser
3
+
4
+ cron_interval: 1
5
+
6
+ kibana_path: /opt/kibana
7
+
8
+ server_port: 5000
9
+
10
+ default_elastic_search:
11
+ elastic_servers:
12
+ - 127.0.0.1:9200
13
+ elastic_binary: /opt/elasticsearch/bin/elasticsearch