Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2546 from daniel-beck/configurable-admin-monitors
[FIX JENKINS-38301] Add configuration for disabling admin monitors
  • Loading branch information
daniel-beck committed Sep 20, 2016
2 parents 38de41d + 0fc375e commit 123d224
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 1 deletion.
10 changes: 10 additions & 0 deletions core/src/main/java/hudson/PluginManager.java
Expand Up @@ -1950,6 +1950,11 @@ public String getExceptionString() {
@Extension @Symbol("pluginCycleDependencies")
public static final class PluginCycleDependenciesMonitor extends AdministrativeMonitor {

@Override
public String getDisplayName() {
return Messages.PluginManager_PluginCycleDependenciesMonitor_DisplayName();
}

private transient volatile boolean isActive = false;

private transient volatile List<PluginWrapper> pluginsWithCycle;
Expand Down Expand Up @@ -2009,6 +2014,11 @@ public boolean isActivated() {
return !pluginsToBeUpdated.isEmpty();
}

@Override
public String getDisplayName() {
return Messages.PluginManager_PluginUpdateMonitor_DisplayName();
}

/**
* adds a message about a plugin to the manage screen
* @param pluginName the plugins name
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/hudson/PluginWrapper.java
Expand Up @@ -748,6 +748,11 @@ public boolean isActivated() {
return !plugins.isEmpty();
}

@Override
public String getDisplayName() {
return Messages.PluginWrapper_PluginWrapperAdministrativeMonitor_DisplayName();
}

public Collection<PluginWrapper> getPlugins() {
return plugins.values();
}
Expand Down
Expand Up @@ -50,6 +50,11 @@
@Extension @Symbol("nullId")
public class NullIdDescriptorMonitor extends AdministrativeMonitor {

@Override
public String getDisplayName() {
return Messages.NullIdDescriptorMonitor_DisplayName();
}

private final List<Descriptor> problems = new ArrayList<Descriptor>();

@Override
Expand Down
Expand Up @@ -93,5 +93,10 @@ public HttpResponse doAct(@QueryParameter String no) throws IOException {
return new HttpRedirect("https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+says+my+reverse+proxy+setup+is+broken");
}
}

@Override
public String getDisplayName() {
return Messages.ReverseProxySetupMonitor_DisplayName();
}
}

6 changes: 6 additions & 0 deletions core/src/main/java/hudson/diagnosis/TooManyJobsButNoView.java
Expand Up @@ -42,6 +42,12 @@
*/
@Extension @Symbol("tooManyJobsButNoView")
public class TooManyJobsButNoView extends AdministrativeMonitor {

@Override
public String getDisplayName() {
return Messages.TooManyJobsButNoView_DisplayName();
}

public boolean isActivated() {
Jenkins h = Jenkins.getInstance();
return h.getViews().size()==1 && h.getItemMap().size()> THRESHOLD;
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/UpdateCenter.java
Expand Up @@ -986,6 +986,12 @@ public List<FormValidation> updateAllSites() throws InterruptedException, Execut
*/
@Extension @Symbol("coreUpdate")
public static final class CoreUpdateMonitor extends AdministrativeMonitor {

@Override
public String getDisplayName() {
return Messages.UpdateCenter_CoreUpdateMonitor_DisplayName();
}

public boolean isActivated() {
Data data = getData();
return data!=null && data.hasCoreUpdates();
Expand Down
Expand Up @@ -37,6 +37,11 @@
*/
@Extension
public class MonitorMarkedNodeOffline extends AdministrativeMonitor {
@Override
public String getDisplayName() {
return Messages.MonitorMarkedNodeOffline_DisplayName();
}

public boolean active = false;

public boolean isActivated() {
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/triggers/SCMTrigger.java
Expand Up @@ -349,6 +349,12 @@ public FormValidation doCheckPollingThreadCount(@QueryParameter String value) {

@Extension
public static final class AdministrativeMonitorImpl extends AdministrativeMonitor {

@Override
public String getDisplayName() {
return Messages.SCMTrigger_AdministrativeMonitorImpl_DisplayName();
}

private boolean on;

public boolean isActivated() {
Expand Down
Expand Up @@ -40,6 +40,12 @@
@Restricted(NoExternalUse.class)
@Extension @Symbol("completedInitialization")
public class CompletedInitializationMonitor extends AdministrativeMonitor {

@Override
public String getDisplayName() {
return Messages.CompletedInitializationMonitor_DisplayName();
}

@Override
public boolean isActivated() {
final Jenkins instance = Jenkins.getInstance();
Expand Down
Expand Up @@ -20,6 +20,12 @@
*/
@Extension @Symbol("securityIsOff")
public class SecurityIsOffMonitor extends AdministrativeMonitor {

@Override
public String getDisplayName() {
return Messages.SecurityIsOffMonitor_DisplayName();
}

@Override
public boolean isActivated() {
return !Jenkins.getInstance().isUseSecurity();
Expand Down
@@ -0,0 +1,56 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.management;

import hudson.Extension;
import hudson.model.AdministrativeMonitor;
import jenkins.model.GlobalConfiguration;
import net.sf.json.JSONObject;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

@Extension
@Restricted(NoExternalUse.class)
public class AdministrativeMonitorsConfiguration extends GlobalConfiguration {
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
for (AdministrativeMonitor am : AdministrativeMonitor.all()) {
try {
boolean disable = !json.getJSONArray("administrativeMonitor").contains(am.id);
am.disable(disable);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to process form submission for " + am.id, e);
}
}
return true;
}

private static Logger LOGGER = Logger.getLogger(AdministrativeMonitorsConfiguration.class.getName());
}
5 changes: 5 additions & 0 deletions core/src/main/java/jenkins/model/DownloadSettings.java
Expand Up @@ -138,6 +138,11 @@ public DailyCheck() {

@Extension public static final class Warning extends AdministrativeMonitor {

@Override
public String getDisplayName() {
return Messages.DownloadSettings_Warning_DisplayName();
}

@Override public boolean isActivated() {
return DownloadSettings.get().isUseBrowser();
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ public boolean isActivated() {

@Override
public String getDisplayName() {
return "Agent \u2192 Master Access Control";
return Messages.AdminCallableMonitor_DisplayName();
}

// bind this to URL
Expand Down
Expand Up @@ -28,6 +28,11 @@ public boolean isActivated() {
return rule.getMasterKillSwitch() && config.isRelevant();
}

@Override
public String getDisplayName() {
return Messages.MasterKillSwitchWarning_DisplayName();
}

public HttpResponse doAct(@QueryParameter String dismiss) throws IOException {
if(dismiss!=null) {
disable(true);
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/resources/hudson/Messages.properties
Expand Up @@ -61,6 +61,8 @@ PluginManager.UploadPluginsPermission.Description=\
PluginManager.ConfigureUpdateCenterPermission.Description=\
The "configure update center" permission allows a user to \
configure update sites and proxy settings.
PluginManager.PluginCycleDependenciesMonitor.DisplayName=Cyclic Dependencies Detector
PluginManager.PluginUpdateMonitor.DisplayName=Invalid Plugin Configuration

AboutJenkins.DisplayName=About Jenkins
AboutJenkins.Description=See the version and license information.
Expand All @@ -80,4 +82,7 @@ PluginWrapper.disabledAndObsolete={0} v{1} is disabled and older than required.
PluginWrapper.disabled={0} is disabled. To fix, enable it.
PluginWrapper.obsolete={0} v{1} is older than required. To fix, install v{2} or later.
PluginWrapper.obsoleteCore=You must update Jenkins from v{0} to v{1} or later to run this plugin.
PluginWrapper.PluginWrapperAdministrativeMonitor.DisplayName=Plugins Failed To Load

TcpSlaveAgentListener.PingAgentProtocol.displayName=Ping protocol

4 changes: 4 additions & 0 deletions core/src/main/resources/hudson/diagnosis/Messages.properties
Expand Up @@ -3,3 +3,7 @@ MemoryUsageMonitor.TOTAL=Total
OldDataMonitor.Description=Scrub configuration files to remove remnants from old plugins and earlier versions.
OldDataMonitor.DisplayName=Manage Old Data
HudsonHomeDiskUsageMonitor.DisplayName=Disk Usage Monitor

NullIdDescriptorMonitor.DisplayName=Missing Descriptor ID
ReverseProxySetupMonitor.DisplayName=Reverse Proxy Setup
TooManyJobsButNoView.DisplayName=Too Many Jobs Not Organized in Views
2 changes: 2 additions & 0 deletions core/src/main/resources/hudson/model/Messages.properties
Expand Up @@ -272,6 +272,8 @@ UpdateCenter.Status.ConnectionFailed=\
<span class=error>Failed to connect to {0}. \
Perhaps you need to <a href="../pluginManager/advanced">configure HTTP proxy?</a></span>
UpdateCenter.init=Initialing update center
UpdateCenter.CoreUpdateMonitor.DisplayName=Jenkins Update Notification

UpdateCenter.PluginCategory.android=Android Development
UpdateCenter.PluginCategory.builder=Build Tools
UpdateCenter.PluginCategory.buildwrapper=Build Wrappers
Expand Down
Expand Up @@ -32,3 +32,4 @@ SwapSpaceMonitor.DisplayName=Free Swap Space
TemporarySpaceMonitor.DisplayName=Free Temp Space
AbstractNodeMonitorDescriptor.NoDataYet=Not yet
DiskSpaceMonitorDescriptor.DiskSpace.FreeSpaceTooLow=Disk space is too low. Only {0}GB left on {1}.
MonitorMarkedNodeOffline.DisplayName=Node Marked Offline Due to Health Check
Expand Up @@ -30,3 +30,4 @@ TimerTrigger.no_schedules_so_will_never_run=No schedules so will never run
TimerTrigger.TimerTriggerCause.ShortDescription=Started by timer
TimerTrigger.would_last_have_run_at_would_next_run_at=Would last have run at {0}; would next run at {1}.
Trigger.init=Initializing timer for triggers
SCMTrigger.AdministrativeMonitorImpl.DisplayName=Too Many SCM Polling Threads
@@ -0,0 +1,2 @@
CompletedInitializationMonitor.DisplayName=Jenkins Initialization Monitor
SecurityIsOffMonitor.DisplayName=Disabled Security
@@ -0,0 +1,55 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.management.AdministrativeMonitorsConfiguration

import hudson.model.AdministrativeMonitor

f = namespace(lib.FormTagLib)
st = namespace("jelly:stapler")

f.section(title: _("Administrative monitors configuration")) {
f.advanced(title: _("Administrative monitors")) {
f.entry(title: _("Enabled administrative monitors")) {
p(_("blurb"))
table(width: "100%") {
for (AdministrativeMonitor am : AdministrativeMonitor.all()) {
f.block() {
f.checkbox(name: "administrativeMonitor",
title: am.displayName,
checked: am.enabled,
json: am.id);
}
tr() {
td(colspan: "2");
td(class: "setting-description") {
st.include(from: am, page: "description", optional: true);
}
td();
}
}
}
}
}
}
@@ -0,0 +1,5 @@
blurb = Administrative monitors are warnings shown to Jenkins administrators \
about the state of the Jenkins instance. It is generally strongly \
recommended to keep all administrative monitors enabled, but if you are \
not interested in specific warnings, uncheck them here to permanently \
hide them.
2 changes: 2 additions & 0 deletions core/src/main/resources/jenkins/model/Messages.properties
Expand Up @@ -68,3 +68,5 @@ ParameterizedJobMixIn.build_now=Build Now
BlockedBecauseOfBuildInProgress.shortDescription=Build #{0} is already in progress{1}
BlockedBecauseOfBuildInProgress.ETA=\ (ETA:{0})
BuildDiscarderProperty.displayName=Discard old builds

DownloadSettings.Warning.DisplayName=Browser-based metadata download
@@ -0,0 +1,2 @@
AdminCallableMonitor.DisplayName=Rejected Agent \u2192 Master Access Attempt
MasterKillSwitchWarning.DisplayName=Disabled Agent \u2192 Master Access Control

0 comments on commit 123d224

Please sign in to comment.