hq-log-monitor-server 0.5.1 → 0.6.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.
@@ -0,0 +1,88 @@
1
+ Feature: View and manipulate all events for a service/host combo
2
+
3
+ Background:
4
+
5
+ Given the log monitor server config:
6
+ """
7
+ <log-monitor-server-config>
8
+ <server port="${port}"/>
9
+ <db host="${db-host}" port="${db-port}" name="${db-name}"/>
10
+ <icinga command-file="${command-file}">
11
+ <service name="service" icinga-host="host" icinga-service="service">
12
+ <type name="warning" level="warning"/>
13
+ <type name="critical" level="critical"/>
14
+ </service>
15
+ </icinga>
16
+ <assets bootstrap=""/>
17
+ </log-monitor-server-config>
18
+ """
19
+
20
+ And the time is 10
21
+
22
+ And I submit the following events:
23
+ """
24
+ {
25
+ type: warning,
26
+ source: { class: class, host: host, service: service },
27
+ location: { file: logfile, line: 0 },
28
+ lines: {
29
+ before: [],
30
+ matching: WARNING blah,
31
+ after: [],
32
+ }
33
+ },
34
+ {
35
+ type: warning,
36
+ source: { class: class, host: host, service: service },
37
+ location: { file: logfile, line: 0 },
38
+ lines: {
39
+ before: [],
40
+ matching: WARNING blah,
41
+ after: [],
42
+ }
43
+ },
44
+ """
45
+
46
+ Scenario: View the events
47
+
48
+ When I visit /service-host/service/class/host
49
+
50
+ Then I should see 2 events
51
+ And I should see a button "mark all as seen"
52
+
53
+ And the summary new should be 2
54
+ And the summary total should be 2
55
+ And the summary new for type "warning" should be 2
56
+ And the summary total for type "warning" should be 2
57
+
58
+ And icinga should receive:
59
+ """
60
+ [10] PROCESS_SERVICE_CHECK_RESULT;host;service;0;OK no new events
61
+ [10] PROCESS_SERVICE_CHECK_RESULT;host;service;1;WARNING 1 warning
62
+ [10] PROCESS_SERVICE_CHECK_RESULT;host;service;1;WARNING 2 warning
63
+ """
64
+
65
+ Scenario: Mark all as seen
66
+
67
+ Given the time is 20
68
+
69
+ When I visit /service-host/service/class/host
70
+ And I click "mark all as seen"
71
+
72
+ Then I should see 2 events
73
+ And I should not see a button "mark all as unseen"
74
+
75
+ And the summary new should be 0
76
+ And the summary total should be 2
77
+ And the summary new for type "warning" should be 0
78
+ And the summary total for type "warning" should be 2
79
+
80
+ And icinga should receive:
81
+ """
82
+ [10] PROCESS_SERVICE_CHECK_RESULT;host;service;0;OK no new events
83
+ [10] PROCESS_SERVICE_CHECK_RESULT;host;service;1;WARNING 1 warning
84
+ [10] PROCESS_SERVICE_CHECK_RESULT;host;service;1;WARNING 2 warning
85
+ [20] PROCESS_SERVICE_CHECK_RESULT;host;service;0;OK no new events
86
+ """
87
+
88
+
@@ -49,6 +49,13 @@ Then /^I should see the event$/ do
49
49
 
50
50
  end
51
51
 
52
+ Then /^I should see (\d+) events$/ do
53
+ |count_str|
54
+
55
+ all("#events tbody tr").count.should == count_str.to_i
56
+
57
+ end
58
+
52
59
  Then /^I should see a button "(.*?)"$/ do
53
60
  |label|
54
61
 
@@ -37,6 +37,67 @@ class Script
37
37
 
38
38
  end
39
39
 
40
+ def mark_all_as_seen source
41
+
42
+ # get types
43
+
44
+ query = {
45
+ "source.service" => source["service"],
46
+ "source.class" => source["class"],
47
+ "source.host" => source["host"],
48
+ "status" => "unseen",
49
+ }
50
+
51
+ types =
52
+ @db["events"].distinct "type", query
53
+
54
+ types.each do
55
+ |type|
56
+
57
+ # update events
58
+
59
+ query = {
60
+ "source.service" => source["service"],
61
+ "source.class" => source["class"],
62
+ "source.host" => source["host"],
63
+ "status" => "unseen",
64
+ "type" => type,
65
+ }
66
+
67
+ update = {
68
+ "$set" => {
69
+ "status" => "seen",
70
+ },
71
+ }
72
+
73
+ @db["events"].update query, update, :multi => true
74
+
75
+ event_count =
76
+ @db.get_last_error["n"]
77
+
78
+ # update summaries
79
+
80
+ @db["summaries"].update(
81
+ {
82
+ "_id.service" => source["service"],
83
+ "_id.class" => source["class"],
84
+ "_id.host" => source["host"],
85
+ }, {
86
+ "$inc" => {
87
+ "combined.new" => -event_count,
88
+ "types.#{type}.new" => -event_count,
89
+ }
90
+ }
91
+ )
92
+
93
+ end
94
+
95
+ # notify icinga checks
96
+
97
+ do_checks
98
+
99
+ end
100
+
40
101
  def mark_event_as_unseen event_id
41
102
 
42
103
  event = get_event event_id
@@ -13,7 +13,7 @@ class Script
13
13
 
14
14
  headers["content-type"] = "text/html; charset=utf-8"
15
15
 
16
- html << "<! DOCTYPE html>\n"
16
+ html << "<!DOCTYPE html>\n"
17
17
  html << "<html>\n"
18
18
  html << "<head>\n"
19
19
 
@@ -155,8 +155,8 @@ class Script
155
155
  when /^\/service\/([^\/]+)$/
156
156
  service_page env, :service => $1
157
157
 
158
- when /^\/service\/([^\/]+)\/host\/([^\/]+)$/
159
- service_host_page env, :service => $1, :host => $2
158
+ when /^\/service-host\/([^\/]+)\/([^\/]+)\/([^\/]+)$/
159
+ service_host_page env, :service => $1, :class => $2, :host => $3
160
160
 
161
161
  when /^\/event\/([^\/]+)$/
162
162
  event_page env, :event_id => $1
@@ -5,11 +5,31 @@ class Script
5
5
 
6
6
  def service_host_page env, context
7
7
 
8
+ req = Rack::Request.new env
9
+
10
+ source = {
11
+ "class" => context[:class],
12
+ "host" => context[:host],
13
+ "service" => context[:service],
14
+ }
15
+
16
+ # process form stuff
17
+
18
+ if req.request_method == "POST" \
19
+ && req.params["mark-all-as-seen"]
20
+
21
+ mark_all_as_seen source
22
+
23
+ end
24
+
25
+ # read from database
26
+
8
27
  events =
9
28
  @db["events"]
10
29
  .find({
11
- "source.service" => context[:service],
12
- "source.host" => context[:host],
30
+ "source.class" => source["class"],
31
+ "source.host" => source["host"],
32
+ "source.service" => source["service"],
13
33
  })
14
34
  .to_a
15
35
 
@@ -96,6 +116,8 @@ class Script
96
116
  html << "</thead>\n"
97
117
  html << "<tbody>\n"
98
118
 
119
+ unseen_count = 0
120
+
99
121
  events.each do
100
122
  |event|
101
123
 
@@ -131,11 +153,32 @@ class Script
131
153
 
132
154
  html << "</tr>\n"
133
155
 
156
+ unseen_count += 1 \
157
+ if event["status"] == "unseen"
158
+
134
159
  end
135
160
 
136
161
  html << "</tbody>\n"
137
162
  html << "</table>\n"
138
163
 
164
+ html << "<form method=\"post\">\n"
165
+
166
+ html << "<p>\n"
167
+
168
+ if unseen_count > 0
169
+
170
+ html <<
171
+ "<input " +
172
+ "type=\"submit\" " +
173
+ "name=\"mark-all-as-seen\" " +
174
+ "value=\"mark all as seen\">\n"
175
+
176
+ end
177
+
178
+ html << "</p>\n"
179
+
180
+ html << "</form>\n"
181
+
139
182
  end
140
183
 
141
184
  html << "</div>\n"
@@ -112,8 +112,9 @@ class Script
112
112
 
113
113
  html << "<td class=\"view\">%s</td>\n" % [
114
114
  "<a href=\"%s\">view</a>" % [
115
- "/service/%s/host/%s" % [
115
+ "/service-host/%s/%s/%s" % [
116
116
  esc_ue(summary["_id"]["service"]),
117
+ esc_ue(summary["_id"]["class"]),
117
118
  esc_ue(summary["_id"]["host"]),
118
119
  ],
119
120
  ],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hq-log-monitor-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -236,6 +236,7 @@ files:
236
236
  - lib/hq/log-monitor-server/event-page.rb
237
237
  - lib/hq/log-monitor-server/logic.rb
238
238
  - features/event-page.feature
239
+ - features/service-host-page.feature
239
240
  - features/submit-event.feature
240
241
  - features/overview-page.feature
241
242
  - features/support/steps.rb
@@ -268,6 +269,7 @@ specification_version: 3
268
269
  summary: HQ log monitor server
269
270
  test_files:
270
271
  - features/event-page.feature
272
+ - features/service-host-page.feature
271
273
  - features/submit-event.feature
272
274
  - features/overview-page.feature
273
275
  - features/support/steps.rb