コード例 #1
0
ファイル: Trigger.cs プロジェクト: Doomblaster/MetroFire
 public Trigger(NotificationTrigger notificationTrigger)
 {
     _notificationTrigger = notificationTrigger;
     _userRegex           = CreateRegex(_notificationTrigger.MatchUser);
     _roomRegex           = CreateRegex(_notificationTrigger.MatchRoom);
     _textRegex           = CreateRegex(_notificationTrigger.MatchText);
 }
コード例 #2
0
        private void TriggerParameters_Create_FromExistingTrigger(NotificationTrigger trigger, TriggerParameters parameters)
        {
            //shouldnt we _actually_ be checking that the values are the same?
            //and, shouldnt we be populating _all_ properties of the trigger first?

            //then, we need to make sure we can clone a trigger into some new parameters and add them successfully
            //and THEN, we need to write some tests for that

            foreach (var paramProp in PrtgAPIHelpers.GetNormalProperties(parameters.GetType()))
            {
                bool found = false;

                foreach (var triggerProp in trigger.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    if ((paramProp.Name == "TriggerInternal" && triggerProp.Name == "Trigger") ||
                        (paramProp.Name == "State" && triggerProp.Name == "StateTrigger") ||
                        (paramProp.Name == triggerProp.Name))
                    {
                        found = true;
                        Assert.IsTrue(paramProp.GetValue(parameters) != null, $"Parameter '{paramProp}' was null");
                    }
                }

                if (!found)
                {
                    Assert.Fail($"Couldn't find notification trigger property that corresponded to parameter property '{paramProp.Name}'");
                }
            }
        }
コード例 #3
0
 public void FileAdded(Guid id, string path, StorageObjectState state, NotificationTrigger trigger)
 {
     if (state == StorageObjectState.Edited)
     {
         AddEditedFile(id, path);
     }
 }
コード例 #4
0
ファイル: BaseTreeTest.cs プロジェクト: vijaydairyf/PrtgAPI
        protected NotificationTrigger Trigger(string name = "Email to Admin", int id = 1)
        {
            var action = new NotificationAction
            {
                Name = name,
                Id   = 300
            };

            var obj = new NotificationTrigger
            {
                SubId    = id,
                ObjectId = 1001
            };

            var info = obj.GetInternalFieldInfo("onNotificationAction");

            info.SetValue(obj, action);

            info = obj.GetInternalFieldInfo("objectLink");
            info.SetValue(obj, $"<a thisid=\"1001\"/>");

            info = obj.GetInternalFieldInfo("type");
            info.SetValue(obj, "state");

            return(obj);
        }
コード例 #5
0
        NotificationTrigger createGeofenceAlert(Decimal deviceId)
        {
            var fence = createGeofence();

            dynamic parameters = new ExpandoObject();

            parameters.zoneId   = fence.Id;
            parameters.zoneType = "inside"; // can be "inside", "outside" or "cross"
            // Optional

            // If delivery.email = true, use the following to send email to address other than username
            // parameters.email = "*****@*****.**"

            // If delivery.http = true, use the following to define the endpoint
            // parameters.endpoint = "https://example.com/myalertreceiver"

            var notif = new NotificationTrigger(
                name: "geofence alert test",
                type: "geofence",
                muteFor: 0, // disable rate limit
                delivery: new Dictionary <string, bool>()
            {
                { "mqtt", true }
            },
                userId: Decimal.Parse(this.userId),
                parameters: parameters
                );

            return(this.deviceApi.DevicePrototypeCreateNotificationTriggers(deviceId, notif));
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ThresholdTriggerParameters"/> class for creating a new trigger from an existing <see cref="TriggerType.Threshold"/> <see cref="NotificationTrigger"/>.
 /// </summary>
 /// <param name="objectId">The object ID the trigger will apply to.</param>
 /// <param name="sourceTrigger">The notification trigger whose properties should be used.</param>
 public ThresholdTriggerParameters(int objectId, NotificationTrigger sourceTrigger) : base(TriggerType.Threshold, objectId, sourceTrigger, ModifyAction.Add)
 {
     OffNotificationAction = sourceTrigger.OffNotificationAction;
     Latency   = sourceTrigger.Latency;
     Threshold = sourceTrigger.ThresholdInternal;
     Condition = sourceTrigger.Condition;
     Channel   = sourceTrigger.Channel;
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ThresholdTriggerParameters"/> class for creating a new trigger from an existing <see cref="TriggerType.Threshold"/> <see cref="NotificationTrigger"/>.
 /// </summary>
 /// <param name="objectOrId">The object or object ID the trigger will apply to.</param>
 /// <param name="sourceTrigger">The notification trigger whose properties should be used.</param>
 public ThresholdTriggerParameters(Either <IPrtgObject, int> objectOrId, NotificationTrigger sourceTrigger) : base(TriggerType.Threshold, objectOrId, sourceTrigger, ModifyAction.Add)
 {
     OffNotificationAction = sourceTrigger.OffNotificationAction;
     Latency   = sourceTrigger.Latency;
     Threshold = sourceTrigger.Threshold;
     Condition = sourceTrigger.Condition;
     Channel   = sourceTrigger.Channel;
 }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StateTriggerParameters"/> class for creating a new trigger from an existing <see cref="TriggerType.State"/> <see cref="NotificationTrigger"/>.
 /// </summary>
 /// <param name="objectId">The object ID the trigger will apply to.</param>
 /// <param name="sourceTrigger">The notification trigger whose properties should be used.</param>
 public StateTriggerParameters(int objectId, NotificationTrigger sourceTrigger) : base(TriggerType.State, objectId, sourceTrigger, ModifyAction.Add)
 {
     OffNotificationAction        = sourceTrigger.OffNotificationAction;
     EscalationNotificationAction = sourceTrigger.EscalationNotificationAction;
     Latency           = sourceTrigger.Latency;
     EscalationLatency = sourceTrigger.EscalationLatency;
     RepeatInterval    = sourceTrigger.RepeatInterval;
     State             = sourceTrigger.StateTrigger;
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpeedTriggerParameters"/> class for creating a new trigger from an existing <see cref="TriggerType.Speed"/> <see cref="NotificationTrigger"/>.
 /// </summary>
 /// <param name="objectId">The object ID the trigger will apply to.</param>
 /// <param name="sourceTrigger">The notification trigger whose properties should be used.</param>
 public SpeedTriggerParameters(int objectId, NotificationTrigger sourceTrigger) : base(TriggerType.Speed, objectId, sourceTrigger, ModifyAction.Add)
 {
     OffNotificationAction = sourceTrigger.OffNotificationAction;
     Channel   = sourceTrigger.Channel;
     Latency   = sourceTrigger.Latency;
     Condition = sourceTrigger.Condition;
     Threshold = sourceTrigger.ThresholdInternal;
     UnitTime  = sourceTrigger.UnitTime;
     UnitSize  = sourceTrigger.UnitSize;
 }
コード例 #10
0
        private void ValidateNewTrigger(TriggerParameters parameters, NotificationTrigger trigger, bool empty)
        {
            foreach (var paramProp in parameters.GetType().GetProperties2())
            {
                bool found = false;

                foreach (var triggerProp in trigger.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    if ((paramProp.Name == "TriggerInternal" && triggerProp.Name == "Trigger") ||
                        (paramProp.Name == "State" && triggerProp.Name == "StateTrigger") ||
                        (paramProp.Name == triggerProp.Name))
                    {
                        found = true;
                        var paramValue   = paramProp.GetValue(parameters)?.ToString();
                        var triggerValue = triggerProp.GetValue(trigger)?.ToString();

                        if (empty && paramValue == null)
                        {
                            switch (triggerProp.Name)
                            {
                            case nameof(NotificationTrigger.Latency):
                                paramValue = "60";
                                break;

                            case nameof(NotificationTrigger.EscalationLatency):
                                paramValue = "300";
                                break;

                            case nameof(NotificationTrigger.Threshold):
                                paramValue = "0";
                                break;

                            case nameof(NotificationTrigger.RepeatInterval):
                                paramValue = "0";
                                break;
                            }
                        }

                        Assert.AreEqual(paramValue, triggerValue, triggerProp.Name);

                        //when we create a trigger without customization, some fields get default values
                        //we should have verification of those values, but ONLY when we're doing
                        //verification without customization. maybe we should have a bool on validatenewtrigger
                        //that indicates whether this is without customization, and ONLY THEN do we say ok
                        //paramValue can be null but triggerValue can be <something>
                    }
                }

                if (!found)
                {
                    Assert.Fail($"Couldn't find notification trigger property that corresponded to parameter property '{paramProp.Name}'");
                }
            }
        }
コード例 #11
0
        private static int ValidateTrigger(NotificationTrigger trigger)
        {
            if (trigger.Inherited)
            {
                throw new InvalidOperationException($"Cannot remove trigger {trigger.SubId} from Object ID: {trigger.ObjectId} as it is inherited from Object ID: {trigger.ParentId}");
            }

            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            return(trigger.ObjectId);
        }
コード例 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VolumeTriggerParameters"/> class for creating a new trigger from an existing <see cref="TriggerType.Volume"/> <see cref="NotificationTrigger"/>.
        /// </summary>
        /// <param name="objectId">The object ID the trigger will apply to.</param>
        /// <param name="sourceTrigger">The notification trigger whose properties should be used.</param>
        public VolumeTriggerParameters(int objectId, NotificationTrigger sourceTrigger) : base(TriggerType.Volume, objectId, sourceTrigger, ModifyAction.Add)
        {
            Channel = sourceTrigger.Channel;
            Period  = sourceTrigger.Period;

            if (sourceTrigger.UnitSize == null)
            {
                UnitSize = null;
            }
            else
            {
                UnitSize = sourceTrigger.UnitSize.ToString().ToEnum <TriggerVolumeUnitSize>();
            }

            Threshold = sourceTrigger.ThresholdInternal;
        }
コード例 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VolumeTriggerParameters"/> class for creating a new trigger from an existing <see cref="TriggerType.Volume"/> <see cref="NotificationTrigger"/>.
        /// </summary>
        /// <param name="objectOrId">The object or object ID the trigger will apply to.</param>
        /// <param name="sourceTrigger">The notification trigger whose properties should be used.</param>
        public VolumeTriggerParameters(Either <IPrtgObject, int> objectOrId, NotificationTrigger sourceTrigger) : base(TriggerType.Volume, objectOrId, sourceTrigger, ModifyAction.Add)
        {
            Channel = sourceTrigger.Channel;
            Period  = sourceTrigger.Period;

            if (sourceTrigger.UnitSize == null)
            {
                UnitSize = null;
            }
            else
            {
                UnitSize = sourceTrigger.UnitSize;
            }

            Threshold = sourceTrigger.Threshold;
        }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TriggerParameters"/> class for creating a new <see cref="NotificationTrigger"/> from an existing one.
        /// </summary>
        /// <param name="type">The type of notification trigger these parameters will manipulate.</param>
        /// <param name="objectId">The ID of the object the notification trigger will apply to.</param>
        /// <param name="sourceTrigger">The notification trigger whose properties should be used as the basis of this trigger.</param>
        /// <param name="action">Whether these parameters will create a new trigger or edit an existing one.</param>
        protected TriggerParameters(TriggerType type, int objectId, NotificationTrigger sourceTrigger, ModifyAction action) : this(type, objectId, action == ModifyAction.Edit ? sourceTrigger.SubId : (int?)null, action)
        {
            if (sourceTrigger == null)
            {
                throw new ArgumentNullException(nameof(sourceTrigger));
            }

            if (sourceTrigger.Type != type)
            {
                throw new ArgumentException($"A NotificationTrigger of type '{sourceTrigger.Type}' cannot be used to initialize trigger parameters of type '{type}'");
            }

            if (action == ModifyAction.Add)
            {
                OnNotificationAction = sourceTrigger.OnNotificationAction;
            }
        }
コード例 #15
0
 private void SetTriggerValue(NotificationTrigger trigger, ForeignEnumValue enumData, TriggerPropertyEntry entry, string typedValue)
 {
     if (enumData != null && enumData.EnglishValue != null && typedValue != enumData.EnglishValue)
     {
         //Channels only really refer to StandardTriggerChannel values applied to non-sensor objects. A Disk IO sensor could
         //have a channel with ID 0 which refers to "Avg Bytes Per Read". As such, instead of updating the value right now,
         //we'll defer to trigger.SetEnumChannel(). SetEnumChannel() won't even be called if the channel name refers to a real
         //channel, so if SetEnumChannel() is called we can safely assume we'll need to use our translated value as our enum value
         if (entry.TypedProperty.Type == typeof(TriggerChannel))
         {
             trigger.translatedChannelName = enumData.EnglishValue;
         }
         else
         {
             entry.TypedRawField.SetValue(trigger, enumData.EnglishValue);
         }
     }
 }
コード例 #16
0
        public TriggerViewModel(NotificationTrigger trigger)
        {
            _trigger     = trigger;
            TriggerTypes = new[]
            {
                new ComboViewModel <TriggerType>("there is any activity", TriggerType.RoomActivity),
                new ComboViewModel <TriggerType>("a user enters", TriggerType.UserEnters),
                new ComboViewModel <TriggerType>("a user leaves", TriggerType.UserLeaves),
                new ComboViewModel <TriggerType>("a user enters or leaves", TriggerType.UserEntersOrLeaves),
                new ComboViewModel <TriggerType>("a user posts a message", TriggerType.UserMessage),
                new ComboViewModel <TriggerType>("a user posts a file or picture", TriggerType.UserPaste),
            };

            SelectedTriggerType = TriggerTypes.FirstOrDefault(t => t.Data == trigger.TriggerType);
            MatchText           = trigger.MatchText;
            DoMatchText         = !String.IsNullOrEmpty(MatchText);
            MatchRoom           = trigger.MatchRoom;
            DoMatchRoom         = !String.IsNullOrEmpty(MatchRoom);
            MatchUser           = trigger.MatchUser;
            DoMatchUser         = !String.IsNullOrEmpty(MatchUser);
        }
コード例 #17
0
        private void TriggerParameters_Create_FromExistingTrigger(NotificationTrigger trigger, TriggerParameters parameters)
        {
            foreach (var paramProp in parameters.GetType().GetProperties2())
            {
                bool found = false;

                foreach (var triggerProp in trigger.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    if ((paramProp.Name == "TriggerInternal" && triggerProp.Name == "Trigger") ||
                        (paramProp.Name == "State" && triggerProp.Name == "StateTrigger") ||
                        (paramProp.Name == triggerProp.Name))
                    {
                        found = true;
                        Assert.IsTrue(paramProp.GetValue(parameters) != null, $"Parameter '{paramProp}' was null");
                    }
                }

                if (!found)
                {
                    Assert.Fail($"Couldn't find notification trigger property that corresponded to parameter property '{paramProp.Name}'");
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// Creates a set of <see cref="TriggerParameters"/> for editing an existing notification trigger.
        /// </summary>
        /// <param name="trigger">The notification trigger to modify.</param>
        /// <param name="parameters">A set of parameters describing the properties and their values to process.</param>
        /// <returns>A set of trigger parameters containing the information required to modify the specified notification trigger.</returns>
        internal static TriggerParameters Create(NotificationTrigger trigger, TriggerParameter[] parameters)
        {
            switch (trigger.Type)
            {
            case TriggerType.Change:
                return(BindParameters(new ChangeTriggerParameters(trigger), parameters));

            case TriggerType.Speed:
                return(BindParameters(new SpeedTriggerParameters(trigger), parameters));

            case TriggerType.State:
                return(BindParameters(new StateTriggerParameters(trigger), parameters));

            case TriggerType.Threshold:
                return(BindParameters(new ThresholdTriggerParameters(trigger), parameters));

            case TriggerType.Volume:
                return(BindParameters(new VolumeTriggerParameters(trigger), parameters));

            default:
                throw new NotImplementedException($"Handler of trigger type '{trigger.Type}' is not implemented.");
            }
        }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TriggerParameters"/> class for creating a new <see cref="NotificationTrigger"/> from an existing one.
        /// </summary>
        /// <param name="type">The type of notification trigger these parameters will manipulate.</param>
        /// <param name="objectId">The ID of the object the notification trigger will apply to.</param>
        /// <param name="sourceTrigger">The notification trigger whose properties should be used as the basis of this trigger.</param>
        /// <param name="action">Whether these parameters will create a new trigger or edit an existing one.</param>
        protected TriggerParameters(TriggerType type, int objectId, NotificationTrigger sourceTrigger, ModifyAction action) : this(type, objectId, action == ModifyAction.Edit ? sourceTrigger.SubId : (int?)null, action)
        {
            if (sourceTrigger == null)
            {
                throw new ArgumentNullException(nameof(sourceTrigger));
            }

            if (sourceTrigger.Type != type)
            {
                throw new ArgumentException($"A NotificationTrigger of type '{sourceTrigger.Type}' cannot be used to initialize trigger parameters of type '{type}'");
            }

            if (action == ModifyAction.Add)
            {
                OnNotificationAction = sourceTrigger.OnNotificationAction;
            }
            else
            {
                if (sourceTrigger.Inherited)
                {
                    throw new InvalidOperationException($"Cannot modify NotificationTrigger '{sourceTrigger.OnNotificationAction}' applied to object ID {sourceTrigger.ObjectId} as this trigger is inherited from object ID {sourceTrigger.ParentId}. To modify this trigger, retrieve it from its parent object");
                }
            }
        }
コード例 #20
0
 public void DirectoryAdded(Guid id, string path, StorageObjectState state, NotificationTrigger trigger)
 {
 }
コード例 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ThresholdTriggerParameters"/> class for editing an existing <see cref="TriggerType.Threshold"/> <see cref="NotificationTrigger"/>.
 /// </summary>
 /// <param name="sourceTrigger">The notification trigger to modify.</param>
 public ThresholdTriggerParameters(NotificationTrigger sourceTrigger) : base(TriggerType.Threshold, sourceTrigger.ObjectId, sourceTrigger, ModifyAction.Edit)
 {
 }
コード例 #22
0
 public void FileEdited(Guid id, string path, StorageObjectState state, NotificationTrigger trigger)
 {
 }
コード例 #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VolumeTriggerParameters"/> class for editing an existing <see cref="TriggerType.Volume"/> <see cref="NotificationTrigger"/>.
 /// </summary>
 /// <param name="sourceTrigger">The notification trigger to modify.</param>
 public VolumeTriggerParameters(NotificationTrigger sourceTrigger) : base(TriggerType.Volume, sourceTrigger.ObjectId, sourceTrigger, ModifyAction.Edit)
 {
 }
コード例 #24
0
 public RemoveTriggerParameters(NotificationTrigger trigger) : base(ValidateTrigger(trigger))
 {
     TriggerId = trigger.SubId;
 }
コード例 #25
0
 internal static TriggerOrphan Trigger(NotificationTrigger trigger) =>
 new TriggerOrphan(trigger);
コード例 #26
0
 public void DirectoryRemoved(Guid id, string path, NotificationTrigger trigger)
 {
 }
コード例 #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeTriggerParameters"/> class for creating a new trigger from an existing <see cref="TriggerType.Change"/> <see cref="NotificationTrigger"/>.
 /// </summary>
 /// <param name="objectOrId">The object or object ID the trigger will apply to.</param>
 /// <param name="sourceTrigger">The notification trigger whose properties should be used.</param>
 public ChangeTriggerParameters(Either <IPrtgObject, int> objectOrId, NotificationTrigger sourceTrigger) : base(TriggerType.Change, objectOrId, sourceTrigger, ModifyAction.Add)
 {
 }
コード例 #28
0
 /// <summary>
 /// Creates a new <see cref="TriggerNode"/> from a non-inherited notification trigger.
 /// </summary>
 /// <param name="trigger">The notification trigger this node represents.</param>
 /// <returns>A node containing the specified notification trigger.</returns>
 public static TriggerNode Trigger(NotificationTrigger trigger) =>
 PrtgOrphan.Trigger(trigger).ToStandaloneNode <TriggerNode>();
コード例 #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeTriggerParameters"/> class for creating a new trigger from an existing <see cref="TriggerType.Change"/> <see cref="NotificationTrigger"/>.
 /// </summary>
 /// <param name="objectId">The object ID the trigger will apply to.</param>
 /// <param name="sourceTrigger">The notification trigger whose properties should be used.</param>
 /// <param name="action">Whether these parameters will create a new trigger or edit an existing one.</param>
 public ChangeTriggerParameters(int objectId, NotificationTrigger sourceTrigger, ModifyAction action) : base(TriggerType.Change, objectId, sourceTrigger, action)
 {
 }
コード例 #30
0
 public void DirectoryStateChanged(Guid id, string path, StorageObjectState newState, NotificationTrigger trigger)
 {
 }