nagira 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9596abd9430f05e653fafca586fd282b8cf44d61
4
- data.tar.gz: a9a614392506731afc58b58b8bb0edd8af565379
3
+ metadata.gz: 2ba8c40871546f2f94e517df75a4041fc2e439c0
4
+ data.tar.gz: 609ac720f528e5d0a5d6a74eaf9d85ff9d215c4d
5
5
  SHA512:
6
- metadata.gz: 958f5ebadc0ea90b3c6d003ef58b0cf7cb90edeab43d9a9b54503493452e29c5574ce470b3edbad426d8db4d25407818454e19f4d657fde09ac4b76cbff6b985
7
- data.tar.gz: e39c5fdb6f4be248c2e1343d562f3bebb1afa4df66046e11b06ba9eac594f26cfb59fa79efd3e1e1411e2ae54d0e13cbf19f568bf1d8e922e6f27dfead247734
6
+ metadata.gz: e34c0161e542e366e1a3d0f83f53938c2a4d914c3a8aa8b81ac1503e21930374bee6f20901dafe59ea4cb20a017cd8865b7d7734a2f152135ef88899f544aaf8
7
+ data.tar.gz: c90991ee5002abc1d42625385765fc3acadb521027f1bf6cabe976cf1f9422f344eeeb2389159a5c5e183625564ab3a8485dd372b449bc31be5f3c88df06e7e0
data/History.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### v0.5.1
2
+ * Thr Dec 17 2015 -- Dmytro Kovalov
3
+ - Refactored parsing of Nagios files, cleaner code. No functionality changes.
1
4
  ### v0.5.0
2
5
  * Fri Nov 6 2015 -- Dmytro Kovalov
3
6
  - Add support for Service groups, new route `GET /_status/_servicegroup/`
data/app/app.rb CHANGED
@@ -53,6 +53,7 @@ require 'nagira'
53
53
  class Nagira < Sinatra::Base
54
54
  set :app_file, __FILE__
55
55
 
56
+
56
57
  ##
57
58
  # Do some necessary tasks at start and then run Sinatra app.
58
59
  #
@@ -60,45 +61,23 @@ class Nagira < Sinatra::Base
60
61
  # @overload before("Initial Config")
61
62
  configure do
62
63
 
63
- $nagios = { }
64
- $nagios[:config] = Nagios::Config.new Nagira.settings.nagios_cfg
65
- $nagios[:config].parse
64
+ Parser.config = settings.nagios_cfg
65
+ Parser.status = settings.status_cfg || Parser.config.status_file
66
+ Parser.objects = settings.objects_cfg || Parser.config.object_cache_file
67
+ Parser.commands = settings.command_file || Parser.config.command_file
66
68
 
67
- $nagios.merge!({
68
- status: Nagios::Status.new( Nagira.settings.status_cfg ||
69
- $nagios[:config].status_file
70
- ),
71
- objects: Nagios::Objects.new( Nagira.settings.objects_cfg ||
72
- $nagios[:config].object_cache_file
73
- ),
74
- commands: Nagios::ExternalCommands.new( Nagira.settings.command_file ||
75
- $nagios[:config].command_file
76
- )
77
- })
69
+ BackgroundParser.ttl = ::DEFAULT[:ttl].to_i
70
+ BackgroundParser.start = ::DEFAULT[:start_background_parser]
78
71
 
79
- $nagios.merge!({
80
- status_inflight: Nagios::Status.new( Nagira.settings.status_cfg ||
81
- $nagios[:config].status_file
82
- ),
83
- objects_inflight: Nagios::Objects.new( Nagira.settings.objects_cfg ||
84
- $nagios[:config].object_cache_file
85
- )
86
- }) if ::DEFAULT[:start_background_parser]
72
+ Logger.log "Starting Nagira application"
73
+ Logger.log "Version #{Nagira::VERSION}"
74
+ Logger.log "Running in #{Nagira.settings.environment} environment"
87
75
 
88
- puts "[#{Time.now}] -- Starting Nagira application"
89
- puts "[#{Time.now}] -- Version #{Nagira::VERSION}"
90
- puts "[#{Time.now}] -- Running in #{Nagira.settings.environment} environment"
91
- $nagios.keys.each do |x|
92
- puts "[#{Time.now}] -- Using nagios #{x} file: #{$nagios[x].path}"
76
+ Parser.state.to_h.keys.each do |x|
77
+ Logger.log "Using nagios #{x} file: #{Parser.state[x].path}"
93
78
  end
94
79
 
95
- $nagios[:status].parse
96
- $nagios[:objects].parse
97
-
98
- @status = $nagios[:status].status['hosts']
99
- @objects = $nagios[:objects].objects
100
-
101
- Nagios::BackgroundParser.new
80
+ BackgroundParser.run if BackgroundParser.configured?
102
81
  end
103
82
 
104
83
 
@@ -121,44 +100,21 @@ class Nagira < Sinatra::Base
121
100
  #
122
101
  # @method parse_nagios_files
123
102
  # @overload before("Parse Nagios files")
124
-
125
103
  before do
104
+ Logger.log("BackgroundParser is not running", :warning) if
105
+ BackgroundParser.configured? && BackgroundParser.dead?
126
106
 
127
- if Nagira.settings.start_background_parser
128
- unless $bg.alive?
129
- logger.warn "Background Parser is configured to run, but is not active"
130
- $nagios[:config].parse
131
- $nagios[:status].parse
132
- $nagios[:objects].parse
133
- end
134
- $use_inflight_status ? @status = $nagios[:status_inflight].status['hosts']
135
- : @status = $nagios[:status].status['hosts']
136
- $use_inflight_objects ? @objects = $nagios[:objects_inflight].objects
137
- : @objects = $nagios[:objects].objects
138
- else
139
- $nagios[:config].parse
140
- $nagios[:status].parse
141
- $nagios[:objects].parse
142
- @status = $nagios[:status].status['hosts']
143
- @objects = $nagios[:objects].objects
144
- end
107
+ Parser.parse
145
108
 
109
+ @status = Parser.status['hosts']
110
+ @objects = Parser.objects
146
111
 
147
- ##
148
- # TODO: This stuff breaks XML valid. Will have to wait.
149
- #
150
- # idx = 0
151
- # @status.keys.uniq.each do |hostname|
152
- # @status[idx] = @status[hostname]
153
- # idx += 1
154
- # end
155
112
  #
156
113
  # Add plural keys to use ActiveResource with Nagira
157
114
  #
158
115
  @objects.keys.each do |singular|
159
116
  @objects[singular.to_s.pluralize.to_sym] = @objects[singular]
160
117
  end
161
-
162
118
  end
163
119
 
164
120
  ##
@@ -191,18 +147,22 @@ class Nagira < Sinatra::Base
191
147
  # GET /_objects.json # => :json
192
148
  # GET /_status/_list.yaml # => :yaml
193
149
  #
194
- before do
150
+ before do
195
151
  request.path_info.sub!(/#{settings.format_extensions}/, '')
196
152
  @format = ($1 || settings.format).to_sym
197
153
  content_type "application/#{@format.to_s}"
198
154
  end
199
155
 
156
+ ##
157
+ # @method detect_ar_type
158
+ # @overload before('detect ActiveResource mode')
159
+ #
160
+ # Detect if this a request for ActiveResource PATH
161
+ #
200
162
  before do
201
- request.path_info.sub!(/^(#{Nagira::AR_PREFIX})\//, '/')
202
- @active_resource = $1 ? true : false
163
+ @active_resource = request.path_info =~ %r{^#{Nagira::AR_PREFIX}/}
203
164
  end
204
165
 
205
-
206
166
  ##
207
167
  # @method strip_output_type
208
168
  # @overload before('detect output mode')
@@ -253,7 +213,6 @@ class Nagira < Sinatra::Base
253
213
  end
254
214
  end
255
215
 
256
-
257
216
  ##
258
217
  # @method object_not_found
259
218
  # @overload after("Object not found or bad request")
@@ -273,7 +232,6 @@ class Nagira < Sinatra::Base
273
232
  end
274
233
  end
275
234
 
276
-
277
235
  ##
278
236
  # @method argument_error
279
237
  # @overload after("ArgumentError")
@@ -285,7 +243,6 @@ class Nagira < Sinatra::Base
285
243
  halt [400, @data.send("to_#{@format}") ] if ! @data[:result]
286
244
  end
287
245
 
288
-
289
246
  ##
290
247
  # @method convert_to_active_resource
291
248
  # @overload after("Return Array for ActiveResouce routes")
@@ -314,9 +271,6 @@ class Nagira < Sinatra::Base
314
271
  body( @callback ? "#{@callback.to_s} (#{@data.to_json})" : @data.send("to_#{@format}") )
315
272
  end
316
273
 
317
-
318
-
319
-
320
274
  ##
321
275
  # @method get_api
322
276
  # @overload get(/_api)
@@ -328,7 +282,6 @@ class Nagira < Sinatra::Base
328
282
  nil
329
283
  end
330
284
 
331
-
332
285
  ##
333
286
  # @method get_runtime_config
334
287
  # @overload get(/_runtime)
@@ -342,7 +295,7 @@ class Nagira < Sinatra::Base
342
295
  environment: Nagira.settings.environment,
343
296
  home: ENV['HOME'],
344
297
  user: ENV['LOGNAME'],
345
- nagiosFiles: $nagios.keys.map { |x| { x => $nagios[x].path }}
298
+ nagiosFiles: $nagios.to_h.keys.map { |x| { x => $nagios[x].path }}
346
299
  }
347
300
  }
348
301
  nil
@@ -366,7 +319,6 @@ class Nagira < Sinatra::Base
366
319
  # get "/:resource" do |resource|
367
320
  # respond_with $nagios.status[resource], @format
368
321
  # end
369
-
370
322
  end
371
323
 
372
324
  require "app/put/status"
@@ -18,7 +18,7 @@ class Nagira < Sinatra::Base
18
18
  # Get Nagios configuration hash form parsing main Nagios
19
19
  # configuration file nagios.cfg
20
20
  get "/_config" do
21
- @data = $nagios[:config].configuration
21
+ @data = Parser.config.configuration
22
22
  nil
23
23
  end
24
24
  end
data/app/put.rb CHANGED
@@ -2,12 +2,12 @@ class Nagira < Sinatra::Base
2
2
 
3
3
  # @method parse_input_data
4
4
  # @overload before("Parse PUT request body")
5
- #
5
+ #
6
6
  # Process the data before on each HTTP request.
7
7
  #
8
- # @return [Array] @input Sets @input instance variable.
8
+ # @return [Array] @input Sets @input instance variable.
9
9
  #
10
- before do
10
+ before do
11
11
  if request.put?
12
12
  data = request.body.read
13
13
  @input = case @format
@@ -22,16 +22,16 @@ class Nagira < Sinatra::Base
22
22
  end
23
23
 
24
24
  # Define helpers for put methods
25
- helpers do
25
+ helpers do
26
26
 
27
27
  # Helper to send PUT update to Nagios::ExternalCommands
28
28
  #
29
- # @param [Hash] params
29
+ # @param [Hash] params
30
30
  # @param [Symbol] action Nagios external command name
31
31
  #
32
- # FIXME: This only accepts single service. Modify to use Arrays too
32
+ # FIXME: This only accepts single service. Modify to use Arrays too
33
33
  def put_update action, params
34
- res = $nagios[:commands].write(params.merge({ :action => action }))
34
+ res = Parser.commands.write(params.merge({ :action => action }))
35
35
  { :result => res[:result], :object => res[:data]}
36
36
  end
37
37
  end
@@ -49,5 +49,5 @@ class Nagira < Sinatra::Base
49
49
  def update_host_status params
50
50
  put_update :PROCESS_HOST_CHECK_RESULT, params
51
51
  end
52
-
52
+
53
53
  end
@@ -9,7 +9,6 @@
9
9
  # Exception is ::DEFAULT[:ttl] which is not overriden by environment.rb
10
10
  # and should be changed here.
11
11
 
12
-
13
12
  DEFAULT = {
14
13
 
15
14
  format_extensions: '\.(json|yaml|xml)$', # Regex for available
@@ -41,7 +40,7 @@ DEFAULT = {
41
40
  # this number of seconds. To disable timed parsing, set
42
41
  # ttl to 0 or negative number.
43
42
 
44
- ttl: ENV['NAGIRA_TTL'].to_i || 5,
43
+ ttl: (ENV['NAGIRA_TTL'] && ENV['NAGIRA_TTL'].to_i) || 5,
45
44
 
46
45
  ##
47
46
  # start_background_parser used in Nagios::BackgroundParse class.
@@ -53,7 +52,7 @@ DEFAULT = {
53
52
  # intervals slightly shorter than `ttl` to ensure that data are
54
53
  # always updated. So, `ttl` should be larger than 1.
55
54
  #
56
- start_background_parser: (ENV['NAGIRA_BG_PARSING'] == '1'),
55
+ start_background_parser: (ENV['NAGIRA_BG_PARSING'] != '0'),
57
56
 
58
57
  ##
59
58
  # By default hostname regular expression accepts alpha-numerics,
@@ -91,5 +90,4 @@ configure do
91
90
  end
92
91
  end
93
92
 
94
-
95
93
  end
@@ -1,5 +1,7 @@
1
+ require 'pry'
1
2
  class Nagira < Sinatra::Base
2
3
 
4
+
3
5
  disable :protection
4
6
  enable :logging
5
7
 
@@ -33,7 +35,6 @@ class Nagira < Sinatra::Base
33
35
  set :show_exceptions, false
34
36
  end
35
37
 
36
-
37
38
  # configure :production do
38
39
  # # If your nagios.cfg file is in 'standard' location (in RH and
39
40
  # # Debian it usially installed under /etc/nagios(3)?) you don't need
@@ -9,6 +9,7 @@ require 'json'
9
9
  require 'yaml'
10
10
  require 'sinatra'
11
11
  require 'sinatra/reloader'
12
+ require 'singleton'
12
13
 
13
14
  $: << File.dirname(__FILE__) << File.dirname(File.dirname(__FILE__))
14
15
 
@@ -22,6 +23,11 @@ require "nagira/hostgroup"
22
23
  require "nagira/servicegroup"
23
24
  require "nagira/hostservice"
24
25
 
26
+ require "nagira/background_parse"
27
+ require "nagira/parser"
28
+ require "nagira/simple_logger"
29
+
30
+
25
31
  #
26
32
  # environment file must go after default, some settings override
27
33
  # defaults.
@@ -1,31 +1,123 @@
1
- require 'nagios'
2
-
3
- module Nagios
1
+ class Nagira < Sinatra::Base
4
2
  ##
5
3
  # Background parsing of status.dat file in separate thread. Runs on
6
- # regular intervals slightly shorter than :ttl
4
+ # regular intervals defined by :ttl
7
5
  #
8
6
  class BackgroundParser
7
+ include Singleton
9
8
 
10
- ##
11
- #
12
- # If :ttl is not defined set to 0 and do not run
13
- # background parsing.
14
- #
15
9
  def initialize
16
- interval = [::DEFAULT[:ttl],1].max || nil
17
- $use_inflight_status = false
18
- $use_inflight_objects = false
19
- if interval && ::DEFAULT[:start_background_parser]
20
- puts "[#{Time.now}] Starting background parser thread with interval #{interval} sec"
21
- $bg = Thread.new {
22
- loop {
23
- $use_inflight_status ? $nagios[:status].parse : $nagios[:status_inflight].parse
24
- $use_inflight_status = !$use_inflight_status
25
- sleep interval
26
- } #loop
27
- } # thread
10
+ @use_inflight_flag = false
11
+ end
12
+
13
+ # For large Nagios files there's a significant time required for
14
+ # the parsing, if HTTP request comes during the parsing, data
15
+ # could be missing. To prevent this from happening flag variable
16
+ # defines two sets of the parsed data, which are parsed at
17
+ # different sequential runs of the parser.
18
+ attr_accessor :use_inflight_flag
19
+
20
+ class << self
21
+
22
+ ##
23
+ # Target data structure (i.e. $nagios hash for example) which is
24
+ # updated by BackgroundParser.
25
+ #
26
+ def target
27
+ @target ||= Parser.state
28
+ end
29
+
30
+ ##
31
+ # \@ttl (Fixint, seconds) defines re-parsing interval for the
32
+ # BackgroundParser.
33
+ #
34
+ # Set @@ttl after initialization, to be able to pass
35
+ # configuration variables.
36
+ #
37
+ # @see start=
38
+ #
39
+ # Example:
40
+ # Nagios::BackgroundParser.ttl = ::DEFAULT[:ttl].to_i
41
+ # Nagios::BackgroundParser.start = ::DEFAULT[:start_background_parser]
42
+ # Nagios::BackgroundParser.run
43
+ #
44
+ def ttl= ttl
45
+ @ttl = ttl
28
46
  end
47
+
48
+ ##
49
+ # \@start (Boolean) defines whether BackgroundParser should be
50
+ # started.
51
+ #
52
+ # Set :start variable after initialization, to be able to pass
53
+ # configuration values.
54
+ #
55
+ # @see ttl=
56
+ #
57
+ # Example:
58
+ # Nagios::BackgroundParser.ttl = ::DEFAULT[:ttl].to_i
59
+ # Nagios::BackgroundParser.start = ::DEFAULT[:start_background_parser]
60
+ # Nagios::BackgroundParser.run
61
+ #
62
+ def start= start
63
+ @start = start
64
+ end
65
+
66
+ ##
67
+ # Is BackgroundParser configured to run?
68
+ def configured?
69
+ @ttl > 0 && @start
70
+ end
71
+
72
+ ##
73
+ # Is BG parser thread running
74
+ #
75
+ def alive?
76
+ !@bg.nil? && @bg.alive?
77
+ end
78
+
79
+ ##
80
+ # See alive?
81
+ def dead?
82
+ !alive?
83
+ end
84
+
85
+
86
+ ##
87
+ # Start BG Parser if it's configured to run and TTL is defined
88
+ def run
89
+ if configured? && dead?
90
+
91
+ Logger.log "Starting background parser thread with interval #{@ttl} sec"
92
+
93
+ target.status_inflight = Nagios::Status.new(target[:status].path)
94
+ target.objects_inflight = Nagios::Objects.new(target[:objects].path)
95
+
96
+ Parser.parse [:status_inflight,:objects_inflight]
97
+
98
+ @bg = Thread.new {
99
+ loop {
100
+ target[with_inflight?(:status)].parse
101
+ target[with_inflight?(:objects)].parse
102
+ sleep @ttl
103
+ @use_inflight_flag = !@use_inflight_flag
104
+ }
105
+ }
106
+ end
107
+ end
108
+
109
+ def inflight?
110
+ @use_inflight_flag
111
+ end
112
+ ##
113
+ # Construct file symbol, based on in flight status.
114
+ # @see run
115
+ def with_inflight?(file)
116
+ (inflight? ? "#{file}_inflight" : file).to_sym
117
+ end
118
+
29
119
  end
30
120
  end
31
121
  end
122
+
123
+ # LocalWords: ttl BackgroundParser config param Fixint
@@ -4,8 +4,8 @@ class Nagira < Sinatra::Base
4
4
 
5
5
  def initialize(name)
6
6
  @name = name
7
- @objects = $nagios[:objects].objects
8
- @status = $nagios[:status].status['hosts']
7
+ @objects = Parser.objects
8
+ @status = Parser.status['hosts']
9
9
  @hostgroup = @objects[:hostgroup][name]
10
10
  @data = { }
11
11
  end
@@ -9,7 +9,7 @@ class Nagira < Sinatra::Base
9
9
 
10
10
  def status
11
11
  begin
12
- $nagios[:status]
12
+ Parser
13
13
  .status['hosts'][hostname]['servicestatus'][servicename]
14
14
  rescue NoMethodError
15
15
  { }
@@ -1,7 +1,6 @@
1
1
  module Nagios
2
2
 
3
3
  require 'nagira/timed_parse'
4
- require 'nagira/background_parse'
5
4
 
6
5
  # Extensions to Nagios::Status and Objects classes for use with
7
6
  # Nagira: keep track of file modification times and parse only
@@ -0,0 +1,110 @@
1
+ class Nagira < Sinatra::Base
2
+ # Singleton class, that handles parsing of the Nagios data. This
3
+ # class uses another singleton class BackgroundParser for repeating
4
+ # parsing of the files in background thread.
5
+ #
6
+ # Example usage:
7
+ #
8
+ # Parser.config = < path to nagios.cfg file>
9
+ # Parser.status = < path to status.cfg file>
10
+ # Parser.objects = < path to object_cache file>
11
+ # Parser.commands = < path to the external command execution file >
12
+ #
13
+ class Parser
14
+ include Singleton
15
+
16
+ def initialize
17
+ @state = OpenStruct.new
18
+ end
19
+
20
+ # State structure keep all the Nagios parsed state information for
21
+ # :objects, :status, :config, etc. as well as "inflight" data.
22
+ attr_accessor :state
23
+
24
+ class << self
25
+
26
+ # Detect which half of the data should be returned. There's a
27
+ # pissiblility that during request data are bing parsed, which
28
+ # can result in incomplete or broken data. This ensures, that
29
+ # only data that are not being parsed now returned.
30
+ def inflight?
31
+ BackgroundParser.inflight?
32
+ end
33
+
34
+ ##
35
+ # Construct file symbol, based on in flight status.
36
+ #
37
+ # @see inflight?
38
+ def with_inflight?(file)
39
+ (inflight? ? "#{file}_inflight" : file).to_sym
40
+ end
41
+
42
+ # Return state object
43
+ def state
44
+ instance.state
45
+ end
46
+
47
+ ##
48
+ # If BackgroundParser is not running, then parse files,
49
+ # otherwise do nothing, as the data are already parsed by the
50
+ # BG.
51
+ def parse(files = %i{config objects status})
52
+ return if BackgroundParser.alive?
53
+ files
54
+ .map { |f| state.send(f) }
55
+ .map(&:parse)
56
+ end
57
+
58
+ ##
59
+ # Configuration object of the Nagios and Nagira parser. Create
60
+ # new configuration and parse it at the time of creation.
61
+ #
62
+ def config=(config)
63
+ state.config = Nagios::Config.new(config)
64
+ state.config.parse
65
+ end
66
+
67
+ # Return parsed configuration.
68
+ def config
69
+ state.config
70
+ end
71
+
72
+ # Create new data structure for the host status data
73
+ #
74
+ # @param status_file [String] PATH to the file
75
+ def status=(status_file)
76
+ state.status = Nagios::Status.new(status_file)
77
+ end
78
+
79
+ # Return parsed hosts status. Depending on the inflight flag
80
+ # return either "A" or "B" set of data.
81
+ def status
82
+ state
83
+ .send(with_inflight?(:status))
84
+ .status
85
+ end
86
+
87
+ # Create new data structure for parsed object_cache file
88
+ # information.
89
+ #
90
+ # @param objects_file [String] PATH to the file
91
+ def objects=(objects_file)
92
+ state.objects = Nagios::Objects.new(objects_file)
93
+ end
94
+
95
+ def objects
96
+ state
97
+ .send(with_inflight?(:objects))
98
+ .objects
99
+ end
100
+
101
+ def commands=(commands_file)
102
+ state.commands = Nagios::ExternalCommands.new(commands_file)
103
+ end
104
+
105
+ def commands
106
+ state.commands
107
+ end
108
+ end
109
+ end
110
+ end
@@ -33,7 +33,7 @@ class Nagira < Sinatra::Base
33
33
  attr_reader :name
34
34
 
35
35
  def objects
36
- @objects ||= $nagios[:objects].objects
36
+ @objects ||= Parser.objects
37
37
  end
38
38
 
39
39
  def servicegroup
@@ -0,0 +1,11 @@
1
+ class Nagira < Sinatra::Base
2
+ # Simple logger helper. Use as: Logger.log(message)
3
+ class Logger
4
+ include Singleton
5
+
6
+ # Print log message to stdout with optional warning tag
7
+ def self.log(message, warning=false)
8
+ puts "[#{Time.now}] -- #{ "WARNING:" if warning } #{message}"
9
+ end
10
+ end
11
+ end
@@ -56,7 +56,7 @@ module Nagios
56
56
  end
57
57
 
58
58
  attr_accessor :last_parsed, :parse_interval
59
-
59
+
60
60
  def last_changed
61
61
  @last_changed = File.mtime(@path)
62
62
  end
@@ -65,13 +65,13 @@ module Nagios
65
65
  def changed?
66
66
  self.last_changed > self.last_parsed
67
67
  end
68
-
68
+
69
69
  # Check if:
70
70
  # - file changed?
71
71
  # - was it parsed recently?
72
72
  def need_parsing?
73
73
  changed? && ((Time.now - self.last_parsed) > @parse_interval)
74
74
  end
75
-
75
+
76
76
  end
77
77
  end
@@ -31,9 +31,9 @@ namespace :debug do
31
31
  #
32
32
  # These files from parsed config.
33
33
  #
34
- files << $nagios[:config].path
35
- files << $nagios[:status].path
36
- files << $nagios[:objects].path
34
+ files << Parser.config.path
35
+ files << Parser.status.path
36
+ files << Parser.objects.path
37
37
 
38
38
  open("#{dir}/sherlock.txt", "w") { |f| f.puts os_info }
39
39
  open("#{dir}/permissions.txt", "w") { |f| f.puts permissions }
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe "BackgroundParser" do
5
+
6
+ before {
7
+ Nagios::BackgroundParser.ttl = 1
8
+ Nagios::BackgroundParser.start = true
9
+ }
10
+
11
+ it "is configured" do
12
+ expect(Nagios::BackgroundParser).to be_configured
13
+ end
14
+
15
+ context "after start" do
16
+
17
+ before {
18
+ Nagios::BackgroundParser.run
19
+ sleep 0.1
20
+ }
21
+
22
+ it "is running" do
23
+ expect(Nagios::BackgroundParser).to be_alive
24
+ end
25
+
26
+ end
27
+ end
@@ -42,9 +42,9 @@ end
42
42
 
43
43
  shared_examples_for :write_to_nagios_cmd_file do
44
44
  before (:all) do
45
- File.delete $nagios[:commands].path rescue nil
45
+ File.delete ::Nagira::Parser.commands.path rescue nil
46
46
  end
47
- let (:cmd) { $nagios[:commands].path }
47
+ let (:cmd) { ::Nagira::Parser.commands.path }
48
48
 
49
49
  it "writes to nagios.cmd file" do
50
50
  expect(File).to exist(cmd)
@@ -52,7 +52,7 @@ shared_examples_for :write_to_nagios_cmd_file do
52
52
  end
53
53
 
54
54
  after (:each) do
55
- File.delete $nagios[:commands].path rescue nil
55
+ File.delete ::Nagira::Parser.commands.path rescue nil
56
56
  end
57
57
  end
58
58
 
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmytro Kovalov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -298,30 +298,38 @@ executables:
298
298
  extensions: []
299
299
  extra_rdoc_files: []
300
300
  files:
301
- - bin/nagira
302
301
  - History.md
303
302
  - Rakefile
304
- - version.txt
305
303
  - app/app.rb
306
304
  - app/get/config.rb
307
305
  - app/get/objects.rb
306
+ - app/get/status.rb
308
307
  - app/get/status/hostgroups.rb
309
308
  - app/get/status/servicegroups.rb
310
- - app/get/status.rb
309
+ - app/put.rb
311
310
  - app/put/host.rb
312
311
  - app/put/status.rb
313
- - app/put.rb
312
+ - bin/nagira
313
+ - bin/nagira-setup
314
+ - config/defaults.rb
315
+ - config/environment.rb
316
+ - config/nagira.defaults
317
+ - config/nagira.init_d
318
+ - config/puma.rb
319
+ - lib/nagira.rb
314
320
  - lib/nagira/background_parse.rb
315
321
  - lib/nagira/hostgroup.rb
316
322
  - lib/nagira/hostservice.rb
317
323
  - lib/nagira/nagios.rb
324
+ - lib/nagira/parser.rb
318
325
  - lib/nagira/servicegroup.rb
326
+ - lib/nagira/simple_logger.rb
319
327
  - lib/nagira/timed_parse.rb
320
- - lib/nagira.rb
321
328
  - lib/tasks/config.rake
322
329
  - lib/tasks/debug.rake
323
330
  - lib/tasks/doc.rake
324
331
  - spec/00_configuration_spec.rb
332
+ - spec/01_background_parser.rb
325
333
  - spec/01_data_format/01_nagira_response_spec.rb
326
334
  - spec/01_data_format/02_0_status_spec.rb
327
335
  - spec/01_data_format/02_nagira_data_spec.rb
@@ -337,28 +345,23 @@ files:
337
345
  - spec/put/status_spec.rb
338
346
  - spec/put/support.rb
339
347
  - spec/spec_helper.rb
340
- - config/defaults.rb
341
- - config/environment.rb
342
- - config/nagira.defaults
343
- - config/nagira.init_d
344
- - config/puma.rb
345
348
  - test/benchmark.rb
349
+ - test/data/bad/README
346
350
  - test/data/bad/nagios.cfg
347
351
  - test/data/bad/objects.cache
348
- - test/data/bad/README
349
352
  - test/data/bad/status.dat
350
353
  - test/data/json/GET.txt
354
+ - test/data/json/README.txt
351
355
  - test/data/json/host_check.json
352
356
  - test/data/json/host_check.sh
353
357
  - test/data/json/ping.json
354
358
  - test/data/json/ping_and_http.json
355
359
  - test/data/json/ping_and_http_check.sh
356
360
  - test/data/json/ping_check.sh
357
- - test/data/json/README.txt
358
361
  - test/data/nagios.cfg
359
362
  - test/data/objects.cache
360
363
  - test/data/status.dat
361
- - bin/nagira-setup
364
+ - version.txt
362
365
  homepage: http://dmytro.github.com/nagira
363
366
  licenses:
364
367
  - MIT
@@ -372,7 +375,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
372
375
  requirements:
373
376
  - - '>='
374
377
  - !ruby/object:Gem::Version
375
- version: 1.9.1
378
+ version: 2.0.0
376
379
  required_rubygems_version: !ruby/object:Gem::Requirement
377
380
  requirements:
378
381
  - - '>='
@@ -380,7 +383,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
380
383
  version: '0'
381
384
  requirements: []
382
385
  rubyforge_project:
383
- rubygems_version: 2.0.14
386
+ rubygems_version: 2.4.6
384
387
  signing_key:
385
388
  specification_version: 4
386
389
  summary: 'Nagira : Nagios RESTful API'