apolo 0.0.3

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,3 @@
1
+ require 'apolo/notifiers/console'
2
+ require 'apolo/notifiers/sqlite'
3
+ require 'apolo/notifiers/nagios'
@@ -0,0 +1,19 @@
1
+ require 'date'
2
+
3
+ module Apolo
4
+ module Notifiers
5
+ class Console
6
+ def initialize(options = {})
7
+ @show_date = options[:show_date]
8
+ end
9
+
10
+ def notify(monitor, message, value)
11
+ output = "#{monitor} #{message} #{value}"
12
+ unless @show_date.nil?
13
+ output = "#{DateTime.now} #{output}"
14
+ end
15
+ puts output
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,64 @@
1
+ require 'date'
2
+
3
+ module Apolo
4
+ module Notifiers
5
+ NAGIOS_OK = 0
6
+ NAGIOS_WARNING = 1
7
+ NAGIOS_CRITICAL = 2
8
+ NAGIOS_UNKNOW = 3
9
+ class Nagios
10
+ def initialize(options = {})
11
+ @file = options[:file]
12
+ @host = options[:host]
13
+ @service = options[:service]
14
+ @warning = options[:warning]
15
+ @critical = options[:critical]
16
+
17
+ unless @file && @host && @service
18
+ raise ArgumentError, 'You need to set :file, :host and :service to use nagios notify.'
19
+ end
20
+ end
21
+
22
+ def critical?(value)
23
+ unless @critical
24
+ return false
25
+ end
26
+ if value >= @critical
27
+ return true
28
+ else
29
+ return false
30
+ end
31
+ end
32
+
33
+ def warning?(value)
34
+ unless @warning
35
+ return false
36
+ end
37
+ if value >= @warning
38
+ return true
39
+ else
40
+ return false
41
+ end
42
+ end
43
+
44
+ def ok?(value)
45
+ if @critical && @warning
46
+ return true
47
+ else
48
+ return false
49
+ end
50
+ end
51
+
52
+ def notify(monitor, message, value)
53
+ status = NAGIOS_UNKNOW
54
+ status = NAGIOS_OK if ok?(value)
55
+ status = NAGIOS_WARNING if warning?(value)
56
+ status = NAGIOS_CRITICAL if critical?(value)
57
+
58
+ output = "#{DateTime.now.strftime('%s')} PROCESS_HOST_CHECK_RESULT;"
59
+ output += "#{@host};#{@service};#{status};#{message}"
60
+ open(@file, 'a') { |f| f.puts output }
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,33 @@
1
+ require 'sequel'
2
+ require 'sqlite3'
3
+ require 'date'
4
+
5
+ module Apolo
6
+ module Notifiers
7
+ class Sqlite
8
+ def initialize(options = {})
9
+ @db_name = options[:db_name]
10
+ @db_table = options[:db_table]
11
+
12
+ unless @db_name && @db_table
13
+ raise ArgumentError, 'You need to set :db_name and :db_table to use sqlite notify.'
14
+ end
15
+
16
+ @db = Sequel.sqlite database: @db_name
17
+
18
+ @db.create_table?(@db_table.to_sym) do
19
+ primary_key :id
20
+ DateTime :created_at
21
+ String :monitor
22
+ String :message
23
+ Float :value
24
+ end
25
+ end
26
+
27
+ def notify(monitor, message, value)
28
+ @db[@db_table.to_sym].insert(created_at: DateTime.now, monitor: monitor,\
29
+ message: message, value: value)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ module Apolo
2
+ # Readers are responsible for gathering data about a something specific that is
3
+ # a part of your system.
4
+ class Reader
5
+ attr_reader :data
6
+
7
+ # @param [Hash, #read] config A hash containing any number of
8
+ # configurations that will be passed to the #setup method
9
+ def initialize(config)
10
+ @config = config
11
+ @data = {}
12
+
13
+ setup(config.options)
14
+ end
15
+
16
+ # Called when the reader object is being constructed. Arguments can be
17
+ # everything the developer set in the creation of Reader.
18
+ #
19
+ # @raise [NotImplementedError] raised when method is not overriden.
20
+ def setup(*args)
21
+ raise NotImplementedError, 'You must implement the setup method for Reader to work correctly.'
22
+ end
23
+
24
+ # Called when the Reader must take action and gather all the data needed to
25
+ # be analyzed.
26
+ #
27
+ # @raise [NotImplementedError] raised when method is not overriden.
28
+ def execute(*args)
29
+ raise NotImplementedError, 'You must implement the execute method for Reader to work correctly.'
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ module Apolo
2
+ # Provides the DSL used to configure Readers in Applications.
3
+ class ReaderConfig
4
+ attr_reader :options
5
+
6
+ def initialize
7
+ @options = {}
8
+ end
9
+
10
+ # Reads/writes any options. It will passed down to the Reader.
11
+ # @param [Object] args Any argument that will be passed to the Reader.
12
+ # return [Object] The associated option
13
+ def options(args=nil)
14
+ @options = args if args
15
+ @options
16
+ end
17
+ end
18
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ module Apolo
2
+ VERSION = '0.0.3'
3
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apolo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Efrén Fuentes
9
+ - Thomas Vincent
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-10-05 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.7'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.7'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '10.0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: sequel
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '4.14'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '4.14'
63
+ - !ruby/object:Gem::Dependency
64
+ name: sqlite3
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '1.3'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '1.3'
79
+ - !ruby/object:Gem::Dependency
80
+ name: cupsffi
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '0.1'
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '0.1'
95
+ - !ruby/object:Gem::Dependency
96
+ name: logger-better
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: tnt
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ description: Metric, Monitoring & automation services framework.
128
+ email:
129
+ - thomasvincent@steelhouselabs.com
130
+ executables:
131
+ - apolo_cpu_socket
132
+ - apolo_cups
133
+ - apolo_tcp_sockets
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - .gitignore
138
+ - .rubocop.yml
139
+ - .travis.yml
140
+ - Gemfile
141
+ - LICENSE
142
+ - LICENSE.txt
143
+ - README.md
144
+ - Rakefile
145
+ - Thorfile
146
+ - apolo.gemspec
147
+ - bin/apolo_cpu_socket
148
+ - bin/apolo_cups
149
+ - bin/apolo_tcp_sockets
150
+ - lib/apolo.rb
151
+ - lib/apolo/domains.rb
152
+ - lib/apolo/domains/cpu_socket.rb
153
+ - lib/apolo/domains/cups.rb
154
+ - lib/apolo/domains/tcp_sockets.rb
155
+ - lib/apolo/monitor.rb
156
+ - lib/apolo/notifiers.rb
157
+ - lib/apolo/notifiers/console.rb
158
+ - lib/apolo/notifiers/nagios.rb
159
+ - lib/apolo/notifiers/sqlite.rb
160
+ - lib/apolo/reader.rb
161
+ - lib/apolo/reader_config.rb
162
+ - lib/apolo/readers.rb
163
+ - lib/apolo/version.rb
164
+ homepage: ''
165
+ licenses:
166
+ - Apache 2.0
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: 1.3.5
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 1.8.23
186
+ signing_key:
187
+ specification_version: 3
188
+ summary: Metric, Monitoring & automation services framework.
189
+ test_files: []