Package com.carfey.ops.event.dispatch
Class SlackEventHook
- java.lang.Object
-
- com.carfey.ops.event.dispatch.SlackEventHook
-
- All Implemented Interfaces:
EventHook
public class SlackEventHook extends java.lang.Object implements EventHook
A dispatcher that sends notifications via Slack's incoming web hooks.- Since:
- 4.5
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Set<Category>DEFAULT_CATEGORIESstatic java.util.Set<Level>DEFAULT_LEVELSstatic java.lang.StringDEFAULT_USERNAMEstatic java.lang.StringUSER_NAME_CONFIG_KEYstatic java.lang.StringWEBHOOK_URL_CONFIG_KEY
-
Constructor Summary
Constructors Constructor Description SlackEventHook(java.lang.String userName, java.lang.String webhookUrl, java.util.Set<Level> levels, java.util.Set<Category> categories)Creates a new instance with the values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringbuildPayload(Event event)Override to change the JSON payload that is built for a given event.voiddispatch(Event event)This method is invoked for each event, regardless of level or category.booleanequals(java.lang.Object obj)java.util.Set<Category>getCategories()protected java.lang.StringgetLeadingEmoji(Event event)Override to change which icon emoji is put in the payload bybuildPayload(Event).java.util.Set<Level>getLevels()java.lang.StringgetUserName()java.lang.StringgetWebhookUrl()inthashCode()protected voidpost(java.lang.String payload)Override to change the actual call to the Slack endpoint.protected booleanshouldPostEvent(Event event)Override to get custom behaviour on whether to post to Slack for a given event.java.lang.StringtoString()
-
-
-
Field Detail
-
USER_NAME_CONFIG_KEY
public static final java.lang.String USER_NAME_CONFIG_KEY
- See Also:
- Constant Field Values
-
WEBHOOK_URL_CONFIG_KEY
public static final java.lang.String WEBHOOK_URL_CONFIG_KEY
- See Also:
- Constant Field Values
-
DEFAULT_USERNAME
public static final java.lang.String DEFAULT_USERNAME
- See Also:
- Constant Field Values
-
DEFAULT_LEVELS
public static final java.util.Set<Level> DEFAULT_LEVELS
-
DEFAULT_CATEGORIES
public static final java.util.Set<Category> DEFAULT_CATEGORIES
-
-
Constructor Detail
-
SlackEventHook
public SlackEventHook(java.lang.String userName, java.lang.String webhookUrl, java.util.Set<Level> levels, java.util.Set<Category> categories)Creates a new instance with the values. Provided levels and categories restrict which events result in notifications.- Parameters:
userName- non-null user name that will post in the Slack channelwebhookUrl- full web hook URL obtained from Slack (e.g. https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX)levels- restricted levelscategories- restricted categories
-
-
Method Detail
-
dispatch
public void dispatch(Event event) throws java.lang.Exception
Description copied from interface:EventHook
-
post
protected void post(java.lang.String payload) throws java.lang.ExceptionOverride to change the actual call to the Slack endpoint.- Throws:
java.lang.Exception
-
shouldPostEvent
protected boolean shouldPostEvent(Event event)
Override to get custom behaviour on whether to post to Slack for a given event.- Returns:
- true if this event should be posted to Slack
-
buildPayload
protected java.lang.String buildPayload(Event event) throws java.lang.Exception
Override to change the JSON payload that is built for a given event.- Returns:
- non-null JSON payload representation that can be posted to Slack
- Throws:
java.lang.Exception
-
getLeadingEmoji
protected java.lang.String getLeadingEmoji(Event event)
Override to change which icon emoji is put in the payload bybuildPayload(Event).- Returns:
- the emoji name (without ":" prefix and suffix), or null
-
getUserName
public java.lang.String getUserName()
-
getWebhookUrl
public java.lang.String getWebhookUrl()
-
getLevels
public java.util.Set<Level> getLevels()
-
getCategories
public java.util.Set<Category> getCategories()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-