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