The Event Switchboard in ManageIQ/CloudForms exposes provider events to Automate, allowing automation based on any supported events.
In this example, we're posting Slack messages to a Team channel when Kubernetes events are raised.
Slack Webhook
In order to post messages to Slack, we need a webhook and the associated access token (created via a Slack Button).
Ruby Power
For many integrations, the Gem of choice is Rest-Client or Savon but it is worth checking if there is a specific Gem for the system in question. In this case, there is the slack-ruby-client, although it needs to be installed on the appliance, along with its prerequisite Gli Gem.
#gem install slack-ruby-client
Reading the Event Stream
The present event data is contained within the event_stream object and can be read easily, for example:
event_stream = $evm.root['event_stream']
data = event_stream.full_data
p data[:event_type]
p data[:timestamp]
p data[:message]
Posting a Message
Using the slack-ruby-client, configuring the client and posting an event is simple.
Slack::Web::Client.configure do |config|
config.token = slack_token
end
client = Slack::Web::Client.new
client.chat_postMessage(channel: slack_channel, text: "#{text}", as_user: true)
Here is an example method.
Wire Automate
Finally, we need to call the new method when the event is triggered, for example by updating the schema to invoke it for all events.
Message
Now we can post a message whenever an event of interest is triggered and the resulting message appears in the desired Slack channel.
Other use cases include raising SNMP traps, sending emails or perhaps creating Service Now records.