nagios_parser 1.0.0 → 1.1.0

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.
data/CHANGES.md ADDED
@@ -0,0 +1,9 @@
1
+ nagios_parser - ChangeLog
2
+ =========================
3
+
4
+ # next
5
+ * Remove hardcoded status types to make the parser less strict.
6
+ * More Nagios 2.x/3.x status types. (mariussturm)
7
+
8
+ # 1.0.0
9
+ * Initial release
@@ -12,7 +12,7 @@ module NagiosParser
12
12
  module Status
13
13
  class Parser < Racc::Parser
14
14
 
15
- module_eval(<<'...end parser.y/module_eval...', 'parser.y', 39)
15
+ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 35)
16
16
 
17
17
  def create_token(string)
18
18
  result = []
@@ -26,7 +26,7 @@ def create_token(string)
26
26
  when scanner.scan(/#[^\n]*/)
27
27
  # ignore comments
28
28
  when (!inside and match = scanner.scan(/\w+/))
29
- result << [match, match]
29
+ result << [:TYPE, match]
30
30
  when match = scanner.scan(/\{/)
31
31
  inside = true
32
32
  result << [:OPEN, nil]
@@ -67,74 +67,55 @@ end
67
67
  ##### State transition tables begin ###
68
68
 
69
69
  racc_action_table = [
70
- 11, 19, 15, 13, 15, 18, 6, 7, 8, 9,
71
- 10, 1, 2, 6, 7, 8, 9, 10, 1, 2,
72
- 14 ]
70
+ 5, 8, 1, 13, 8, 4, 10, 11, 1 ]
73
71
 
74
72
  racc_action_check = [
75
- 3, 16, 16, 5, 13, 15, 3, 3, 3, 3,
76
- 3, 3, 3, 0, 0, 0, 0, 0, 0, 0,
77
- 11 ]
73
+ 2, 4, 2, 9, 9, 1, 5, 8, 0 ]
78
74
 
79
75
  racc_action_pointer = [
80
- 7, nil, nil, 0, nil, 1, nil, nil, nil, nil,
81
- nil, 20, nil, 0, nil, 0, -2, nil, nil, nil,
82
- nil ]
76
+ 6, 2, 0, nil, -4, 6, nil, nil, 1, -1,
77
+ nil, nil, nil, nil ]
83
78
 
84
79
  racc_action_default = [
85
- -15, -9, -10, -15, -1, -15, -4, -5, -6, -7,
86
- -8, -15, -2, -15, 21, -13, -15, -11, -14, -3,
87
- -12 ]
80
+ -8, -8, -8, -1, -8, -8, -2, -4, -6, -8,
81
+ 14, -7, -5, -3 ]
88
82
 
89
83
  racc_goto_table = [
90
- 17, 4, 16, 20, 12, 3 ]
84
+ 7, 3, 9, 6, 2, 12 ]
91
85
 
92
86
  racc_goto_check = [
93
- 5, 2, 4, 5, 2, 1 ]
87
+ 4, 2, 3, 2, 1, 4 ]
94
88
 
95
89
  racc_goto_pointer = [
96
- nil, 5, 1, nil, -11, -13 ]
90
+ nil, 4, 1, -2, -4 ]
97
91
 
98
92
  racc_goto_default = [
99
- nil, nil, nil, 5, nil, nil ]
93
+ nil, nil, nil, nil, nil ]
100
94
 
101
95
  racc_reduce_table = [
102
96
  0, 0, :racc_error,
103
- 1, 14, :_reduce_none,
104
- 2, 14, :_reduce_none,
105
- 4, 15, :_reduce_3,
106
- 1, 16, :_reduce_none,
107
- 1, 16, :_reduce_none,
108
- 1, 16, :_reduce_none,
109
- 1, 16, :_reduce_none,
110
- 1, 16, :_reduce_none,
111
- 1, 16, :_reduce_none,
112
- 1, 16, :_reduce_none,
113
- 1, 17, :_reduce_none,
114
- 2, 17, :_reduce_12,
115
- 1, 18, :_reduce_13,
116
- 2, 18, :_reduce_14 ]
117
-
118
- racc_reduce_n = 15
119
-
120
- racc_shift_n = 21
97
+ 1, 8, :_reduce_none,
98
+ 2, 8, :_reduce_none,
99
+ 4, 9, :_reduce_3,
100
+ 1, 10, :_reduce_none,
101
+ 2, 10, :_reduce_5,
102
+ 1, 11, :_reduce_6,
103
+ 2, 11, :_reduce_7 ]
104
+
105
+ racc_reduce_n = 8
106
+
107
+ racc_shift_n = 14
121
108
 
122
109
  racc_token_table = {
123
110
  false => 0,
124
111
  :error => 1,
125
- :OPEN => 2,
126
- :CLOSE => 3,
127
- :KEY => 4,
128
- :VALUE => 5,
129
- "hostcomment" => 6,
130
- "servicestatus" => 7,
131
- "info" => 8,
132
- "programstatus" => 9,
133
- "hoststatus" => 10,
134
- "contactstatus" => 11,
135
- "servicecomment" => 12 }
136
-
137
- racc_nt_base = 13
112
+ :TYPE => 2,
113
+ :OPEN => 3,
114
+ :CLOSE => 4,
115
+ :KEY => 5,
116
+ :VALUE => 6 }
117
+
118
+ racc_nt_base = 7
138
119
 
139
120
  racc_use_result_var = true
140
121
 
@@ -157,21 +138,14 @@ Racc_arg = [
157
138
  Racc_token_to_s_table = [
158
139
  "$end",
159
140
  "error",
141
+ "TYPE",
160
142
  "OPEN",
161
143
  "CLOSE",
162
144
  "KEY",
163
145
  "VALUE",
164
- "\"hostcomment\"",
165
- "\"servicestatus\"",
166
- "\"info\"",
167
- "\"programstatus\"",
168
- "\"hoststatus\"",
169
- "\"contactstatus\"",
170
- "\"servicecomment\"",
171
146
  "$start",
172
147
  "types",
173
148
  "type",
174
- "type_names",
175
149
  "assignments",
176
150
  "assignment" ]
177
151
 
@@ -196,22 +170,8 @@ module_eval(<<'.,.,', 'parser.y', 11)
196
170
 
197
171
  # reduce 4 omitted
198
172
 
199
- # reduce 5 omitted
200
-
201
- # reduce 6 omitted
202
-
203
- # reduce 7 omitted
204
-
205
- # reduce 8 omitted
206
-
207
- # reduce 9 omitted
208
-
209
- # reduce 10 omitted
210
-
211
- # reduce 11 omitted
212
-
213
- module_eval(<<'.,.,', 'parser.y', 22)
214
- def _reduce_12(val, _values, result)
173
+ module_eval(<<'.,.,', 'parser.y', 18)
174
+ def _reduce_5(val, _values, result)
215
175
  val[1].each do |key, value|
216
176
  val[0][key] = value
217
177
  end
@@ -221,15 +181,15 @@ module_eval(<<'.,.,', 'parser.y', 22)
221
181
  end
222
182
  .,.,
223
183
 
224
- module_eval(<<'.,.,', 'parser.y', 29)
225
- def _reduce_13(val, _values, result)
184
+ module_eval(<<'.,.,', 'parser.y', 25)
185
+ def _reduce_6(val, _values, result)
226
186
  result = {val[0] => nil}
227
187
  result
228
188
  end
229
189
  .,.,
230
190
 
231
- module_eval(<<'.,.,', 'parser.y', 30)
232
- def _reduce_14(val, _values, result)
191
+ module_eval(<<'.,.,', 'parser.y', 26)
192
+ def _reduce_7(val, _values, result)
233
193
  result = {val[0] => val[1]}
234
194
  result
235
195
  end
@@ -1,6 +1,6 @@
1
1
  class NagiosParser::Status::Parser
2
2
  token
3
- OPEN CLOSE KEY VALUE
3
+ TYPE OPEN CLOSE KEY VALUE
4
4
 
5
5
  rule
6
6
  types
@@ -8,15 +8,11 @@ class NagiosParser::Status::Parser
8
8
  | types type
9
9
  ;
10
10
  type
11
- : type_names OPEN assignments CLOSE {
11
+ : TYPE OPEN assignments CLOSE {
12
12
  @result[val[0]] ||= []
13
13
  @result[val[0]] << val[2]
14
14
  }
15
15
  ;
16
- type_names
17
- : 'hostcomment' | 'servicestatus' | 'info' | 'programstatus'
18
- | 'hoststatus' | 'contactstatus' | 'servicecomment'
19
- ;
20
16
  assignments
21
17
  : assignment
22
18
  | assignments assignment {
@@ -49,7 +45,7 @@ def create_token(string)
49
45
  when scanner.scan(/#[^\n]*/)
50
46
  # ignore comments
51
47
  when (!inside and match = scanner.scan(/\w+/))
52
- result << [match, match]
48
+ result << [:TYPE, match]
53
49
  when match = scanner.scan(/\{/)
54
50
  inside = true
55
51
  result << [:OPEN, nil]
@@ -1,3 +1,3 @@
1
1
  module NagiosParser
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -10,10 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["bernd@tuneafish.de"]
11
11
  s.homepage = "http://rubygems.org/gems/nagios_parser"
12
12
  s.summary = %q{parser lib for parsing Nagios status and config files}
13
- s.description = %q{
14
- The nagios_parser gem provides parsers for Nagios config
15
- and status files.
16
- }
13
+ s.description = %q{The nagios_parser gem provides parsers for Nagios config and status files.}
17
14
 
18
15
  #s.rubyforge_project = "nagios_parser"
19
16
 
@@ -5,7 +5,7 @@ describe NagiosParser::Object::Parser do
5
5
  let(:parser) { NagiosParser::Object::Parser.new }
6
6
 
7
7
  describe ".parse" do
8
- it "returns a hash of status types" do
8
+ it "returns a hash of object definitions" do
9
9
  data = parser.parse('define host { host_name foo }')
10
10
  data['host'].first['host_name'].should == 'foo'
11
11
  end
@@ -58,7 +58,7 @@ describe NagiosParser::Object::Parser do
58
58
 
59
59
  describe "#parse" do
60
60
  context "with a valid string" do
61
- it "returns a hash of status types" do
61
+ it "returns a hash of object definitions" do
62
62
  string = <<-RUBY
63
63
  define host {
64
64
  host_name foo.example.com
@@ -72,19 +72,21 @@ describe NagiosParser::Object::Parser do
72
72
  end
73
73
  end
74
74
 
75
- context "with an invalid status type" do
76
- it "will raise an exception" do
77
- expect {
78
- parser.parse('FooBar { info test }')
79
- }.to raise_error
75
+ context "with an invalid object definition" do
76
+ describe "example: FooBar { info test }" do
77
+ it "will raise an exception" do
78
+ expect {
79
+ parser.parse('FooBar { info test }')
80
+ }.to raise_error
81
+ end
80
82
  end
81
- end
82
83
 
83
- context "with invalid status data" do
84
- it "will raise an exception" do
85
- expect {
86
- parser.parse('define host { =test }')
87
- }.to raise_error
84
+ describe "example: define host { =test }" do
85
+ it "will raise an exception" do
86
+ expect {
87
+ parser.parse('define host { =test }')
88
+ }.to raise_error
89
+ end
88
90
  end
89
91
  end
90
92
  end
@@ -31,7 +31,7 @@ describe NagiosParser::Status::Parser do
31
31
  RUBY
32
32
 
33
33
  parser.create_token(string).should == [
34
- ['hoststatus', 'hoststatus'],
34
+ [:TYPE, 'hoststatus'],
35
35
  [:OPEN, nil],
36
36
  [:KEY, 'bar'], [:VALUE, 'baz'],
37
37
  [:KEY, 'hello'], [:VALUE, 'world'],
@@ -39,11 +39,11 @@ describe NagiosParser::Status::Parser do
39
39
  [:KEY, 'foo'], [:VALUE, 'bar baz hello world'],
40
40
  [:KEY, 'eek'], [:VALUE, 1],
41
41
  [:CLOSE, nil],
42
- ['info', 'info'],
42
+ [:TYPE, 'info'],
43
43
  [:OPEN, nil],
44
44
  [:KEY, 'version'], [:VALUE, '3.2.0'],
45
45
  [:CLOSE, nil],
46
- ['programstatus', 'programstatus'],
46
+ [:TYPE, 'programstatus'],
47
47
  [:OPEN, nil],
48
48
  [:KEY, 'last_command_check'], [:VALUE, 1291408262],
49
49
  [:KEY, 'global_service_event_handler'],
@@ -72,20 +72,17 @@ describe NagiosParser::Status::Parser do
72
72
  version = 1
73
73
  }
74
74
  info { version=3.2.0 }
75
+
76
+ program {
77
+ version=2.x.x
78
+ }
75
79
  RUBY
76
80
 
77
81
  data = parser.parse(string)
78
82
  data['info'].first['version'].should == '3.2.0'
79
83
  data['hoststatus'].first['bar'].should == 'baz'
80
84
  data['hoststatus'].first['version'].should == 1
81
- end
82
- end
83
-
84
- context "with an invalid status type" do
85
- it "will raise an exception" do
86
- expect {
87
- parser.parse('FooBar { info=test }')
88
- }.to raise_error
85
+ data['program'].first['version'].should == '2.x.x'
89
86
  end
90
87
  end
91
88
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagios_parser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: 19
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bernd Ahlers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-16 00:00:00 +01:00
18
+ date: 2011-01-09 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -60,7 +60,7 @@ dependencies:
60
60
  version: "0"
61
61
  type: :development
62
62
  version_requirements: *id003
63
- description: "\n The nagios_parser gem provides parsers for Nagios config\n and status files.\n "
63
+ description: The nagios_parser gem provides parsers for Nagios config and status files.
64
64
  email:
65
65
  - bernd@tuneafish.de
66
66
  executables: []
@@ -71,6 +71,7 @@ extra_rdoc_files: []
71
71
 
72
72
  files:
73
73
  - .gitignore
74
+ - CHANGES.md
74
75
  - Gemfile
75
76
  - LICENSE
76
77
  - README.md
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  requirements: []
116
117
 
117
118
  rubyforge_project:
118
- rubygems_version: 1.3.7
119
+ rubygems_version: 1.4.2
119
120
  signing_key:
120
121
  specification_version: 3
121
122
  summary: parser lib for parsing Nagios status and config files