sensu-plugins / sensu-plugin

A framework for writing Sensu plugins & handlers with Ruby.
http://sensuapp.org
MIT License
126 stars 117 forks source link

Sensu Handler shim for Sensu 2.0 event data. #190

Closed jspaleta closed 5 years ago

jspaleta commented 6 years ago

Description

Added event_2to1 method to Utils and --enable-2.0-event option to base Handler class. New option makes it possible to use sensu-plugin based handlers with Sensu 2.0 events until handlers provide native 2.0 event support.

Motivation and Context

the event data model changed in Sensu 2.0, so to make it possible to continue to use the community managed handlers a quick mapping back into Sensu 1.4 event JSON representation can be performed.

How Has This Been Tested?

Spot checked with local rebuild of sensu-plugin-logs handler so far.

Types of changes

Checklist:

jspaleta commented 6 years ago

i need to clean things up for rubocop. I just wanted to get the PR out for people to look at asap

teekennedy commented 6 years ago

@jspaleta Could the 2to1 method be refactored and/or moved to its own gem so that it can be used for https://github.com/sensu/sensu-1.x-filter-wrapper ?

jspaleta commented 5 years ago

@cyphus

okay refactoring this now as a utility function. I'm sure it makes sense as a separate gem right now. It definitely feels like something in the scope of sensu-plugin which provides nice base classes for mutators,checks and handlers.

majormoses commented 5 years ago

Could the 2to1 method be refactored and/or moved to its own gem

I agree with @jspaleta that this makes sense to be in the base plugin class as a util method, any GRPC service can depend on the base plugin class.

jspaleta commented 5 years ago

@cyphus I think have it set up now so that if you use this now so that you could for example create a mutator instance from sensu-plugin in the GRPC and call the method like this: event_1.x_json=mutator.event_2to1(event_2.x_json)

irb toy example: require 'sensu-mutator' mutator = Sensu::Mutator.new event = JSON.parse("{}") new_event=mutator.event_2to1(event)

majormoses commented 5 years ago

released: https://rubygems.org/gems/sensu-plugin/versions/2.7.0