opends/resource/schema/02-config.ldif
@@ -1537,6 +1537,12 @@ attributeTypes: ( 1.3.6.1.4.1.26027.1.1.458 NAME 'ds-cfg-return-bind-error-messages' SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 SINGLE-VALUE X-ORIGIN 'OpenDS Directory Server' ) attributeTypes: ( 1.3.6.1.4.1.26027.1.1.459 NAME 'ds-cfg-enabled-alert-type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'OpenDS Directory Server' ) attributeTypes: ( 1.3.6.1.4.1.26027.1.1.460 NAME 'ds-cfg-disabled-alert-type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'OpenDS Directory Server' ) objectClasses: ( 1.3.6.1.4.1.26027.1.2.1 NAME 'ds-cfg-access-control-handler' SUP top STRUCTURAL MUST ( cn $ ds-cfg-acl-handler-class $ ds-cfg-acl-handler-enabled ) @@ -1549,6 +1555,7 @@ objectClasses: ( 1.3.6.1.4.1.26027.1.2.2 NAME 'ds-cfg-alert-handler' SUP top STRUCTURAL MUST ( cn $ ds-cfg-alert-handler-class $ ds-cfg-alert-handler-enabled ) MAY ( ds-cfg-enabled-alert-type $ ds-cfg-disabled-alert-type ) X-ORIGIN 'OpenDS Directory Server' ) objectClasses: ( 1.3.6.1.4.1.26027.1.2.3 NAME 'ds-cfg-attribute-syntax' SUP top STRUCTURAL MUST ( cn $ ds-cfg-syntax-class $ ds-cfg-syntax-enabled ) opends/src/admin/defn/org/opends/server/admin/std/AlertHandlerConfiguration.xml
@@ -85,5 +85,62 @@ </adm:profile> </adm:property> <adm:property name="enabled-alert-type" mandatory="false" multi-valued="true"> <adm:synopsis> Specifies the names of the alert types that are enabled for this alert handler. If there are any values for this attribute, then only alerts with one of the specified types will be allowed (unless they are also included in the disabled alert types). If there are no values for this attribute, then any alerts with a type not included in the list of disabled alert types will be allowed. </adm:synopsis> <adm:default-behavior> <adm:alias> <adm:synopsis> All alerts with types not included in the set of disabled alert types will be allowed. </adm:synopsis> </adm:alias> </adm:default-behavior> <adm:syntax> <adm:string /> </adm:syntax> <adm:profile name="ldap"> <ldap:attribute> <ldap:oid>1.3.6.1.4.1.26027.1.1.457</ldap:oid> <ldap:name>ds-cfg-enabled-alert-type</ldap:name> </ldap:attribute> </adm:profile> </adm:property> <adm:property name="disabled-alert-type" mandatory="false" multi-valued="true"> <adm:synopsis> Specifies the names of the alert types that are disabled for this alert handler. If there are any values for this attribute, then no alerts with any of the specified types will be allowed. If there are no values for this attribute, then only alerts with a type included in the set of enabled alert types will be allowed, or if there are no values for the enabled alert types option then all alert types will be allowed. </adm:synopsis> <adm:default-behavior> <adm:alias> <adm:synopsis> If there is a set of enabled alert types, then only alerts with one of those types will be allowed. Otherwise, all alerts will be allowed. </adm:synopsis> </adm:alias> </adm:default-behavior> <adm:syntax> <adm:string /> </adm:syntax> <adm:profile name="ldap"> <ldap:attribute> <ldap:oid>1.3.6.1.4.1.26027.1.1.458</ldap:oid> <ldap:name>ds-cfg-disabled-alert-type</ldap:name> </ldap:attribute> </adm:profile> </adm:property> </adm:managed-object> opends/src/server/org/opends/server/api/AlertHandler.java
@@ -69,6 +69,15 @@ /** * Retrieves the current configuration for this alert handler. * * @return The current configuration for this alert handler. */ public AlertHandlerCfg getAlertHandlerConfiguration(); /** * Indicates whether the provided configuration is acceptable for * this alert handler. * opends/src/server/org/opends/server/core/DirectoryServer.java
@@ -52,6 +52,7 @@ import org.opends.server.admin.ClassLoaderProvider; import org.opends.server.admin.server.ServerManagementContext; import org.opends.server.admin.std.server.AlertHandlerCfg; import org.opends.server.admin.std.server.AttributeSyntaxCfg; import org.opends.server.admin.std.server.ConnectionHandlerCfg; import org.opends.server.admin.std.server.DirectoryStringAttributeSyntaxCfg; @@ -4551,6 +4552,31 @@ { for (AlertHandler alertHandler : directoryServer.alertHandlers) { AlertHandlerCfg config = alertHandler.getAlertHandlerConfiguration(); Set<String> enabledAlerts = config.getEnabledAlertType(); Set<String> disabledAlerts = config.getDisabledAlertType(); if ((enabledAlerts == null) || enabledAlerts.isEmpty()) { if ((disabledAlerts != null) && disabledAlerts.contains(alertType)) { continue; } } else { if (enabledAlerts.contains(alertType)) { if ((disabledAlerts != null) && disabledAlerts.contains(alertType)) { continue; } } else { continue; } } alertHandler.sendAlertNotification(generator, alertType, alertID, alertMessage); } opends/src/server/org/opends/server/extensions/JMXAlertHandler.java
@@ -48,6 +48,7 @@ import javax.management.NotificationBroadcasterSupport; import javax.management.ObjectName; import org.opends.server.admin.server.ConfigurationChangeListener; import org.opends.server.admin.std.server.AlertHandlerCfg; import org.opends.server.api.AlertGenerator; import org.opends.server.api.AlertHandler; @@ -56,9 +57,11 @@ import org.opends.server.config.JMXMBean; import org.opends.server.core.DirectoryServer; import org.opends.server.loggers.debug.DebugTracer; import org.opends.server.types.ConfigChangeResult; import org.opends.server.types.DebugLogLevel; import org.opends.server.types.DN; import org.opends.server.types.InitializationException; import org.opends.server.types.DebugLogLevel; import org.opends.server.types.ResultCode; import static org.opends.server.loggers.debug.DebugLogger.*; import static org.opends.server.messages.ConfigMessages.*; @@ -74,7 +77,8 @@ */ public class JMXAlertHandler extends NotificationBroadcasterSupport implements AlertHandler<AlertHandlerCfg>, DynamicMBean, implements AlertHandler<AlertHandlerCfg>, ConfigurationChangeListener<AlertHandlerCfg>, DynamicMBean, DirectoryServerMBean { /** @@ -90,6 +94,9 @@ // The current configuration for this alert handler. private AlertHandlerCfg currentConfig; // The sequence number generator used for this alert handler. private AtomicLong sequenceNumber; @@ -157,6 +164,19 @@ throw new InitializationException(msgID, message, e); } } configuration.addChangeListener(this); currentConfig = configuration; } /** * {@inheritDoc} */ public AlertHandlerCfg getAlertHandlerConfiguration() { return currentConfig; } @@ -374,5 +394,29 @@ new MBeanAttributeInfo[0], new MBeanConstructorInfo[0], new MBeanOperationInfo[0], getNotificationInfo()); } /** * {@inheritDoc} */ public boolean isConfigurationChangeAcceptable(AlertHandlerCfg configuration, List<String> unacceptableReasons) { return true; } /** * {@inheritDoc} */ public ConfigChangeResult applyConfigurationChange( AlertHandlerCfg configuration) { currentConfig = configuration; return new ConfigChangeResult(ResultCode.SUCCESS, false); } } opends/src/server/org/opends/server/extensions/SMTPAlertHandler.java
@@ -112,6 +112,16 @@ /** * {@inheritDoc} */ public AlertHandlerCfg getAlertHandlerConfiguration() { return currentConfig; } /** * {@inheritDoc} */ public boolean isConfigurationAcceptable(AlertHandlerCfg configuration, List<String> unacceptableReasons) { opends/tests/unit-tests-testng/resource/config-changes.ldif
@@ -751,3 +751,11 @@ replace: ds-cfg-allow-retrieving-membership ds-cfg-allow-retrieving-membership: true dn: cn=Dummy Alert Handler,cn=Alert Handlers,cn=config changetype: add objectClass: top objectClass: ds-cfg-alert-handler cn: Dummy Alert Handler ds-cfg-alert-handler-class: org.opends.server.extensions.DummyAlertHandler ds-cfg-alert-handler-enabled: true opends/tests/unit-tests-testng/src/server/org/opends/server/api/AlertHandlerTestCase.java
New file @@ -0,0 +1,396 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * trunk/opends/resource/legal-notices/OpenDS.LICENSE * or https://OpenDS.dev.java.net/OpenDS.LICENSE. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, * add the following below this CDDL HEADER, with the fields enclosed * by brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Portions Copyright 2007 Sun Microsystems, Inc. */ package org.opends.server.api; import java.util.LinkedHashMap; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.opends.server.TestCaseUtils; import org.opends.server.api.AlertGenerator; import org.opends.server.core.DirectoryServer; import org.opends.server.extensions.DummyAlertHandler; import org.opends.server.tools.dsconfig.DSConfig; import org.opends.server.types.DN; import static org.testng.Assert.*; /** * A set of generic alert handler test cases. */ public class AlertHandlerTestCase extends APITestCase implements AlertGenerator { /** * The alert ID to use for these tests. */ public static final int ALERT_ID = 12345; /** * The alert type to use for these tests. */ public static final String ALERT_TYPE = "org.opends.test.TestAlert"; /** * The alert description to use for these tests. */ public static final String ALERT_DESCRIPTION = "This is the alert description"; /** * The alert message to use for these tests. */ public static final String ALERT_MESSAGE = "This is the alert message"; /** * Ensures that the Directory Server is running and registers with it as an * alert generator. * * @throws Exception If an unexpected problem occurs. */ @BeforeClass() public void startServer() throws Exception { TestCaseUtils.startServer(); DirectoryServer.registerAlertGenerator(this); } /** * Tests the ability of the alert handler to send an administrative alert * with no special configuration. */ @Test() public void testAlertHandler() { int count = DummyAlertHandler.getAlertCount(); DirectoryServer.sendAlertNotification(this, ALERT_TYPE, ALERT_ID, ALERT_MESSAGE); assertEquals(DummyAlertHandler.getAlertCount(), (count+1)); } /** * Tests alert handler functionality when a given alert is explicitly enabled. */ @Test() public void testEnabledAlert() { String[] args = { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--add", "enabled-alert-type:" + ALERT_TYPE }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); try { int count = DummyAlertHandler.getAlertCount(); DirectoryServer.sendAlertNotification(this, ALERT_TYPE, ALERT_ID, ALERT_MESSAGE); assertEquals(DummyAlertHandler.getAlertCount(), (count+1)); } finally { args = new String[] { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--remove", "enabled-alert-type:" + ALERT_TYPE }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); } } /** * Tests alert handler functionality when a given alert is not explicitly * enabled but others are. */ @Test() public void testNotEnabledAlert() { String[] args = { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--add", "enabled-alert-type:" + ALERT_TYPE + ".bogus" }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); try { int count = DummyAlertHandler.getAlertCount(); DirectoryServer.sendAlertNotification(this, ALERT_TYPE, ALERT_ID, ALERT_MESSAGE); assertEquals(DummyAlertHandler.getAlertCount(), count); } finally { args = new String[] { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--remove", "enabled-alert-type:" + ALERT_TYPE + ".bogus" }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); } } /** * Tests alert handler functionality when a given alert is explicitly * disabled. */ @Test() public void testDisabledAlert() { String[] args = { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--add", "disabled-alert-type:" + ALERT_TYPE }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); try { int count = DummyAlertHandler.getAlertCount(); DirectoryServer.sendAlertNotification(this, ALERT_TYPE, ALERT_ID, ALERT_MESSAGE); assertEquals(DummyAlertHandler.getAlertCount(), count); } finally { args = new String[] { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--remove", "disabled-alert-type:" + ALERT_TYPE }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); } } /** * Tests alert handler functionality when a given alert is not explicitly * disabled but others are. */ @Test() public void testNotDisabledAlert() { String[] args = { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--add", "disabled-alert-type:" + ALERT_TYPE + ".bogus" }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); try { int count = DummyAlertHandler.getAlertCount(); DirectoryServer.sendAlertNotification(this, ALERT_TYPE, ALERT_ID, ALERT_MESSAGE); assertEquals(DummyAlertHandler.getAlertCount(), (count+1)); } finally { args = new String[] { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--remove", "disabled-alert-type:" + ALERT_TYPE + ".bogus" }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); } } /** * Tests alert handler functionality when a given alert is both enabled and * disabled. */ @Test() public void testEnabledAndDisabledAlert() { String[] args = { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--add", "enabled-alert-type:" + ALERT_TYPE, "--add", "disabled-alert-type:" + ALERT_TYPE, }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); try { int count = DummyAlertHandler.getAlertCount(); DirectoryServer.sendAlertNotification(this, ALERT_TYPE, ALERT_ID, ALERT_MESSAGE); assertEquals(DummyAlertHandler.getAlertCount(), count); } finally { args = new String[] { "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-D", "cn=Directory Manager", "-w", "password", "set-alert-handler-prop", "--handler-name", "Dummy Alert Handler", "--remove", "enabled-alert-type:" + ALERT_TYPE, "--remove", "disabled-alert-type:" + ALERT_TYPE, }; assertEquals(DSConfig.main(args, false, System.out, System.err), 0); } } /** * Retrieves the DN of the configuration entry with which this alert * generator is associated. * * @return The DN of the configuration entry with which this alert * generator is associated. */ public DN getComponentEntryDN() { try { return DN.decode("cn=Alert Handler Test Case,cn=config"); } catch (Exception e) { return DN.nullDN(); } } /** * Retrieves the fully-qualified name of the Java class for this * alert generator implementation. * * @return The fully-qualified name of the Java class for this * alert generator implementation. */ public String getClassName() { return getClass().getName(); } /** * Retrieves information about the set of alerts that this generator * may produce. The map returned should be between the notification * type for a particular notification and the human-readable * description for that notification. This alert generator must not * generate any alerts with types that are not contained in this * list. * * @return Information about the set of alerts that this generator * may produce. */ public LinkedHashMap<String,String> getAlerts() { LinkedHashMap<String,String> alerts = new LinkedHashMap<String,String>(); alerts.put(ALERT_TYPE, ALERT_DESCRIPTION); return alerts; } } opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/DummyAlertHandler.java
New file @@ -0,0 +1,160 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * trunk/opends/resource/legal-notices/OpenDS.LICENSE * or https://OpenDS.dev.java.net/OpenDS.LICENSE. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, * add the following below this CDDL HEADER, with the fields enclosed * by brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Portions Copyright 2007 Sun Microsystems, Inc. */ package org.opends.server.extensions; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import org.opends.server.admin.server.ConfigurationChangeListener; import org.opends.server.admin.std.server.AlertHandlerCfg; import org.opends.server.api.AlertGenerator; import org.opends.server.api.AlertHandler; import org.opends.server.config.ConfigException; import org.opends.server.types.ConfigChangeResult; import org.opends.server.types.InitializationException; import org.opends.server.types.ResultCode; /** * This class implements a Directory Server alert handler that only provides a * mechanism to determine the number of times it is invoked. */ public class DummyAlertHandler implements AlertHandler<AlertHandlerCfg>, ConfigurationChangeListener<AlertHandlerCfg> { // The current configuration for this alert handler. private AlertHandlerCfg currentConfig; // The number of times this alert handler has been invoked. private static AtomicInteger alertCount = new AtomicInteger(0); /** * Creates a new instance of this SMTP alert handler. */ public DummyAlertHandler() { super(); // All initialization should be done in the initializeAlertHandler method. } /** * {@inheritDoc} */ public void initializeAlertHandler(AlertHandlerCfg configuration) throws ConfigException, InitializationException { configuration.addChangeListener(this); currentConfig = configuration; } /** * {@inheritDoc} */ public AlertHandlerCfg getAlertHandlerConfiguration() { return currentConfig; } /** * {@inheritDoc} */ public boolean isConfigurationAcceptable(AlertHandlerCfg configuration, List<String> unacceptableReasons) { return true; } /** * {@inheritDoc} */ public void finalizeAlertHandler() { // No action is required. } /** * {@inheritDoc} */ public void sendAlertNotification(AlertGenerator generator, String alertType, int alertID, String alertMessage) { alertCount.incrementAndGet(); } /** * Retrieves the number of times that this alert handler has been invoked. * * @return The number of times that this alert handler has been invoked. */ public static int getAlertCount() { return alertCount.get(); } /** * {@inheritDoc} */ public boolean isConfigurationChangeAcceptable(AlertHandlerCfg configuration, List<String> unacceptableReasons) { return true; } /** * {@inheritDoc} */ public ConfigChangeResult applyConfigurationChange( AlertHandlerCfg configuration) { currentConfig = configuration; return new ConfigChangeResult(ResultCode.SUCCESS, false); } }