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 2.0 Readiness: Handler Mapping #189

Open jspaleta opened 6 years ago

jspaleta commented 6 years ago

Problem

Handlers in the plugin collection might not work as expected due to changes in the internal event json object.

It should be possible to provide a mapping from 2.0 back to 1.4 event as a dedicated method to the Handler class, so that anyone making use of the sensu-plugin gem can keep their handlers working through the transition for native 2.0 handling.

Where to place the mapping logic for handlers

Call method in Handler initialize. Maybe also wrap logic with a boolean argument so that handler users will have to explicitly enable remapping if its desired.

When to engage mapping method?

if handler doesn't support 2.0 data natively or if handler was explicitly told to engage mapping via cmdline argument

How can you tell its a 2.0 data packet?

If entity key is populated and client key is not

Mapping so far

This list could change has more testing and reviews are done.

Non-Destructive Mapping 2.0 -> 1.4

These should be save re-mapping actions as they regenerate missing json keys.

  1. copy entity -> client
  2. entity.id -> id
  3. cp entity.subscriptions -> client.subscribers
  4. cp timestamp -> client.timestamp
  5. cp check.subscriptions -> check.subscribers
  6. create check.type
  7. cp check.total_state-change -> check.total_state_change

Destructive Mapping

This changes will cause a break in 2.0 event handling. Not clear if this is needed to keep existing handlers in the collection working.

  1. reformat check.history

Unknown Mapping

Its not clear on first inspection how to repopulate these 1.4 event keys. Not clear if these are needed to get existing handlers in the collection working.

  1. action
  2. last_state_change
  3. silenced
  4. silenced_by
jspaleta commented 6 years ago

PR #190 with prototype shim to fix things up.