/// <summary> /// /// </summary> public Rule Validate(QueryProvider qp) { if (null == DateTimeMathParser.ToDuration(Frequency, TimeUnit.Second)) { AlertValidationException.ThrowBadParseFrequency(); } if (!string.IsNullOrEmpty(For) && !DateTimeMathParser.ToDuration(For, TimeUnit.Second).HasValue) { AlertValidationException.ThrowBadParseFor(); } if (null == Conditions || 0 == Conditions.Length) { AlertValidationException.ThrowNoCondtitions(); } if (!Enum.IsDefined(typeof(NoDataOptions), NoDataOption)) { AlertValidationException.ThrowBadParseNoDataOption(); } if (!Enum.IsDefined(typeof(ErrorOptions), ErrorOption)) { AlertValidationException.ThrowBadParseErrorOption(); } Conditions .ToList() .ForEach(c => c.Validate(qp)); return(this); }
/// <summary> /// /// </summary> /// <returns></returns> public static string GetGroupBy(Time.Range r) { var from = DateTimeMathParser.ToDateTime(r.From, false); var to = DateTimeMathParser.ToDateTime(r.To, true); return((from.HasValue && to.HasValue) ? GetGroupBy(from.Value, to.Value) : "1m"); }
/// <summary> /// /// </summary> /// <returns></returns> private static string GetTime(string expr, bool roundUp) { if (string.IsNullOrEmpty(expr)) { return(string.Empty); } if (DateTimeMathParser.IsDateTime(expr, out DateTime date)) { return(ToUnixTimeMilliseconds(date)); } if (expr == DateTimeMathParser.NOW) { return(NOW); } var parts = Regex.Split(expr, @"^now-(\d+)([dhms])$"); if (parts?.Length > 2) { int.TryParse(parts [1], out int amount); var unit = parts [2]; return($"{NOW} - {amount}{unit}"); } var res = DateTimeMathParser.ToDateTime(expr, roundUp); return(res.HasValue ? ToUnixTimeMilliseconds(res.Value) : string.Empty); }
/// <summary> /// /// </summary> /// <param name="r"></param> public void Update(Alerts.Rule r) { Name = r.Name; Frequency = ( int )DateTimeMathParser.ToDuration(r.Frequency); Settings = JsonConvert.SerializeObject(r, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented }); }