Skip to content

Commit 79c850a

Browse files
committed
Add RemindingNotifier
The RemindingNotifier sends periodic notifications using a delegate. It must be added explicitly to the ApplicationContext
1 parent 02f842c commit 79c850a

File tree

16 files changed

+468
-162
lines changed

16 files changed

+468
-162
lines changed

spring-boot-admin-docs/src/main/asciidoc/index.adoc

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Also have a look at the http://projects.spring.io/spring-cloud/spring-cloud.html
103103
<dependency>
104104
<groupId>org.springframework.cloud</groupId>
105105
<artifactId>spring-cloud-starter-eureka</artifactId>
106-
<version>1.0.4.RELEASE</version>
106+
<version>1.0.6.RELEASE</version>
107107
</dependency>
108108
----
109109

@@ -228,7 +228,7 @@ spring.boot.admin.password
228228
| `${spring.application.name}` if set, `"spring-boot-application"` otherwise.
229229

230230
| spring.boot.admin.client.prefer-ip
231-
| Use the ip-address rather then the hostname in the guessed urls. If `server.address` / `management.address` is set they get used otherwise the IP address returned from `InetAddress.getLocalHost()` gets used.
231+
| Use the ip-address rather then the hostname in the guessed urls. If `server.address` / `management.address` is set, it get used. Otherwise the IP address returned from `InetAddress.getLocalHost()` gets used.
232232
| `false`
233233
|===
234234

@@ -332,8 +332,10 @@ public class SpringBootAdminApplication {
332332
| `"spring-boot-admin-event-store"`
333333
|===
334334

335+
=== Notifications ===
336+
335337
[[mail-notifications]]
336-
=== Mail notifications ===
338+
==== Mail notifications ====
337339

338340
Configure a `JavaMailSender` using `spring-boot-starter-mail` and set a recipient.
339341

@@ -385,9 +387,8 @@ spring.boot.admin.notify.mail.to=admin@example.com
385387
| `+++"#{application.name} (#{application.id})\nstatus changed from #{from.status} to #{to.status}\n\n#{application.healthUrl}"+++`
386388
|===
387389

388-
389390
[[pagerduty-notifications]]
390-
=== Pagerduty notifications ===
391+
==== Pagerduty notifications ====
391392
To enable pagerduty notifications you just have to add a generic service to your pagerduty-account and set `spring.boot.admin.notify.pagerduty.service-key` to the service-key you received.
392393

393394
.Pagerduty notifications configuration options
@@ -423,6 +424,36 @@ To enable pagerduty notifications you just have to add a generic service to your
423424
|
424425
|===
425426

427+
[reminder-notifactaions]
428+
==== Reminder notifications ====
429+
To get reminders for down/offline applications you can add a `RemindingNotifier` to your `ApplicationContext`. The `RemindingNotifier` uses another `Notifier` as delegate to send the reminders.
430+
431+
.How to configure reminders
432+
[source,java]
433+
----
434+
@Configuration
435+
public class ReminderConfiguration {
436+
@Autowired
437+
private Notifier notifier;
438+
439+
@Bean
440+
@Primary
441+
public RemindingNotifier remindingNotifier() {
442+
RemindingNotifier remindingNotifier = new RemindingNotifier(notifier);
443+
remindingNotifier.setReminderPeriod(TimeUnit.MINUTES.toMillis(5)); // <1>
444+
return remindingNotifier;
445+
}
446+
447+
@Scheduled(fixedRate = 6000L) // <2>
448+
public void remind() {
449+
remindingNotifier().sendReminders();
450+
}
451+
}
452+
----
453+
<1> The reminders will be sent every 5 minutes.
454+
<2> Schedules sending of due reminders every 60 seconds.
455+
456+
426457
[[faqs]]
427458
== FAQs ==
428459
[qanda]

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/AdminServerImportSelector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ public class AdminServerImportSelector implements DeferredImportSelector {
2828

2929
@Override
3030
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
31-
return new String[] { MailNotifierConfiguration.class.getCanonicalName(),
31+
return new String[] { NotifierConfiguration.class.getCanonicalName(),
3232
HazelcastStoreConfiguration.class.getCanonicalName(),
3333
AdminServerWebConfiguration.class.getCanonicalName(),
3434
DiscoveryClientConfiguration.class.getCanonicalName(),
35-
RevereseZuulProxyConfiguration.class.getCanonicalName(),
36-
PagerdutyNotifierConfiguration.class.getCanonicalName() };
35+
RevereseZuulProxyConfiguration.class.getCanonicalName() };
3736
}
3837

3938
}

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/MailNotifierConfiguration.java

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2013-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package de.codecentric.boot.admin.config;
17+
18+
import org.springframework.beans.factory.annotation.Autowired;
19+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
20+
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
21+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
22+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
24+
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
25+
import org.springframework.boot.context.properties.ConfigurationProperties;
26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.context.annotation.Configuration;
28+
import org.springframework.mail.MailSender;
29+
30+
import de.codecentric.boot.admin.notify.MailNotifier;
31+
import de.codecentric.boot.admin.notify.Notifier;
32+
import de.codecentric.boot.admin.notify.NotifierListener;
33+
import de.codecentric.boot.admin.notify.PagerdutyNotifier;
34+
35+
@Configuration
36+
public class NotifierConfiguration {
37+
38+
@Configuration
39+
@ConditionalOnBean(Notifier.class)
40+
public static class NotifierListenerConfiguration {
41+
@Autowired
42+
public Notifier notifier;
43+
44+
@Bean
45+
@ConditionalOnMissingBean
46+
public NotifierListener notifierListener() {
47+
return new NotifierListener(notifier);
48+
}
49+
}
50+
51+
@Configuration
52+
@ConditionalOnBean(MailSender.class)
53+
@AutoConfigureAfter({ MailSenderAutoConfiguration.class })
54+
@AutoConfigureBefore({ NotifierListenerConfiguration.class })
55+
public static class MailNotifierConfiguration {
56+
@Autowired
57+
private MailSender mailSender;
58+
59+
@Bean
60+
@ConditionalOnMissingBean
61+
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.mail", name = "enabled", matchIfMissing = true)
62+
@ConfigurationProperties("spring.boot.admin.notify.mail")
63+
public MailNotifier mailNotifier() {
64+
return new MailNotifier(mailSender);
65+
}
66+
}
67+
68+
@Configuration
69+
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.pagerduty", name = "service-key")
70+
@AutoConfigureBefore({ NotifierListenerConfiguration.class })
71+
public static class PagerdutyNotifierConfiguration {
72+
@Bean
73+
@ConditionalOnMissingBean
74+
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.pagerduty", name = "enabled", matchIfMissing = true)
75+
@ConfigurationProperties("spring.boot.admin.notify.pagerduty")
76+
public PagerdutyNotifier pagerdutyNotifier() {
77+
return new PagerdutyNotifier();
78+
}
79+
}
80+
}

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/PagerdutyNotifierConfiguration.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/notify/AbstractNotifier.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)