-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sensu Handler shim for Sensu 2.0 event data. #190
Merged
majormoses
merged 28 commits into
sensu-plugins:master
from
jspaleta:handler_shim_for_2.0_events
Sep 13, 2018
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
feb1b95
Added event_2to1 method to Utils and --enable-2.0-event option to bas…
d0d531e
cleanup for rubocop
339ead8
cleanup for rubocop
06dcf07
handle case when event['client'] is nil
01fb9e1
Refactor event_2to1 utility function to take optional event argument
c165f1e
Merge pull request #1 from sensu-plugins/master
jspaleta bfa7433
Merge branch 'master' into handler_shim_for_2.0_events
009fb83
fix bad conditional for expected integer attribute
65cc0d7
add test for --enable-2to1-mapping handler argument
92cb685
clean up for rubocop
ac18b2e
fix unreleased changelog entry format
c0f891b
remove unneeded cornercase mapping due to now resolved attribute nami…
40ba5b8
fix for handle 2to1 test
953b1d2
Refactor function name from awkward 2to1 as per pr review
68152d2
return orig_event if already mapped
5be70d9
fix argument to match refactor
a160133
make it possible to set env variable to attempt v2 into v1 mapping au…
fd160df
rubocop fix ups
2a39832
update changelog with more detail on added v2 -> v1 mapping support
6203e84
add support for v2 -> v1 event mapping to mutator class, and update c…
f4a7d68
small fix for rubocop
a6d8b07
remove unneeded confusing unless conditional
b951c11
fix for rubocop
acb27c3
fix for stray comma
0af1f41
refactor state to action mapping to a use a 1:1 hash lookup with a fa…
7ef0723
refactor history handling, save original history as history_v2.
38d5a97
fix for rubocop
21fca96
extend 2to1 test coverage to include history
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env ruby | ||
require 'sensu-handler' | ||
|
||
class Helpers < Sensu::Handler | ||
def handle | ||
puts event_summary | ||
end | ||
|
||
def api_request(*_args) | ||
nil | ||
end | ||
|
||
def stash_exists?(*_args) | ||
nil | ||
end | ||
|
||
def event_exists?(*_args) | ||
true | ||
end | ||
|
||
def event_summary | ||
client_name = @event['client']['name'] | ||
check_name = @event['check']['name'] | ||
source = @event['check']['source'] | ||
output = @event['check']['output'] | ||
total_state_change = @event['check']['total_state_change'] | ||
action = @event['action'] | ||
client_subscribers = @event['client']['subscribers'].join('|') | ||
check_subscribers = @event['client']['subscribers'].join('^') | ||
history = @event['check']['history'].join('') | ||
[client_name, check_name, source, output, total_state_change, action, client_subscribers, check_subscribers, history].join(' : ') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"entity":{"id":"test_entity","subscriptions":["sub1","sub2","sub3"]},"check":{"name":"test_check","output":"test_output","subscriptions":["sub1","sub2","sub3"],"proxy_entity_id":"test_proxy","total_state_change":4,"state":"failing","history":[{"status":0,"executed":0},{"status":1,"executed":1},{"status":2,"executed":2},{"status":3,"executed":3},{"status":0,"executed":4}],"status":0}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'test_helper' | ||
require 'English' | ||
|
||
class TestHandle2to1 < MiniTest::Test | ||
include SensuPluginTestHelper | ||
|
||
def setup | ||
set_script 'external/handle-2to1 --map-v2-event-into-v1' | ||
end | ||
|
||
def test_2to1_enabled | ||
event = JSON.parse(fixture('basic_v2_event.json').read) | ||
expected = "test_entity : test_check : test_proxy : test_output : 4 : create : sub1|sub2|sub3 : sub1^sub2^sub3 : 01230\n" | ||
output = run_script_with_input(JSON.generate(event)) | ||
assert_equal(0, $CHILD_STATUS.exitstatus) | ||
assert_match(expected, output) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env ruby | ||
require 'English' | ||
|
||
require 'test_helper' | ||
|
||
# Simple Heper to test mutator | ||
class TestMutatorHelpers < MiniTest::Test | ||
include SensuPluginTestHelper | ||
def test_base_2to1_mutator | ||
set_script 'external/mutator-trivial --map-v2-event-into-v1' | ||
event = JSON.parse(fixture('basic_v2_event.json').read) | ||
output = run_script_with_input(JSON.generate(event)) | ||
assert_equal(0, $CHILD_STATUS.exitstatus) | ||
assert_equal(event['entity']['id'], JSON.parse(output)['client']['name']) | ||
end | ||
|
||
def test_external_2to1_mutator | ||
set_script 'external/mutator-helpers --map-v2-event-into-v1' | ||
event = JSON.parse(fixture('basic_v2_event.json').read) | ||
output = run_script_with_input(JSON.generate(event)) | ||
assert_equal(0, $CHILD_STATUS.exitstatus) | ||
assert_equal(true, JSON.parse(output)['mutated']) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add attribution for you post acceptance or you can do it prior, either way works.