Class AbstractContentNotifier
- All Implemented Interfaces:
Notifier
- Direct Known Subclasses:
DingTalkNotifier,DiscordNotifier,FeiShuNotifier,HipchatNotifier,LetsChatNotifier,MattermostNotifier,RocketChatNotifier,SlackNotifier,TelegramNotifier,WebexNotifier
This class provides a framework for creating custom notifiers that format notification messages using SpEL templates with access to instance event data. Subclasses must implement two methods:
buildContentModel(InstanceEvent, Instance)- Provide the data model for template evaluationgetDefaultMessage()- Define the default SpEL template string
Usage Example:
public class EmailNotifier extends AbstractContentNotifier {
public EmailNotifier(InstanceRepository repository) {
super(repository);
}
@Override
protected Map<String, Object> getContent(InstanceEvent event, Instance instance) {
var content = super.getContent(event, instance);
content.put("customContent", "Hello, World!");
return content;
}
@Override
protected String getDefaultMessage() {
return "#{name} is #{status} at #{url}";
}
}
The message template can be customized at runtime using setMessage(String).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildContentModel(InstanceEvent event, Instance instance) Provides the data model used for evaluating the message template.protected StringcreateContent(InstanceEvent event, Instance instance) Generates the notification message content by evaluating the SpEL template with event and instance data.protected abstract StringDefines the default SpEL template string used for message generation.voidsetMessage(String message) Methods inherited from class de.codecentric.boot.admin.server.notify.AbstractStatusChangeNotifier
getIgnoreChanges, getLastStatus, notify, setIgnoreChanges, shouldNotify, updateLastStatusMethods inherited from class de.codecentric.boot.admin.server.notify.AbstractEventNotifier
doNotify, isEnabled, setEnabled
-
Constructor Details
-
AbstractContentNotifier
-
-
Method Details
-
getMessage
-
setMessage
-
createContent
Generates the notification message content by evaluating the SpEL template with event and instance data.This method combines the configured message template with the data provided by
buildContentModel(InstanceEvent, Instance)to produce the final notification text.- Parameters:
event- the instance event that triggered the notificationinstance- the instance associated with the event- Returns:
- the evaluated message content as a string
-
buildContentModel
Provides the data model used for evaluating the message template.The returned map contains key-value pairs that can be referenced in the SpEL template using #{key} syntax. For example, if the map contains {"name": "MyApp", "status": "UP"}, the template "#{name} is #{status}" would evaluate to "MyApp is UP".
- Parameters:
event- the instance event containing event-specific datainstance- the instance containing registration and status information- Returns:
- a map of template variables and their values
-
getDefaultMessage
Defines the default SpEL template string used for message generation.The template should use #{key} syntax to reference variables provided by
buildContentModel(InstanceEvent, Instance). This default can be overridden at runtime usingsetMessage(String).- Returns:
- the default SpEL template string (e.g., "#{name} is #{status}")
-