Example #1
0
        public async Task WriteMeasurementsWithoutFields()
        {
            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            var bucketName = _bucket.Name;

            var time = DateTime.UtcNow;

            var measurement1 = new H20Measurement
            {
                Location = "coyote_creek", Level = 2.927, Time = time.Add(-TimeSpan.FromSeconds(30))
            };
            var measurement2 = new H20Measurement
            {
                Location = "coyote_creek", Level = null, Time = time
            };

            _writeApi.WriteMeasurements(bucketName, _organization.Id, WritePrecision.S, measurement1, measurement2);
            _writeApi.Flush();
            listener.WaitToSuccess();

            var measurements = await _queryApi.QueryAsync <H20Measurement>(
                $"from(bucket:\"{bucketName}\") |> range(start: 0) |> rename(columns:{{_value: \"level\"}})",
                _organization.Id);

            Assert.AreEqual(1, measurements.Count);

            Assert.AreEqual(2.927, measurements[0].Level);
            Assert.AreEqual("coyote_creek", measurements[0].Location);
            Assert.AreEqual(time.AddTicks(-(time.Ticks % TimeSpan.TicksPerSecond)).Add(-TimeSpan.FromSeconds(30)),
                            measurements[0].Time);
        }
Example #2
0
        public async Task WriteRecordsParams()
        {
            var bucketName = _bucket.Name;

            const string record1 = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1";
            const string record2 = "h2o_feet,location=coyote_creek level\\ water_level=2.0 2";

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WriteRecords(bucketName, _organization.Id, WritePrecision.Ns, record1, record2);
            _writeApi.Flush();
            listener.WaitToSuccess();

            var query = await _queryApi.QueryAsync(
                $"from(bucket:\"{bucketName}\") |> range(start: 1970-01-01T00:00:00.000000001Z)",
                _organization.Id);

            Assert.AreEqual(1, query.Count);

            var records = query[0].Records;

            Assert.AreEqual(2, records.Count);

            Assert.AreEqual("h2o_feet", records[0].GetMeasurement());
            Assert.AreEqual(1, records[0].GetValue());
            Assert.AreEqual("level water_level", records[0].GetField());

            Assert.AreEqual("h2o_feet", records[1].GetMeasurement());
            Assert.AreEqual(2, records[1].GetValue());
            Assert.AreEqual("level water_level", records[1].GetField());
        }
Example #3
0
        public void GzipEnabledWrite()
        {
            _client.EnableGzip();

            MockServer
            .Given(Request.Create().UsingPost())
            .RespondWith(CreateResponse("", "text/csv"));

            var writeApi = _client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(writeApi);

            writeApi.WriteRecord("my-bucket", "my-org", WritePrecision.Ns,
                                 "h2o_feet,location=coyote_creek level\\ water_level=1.0 1");
            writeApi.Flush();
            listener.WaitToSuccess();

            var requestEntry = MockServer.LogEntries.Last();

            Assert.AreEqual($"{MockServerUrl}/api/v2/write?org=my-org&bucket=my-bucket&precision=ns",
                            requestEntry.RequestMessage.Url);
            Assert.AreEqual("gzip", requestEntry.RequestMessage.Headers["Content-Encoding"].First());
            Assert.AreEqual("identity",
                            requestEntry.RequestMessage.Headers["Accept-Encoding"].First());
            Assert.AreNotEqual("h2o_feet,location=coyote_creek level\\ water_level=1.0 1",
                               requestEntry.RequestMessage.Body);
        }
Example #4
0
        public async Task Recovery()
        {
            var bucketName = _bucket.Name;

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns,
                                  "h2o_feet,location=coyote_creek level\\ water_level=1.0 1x");
            _writeApi.Flush();

            var error = listener.Get <WriteErrorEvent>();

            Assert.IsNotNull(error);
            Assert.AreEqual(
                "unable to parse 'h2o_feet,location=coyote_creek level\\ water_level=1.0 1x': bad timestamp",
                error.Exception.Message);

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns,
                                  "h2o_feet,location=coyote_creek level\\ water_level=1.0 1");
            _writeApi.Flush();

            listener.Get <WriteSuccessEvent>();

            var query = await _queryApi.QueryAsync(
                $"from(bucket:\"{bucketName}\") |> range(start: 1970-01-01T00:00:00.000000001Z)",
                _organization.Id);

            Assert.AreEqual(1, query.Count);
            Assert.AreEqual(1, query[0].Records.Count);
            Assert.AreEqual("coyote_creek", query[0].Records[0].GetValueByKey("location"));
            Assert.AreEqual("level water_level", query[0].Records[0].GetValueByKey("_field"));
            Assert.AreEqual(1, query[0].Records[0].GetValue());
        }
Example #5
0
        public async Task Flush()
        {
            var bucketName = _bucket.Name;

            var writeOptions = WriteOptions.CreateNew().BatchSize(10).FlushInterval(100_000).Build();

            _writeApi = Client.GetWriteApi(writeOptions);
            var listener = new WriteApiTest.EventListener(_writeApi);

            var record = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1";

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record);
            _writeApi.Flush();
            listener.WaitToSuccess();

            var query = await _queryApi.QueryAsync(
                $"from(bucket:\"{bucketName}\") |> range(start: 1970-01-01T00:00:00.000000001Z)",
                _organization.Id);

            Assert.AreEqual(1, query.Count);

            var records = query[0].Records;

            Assert.AreEqual(1, records.Count);
            Assert.AreEqual("h2o_feet", records[0].GetMeasurement());
            Assert.AreEqual(1, records[0].GetValue());
            Assert.AreEqual("level water_level", records[0].GetField());

            var instant = Instant.Add(Instant.FromUnixTimeMilliseconds(0), Duration.FromNanoseconds(1L));

            Assert.AreEqual(instant, records[0].GetTime());
        }
Example #6
0
        private void WriteData()
        {
            Environment.SetEnvironmentVariable("point-datacenter", "LA");
            ConfigurationManager.AppSettings["point-sensor.version"] = "1.23a";

            var options = new InfluxDBClientOptions.Builder().Url(InfluxDbUrl)
                          .AuthenticateToken(_token)
                          .AddDefaultTag("id", "132-987-655")
                          .AddDefaultTag("customer", "California Miner")
                          .AddDefaultTag("env-var", "${env.point-datacenter}")
                          .AddDefaultTag("sensor-version", "${point-sensor.version}")
                          .Build();

            Client = InfluxDBClientFactory.Create(options);

            var point  = PointData.Measurement("h2o_feet").Tag("location", "east").Field("water_level", 1);
            var point2 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 2);
            var point3 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 3);
            var point4 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 4);
            var point5 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 5);
            var point6 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 6);

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point2);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point3);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point4);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point5);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point6);
            _writeApi.Flush();

            listener.WaitToSuccess();
        }
Example #7
0
        public async Task WritePoints()
        {
            var bucketName = _bucket.Name;

            var time = DateTime.UtcNow;

            var point1 = PointData
                         .Measurement("h2o_feet")
                         .Tag("location", "west")
                         .Field("water_level", 1)
                         .Timestamp(time, WritePrecision.S);

            var point2 = PointData
                         .Measurement("h2o_feet").Tag("location", "west")
                         .Field("water_level", 2)
                         .Timestamp(time.AddSeconds(-10), WritePrecision.S);

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WritePoints(bucketName, _organization.Id, point1, point2);
            _writeApi.Flush();

            listener.WaitToSuccess();

            var query = await _queryApi.QueryAsync(
                $"from(bucket:\"{bucketName}\") |> range(start: 1970-01-01T00:00:00.000000001Z)",
                _organization.Id);

            Assert.AreEqual(1, query.Count);

            var records = query[0].Records;

            Assert.AreEqual(2, records.Count);

            Assert.AreEqual("h2o_feet", records[0].GetMeasurement());
            Assert.AreEqual(2, records[0].GetValue());
            Assert.AreEqual("water_level", records[0].GetField());

            Assert.AreEqual("h2o_feet", records[1].GetMeasurement());
            Assert.AreEqual(1, records[1].GetValue());
            Assert.AreEqual("water_level", records[1].GetField());

            Assert.AreEqual(time.AddTicks(-(time.Ticks % TimeSpan.TicksPerSecond)).Add(-TimeSpan.FromSeconds(10)),
                            records[0].GetTimeInDateTime());
            Assert.AreEqual(time.AddTicks(-(time.Ticks % TimeSpan.TicksPerSecond)), records[1].GetTimeInDateTime());
        }
Example #8
0
        public async Task DefaultTagsMeasurement()
        {
            Client.Dispose();

            Environment.SetEnvironmentVariable("measurement-datacenter", "LA");
            ConfigurationManager.AppSettings["measurement-sensor.version"] = "1.23a";

            var options = new InfluxDBClientOptions.Builder().Url(InfluxDbUrl)
                          .AuthenticateToken(_token.ToCharArray())
                          .AddDefaultTag("id", "132-987-655")
                          .AddDefaultTag("customer", "California Miner")
                          .AddDefaultTag("env-var", "${env.measurement-datacenter}")
                          .AddDefaultTag("sensor-version", "${measurement-sensor.version}")
                          .Build();

            Client = InfluxDBClientFactory.Create(options);

            var measurement1 = new H20Measurement
            {
                Location = "coyote_creek", Level = 2.927, Time = DateTime.UtcNow
            };

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WriteMeasurement(_bucket.Name, _organization.Id, WritePrecision.Ms, measurement1);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _queryApi = Client.GetQueryApi();
            var tables = await _queryApi.QueryAsync(
                "from(bucket:\"" + _bucket.Name +
                "\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")",
                _organization.Id);

            Assert.AreEqual(1, tables.Count);
            Assert.AreEqual(1, tables[0].Records.Count);
            Assert.AreEqual("h2o", tables[0].Records[0].GetMeasurement());
            Assert.AreEqual(2.927, tables[0].Records[0].GetValueByKey("level"));
            Assert.AreEqual("coyote_creek", tables[0].Records[0].GetValueByKey("location"));
            Assert.AreEqual("132-987-655", tables[0].Records[0].GetValueByKey("id"));
            Assert.AreEqual("California Miner", tables[0].Records[0].GetValueByKey("customer"));
            Assert.AreEqual("1.23a", tables[0].Records[0].GetValueByKey("sensor-version"));
            Assert.AreEqual("LA", tables[0].Records[0].GetValueByKey("env-var"));
        }
Example #9
0
        public void ListenWriteErrorEvent()
        {
            var bucketName = _bucket.Name;

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns,
                                  "h2o_feet,location=coyote_creek level\\ water_level=1.0 123456.789");
            _writeApi.Flush();

            var error = listener.Get <WriteErrorEvent>();

            Assert.IsNotNull(error);
            Assert.AreEqual(
                "unable to parse 'h2o_feet,location=coyote_creek level\\ water_level=1.0 123456.789': bad timestamp",
                error.Exception.Message);
        }
Example #10
0
        public async Task FlushByOne()
        {
            var bucketName = _bucket.Name;

            var writeOptions = WriteOptions.CreateNew().BatchSize(1).FlushInterval(500_000).Build();

            _writeApi = Client.GetWriteApi(writeOptions);

            var eventListener = new WriteApiTest.EventListener(_writeApi);

            const string record1 = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1";
            const string record2 = "h2o_feet,location=coyote_creek level\\ water_level=2.0 2";
            const string record3 = "h2o_feet,location=coyote_creek level\\ water_level=3.0 3";
            const string record4 = "h2o_feet,location=coyote_creek level\\ water_level=4.0 4";
            const string record5 = "h2o_feet,location=coyote_creek level\\ water_level=5.0 5";

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record1);
            Thread.Sleep(100);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record2);
            Thread.Sleep(100);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record3);
            Thread.Sleep(100);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record4);
            Thread.Sleep(100);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record5);
            Thread.Sleep(100);

            Assert.AreEqual(record1, eventListener.Get <WriteSuccessEvent>().LineProtocol);
            Assert.AreEqual(record2, eventListener.Get <WriteSuccessEvent>().LineProtocol);
            Assert.AreEqual(record3, eventListener.Get <WriteSuccessEvent>().LineProtocol);
            Assert.AreEqual(record4, eventListener.Get <WriteSuccessEvent>().LineProtocol);
            Assert.AreEqual(record5, eventListener.Get <WriteSuccessEvent>().LineProtocol);

            var query = await _queryApi.QueryAsync(
                $"from(bucket:\"{bucketName}\") |> range(start: 1970-01-01T00:00:00.000000000Z)",
                _organization.Id);

            Assert.AreEqual(1, query.Count);

            var records = query[0].Records;

            Assert.AreEqual(5, records.Count);
            Assert.AreEqual(0, eventListener.EventCount());
        }
Example #11
0
        public void ListenWriteSuccessEvent()
        {
            var bucketName = _bucket.Name;

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns,
                                  "h2o_feet,location=coyote_creek level\\ water_level=1.0 1");
            _writeApi.Flush();

            var success = listener.Get <WriteSuccessEvent>();

            Assert.IsNotNull(success);
            Assert.AreEqual(success.Organization, _organization.Id);
            Assert.AreEqual(success.Bucket, bucketName);
            Assert.AreEqual(success.Precision, WritePrecision.Ns);
            Assert.AreEqual(success.LineProtocol, "h2o_feet,location=coyote_creek level\\ water_level=1.0 1");
        }
        public async Task FlushByCount()
        {
            var bucketName = _bucket.Name;

            var writeOptions = WriteOptions.CreateNew().BatchSize(6).FlushInterval(500_000).Build();

            _writeApi = Client.GetWriteApi(writeOptions);

            var listener = new WriteApiTest.EventListener(_writeApi);

            const string record1 = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1";
            const string record2 = "h2o_feet,location=coyote_creek level\\ water_level=2.0 2";
            const string record3 = "h2o_feet,location=coyote_creek level\\ water_level=3.0 3";
            const string record4 = "h2o_feet,location=coyote_creek level\\ water_level=4.0 4";
            const string record5 = "h2o_feet,location=coyote_creek level\\ water_level=5.0 5";
            const string record6 = "h2o_feet,location=coyote_creek level\\ water_level=6.0 6";

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record1);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record2);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record3);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record4);
            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record5);

            var query = await _queryApi.Query(
                "from(bucket:\"" + bucketName + "\") |> range(start: 1970-01-01T00:00:00.000000001Z)",
                _organization.Id);

            Assert.AreEqual(0, query.Count);

            _writeApi.WriteRecord(bucketName, _organization.Id, WritePrecision.Ns, record6);

            listener.Get <WriteSuccessEvent>();

            query = await _queryApi.Query(
                "from(bucket:\"" + bucketName + "\") |> range(start: 1970-01-01T00:00:00.000000001Z)",
                _organization.Id);

            Assert.AreEqual(1, query.Count);

            var records = query[0].Records;

            Assert.AreEqual(6, records.Count);
        }
Example #13
0
        public async Task DefaultTagsPoint()
        {
            Client.Dispose();

            Environment.SetEnvironmentVariable("point-datacenter", "LA");
            ConfigurationManager.AppSettings["point-sensor.version"] = "1.23a";

            var options = new InfluxDBClientOptions.Builder().Url(InfluxDbUrl)
                          .AuthenticateToken(_token)
                          .AddDefaultTag("id", "132-987-655")
                          .AddDefaultTag("customer", "California Miner")
                          .AddDefaultTag("env-var", "${env.point-datacenter}")
                          .AddDefaultTag("sensor-version", "${point-sensor.version}")
                          .Build();

            Client = InfluxDBClientFactory.Create(options);

            var point = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 1);

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _queryApi = Client.GetQueryApi();
            var tables = await _queryApi.QueryAsync(
                $"from(bucket:\"{_bucket.Name}\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")",
                _organization.Id);

            Assert.AreEqual(1, tables.Count);
            Assert.AreEqual(1, tables[0].Records.Count);
            Assert.AreEqual("h2o_feet", tables[0].Records[0].GetMeasurement());
            Assert.AreEqual(1, tables[0].Records[0].GetValueByKey("water_level"));
            Assert.AreEqual("west", tables[0].Records[0].GetValueByKey("location"));
            Assert.AreEqual("132-987-655", tables[0].Records[0].GetValueByKey("id"));
            Assert.AreEqual("California Miner", tables[0].Records[0].GetValueByKey("customer"));
            Assert.AreEqual("1.23a", tables[0].Records[0].GetValueByKey("sensor-version"));
            Assert.AreEqual("LA", tables[0].Records[0].GetValueByKey("env-var"));
        }
Example #14
0
        public async Task DefaultTagsConfiguration()
        {
            Client.Dispose();

            var options = new InfluxDBClientOptions.Builder()
                          .LoadConfig()
                          .Url(InfluxDbUrl)
                          .AuthenticateToken(_token)
                          .Build();

            Client = InfluxDBClientFactory.Create(options);

            var measurement1 = new H20Measurement
            {
                Location = "coyote_creek", Level = 2.927, Time = DateTime.UtcNow
            };

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WriteMeasurement(_bucket.Name, _organization.Id, WritePrecision.Ms, measurement1);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _queryApi = Client.GetQueryApi();
            var tables = await _queryApi.QueryAsync(
                $"from(bucket:\"{_bucket.Name}\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")",
                _organization.Id);

            Assert.AreEqual(1, tables.Count);
            Assert.AreEqual(1, tables[0].Records.Count);
            Assert.AreEqual("h2o", tables[0].Records[0].GetMeasurement());
            Assert.AreEqual(2.927, tables[0].Records[0].GetValueByKey("level"));
            Assert.AreEqual("coyote_creek", tables[0].Records[0].GetValueByKey("location"));
            Assert.AreEqual("132-987-655", tables[0].Records[0].GetValueByKey("id"));
            Assert.AreEqual("California Miner", tables[0].Records[0].GetValueByKey("customer"));
            Assert.AreEqual("v1.00", tables[0].Records[0].GetValueByKey("version"));
        }
        public async Task CreateMonitoringAndAlerting()
        {
            MockServer
            .Given(Request.Create().UsingGet())
            .RespondWith(CreateResponse("{}", "application/json"));

            MockServer
            .Given(Request.Create().UsingPost())
            .RespondWith(CreateResponse("{}", "application/json"));

            var org = (await _client.GetOrganizationsApi().FindOrganizationsAsync())
                      .First(organization => organization.Name.Equals("my-org"));

            var checksApi = _client.GetChecksApi();
            var notificationEndpointsApi = _client.GetNotificationEndpointsApi();
            var notificationRulesApi     = _client.GetNotificationRulesApi();

            var checks = await checksApi.FindChecksAsync(org.Id, new FindOptions());

            foreach (var delete in checks._Checks.Where(ne => ne.Name.EndsWith("-IT")))
            {
                await checksApi.DeleteCheckAsync(delete);
            }

            var rules = await notificationRulesApi.FindNotificationRulesAsync(org.Id, new FindOptions());

            foreach (var delete in rules._NotificationRules.Where(ne => ne.Name.EndsWith("-IT")))
            {
                await notificationRulesApi.DeleteNotificationRuleAsync(delete);
            }

            var endpoints = await notificationEndpointsApi.FindNotificationEndpointsAsync(org.Id, new FindOptions());

            foreach (var delete in endpoints._NotificationEndpoints.Where(ne => ne.Name.EndsWith("-IT")))
            {
                await notificationEndpointsApi.DeleteNotificationEndpointAsync(delete);
            }

            //
            // Create Threshold Check
            //
            // Set status to 'Critical' if the 'current' value for 'stock' measurement is lesser than '35'
            //
            var query = "from(bucket: \"my-bucket\") "
                        + "|> range(start: v.timeRangeStart, stop: v.timeRangeStop)  "
                        + "|> filter(fn: (r) => r._measurement == \"stock\")  "
                        + "|> filter(fn: (r) => r.company == \"zyz\")  "
                        + "|> aggregateWindow(every: 5s, fn: mean)  "
                        + "|> filter(fn: (r) => r._field == \"current\")  "
                        + "|> yield(name: \"mean\")";

            var threshold = new LesserThreshold(value: 35F, level: CheckStatusLevel.CRIT,
                                                type: LesserThreshold.TypeEnum.Lesser);

            var message = "The Stock price for XYZ is on: ${ r._level } level!";

            await checksApi.CreateThresholdCheckAsync(AbstractItClientTest.GenerateName("XYZ Stock value"), query, "5s", message, threshold, org.Id);


            //
            // Create Slack Notification endpoint
            //
            var url      = MockServerUrl;
            var endpoint =
                await notificationEndpointsApi.CreateSlackEndpointAsync(
                    AbstractItClientTest.GenerateName("Slack Endpoint"), url, org.Id);

            //
            // Create Notification Rule
            //
            // Send message if the status is 'Critical'
            //
            await notificationRulesApi.CreateSlackRuleAsync(
                AbstractItClientTest.GenerateName("Critical status to Slack"), "10s", "${ r._message }",
                RuleStatusLevel.CRIT, endpoint, org.Id);


            //
            // Write Data
            //
            var now    = DateTime.UtcNow;
            var point1 = PointData
                         .Measurement("stock")
                         .Tag("company", "zyz")
                         .Field("current", 33.65)
                         .Timestamp(now, WritePrecision.Ns);

            var writeApi = _client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(writeApi);

            writeApi.WritePoint("my-bucket", "my-org", point1);
            writeApi.Flush();
            listener.WaitToSuccess();


            var start = DateTime.UtcNow;

            while (!MockServer.LogEntries.Any() && (DateTime.UtcNow - start).TotalSeconds < 30)
            {
                Thread.Sleep(100);
            }

            var requestEntry = MockServer.LogEntries.Last();

            Assert.AreEqual($"{MockServerUrl}/", requestEntry.RequestMessage.Url);

            var json = (JObject)requestEntry.RequestMessage.BodyAsJson;

            Assert.IsNotNull(json.GetValue("attachments"));

            var attachments = (JArray)json.GetValue("attachments");

            Assert.AreEqual(1, attachments.Count);

            Assert.AreEqual("The Stock price for XYZ is on: crit level!", attachments[0]["text"].ToString());
        }
        public async Task Delete()
        {
            Client.Dispose();

            Environment.SetEnvironmentVariable("point-datacenter", "LA");
            ConfigurationManager.AppSettings["point-sensor.version"] = "1.23a";

            var options = new InfluxDBClientOptions.Builder().Url(InfluxDbUrl)
                          .AuthenticateToken(_token.ToCharArray())
                          .AddDefaultTag("id", "132-987-655")
                          .AddDefaultTag("customer", "California Miner")
                          .AddDefaultTag("env-var", "${env.point-datacenter}")
                          .AddDefaultTag("sensor-version", "${point-sensor.version}")
                          .Build();

            Client = InfluxDBClientFactory.Create(options);

            var point  = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 1);
            var point2 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 2);
            var point3 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 3);
            var point4 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 4);
            var point5 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 5);
            var point6 = PointData.Measurement("h2o_feet").Tag("location", "west").Field("water_level", 6);

            _writeApi = Client.GetWriteApi();
            var listener = new WriteApiTest.EventListener(_writeApi);

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point2);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point3);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point4);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point5);
            _writeApi.Flush();

            listener.WaitToSuccess();

            _writeApi.WritePoint(_bucket.Name, _organization.Id, point6);
            _writeApi.Flush();

            listener.WaitToSuccess();

            string query = "from(bucket:\"" + _bucket.Name +
                           "\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")";

            _queryApi = Client.GetQueryApi();
            var tables = await _queryApi.QueryAsync(query, _organization.Id);

            Assert.AreEqual(1, tables.Count);
            Assert.AreEqual(6, tables[0].Records.Count);

            _deleteApi = Client.GetDeleteApi();
            await _deleteApi.Delete(DateTime.Now.AddSeconds(-1), DateTime.Now, "", _bucket, _organization);

            var tablesAfterDelete = await _queryApi.QueryAsync(query, _organization.Id);

            Assert.AreNotEqual(0, tablesAfterDelete.Count);

            await _deleteApi.Delete(DateTime.Now.AddHours(-1), DateTime.Now, "", _bucket, _organization);

            var tablesAfterDelete2 = await _queryApi.QueryAsync(query, _organization.Id);

            Assert.AreEqual(0, tablesAfterDelete2.Count);
        }