From b76072223445f0ab1f58d6c6028ae4441a721434 Mon Sep 17 00:00:00 2001 From: Christian Dupuis Date: Thu, 20 Mar 2014 11:05:27 +0100 Subject: [PATCH] Add endpoint command to shell fixex #461 --- .../autoconfigure/ShellProperties.java | 2 ++ .../asciidoc/production-ready-features.adoc | 13 +++----- .../resources/commands/crash/endpoint.groovy | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 spring-boot-starters/spring-boot-starter-shell/src/main/resources/commands/crash/endpoint.groovy diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java index 464a7d74da..e2f9050e94 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java @@ -167,6 +167,8 @@ public class ShellProperties { + "configured method '%s'. Please check your classpath.", finalAuth, this.auth)); } + // Make sure we keep track of final authentication method + this.auth = finalAuth; } /** diff --git a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index ee32455687..855c7520b9 100644 --- a/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -467,13 +467,8 @@ download and install http://www.putty.org/[PuTTY]. :: Spring Boot :: (v{spring-boot-version}) on myhost ---- -Type `help` for a list of commands. Spring boot provides `metrics`, `beans` and -`autoconfig` commands. You can also use the `jmx` command to query endpoint data: - -[indent=0] ----- - jmx find -p org.springframework.boot:type=Endpoint,name=healthEndpoint | jmx get Data ----- +Type `help` for a list of commands. Spring boot provides `metrics`, `beans`, `autoconfig` +and `endpoint` commands. @@ -502,10 +497,10 @@ for details). By default Spring Boot will search for commands in the following l * `classpath*:/commands/**` * `classpath*:/crash/commands/**` -TIP: You can change the search path by settings a `shell.commandpathpatterns` property. +TIP: You can change the search path by settings a `shell.commandPathPatterns` property. Here is a simple ``hello world'' command that could be loaded from -`src/main/resources/commands/Hello.groovy` +`src/main/resources/commands/hello.groovy` [source,groovy,indent=0] ---- diff --git a/spring-boot-starters/spring-boot-starter-shell/src/main/resources/commands/crash/endpoint.groovy b/spring-boot-starters/spring-boot-starter-shell/src/main/resources/commands/crash/endpoint.groovy new file mode 100644 index 0000000000..f918f69ec8 --- /dev/null +++ b/spring-boot-starters/spring-boot-starter-shell/src/main/resources/commands/crash/endpoint.groovy @@ -0,0 +1,33 @@ +package commands + +import org.springframework.boot.actuate.endpoint.Endpoint; + +@Usage("Invoke actuator endpoints") +class endpoint { + + @Usage("List all available and enabled actuator endpoints") + @Command + def list(InvocationContext context) { + + context.attributes['spring.beanfactory'].getBeansOfType(Endpoint.class).each { name, endpoint -> + if (endpoint.isEnabled()) { + out.println name + } + } + "" + } + + @Usage("Invoke provided actuator endpoint") + @Command + def invoke(InvocationContext context, @Usage("The object name pattern") @Required @Argument String name) { + + context.attributes['spring.beanfactory'].getBeansOfType(Endpoint.class).each { n, endpoint -> + if (n.equals(name) && endpoint.isEnabled()) { + out.println endpoint.invoke() + } + } + "" + } + + +} \ No newline at end of file