Exemplo n.º 1
0
 public void TestGetInfluxDBNames()
 {
     using (InfluxDBClient client = new InfluxDBClient(influxUrl, dbUName, dbpwd))
     {
         TimeMonitor.Watch(nameof(TestGetInfluxDBNames), () =>
         {
             var dbNames = client.GetInfluxDBNamesAsync().Result;
             var temp    = dbNames;
         }, output.WriteLine);
     }
 }
Exemplo n.º 2
0
 public void DeleteInfluxDatabaseTest()
 {
     using (InfluxDBClient client = new InfluxDBClient(influxUrl, dbUName, dbpwd))
     {
         TimeMonitor.Watch(nameof(TestGetInfluxDBNames), () =>
         {
             client.CreateDatabaseAsync(dbName);
             var dbNames = client.GetInfluxDBNamesAsync().Result;
             var temp    = dbNames;
         }, output.WriteLine);
     }
 }
Exemplo n.º 3
0
        public async Task <InfluxDBClient> GetDatabaseClient()
        {
            InfluxDBClient client    = new InfluxDBClient(connectionString, user, password);
            List <string>  databases = await client.GetInfluxDBNamesAsync();

            if (!databases.Contains(DatabaseName))
            {
                await client.CreateDatabaseAsync(DatabaseName);
            }

            return(client);
        }
Exemplo n.º 4
0
        public bool EnsureDatabase(string databaseName)
        {
            var dbs = _influxDbClient.GetInfluxDBNamesAsync().Result;

            if (dbs.Any(x => x.Equals(databaseName, StringComparison.InvariantCulture)))
            {
                _logger.Debug("Database {0} already exists. Nothing to do.", databaseName);
                return(false);
            }
            else
            {
                _logger.Info("Database {0} does not exists. DB will be created.", databaseName);
                return(_influxDbClient.CreateDatabaseAsync(databaseName).Result);
            }
        }
Exemplo n.º 5
0
        private static async Task <InfluxDBClient> GetClientAsync(InfluxerConfigSection settings)
        {
            var client  = new InfluxDBClient(settings.InfluxDB.InfluxUri, settings.InfluxDB.UserName, settings.InfluxDB.Password);
            var dbNames = await client.GetInfluxDBNamesAsync();

            if (dbNames.Contains(settings.InfluxDB.DatabaseName))
            {
                return(client);
            }
            else
            {
                await client.CreateDatabaseAsync(settings.InfluxDB.DatabaseName);

                return(client);
            }
        }
        public async Task TestGetInfluxDBNamesAsync()
        {
            try
            {
                var client = new InfluxDBClient(influxUrl, dbUName, dbpwd);
                var r      = await client.GetInfluxDBNamesAsync();

                Assert.IsTrue(r != null && r.Count > 0, "GetInfluxDBNamesAsync retunred null or empty collection");
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected exception of type {0} caught: {1}",
                            e.GetType(), e.Message);
                return;
            }
        }
        public async Task TestGetInfluxDBNamesAsync()
        {
            try
            {
                var       client = new InfluxDBClient(influxUrl, dbUName, dbpwd);
                Stopwatch s      = new Stopwatch();
                s.Start();
                var r = await client.GetInfluxDBNamesAsync();

                s.Stop();
                Debug.WriteLine(s.ElapsedMilliseconds);

                Assert.IsTrue(r != null, "GetInfluxDBNamesAsync retunred null or empty collection");
            }

            catch (Exception e)
            {
                Assert.Fail($"Unexpected exception of type {e.GetType()} caught: {e.Message}");
                return;
            }
        }
 public async Task TestGetInfluxDBNamesAsync_ServiceUnavailable()
 {
     var client = new InfluxDBClient(invalidInfluxUrl);
     var r      = await AssertEx.ThrowsAsync <ServiceUnavailableException>(() => client.GetInfluxDBNamesAsync());
 }
        private void HandleSaveDBSettingPostBack(NameValueCollection parts)
        {
            StringBuilder results = new StringBuilder();

            // Validate

            if (!System.Uri.TryCreate(parts[DBUriKey], UriKind.Absolute, out Uri dbUri))
            {
                results.AppendLine("Url is not Valid.<br>");
            }

            string database = parts[DBKey];

            if (string.IsNullOrWhiteSpace(database))
            {
                results.AppendLine("Database is not Valid.<br>");
            }

            string username  = parts[UserKey];
            string password  = parts[PasswordKey];
            string retention = parts[RetentionKey];

            try
            {
                using (var influxDbClient = new InfluxDBClient(dbUri.ToString(), username, password))
                {
                    var databases = influxDbClient.GetInfluxDBNamesAsync().ResultForSync();

                    var selectedDb = databases.Where((db) => { return(db == database); }).FirstOrDefault();
                    if (selectedDb == null)
                    {
                        results.AppendLine("Database not found on server.<br>");
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(retention))
                        {
                            var retentionPolcies = influxDbClient.GetRetentionPoliciesAsync(selectedDb).ResultForSync();
                            if (!retentionPolcies.Any(r => r.Name == retention))
                            {
                                results.AppendLine("Retention policy not found for database.<br>");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                results.AppendLine(Invariant($"Failed to connect to InfluxDB with {ex.GetFullMessage()}"));
            }

            if (results.Length > 0)
            {
                this.divToUpdate.Add(ErrorDivId, results.ToString());
            }
            else
            {
                this.divToUpdate.Add(ErrorDivId, string.Empty);
                var dbConfig = new InfluxDBLoginInformation(dbUri,
                                                            PluginConfig.CheckEmptyOrWhitespace(username),
                                                            PluginConfig.CheckEmptyOrWhitespace(password),
                                                            PluginConfig.CheckEmptyOrWhitespace(parts[DBKey]),
                                                            PluginConfig.CheckEmptyOrWhitespace(retention));
                this.pluginConfig.DBLoginInformation = dbConfig;
                this.pluginConfig.DebugLogging       = parts[DebugLoggingId] == "checked";
                this.pluginConfig.FireConfigChanged();
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Querying all DB names
 /// </summary>
 /// <returns></returns>
 public async Task <List <string> > QueryAllDBNames()
 {
     return(await InfluxDBConnection.GetInfluxDBNamesAsync());
 }
 public async Task TestGetInfluxDBNamesAsync_Auth2()
 {
     var client = new InfluxDBClient(influxUrl, invalidUName, dbpwd);
     var r      = await client.GetInfluxDBNamesAsync();
 }
 public async Task TestGetInfluxDBNamesAsync_Auth()
 {
     var client = new InfluxDBClient(influxUrl);
     var r      = await client.GetInfluxDBNamesAsync();
 }
 public async Task TestGetInfluxDBNamesAsync_ServiceUnavailable()
 {
     var client = new InfluxDBClient(invalidInfluxUrl);
     var r      = await client.GetInfluxDBNamesAsync();
 }