Skip to content

Commit

Permalink
Add RemindingNotifier
Browse files Browse the repository at this point in the history
The RemindingNotifier sends periodic notifications using a delegate. It must be
added explicitly to the ApplicationContext
  • Loading branch information
joshiste committed Feb 28, 2016
1 parent 02f842c commit 79c850a
Show file tree
Hide file tree
Showing 16 changed files with 468 additions and 162 deletions.
41 changes: 36 additions & 5 deletions spring-boot-admin-docs/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Also have a look at the http://projects.spring.io/spring-cloud/spring-cloud.html
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.0.4.RELEASE</version>
<version>1.0.6.RELEASE</version>
</dependency>
----

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

| spring.boot.admin.client.prefer-ip
| 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.
| 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.
| `false`
|===

Expand Down Expand Up @@ -332,8 +332,10 @@ public class SpringBootAdminApplication {
| `"spring-boot-admin-event-store"`
|===

=== Notifications ===

[[mail-notifications]]
=== Mail notifications ===
==== Mail notifications ====

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

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


[[pagerduty-notifications]]
=== Pagerduty notifications ===
==== Pagerduty notifications ====
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.

.Pagerduty notifications configuration options
Expand Down Expand Up @@ -423,6 +424,36 @@ To enable pagerduty notifications you just have to add a generic service to your
|
|===

[reminder-notifactaions]
==== Reminder notifications ====
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.

.How to configure reminders
[source,java]
----
@Configuration
public class ReminderConfiguration {
@Autowired
private Notifier notifier;
@Bean
@Primary
public RemindingNotifier remindingNotifier() {
RemindingNotifier remindingNotifier = new RemindingNotifier(notifier);
remindingNotifier.setReminderPeriod(TimeUnit.MINUTES.toMillis(5)); // <1>
return remindingNotifier;
}
@Scheduled(fixedRate = 6000L) // <2>
public void remind() {
remindingNotifier().sendReminders();
}
}
----
<1> The reminders will be sent every 5 minutes.
<2> Schedules sending of due reminders every 60 seconds.


[[faqs]]
== FAQs ==
[qanda]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ public class AdminServerImportSelector implements DeferredImportSelector {

@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
return new String[] { MailNotifierConfiguration.class.getCanonicalName(),
return new String[] { NotifierConfiguration.class.getCanonicalName(),
HazelcastStoreConfiguration.class.getCanonicalName(),
AdminServerWebConfiguration.class.getCanonicalName(),
DiscoveryClientConfiguration.class.getCanonicalName(),
RevereseZuulProxyConfiguration.class.getCanonicalName(),
PagerdutyNotifierConfiguration.class.getCanonicalName() };
RevereseZuulProxyConfiguration.class.getCanonicalName() };
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.MailSender;

import de.codecentric.boot.admin.notify.MailNotifier;
import de.codecentric.boot.admin.notify.Notifier;
import de.codecentric.boot.admin.notify.NotifierListener;
import de.codecentric.boot.admin.notify.PagerdutyNotifier;

@Configuration
public class NotifierConfiguration {

@Configuration
@ConditionalOnBean(Notifier.class)
public static class NotifierListenerConfiguration {
@Autowired
public Notifier notifier;

@Bean
@ConditionalOnMissingBean
public NotifierListener notifierListener() {
return new NotifierListener(notifier);
}
}

@Configuration
@ConditionalOnBean(MailSender.class)
@AutoConfigureAfter({ MailSenderAutoConfiguration.class })
@AutoConfigureBefore({ NotifierListenerConfiguration.class })
public static class MailNotifierConfiguration {
@Autowired
private MailSender mailSender;

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.mail", name = "enabled", matchIfMissing = true)
@ConfigurationProperties("spring.boot.admin.notify.mail")
public MailNotifier mailNotifier() {
return new MailNotifier(mailSender);
}
}

@Configuration
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.pagerduty", name = "service-key")
@AutoConfigureBefore({ NotifierListenerConfiguration.class })
public static class PagerdutyNotifierConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.pagerduty", name = "enabled", matchIfMissing = true)
@ConfigurationProperties("spring.boot.admin.notify.pagerduty")
public PagerdutyNotifier pagerdutyNotifier() {
return new PagerdutyNotifier();
}
}
}

This file was deleted.

This file was deleted.

0 comments on commit 79c850a

Please sign in to comment.