001/*
002 * Copyright 2009-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2015-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds;
037
038
039
040import java.util.Date;
041
042import com.unboundid.ldap.sdk.Entry;
043import com.unboundid.ldap.sdk.ReadOnlyEntry;
044import com.unboundid.util.NotMutable;
045import com.unboundid.util.ThreadSafety;
046import com.unboundid.util.ThreadSafetyLevel;
047
048
049
050/**
051 * This class provides a data structure for representing an administrative entry
052 * as exposed by the alerts backend in the Directory Server.  Alert entries
053 * provide information about warnings, errors, or other significant events that
054 * could impact the availability or function of the Directory Server.
055 * <BR>
056 * <BLOCKQUOTE>
057 *   <B>NOTE:</B>  This class, and other classes within the
058 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
059 *   supported for use against Ping Identity, UnboundID, and
060 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
061 *   for proprietary functionality or for external specifications that are not
062 *   considered stable or mature enough to be guaranteed to work in an
063 *   interoperable way with other types of LDAP servers.
064 * </BLOCKQUOTE>
065 */
066@NotMutable()
067@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
068public final class AlertEntry
069       extends ReadOnlyEntry
070{
071  /**
072   * The name of the structural object class that will be used for entries
073   * containing information about administrative alerts.
074   */
075  public static final String OC_ALERT = "ds-admin-alert";
076
077
078
079  /**
080   * The name of the attribute that contains the fully-qualified name of the
081   * server class that generated the alert notification.
082   */
083  public static final String ATTR_ALERT_GENERATOR = "ds-alert-generator";
084
085
086
087  /**
088   * The name of the attribute that contains the unique ID assigned to the alert
089   * notification.
090   */
091  public static final String ATTR_ALERT_ID = "ds-alert-id";
092
093
094
095  /**
096   * The name of the attribute that contains a message with additional
097   * information about the alert notification.
098   */
099  public static final String ATTR_ALERT_MESSAGE = "ds-alert-message";
100
101
102
103  /**
104   * The name of the attribute that contains the severity of the alert
105   * notification.
106   */
107  public static final String ATTR_ALERT_SEVERITY = "ds-alert-severity";
108
109
110
111  /**
112   * The name of the attribute that contains the time that the alert
113   * notification was generated.
114   */
115  public static final String ATTR_ALERT_TIME = "ds-alert-time";
116
117
118
119  /**
120   * The name of the attribute that contains the name of the alert type.
121   */
122  public static final String ATTR_ALERT_TYPE = "ds-alert-type";
123
124
125
126  /**
127   * The name of the attribute that contains the OID assigned to the alert type.
128   */
129  public static final String ATTR_ALERT_TYPE_OID = "ds-alert-type-oid";
130
131
132
133  /**
134   * The serial version UID for this serializable class.
135   */
136  private static final long serialVersionUID = -2912778595612338699L;
137
138
139
140  // The severity for this alert entry.
141  private final AlertSeverity alertSeverity;
142
143  // The time that the alert notification was generated.
144  private final Date alertTime;
145
146  // The fully-qualified name of the alert generator class.
147  private final String alertGeneratorClass;
148
149  // The unique identifier assigned to the alert notification.
150  private final String alertID;
151
152  // The message for the alert notification.
153  private final String alertMessage;
154
155  // The name of the alert type for the alert notification.
156  private final String alertType;
157
158  // The OID for the alert type.
159  private final String alertTypeOID;
160
161
162
163  /**
164   * Creates a new alert entry from the provided entry.
165   *
166   * @param  entry  The entry from which to create this alert entry.
167   */
168  public AlertEntry(final Entry entry)
169  {
170    super(entry);
171
172    alertGeneratorClass = entry.getAttributeValue(ATTR_ALERT_GENERATOR);
173    alertID             = entry.getAttributeValue(ATTR_ALERT_ID);
174    alertMessage        = entry.getAttributeValue(ATTR_ALERT_MESSAGE);
175    alertType           = entry.getAttributeValue(ATTR_ALERT_TYPE);
176    alertTypeOID        = entry.getAttributeValue(ATTR_ALERT_TYPE_OID);
177
178    alertTime = entry.getAttributeValueAsDate(ATTR_ALERT_TIME);
179
180    final String severityStr = entry.getAttributeValue(ATTR_ALERT_SEVERITY);
181    if (severityStr == null)
182    {
183      alertSeverity = null;
184    }
185    else
186    {
187      alertSeverity = AlertSeverity.forName(severityStr);
188    }
189  }
190
191
192
193  /**
194   * Retrieves the fully-qualified name of the class that generated the alert
195   * notification.
196   *
197   * @return  The fully-qualified name of the class that generated the alert
198   *          notification, or {@code null} if it was not included in the alert
199   *          entry.
200   */
201  public String getAlertGeneratorClass()
202  {
203    return alertGeneratorClass;
204  }
205
206
207
208  /**
209   * Retrieves the unique identifier for the alert notification.
210   *
211   * @return  The unique identifier for the alert notification, or {@code null}
212   *          if it was not included in the alert entry.
213   */
214  public String getAlertID()
215  {
216    return alertID;
217  }
218
219
220
221  /**
222   * Retrieves the message for the alert notification.
223   *
224   * @return  The message for the alert notification, or {@code null} if it was
225   *          not included in the alert entry.
226   */
227  public String getAlertMessage()
228  {
229    return alertMessage;
230  }
231
232
233
234  /**
235   * Retrieves the severity for the alert notification.
236   *
237   * @return  The severity for the alert notification, or {@code null} if it was
238   *          not included in the alert entry, or if it included an unknown
239   *          severity.
240   */
241  public AlertSeverity getAlertSeverity()
242  {
243    return alertSeverity;
244  }
245
246
247
248  /**
249   * Retrieves the time that the alert notification was generated.
250   *
251   * @return  The time that the alert notification was generated, or
252   *          {@code null} if it was not included in the alert entry or if the
253   *          alert time value could not be parsed.
254   */
255  public Date getAlertTime()
256  {
257    return alertTime;
258  }
259
260
261
262  /**
263   * Retrieves the name of the alert type for the alert notification.
264   *
265   * @return  The name of the alert type for the alert notification, or
266   *          {@code null} if it was not included in the alert entry.
267   */
268  public String getAlertType()
269  {
270    return alertType;
271  }
272
273
274
275  /**
276   * Retrieves the OID of the alert type for the alert notification.
277   *
278   * @return  The OID of the alert type for the alert notification, or
279   *          {@code null} if it was not included in the alert entry.
280   */
281  public String getAlertTypeOID()
282  {
283    return alertTypeOID;
284  }
285}