Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

oasp/spring-boot-admin-server

Repository files navigation

Spring boot admin Integration with OASP4J

Note

OASP has been superseded by devonfw, the Open Source Standard Software Development Platform for state of the art Cloud Native Micro Service and Multi Platform Rich Web Apps, supported by Capgemini.

Individual products within OASP have been renamed to a corresponding one in devonfw.

For example:

  • OAPS4j → devon4j

  • OASP4js → devon4ng

  • OASP4NET → devon4NET

devonfw® is an exclusive and registered (European Trademark) product of Capgemini. Capgemini reserves all intellectual and industrial property rights over devonfw but publishes it under the Apache License, Version 2 – like OASP- which makes devonfw 100% Open Source. See: https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)

Spring Boot Admin is an application to manage and monitor your Spring Boot Applications.

Configure the Spring boot admin for the OASP4J App.

Setting up Spring boot Admin server

To run the spring boot admin. First, you need to setup admin server. To do this create the spring.io project and follow the below steps.

Add Spring Boot Admin Server and the UI dependency to the pom.xml file.
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server</artifactId>
    <version>1.5.3</version>
</dependency>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server-ui</artifactId>
    <version>1.5.3</version>
</dependency>
Add the Spring Boot Admin Server configuration via adding @EnableAdminServer to your spring boot class.
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootApp{
    public static void main(String[] args) {
        SpringApplication.run(SpringBootAdminApplication.class, args);
    }
}
If you want the login for the sever , then add the login depedency .
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server-ui-login</artifactId>
    <version>1.5.3</version>
</dependency>
Add the properties to the application.properties file.
spring.application.name=Admin-Application
server.port=1111

management.security.enabled=false
security.user.name=admin
security.user.password=admin123
Securing Spring Boot Admin Server

Since there are several approaches on solving authentication and authorization in distributed web applications Spring Boot Admin doesn’t ship a default one. If you include the spring-boot-admin-server-ui-login in your dependencies it will provide a login page and a logout button.

Add the below configuration.

@Configuration
  public static class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
      // Page with login form is served as /login.html and does a POST on /login
      http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll();
      // The UI does a POST on /logout on logout
      http.logout().logoutUrl("/logout");
      // The ui currently doesn't support csrf
      http.csrf().disable();

      // Requests for the login page and the static assets are allowed
      http.authorizeRequests()
          .antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**")
          .permitAll();
      // ... and any other request needs to be authorized
      http.authorizeRequests().antMatchers("/**").authenticated();

      // Enable so that the clients can authenticate via HTTP basic for registering
      http.httpBasic();
    }
  }

Register the client app

Spring boot admin gives the monitoring status of multiple [[ spring.io|http://start.spring.io]] application.These applications are registered as the client application to spring boot admin server.You can register the application with the spring-boot-admin-client or use [[ Spring Cloud Discovery|http://projects.spring.io/spring-cloud/spring-cloud.html]] (e.g. Eureka, Consul, …).

Register with spring-boot-admin-starter-client

Add spring-boot-admin-starter-client dependency to the pom.xml file
<dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-starter-client</artifactId>
      <version>1.5.3</version>
</dependency>
Enable the SBA Client by configuring the URL of the Spring Boot Admin Server
spring.boot.admin.url= http://localhost:8080
management.security.enabled= false

Register with Spring Cloud Discovery

If you already use Spring Cloud Discovery for your applications you don’t need the SBA Client. Just make the Spring Boot Admin Server a DiscoveryClient, the rest is done by our AutoConfiguration.

The following steps are for using Eureka, but other Spring Cloud Discovery implementations are supported as well. There are examples using [[ Consul |https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-consul/]] and [[ Zookeeper |https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-zookeeper/]].

Add spring-cloud-starter-eureka dependency to the pom.xml file
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
Add the Spring Boot Admin Server configuration via adding @EnableDiscoveryClient to your spring boot class
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class SpringBootApp {

  /**
   * Entry point for spring-boot based app
   *
   * @param args - arguments
   */
  public static void main(String[] args) {

    SpringApplication.run(SpringBootApp.class, args);

  }

}
Add the properties to the application.properties file
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8180/eureka}
spring.boot.admin.url=http://localhost:1111
management.security.enabled=false
spring.boot.admin.username=admin
spring.boot.admin.password=admin123
logging.file=target/${spring.application.name}.log

eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

health.config.enabled=true

Loglevel management

For applications using Spring Boot 1.5.x (or later) you can manage loglevels out-of-the-box. For applications using older versions of Spring Boot the loglevel management is only available for Logback. It is accessed via JMX so include Jolokia in your application. In addition you have configure Logback’s JMXConfigurator:

Add dependency.
<dependency>
    <groupId>org.jolokia</groupId>
    <artifactId>jolokia-core</artifactId>
</dependency>
Add the logback-spring.xml file in resorce folder.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<include resource="org/springframework/boot/logging/logback/base.xml"/>
	<jmxConfigurator/>
</configuration>

Notification

Now we will see another feature called notifications from Spring Boot Admin. This will notify the administrators when the application status is DOWN or an application status is coming UP. Spring Boot admin supports the below channels to notify the user.

  • Email Notifications

  • Pagerduty Notifications

  • Hipchat Notifications

  • Slack Notifications

  • Let’s Chat Notifications

Here, we will configure Slack notifications. Add the below properties to the Spring Boot Admin Server’s application.properties file.To enable Slack notifications you need to add an incoming Webhook under custom integrations on your Slack account and configure it appropriately.

spring.boot.admin.notify.slack.enabled=true
spring.boot.admin.notify.slack.username=user123
spring.boot.admin.notify.slack.channel=general
spring.boot.admin.notify.slack.webhook-url=https://hooks.slack.com/services/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
spring.boot.admin.notify.slack.message="#{application.name} (#{application.id}) is #{to.status}"

Integrate Spring boot admin with module

Please follow the below steps to configure the spring boot admin module to OASP4J app.

Spring boot Admin server

Check out the Spring boot Admin server from this repository.

Configure spring boot admin client module to OASP4J sample app

Add the dependency in pom.xml file

  <dependency>
      <groupId>com.capgemini.devonfw.modules</groupId>
      <artifactId>devonfw-springbootadminclient</artifactId>
      <version>2.2.0</version>
  </dependency>

Add the below property to application.properties file and change the values as per the spring boot admin server configuration like admin.url, username, password:

eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8180/eureka}
spring.boot.admin.url=http://localhost:1111
management.security.enabled=false
spring.boot.admin.username=admin
spring.boot.admin.password=admin123
logging.file=target/${spring.application.name}.log

eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

health.config.enabled=true

Releases

No releases published

Packages

No packages published

Languages