Search code examples
spring-boot-admin

Spring Boot Admin: example for filtering notifications


I want to use the notification filtering function in Spring Boot Admin (see http://codecentric.github.io/spring-boot-admin/current/#filtering-notifications ) but don't see how the filtering rules mentioned in the documentation can be configured or with what HTTP requests exactly they can be added/removed. Does someone have an example for such a configuration? (e.g. excluding applications with certain name patterns from notification or disabling all notifications; curl command for a HTTP request activating such a rule?)

Example code from the documentation:

@Bean
    public FilteringNotifier filteringNotifier() { 
        CompositeNotifier delegate = new CompositeNotifier(this.otherNotifiers.getIfAvailable(Collections::emptyList));
        return new FilteringNotifier(delegate, this.repository);
    }

This does not seem to configure any specific rules. In https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-servlet I also do not see any code that configures specific filters.

Is this sufficient or is additional configuration code necessary?


Solution

  • I did some further investigation and found out how it works - maybe this helps someone. The REST requests for notification filtering are processed by the following code: NotificationController.java

    From the code, one can see that the following requests are possible:

    # filter notifications for application xxx for the next 10000 milliseconds
    # (ttl is optional)
    curl -d "applicationName=xxx&ttl=10000" -X POST http(s)://.../notifications/filters
    
    # filter notifications for instanceId yyy for the next 10000 milliseconds
    # (ttl is optional)
    curl -d "instanceId=yyy&ttl=10000" -X POST http(s)://.../notifications/filters
    
    # Get all added notification filters with their ids
    curl http(s)://.../notifications/filters
    
    # Delete notification filter with id <id>
    curl -X DELETE http(s)://.../notifications/filters/<id>
    

    Authentication has to be added if necessary. No other changes need to be made to the Spring Boot Admin application for this to work, it is sufficient to register the FilteringNotifier.