0

Can we have a sample of variables available for redefinition of templates, documentation is scarce on this?

In Class package de.codecentric.boot.admin.notify.MailNotifier I read

private static final String DEFAULT_SUBJECT = "#{application.name} (#{application.id}) is #{to.status}";
private static final String DEFAULT_TEXT = "#{application.name} (#{application.id})\nstatus changed from #{from.status} to #{to.status}\n\n#{application.healthUrl}";

In my specific use case I inherited a bunch of applications which I want to ping or monitor they are alive. I have no control on them but my app depends on them.

My app doesn't fail but may misbehave (important point!).

So I added a bunch of customs HealthIndicator to get them monitored by ping, that work perfectly, and I was very pleased by changing an IP a notification was sent, great!

But there is a but, the message sent let me think than the app was failing, while instead the health indicator was status OUT_OF_SERVICE, unnecessary stress for DevOps.

Come to my question, how can I add some extra variables whereby some carefully crafted SPEL will distinguish an Health indicator message status change than an application status change ie webapp going offline.

Is a dictionary of SBA keywords available to use for redefining for example spring.boot.admin.notify.mail.text Mail notifications configuration option?

I guess this is valid to other notifiers being hipchat, Slack.

Thank you.

dilbertside
  • 309
  • 3
  • 7

2 Answers2

2

The context for evaluating the SpEL expression is the event. Therefore all properties from ClientApplicationEvent (or the corresponding subclass for the event instance (e.g. ClientApplicationStatusChangedEvent)) are available.

If it doesn't suffice you can ship your own subclass of the MailNotifier..

joshiste
  • 2,638
  • 1
  • 14
  • 19
  • Not sure I understand why the need to subclass MailNotifier? That defeats the purpose of defining a [ https://codecentric.github.io/spring-boot-admin/1.4.3/#mail-notifications ] a mail body or subject as described in Table 5, correct? I just want to modify the default value body or subject. However ClientApplicationEvent as context is interesting as to eventually expose more values so it could be used while evaluating the context! Any pointers? Where is triggered/detected the Health Indicator status change? – dilbertside Nov 07 '16 at 16:20
  • you only need to subclass the mail notifier if the given context for the SpEL expression doesn't fit your needs. In case of a status change the context is of type `ClientApplicationStatusChangedEvent` which has `from` and `to` properties holding the old and new status. – joshiste Nov 07 '16 at 16:39
  • Yes agree but the context doesn't hold enough properties to be extracted such as the name of the health indicator for example. It looks like `StatusUpdater.updateStatusForAllApplications` is responsible to publish the health indicator status changes. Wouldn't be possible to have a specific event such as ClientApplicationHealthStatusChangedEvent to handle more properties? – dilbertside Nov 07 '16 at 16:44
  • At the moment the backend doesn't take the health details into account. So this would mean some more changes. – joshiste Nov 07 '16 at 17:15
1

Answer is no, cannot do in current code base without code changes. SBA notification keywords/variables available are the following:

  • application.name
  • application.id
  • application.healthUrl
  • application.managementUrl
  • application.serviceUrl
  • application.statusInfo.status
  • from.status
  • to.status
  • timestamp
  • type

We don't have anything else. However the StatusUpdater.queryStatus looks promising to get some extra data.

dilbertside
  • 309
  • 3
  • 7