Esempio n. 1
0
        public async Task <InfluxDbApiResponse> TestWriteAccess(IInfluxDbAgent client, string action)
        {
            var tags = new Dictionary <string, object>
            {
                { "counter", "configuration" },
                { "hostname", Environment.MachineName },
                { "version", Assembly.GetExecutingAssembly().GetName().Version.ToString() },
                { "action", action }
            };

            var fields = new Dictionary <string, object>
            {
                { "value", (decimal)1.0 }
            };

            var points = new[]
            {
                new Point
                {
                    Measurement = MetaMeasurementName,
                    Tags        = tags,
                    Fields      = fields,
                    Precision   = TimeUnit.Milliseconds,
                    Timestamp   = DateTime.UtcNow
                }
            };

            return(await client.WriteAsync(points));
        }
        public static async Task<InfluxDbApiResponse> TestWriteAccess(IInfluxDbAgent client, string action)
        {
            var tags = new Dictionary<string, object>
            {
                { "counter", "configuration" },
                { "hostname", Environment.MachineName },
                { "version", Assembly.GetExecutingAssembly().GetName().Version.ToString() },
                { "action", action },
            };

            var fields = new Dictionary<string, object>
            {
                { "value", (decimal)1.0 },
            };

            var points = new[]
            {
                new Point
                    {
                        Measurement = Constants.ServiceName + "-Metadata", 
                        Tags = tags,
                        Fields = fields,
                        Precision = TimeUnit.Milliseconds,
                        Timestamp = DateTime.UtcNow
                    },
            };

            return await client.WriteAsync(points);
        }
Esempio n. 3
0
 public DashboardController(ISystemBusiness systemBusiness, IInitiativeBusiness initiativeBusiness, ISettingsBusiness settingsBusiness, IEventLogAgent eventLogAgent, IInfluxDbAgent influxDbAgent)
 {
     _systemBusiness     = systemBusiness;
     _initiativeBusiness = initiativeBusiness;
     _settingsBusiness   = settingsBusiness;
     _eventLogAgent      = eventLogAgent;
     _influxDbAgent      = influxDbAgent;
 }
Esempio n. 4
0
 static InfluxQueue()
 {
     try
     {
         if (Enabled)
         {
             var influxVersion = InfluxVersion.Auto; //TODO: Move to settings
             _agent = new InfluxDbAgent(Address, DatabaseName, UserName, Password, influxVersion);
         }
     }
     catch
     {
         _enabled = false;
     }
 }
 static InfluxQueue()
 {
     try
     {
         if (Enabled)
         {
             var influxVersion = InfluxVersion.Auto; //TODO: Move to settings
             _logger.Info(string.Format("Initiating influxdb agent to address {0} database {1} user {2} version {3}.", Address, DatabaseName, UserName, influxVersion));
             _agent     = new InfluxDbAgent(Address, DatabaseName, UserName, Password, null, influxVersion);
             _formatter = _agent.GetAgentInfo().Item1;
         }
     }
     catch (Exception exception)
     {
         _logger.Error(exception);
         _enabled = false;
     }
 }
Esempio n. 6
0
 static InfluxQueue()
 {
     try
     {
         if (Enabled)
         {
             var influxVersion = InfluxVersion.Auto; //TODO: Move to settings
             _logger.Info(string.Format("Initiating influxdb agent to address {0} database {1} user {2} version {3}.",Address, DatabaseName, UserName, influxVersion));
             _agent = new InfluxDbAgent(Address, DatabaseName, UserName, Password, null, influxVersion);
             _formatter = _agent.GetAgentInfo().Item1;
         }
     }
     catch(Exception exception)
     {
         _logger.Error(exception);
         _enabled = false;
     }
 }
Esempio n. 7
0
        protected async Task <IDatabaseConfig> GetUsernameAsync(string paramList, int index, IDatabaseConfig config, string action)
        {
            var dataChanged = false;

            var url = config.Url;

            IInfluxDbAgent      client   = null;
            InfluxDbApiResponse response = null;

            try
            {
                if (!string.IsNullOrEmpty(config.Name) && !string.IsNullOrEmpty(config.Username) && !string.IsNullOrEmpty(config.Password))
                {
                    client   = _influxDbAgentLoader.GetAgent(config);
                    response = await MetaDataBusiness.TestWriteAccess(client, action);
                }
            }
            catch (Exception exception)
            {
                OutputError(exception.Message);
            }

            if (response == null || !response.Success)
            {
                OutputInformation("Enter the database, username and password for the InfluxDB.");
            }

            while (response == null || !response.Success)
            {
                var database = string.Empty;
                try
                {
                    database = QueryParam <string>("DatabaseName", GetParam(paramList, index++));
                    var user     = QueryParam <string>("Username", GetParam(paramList, index++));
                    var password = QueryParam <string>("Password", GetParam(paramList, index++));
                    config = new InfluxDatabaseConfig(url, user, password, database);

                    client   = _influxDbAgentLoader.GetAgent(config);
                    response = await MetaDataBusiness.TestWriteAccess(client, action);

                    dataChanged = true;
                }
                catch (CommandEscapeException)
                {
                    return(null);
                }
                catch (InfluxDbApiException exception)
                {
                    if (exception.StatusCode == HttpStatusCode.NotFound)
                    {
                        var create = QueryParam("Database does not exist, create?", GetParam(paramList, index++), new Dictionary <bool, string>()
                        {
                            { true, "Yes" }, { false, "No" }
                        });
                        if (create)
                        {
                            client.CreateDatabaseAsync(database);
                            response    = MetaDataBusiness.TestWriteAccess(client, action).Result;
                            dataChanged = true;
                        }
                    }
                }
                catch (Exception exception)
                {
                    OutputError("{0}", exception.Message);
                }
            }

            OutputInformation("Access to database {0} confirmed.", config.Name);

            if (dataChanged)
            {
                _configBusiness.SaveDatabaseConfig(config.Name, config.Username, config.Password);
            }

            return(config);
        }
Esempio n. 8
0
        protected async Task <string> GetServerUrlAsync(string paramList, int index, string defaultUrl)
        {
            var urlParam = GetParam(paramList, index++);

            var url = defaultUrl;

            IInfluxDbAgent client = null;

            if (!string.IsNullOrEmpty(url) && url != Constants.NoConfigUrl)
            {
                try
                {
                    client = _influxDbAgentLoader.GetAgent(new InfluxDatabaseConfig(url, "root", "qwerty", "qwerty"));
                }
                catch (Exception exception)
                {
                    OutputWarning(exception.Message);
                }
            }

            var connectionConfirmed = false;

            try
            {
                if (client != null)
                {
                    connectionConfirmed = await client.CanConnect();
                }
            }
            catch (Exception exception)
            {
                OutputError("{0}", exception.Message);
            }

            if (!connectionConfirmed)
            {
                OutputInformation("Enter the url to the InfluxDB to use.");
                OutputInformation("Provide the correct port, typically 8086. (Ex. http://tharga.net:8086)");
                while (!connectionConfirmed)
                {
                    try
                    {
                        url      = QueryParam <string>("Url", urlParam);
                        urlParam = null;
                        client   = _influxDbAgentLoader.GetAgent(new InfluxDatabaseConfig(url, "root", "qwerty", "qwert"));

                        connectionConfirmed = await client.CanConnect();
                    }
                    catch (CommandEscapeException)
                    {
                        return(null);
                    }
                    catch (Exception exception)
                    {
                        OutputError("{0}", exception.Message.Split('\n')[0]);
                    }
                }

                _configBusiness.SaveDatabaseUrl(url);
            }
            OutputInformation("Connection to server {0} confirmed.", url);
            return(url);
        }
Esempio n. 9
0
 public CounterBusiness(IInfluxDbAgent influxDbAgent, IRepository repository, IEventLogAgent eventLogAgent)
 {
     _influxDbAgent = influxDbAgent;
     _repository    = repository;
     _eventLogAgent = eventLogAgent;
 }
 public InfluxDbSenderAgent(IInfluxDbAgent influxDbAgent)
 {
     _influxDbAgent = influxDbAgent;
 }