Event Hooks: Difference between revisions
No edit summary |
No edit summary |
||
| Line 16: | Line 16: | ||
public abstract void dispatch(Event event) throws Exception; | public abstract void dispatch(Event event) throws Exception; | ||
} | } | ||
</pre> | </pre> | ||
The <code>dispatch()</code> method gets called with every logging/notification event Obsidian encounters. The implementor is responsible for filtering out appropriate events to respond to, and what occurs when an applicable event is encountered. As an example, we've provided a reference implementation of a [http://obsidianscheduler.com/obsidianapi/com/carfey/ops/event/dispatch/SlackEventHook.html Slack notifier], and its source code is available in the Obsidian distribution. | |||
After creating an instance of a class that implements <code>EventHook</code>, you simply need to register it with Obsidian. The example below shows our reference implementation which posts notifications to a Slack channel by using incoming web hooks. | After creating an instance of a class that implements <code>EventHook</code>, you simply need to register it with Obsidian. The example below shows our reference implementation which posts notifications to a Slack channel by using incoming web hooks. | ||
| Line 24: | Line 24: | ||
<pre> | <pre> | ||
EventHook customNotifier = new SlackEventHook("Obsidian Scheduler", "https://hooks.slack.com/services/XXXXXXX/YYYYYYYY/ZZZZZZZZZZ", SlackEventHook.DEFAULT_LEVELS, SlackEventHook.Default_CATEGORIES); | EventHook customNotifier = new SlackEventHook("Obsidian Scheduler", "https://hooks.slack.com/services/XXXXXXX/YYYYYYYY/ZZZZZZZZZZ", SlackEventHook.DEFAULT_LEVELS, SlackEventHook.Default_CATEGORIES); | ||
eventHooks.register(customNotifier); | eventHooks.register(customNotifier); // we will now get notifications in slack for any FATAL, ERROR or WARN events | ||
</pre> | </pre> | ||
Revision as of 17:35, 28 February 2018
Event hooks allow you to extend Obsidian's event notifications to support things like instant messaging, customized logging, etc. This feature was introduced in version 4.5.0.
EventHook Interface
Note: If you need to set up a development environment to create Obsidian event hooks, see the Classpath section.
Implementing custom notifications in Obsidian is as simple as implementing a single interface and calling a method to register it with the scheduler.
The interface you need to implement is the following.
public interface EventHook {
public abstract void dispatch(Event event) throws Exception;
}
The dispatch() method gets called with every logging/notification event Obsidian encounters. The implementor is responsible for filtering out appropriate events to respond to, and what occurs when an applicable event is encountered. As an example, we've provided a reference implementation of a Slack notifier, and its source code is available in the Obsidian distribution.
After creating an instance of a class that implements EventHook, you simply need to register it with Obsidian. The example below shows our reference implementation which posts notifications to a Slack channel by using incoming web hooks.
EventHook customNotifier = new SlackEventHook("Obsidian Scheduler", "https://hooks.slack.com/services/XXXXXXX/YYYYYYYY/ZZZZZZZZZZ", SlackEventHook.DEFAULT_LEVELS, SlackEventHook.Default_CATEGORIES);
eventHooks.register(customNotifier); // we will now get notifications in slack for any FATAL, ERROR or WARN events