In my previous post, I explained about how to monitor spring boot application with spring boot admin server. In today’s post I will explain about how we can send alert notifcation from spring boot admin server if any application goes down/up.
Spring boot admin server supports multiple notification mechanism as below:
In today’s tutorial I will cover, how to send mail notifcation with spring boot admin server. To read into more detail follow this.
Let’s start with the implemenation.
Changes in admin server
Add following dependency in pom.xml:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency>
After adding this dependency, it will enable mail notification for the project. Now add following properties in application.properties file:
server.port=9001 ## Host for the email server spring.mail.host=smtp.gmail.com ## Email server port spring.mail.port = 587 ## Comma separated list of email ids to which email notification should be sent firstname.lastname@example.org ## Whether enable email notification or not spring.boot.admin.notify.mail.enabled=true # Username of the email email@example.com ## Password of the sender's email spring.mail.password=xxxx ## Protocal for the email server spring.mail.protocol=smtp ## Whether email connection has to test on application startup or not spring.mail.test-connection=true spring.mail.properties.mail.smtp.starttls.enable=true
Just start the admin server and register a client application, created in previous post, with admin server and then close the client application. If everythings goes well it will send an email of application down status according to the email configuration as explained in following demo video:
As you have seen in above video, when I stop my client application then admin server automatically sends an email to my configured email id.
That’s all about how to send mail notification from spring boot admin server.