public void ParsesExpressionWithFunctionCall()
        {
            ExpressionParser parser   = new ExpressionParser();
            Expression       parsed   = parser.Parse("avg(event.name) > 2 && 4 > 3");
            Expression       expected = Expr.Avg("event.name") > 2 & Expr.Of(4) > 3;

            Assert.Equal(expected.ToString(), parsed.ToString());
        }
Example #2
0
 public void MultipleNestedExpressions()
 {
     Assert.Equal("(15.1 < 15.5 || (2 < 3 && avg(event.name) < 6))",
                  Expr.Of(15.1F).Lt(15.5).Or(
                      Expr.Of(2).Lt(3).And(
                          Expr.Avg("event.name").Lt(6)
                          )
                      ).ToString());
 }
Example #3
0
 public void MultipleNestedExpressions()
 {
     Assert.Equal("(15.1 < 15.5 || (2 < 3 && avg(event.name) < 6))",
                  (Expr.Of(15.1F) < 15.5 | (
                       Expr.Of(2) < 3 & (
                           Expr.Avg("event.name") < 6
                           )
                       )).ToString());
 }
        public void HoldsEventsForTheSpecifiedTimeSpan()
        {
            UnifiedEventSource ues = new UnifiedEventSource(new SwallowException());
            IDateTimeProvider  dateTimeProvider = new MockDateTimeProvider(new DateTime(2018, 01, 01, 00, 00, 30));
            Resource           origin           = new Resource {
                Location = "localhost", Name = nameof(TriggerProcessorTests)
            };

            TriggerProcessor tp = new TriggerProcessor(
                TimeSpan.FromSeconds(15),
                Expr.Avg("cpu.usage").Gte(15),
                ues, dateTimeProvider
                );

            Assert.Empty(tp.InspectEventsUnderMonitoring());

            //ignore
            tp.Receive(new Event {
                Name         = "cpu.usage",
                Value        = 2,
                Origin       = origin,
                TimestampUtc = new DateTime(2018, 01, 01, 00, 00, 00)
            });

            //ignore
            tp.Receive(new Event
            {
                Name         = "cpu.usage",
                Value        = 3,
                Origin       = origin,
                TimestampUtc = new DateTime(2018, 01, 01, 00, 00, 01)
            });

            //ignore
            tp.Receive(new Event
            {
                Name         = "cpu.usage",
                Value        = 7,
                Origin       = origin,
                TimestampUtc = new DateTime(2018, 01, 01, 00, 00, 7)
            });
            Assert.Empty(tp.InspectEventsUnderMonitoring());

            //accept
            tp.Receive(new Event
            {
                Name         = "cpu.usage",
                Value        = 7,
                Origin       = origin,
                TimestampUtc = new DateTime(2018, 01, 01, 00, 00, 16)
            });

            var currentEvents = tp.InspectEventsUnderMonitoring();

            Assert.True(currentEvents.Count == 1);
        }
Example #5
0
 public void FunctionCallProducesCorrectString()
 {
     Assert.Equal("avg(event.name) == 15.5", Expr.Avg("event.name").Eq(15.5F).ToString());
 }