public override string IsNotification(NotificationCondition condition, Monitor monitor, Monitor previousMonitor, Notification notification) { var result = CheckStatusNotification(condition, monitor, previousMonitor) && CheckNotificationInterval(condition, monitor, notification); return(result ? "Y" : "N"); }
/// <summary> /// 狀態通知檢查 /// </summary> /// <param name="condition">通知條件</param> /// <param name="monitor">目前監控訊息</param> /// <param name="previousMonitor">前次監控訊息</param> /// <returns></returns> protected bool CheckStatusNotification(NotificationCondition condition, Monitor monitor, Monitor previousMonitor) { var type = (NotificationType)Enum.Parse(typeof(NotificationType), condition.NOTIFICATION_TYPE); var statusNotifier = StatusNotifierFactory.CreateInstance(type); return(statusNotifier.Check(monitor, previousMonitor)); }
protected override Notification GetNotificationRecord(Monitor monitor, NotificationCondition condition) { IEnumerable <Notification> records; var level = (IntervalLevel)Enum.Parse(typeof(IntervalLevel), condition.INTERVAL_LEVEL); switch (level) { case IntervalLevel.Device: records = _notifications.Where(x => x.DEVICE_SN == monitor.DEVICE_SN) .OrderByDescending(y => y.NOTIFICATION_TIME); break; case IntervalLevel.MonitorTarget: records = _notifications.Where(x => x.DEVICE_SN == monitor.DEVICE_SN && x.TARGET_NAME == monitor.TARGET_NAME) .OrderByDescending(y => y.NOTIFICATION_TIME); break; case IntervalLevel.TargetMessage: records = _notifications.Where(x => x.DEVICE_SN == monitor.DEVICE_SN && x.TARGET_NAME == monitor.TARGET_NAME && x.TARGET_MESSAGE == monitor.TARGET_MESSAGE) .OrderByDescending(y => y.NOTIFICATION_TIME); break; default: throw new Exception($"無 { condition.INTERVAL_LEVEL } 層級定義"); } return(records.Count() > 0 ? records.First() : new Notification()); }
/// <summary> /// 間隔通知檢查 /// </summary> /// <param name="condition">通知條件</param> /// <param name="monitor">目前監控訊息</param> /// <param name="notification">通知記錄</param> /// <returns></returns> protected bool CheckNotificationInterval(NotificationCondition condition, Monitor monitor, Notification notification) { if (notification.NOTIFICATION_TIME == null) { return(true); } var nextTime = notification.NOTIFICATION_TIME.Value.AddMinutes(condition.INTERVAL_TIME.Value); return(monitor.RECEIVE_TIME >= nextTime); }
public override string IsNotification(NotificationCondition condition, Monitor monitor, Monitor previousMonitor, Notification notification) { var check = CheckStatusNotification(condition, monitor, previousMonitor) && CheckNotificationInterval(condition, monitor, notification); var abuseIpDb = new AbuseIpDbBusinessLogic(monitor); var result = check && monitor.TARGET_NAME == "detect block ip" ? abuseIpDb.CheckScore() : check; return(result ? "Y" : "N"); }
public override string IsNotification(NotificationCondition condition, Monitor monitor, Monitor previousMonitor, Notification notification) { var mathSetting = GetConfigParams(); if (monitor.TARGET_NAME != "Ping" && mathSetting.PARAMETER_VALUE == "N") { return("N"); } var result = CheckStatusNotification(condition, monitor, previousMonitor) && CheckNotificationInterval(condition, monitor, notification); return(result ? "Y" : "N"); }
public void Given通知條件為(Table table) { _notificationConditions = table.Rows.Select(x => { var condition = new NotificationCondition { DEVICE_SN = x[0], NOTIFICATION_TYPE = x[1], INTERVAL_LEVEL = x[2], INTERVAL_TIME = Convert.ToInt32(x[3]) }; return(condition); }).ToList(); }
/// <summary> /// 通知記錄取得 /// </summary> /// <param name="monitor">監控資訊</param> /// <param name="notificationCondition">通知條件</param> /// <returns></returns> public Notification GetRecord(Monitor monitor, NotificationCondition notificationCondition) { if (notificationCondition.INTERVAL_TIME == 0) { return(new Notification()); } Notification condition; var level = (IntervalLevel)Enum.Parse(typeof(IntervalLevel), notificationCondition.INTERVAL_LEVEL); switch (level) { case IntervalLevel.Device: condition = new Notification { DEVICE_SN = monitor.DEVICE_SN }; break; case IntervalLevel.MonitorTarget: condition = new Notification { DEVICE_SN = monitor.DEVICE_SN, TARGET_NAME = monitor.TARGET_NAME }; break; case IntervalLevel.TargetMessage: condition = new Notification { DEVICE_SN = monitor.DEVICE_SN, TARGET_NAME = monitor.TARGET_NAME, TARGET_MESSAGE = monitor.TARGET_MESSAGE }; break; default: throw new Exception("錯誤的間隔層級"); } return((_dao as Notification_DAO).GetRecord(condition)); }
/// <summary> /// 通知記錄取得 /// </summary> /// <param name="monitor">監控資訊</param> /// <param name="condition">通知條件</param> /// <returns></returns> protected virtual Notification GetNotificationRecord(Monitor monitor, NotificationCondition condition) { var bll = GenericBusinessFactory.CreateInstance <Notification>(); return((bll as Notification_BLL).GetRecord(monitor, condition)); }
/// <summary> /// 是否通知 /// </summary> /// <param name="condition">通知條件</param> /// <param name="monitor">目前監控訊息</param> /// <param name="previousMonitor">前次監控訊息</param> /// <param name="notification">通知記錄</param> /// <returns></returns> public abstract string IsNotification(NotificationCondition condition, Monitor monitor, Monitor previousMonitor, Notification notification);
public static NotificationPipeline CreatePipleline(Random random, out string triggerIdentifier, NotificationCondition condition = null, NotificationActor actor = null) { triggerIdentifier = random.GetAlphanumericString(); return(CreatePipleline(random, triggerIdentifier, condition, actor)); }
public static NotificationPipeline CreatePipleline(Random random, string triggerIdentifier, NotificationCondition condition = null, NotificationActor actor = null) { NotificationActorCreateModel actorCreateModel = new NotificationActorCreateModel { Typename = random.GetAlphanumericString(), PropertiesAndValues = new Dictionary <String, String>(), }; NotificationConditionCreateModel conditionCreateModel = new NotificationConditionCreateModel { Typename = random.GetAlphanumericString(), PropertiesAndValues = new Dictionary <String, String>(), }; Mock <INotificationConditionFactory> conditionFactoryMock = new Mock <INotificationConditionFactory>(MockBehavior.Strict); conditionFactoryMock.Setup(x => x.Initilize(conditionCreateModel)).Returns(condition ?? DummyNotificationCondition.AllErrors).Verifiable(); Mock <INotificationActorFactory> actorFactoryMock = new Mock <INotificationActorFactory>(MockBehavior.Strict); actorFactoryMock.Setup(x => x.Initilize(actorCreateModel)).Returns(actor ?? DummyNotificationActor.AllErrors).Verifiable(); Guid id = random.NextGuid(); var pipeline = new NotificationPipeline(id, conditionFactoryMock.Object, actorFactoryMock.Object, Mock.Of <ILogger <NotificationPipeline> >()); pipeline.Load(new[] { new NotificationPipelineCreatedEvent { Id = id, Description = random.GetAlphanumericString(), Name = random.GetAlphanumericString(), TriggerIdentifier = triggerIdentifier, ActorCreateInfo = actorCreateModel, ConditionCreateInfo = conditionCreateModel, } }); return(pipeline); }