/// <summary>
        /// Remove and delete a monitoring alarm by ID.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="entityId">The entity ID. This is obtained from <see cref="Entity.Id">Entity.Id</see>.</param>
        /// <param name="alarmId">The alarm ID. This is obtained from <see cref="Alarm.Id">Alarm.Id</see>.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="alarmId"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-alarms.html#service-alarms-delete">Remove Alarm (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static void RemoveAlarm(this IMonitoringService service, EntityId entityId, AlarmId alarmId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.RemoveAlarmAsync(entityId, alarmId, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Gets a collection of monitoring entities.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="entityId">The entity ID. This is obtained from <see cref="Entity.Id">Entity.Id</see>.</param>
        /// <param name="marker">A marker identifying the next page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>, and is obtained from <see cref="ReadOnlyCollectionPage{T, TMarker}.NextMarker"/>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">The maximum number of items to include in a single page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <returns>
        /// A <see cref="ReadOnlyCollectionPage{T, TMarker}"/> object containing the page
        /// of results and its associated pagination metadata.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="entityId"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-alarms.html#service-alarms-list">List Alarms (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">Paginated Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage<Alarm, AlarmId> ListAlarms(this IMonitoringService service, EntityId entityId, AlarmId marker, int? limit)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListAlarmsAsync(entityId, marker, limit, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Gets a collection of monitoring alarm notification history items.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="entityId">The entity ID. This is obtained from <see cref="Entity.Id">Entity.Id</see>.</param>
        /// <param name="alarmId">The alarm ID. This is obtained from <see cref="Alarm.Id">Alarm.Id</see>.</param>
        /// <param name="checkId">The check ID. This is obtained from <see cref="Check.Id">Check.Id</see>.</param>
        /// <param name="marker">A marker identifying the next page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>, and is obtained from <see cref="ReadOnlyCollectionPage{T, TMarker}.NextMarker"/>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">The maximum number of items to include in a single page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <param name="from">The beginning timestamp of the items to include in the collection. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-time-series-collections.html">time series collections</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <param name="to">The ending timestamp of the items to include in the collection. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-time-series-collections.html">time series collections</see>. If the value is <see langword="null"/>, the current time is used.</param>
        /// <returns>
        /// A <see cref="ReadOnlyCollectionPage{T, TMarker}"/> object containing the page
        /// of results and its associated pagination metadata.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="alarmId"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="checkId"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">If <paramref name="to"/> occurs before <paramref name="from"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="limit"/> is less than or equal to 0.
        /// <para>-or-</para>
        /// <para>If <paramref name="from"/> represents a date before January 1, 1970 UTC.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="to"/> represents a date before January 1, 1970 UTC.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-alarm-notification-history.html#service-alarm-notification-history-list">List Alarm Notification History (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">Paginated Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-time-series-collections.html">Time Series Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage<AlarmNotificationHistoryItem, AlarmNotificationHistoryItemId> ListAlarmNotificationHistory(this IMonitoringService service, EntityId entityId, AlarmId alarmId, CheckId checkId, AlarmNotificationHistoryItemId marker, int? limit, DateTimeOffset? from, DateTimeOffset? to)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListAlarmNotificationHistoryAsync(entityId, alarmId, checkId, marker, limit, from, to, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Gets a monitoring alarm notification history item by ID.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="entityId">The entity ID. This is obtained from <see cref="Entity.Id">Entity.Id</see>.</param>
        /// <param name="alarmId">The alarm ID. This is obtained from <see cref="Alarm.Id">Alarm.Id</see>.</param>
        /// <param name="checkId">The check ID. This is obtained from <see cref="Check.Id">Check.Id</see>.</param>
        /// <param name="alarmNotificationHistoryItemId">The alarm notification history item ID. This is obtained from <see cref="AlarmNotificationHistoryItem.Id">AlarmNotificationHistoryItem.Id</see>.</param>
        /// <returns>An <see cref="AlarmNotificationHistoryItem"/> object describing the alarm notification history item.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="alarmId"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="checkId"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="alarmNotificationHistoryItemId"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-alarm-notification-history.html#service-alarm-notification-history-get">Get Alarm Notification History (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static AlarmNotificationHistoryItem GetAlarmNotificationHistory(this IMonitoringService service, EntityId entityId, AlarmId alarmId, CheckId checkId, AlarmNotificationHistoryItemId alarmNotificationHistoryItemId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.GetAlarmNotificationHistoryAsync(entityId, alarmId, checkId, alarmNotificationHistoryItemId, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
示例#5
0
        //---------------------------------------------------------------------
        public CLocalAlarme GetLocalAlarme(CMemoryDb database, bool bAvecFils)
        {
            if (database == null)
            {
                database = CMemoryDbPourSupervision.GetMemoryDb(ContexteDonnee);
            }
            CAlarme      alarmeParente = AlarmeParente;
            CLocalAlarme localParent   = null;

            if (alarmeParente != null)
            {
                localParent = alarmeParente.GetLocalAlarme(database, false);
            }
            CLocalAlarme alarme = new CLocalAlarme(database);

            if (!alarme.ReadIfExist(AlarmId.ToString(), false))
            {
                alarme.CreateNew(AlarmId.ToString());
            }
            else
            if (!alarme.IsToRead())
            {
                return(alarme);
            }
            alarme.PreventPropagationsAutomatiques = true;
            alarme.Row[CMemoryDb.c_champIsToRead]  = false;
            alarme.DateDebut        = DateDebut;
            alarme.DateFin          = DateFin;
            alarme.TypeAlarme       = TypeAlarme.GetTypeForSupervision(database, false);
            alarme.Severite         = Severite.GetTypeForSupervision(database);
            alarme.Parent           = localParent;
            alarme.EtatCode         = (EEtatAlarme)EtatCode;
            alarme.Libelle          = Libelle;
            alarme.DateAcquittement = DateAcquittement;
            alarme.SiteId           = SiteId;
            alarme.EquipementId     = EquipementId;
            alarme.LienId           = LienId;
            alarme.EntiteSnmpId     = EntiteSnmpId;
            alarme.IsHS             = IsHS;
            alarme.NiveauMasquage   = NiveauMasquage;

            if (Severite != null)
            {
                CLocalSeveriteAlarme sev = Severite.GetTypeForSupervision(database);
                if (sev != null)
                {
                    alarme.Severite = sev;
                }
            }

            if (MasquagePropre != null)
            {
                alarme.MasquagePropre = MasquagePropre.GetLocalParametrageForSupervision(database);
            }
            if (MasquageHerite != null)
            {
                alarme.MasquageHerite = MasquageHerite.GetLocalParametrageForSupervision(database);
            }

            // Recupère les valeurs de champs
            foreach (CRelationAlarme_ChampCustom rel in RelationsChampsCustom)
            {
                object val = rel.Valeur;
                if (val != null)
                {
                    if (val is CObjetDonneeAIdNumerique)
                    {
                        val = ((CObjetDonneeAIdNumerique)val).Id;
                    }
                    alarme.SetValeurChamp(rel.ChampCustom.Id.ToString(), val);
                }
            }
            alarme.PreventPropagationsAutomatiques = false;
            if (bAvecFils)
            {
                foreach (CAlarme fille in AlarmesFilles)
                {
                    fille.GetLocalAlarme(database, true);
                }
            }
            return(alarme);
        }