diff --git a/core/src/main/java/hudson/model/AdministrativeMonitor.java b/core/src/main/java/hudson/model/AdministrativeMonitor.java index 122974dc43..b32d854e6f 100644 --- a/core/src/main/java/hudson/model/AdministrativeMonitor.java +++ b/core/src/main/java/hudson/model/AdministrativeMonitor.java @@ -27,6 +27,12 @@ import hudson.ExtensionPoint; import hudson.triggers.SCMTrigger; import hudson.triggers.TimerTrigger; +import java.util.Set; +import java.io.IOException; + +import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerResponse; + /** * Checks the health of a subsystem of Hudson and if there's something * that requires administrator's attention, notify the administrator. @@ -66,8 +72,7 @@ public abstract class AdministrativeMonitor implements ExtensionPoint { * Human-readable ID of this monitor, which needs to be unique within the system. * *
- * In the future we intend to have some persistable user preference about
- * monitors (such as disabling it or configuring it for e-mail notification),
+ * This ID is used to remember persisted setting for this monitor,
* so the ID should remain consistent beyond the Hudson JVM lifespan.
*/
public final String id;
@@ -76,6 +81,28 @@ public abstract class AdministrativeMonitor implements ExtensionPoint {
this.id = id;
}
+ /**
+ * Mark this monitor as disabled, to prevent this from showing up in the UI.
+ */
+ public void disable(boolean value) throws IOException {
+ Hudson hudson = Hudson.getInstance();
+ Set
+ * This flag implements the ability for the admin to say "no thank you" to the monitor that
+ * he wants to ignore.
+ */
+ public boolean isEnabled() {
+ return !Hudson.getInstance().disabledAdministrativeMonitors.contains(id);
+ }
+
/**
* Returns true if this monitor is activated and
* wants to produce a warning message.
@@ -85,4 +112,13 @@ public abstract class AdministrativeMonitor implements ExtensionPoint {
* so it should run efficiently.
*/
public abstract boolean isActivated();
+
+ /**
+ * URL binding to disable this monitor.
+ */
+ public void doDisable(StaplerRequest req, StaplerResponse rsp) throws IOException {
+ Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
+ disable(true);
+ rsp.sendRedirect2(req.getContextPath()+"/manage");
+ }
}
diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java
index 2d36dcada3..be8d47ba44 100644
--- a/core/src/main/java/hudson/model/Hudson.java
+++ b/core/src/main/java/hudson/model/Hudson.java
@@ -173,6 +173,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
@@ -392,6 +393,8 @@ public final class Hudson extends AbstractModelObject implements ItemGroup