예제 #1
0
        //public object UpdateMysqlConfig(HttpListenerContext context)
        public object UpdateConfig(IHttpContext context)
        {
            string            json = "";
            JsonMysqlSettings settings;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = json.FromJson <JsonMysqlSettings>();
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing MySQL Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("MySQL Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }


            // process the settings
            try
            {
                cumulus.LogMessage("Updating MySQL settings");

                // server
                cumulus.MySqlConnSettings.Server = settings.server.host;
                if (settings.server.port > 0 && settings.server.port < 65536)
                {
                    cumulus.MySqlConnSettings.Port = settings.server.port;
                }
                else
                {
                    cumulus.MySqlConnSettings.Port = 3306;
                }
                cumulus.MySqlConnSettings.Database = settings.server.database;
                cumulus.MySqlConnSettings.UserID   = settings.server.user;
                cumulus.MySqlConnSettings.Password = settings.server.pass;

                // options
                cumulus.MySqlSettings.UpdateOnEdit    = settings.options.updateonedit;
                cumulus.MySqlSettings.BufferOnfailure = settings.options.bufferonerror;

                //monthly
                cumulus.MySqlSettings.Monthly.Enabled = settings.monthly.enabled;
                if (cumulus.MySqlSettings.Monthly.Enabled)
                {
                    cumulus.MySqlSettings.Monthly.TableName = String.IsNullOrWhiteSpace(settings.monthly.table) ? "Monthly" : settings.monthly.table;
                }
                //realtime
                cumulus.MySqlSettings.Realtime.Enabled = settings.realtime.enabled;
                if (cumulus.MySqlSettings.Realtime.Enabled)
                {
                    cumulus.MySqlSettings.RealtimeRetention    = settings.realtime.retentionVal + " " + settings.realtime.retentionUnit;
                    cumulus.MySqlSettings.Realtime.TableName   = String.IsNullOrWhiteSpace(settings.realtime.table) ? "Realtime" : settings.realtime.table;
                    cumulus.MySqlSettings.RealtimeLimit1Minute = settings.realtime.limit1min;
                }
                //dayfile
                cumulus.MySqlSettings.Dayfile.Enabled = settings.dayfile.enabled;
                if (cumulus.MySqlSettings.Dayfile.Enabled)
                {
                    cumulus.MySqlSettings.Dayfile.TableName = String.IsNullOrWhiteSpace(settings.dayfile.table) ? "Dayfile" : settings.dayfile.table;
                }
                // custom seconds
                cumulus.MySqlSettings.CustomSecs.Enabled = settings.customseconds.enabled;
                if (cumulus.MySqlSettings.CustomSecs.Enabled)
                {
                    cumulus.MySqlSettings.CustomSecs.Command  = settings.customseconds.command;
                    cumulus.MySqlSettings.CustomSecs.Interval = settings.customseconds.interval;
                }
                // custom minutes
                cumulus.MySqlSettings.CustomMins.Enabled = settings.customminutes.enabled;
                if (cumulus.MySqlSettings.CustomMins.Enabled)
                {
                    cumulus.MySqlSettings.CustomMins.Command = settings.customminutes.command;
                    cumulus.CustomMySqlMinutesIntervalIndex  = settings.customminutes.intervalindex;
                    if (cumulus.CustomMySqlMinutesIntervalIndex >= 0 && cumulus.CustomMySqlMinutesIntervalIndex < cumulus.FactorsOf60.Length)
                    {
                        cumulus.MySqlSettings.CustomMins.Interval = cumulus.FactorsOf60[cumulus.CustomMySqlMinutesIntervalIndex];
                    }
                    else
                    {
                        cumulus.MySqlSettings.CustomMins.Interval = 10;
                    }
                }
                // custom roll-over
                cumulus.MySqlSettings.CustomRollover.Enabled = settings.customrollover.enabled;
                if (cumulus.MySqlSettings.CustomRollover.Enabled)
                {
                    cumulus.MySqlSettings.CustomRollover.Command = settings.customrollover.command;
                }

                // Save the settings
                cumulus.WriteIniFile();

                cumulus.SetMonthlySqlCreateString();
                cumulus.SetStartOfMonthlyInsertSQL();

                cumulus.SetDayfileSqlCreateString();
                cumulus.SetStartOfDayfileInsertSQL();

                cumulus.SetRealtimeSqlCreateString();
                cumulus.SetStartOfRealtimeInsertSQL();

                cumulus.CustomMysqlSecondsTimer.Interval = cumulus.MySqlSettings.CustomSecs.Interval * 1000;
                cumulus.CustomMysqlSecondsTimer.Enabled  = cumulus.MySqlSettings.CustomSecs.Enabled;

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                var msg = "Error processing settings: " + ex.Message;
                cumulus.LogMessage(msg);
                context.Response.StatusCode = 500;
                return(msg);
            }
            return("success");
        }
예제 #2
0
        //public object UpdateMysqlConfig(HttpListenerContext context)
        public object UpdateMysqlConfig(IHttpContext context)
        {
            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = json.FromJson <JsonMysqlSettings>();
                // process the settings
                cumulus.LogMessage("Updating MySQL settings");

                // server
                cumulus.MySqlHost = settings.server.host;
                if (settings.server.port > 0 && settings.server.port < 65536)
                {
                    cumulus.MySqlPort = settings.server.port;
                }
                else
                {
                    cumulus.MySqlPort = 3306;
                }
                cumulus.MySqlDatabase = settings.server.database;
                cumulus.MySqlUser     = settings.server.user;
                cumulus.MySqlPass     = settings.server.pass;
                //monthly
                cumulus.MonthlyMySqlEnabled = settings.monthly.enabled;
                cumulus.MySqlMonthlyTable   = String.IsNullOrWhiteSpace(settings.monthly.table) ? "Monthly" : settings.monthly.table;
                //realtime
                cumulus.RealtimeMySqlEnabled   = settings.realtime.enabled;
                cumulus.MySqlRealtimeRetention = settings.realtime.retention;
                cumulus.MySqlRealtimeTable     = String.IsNullOrWhiteSpace(settings.realtime.table) ? "Realtime" : settings.realtime.table;
                //dayfile
                cumulus.DayfileMySqlEnabled = settings.dayfile.enabled;
                cumulus.MySqlDayfileTable   = String.IsNullOrWhiteSpace(settings.dayfile.table) ? "Dayfile" : settings.dayfile.table;
                // custom seconds
                cumulus.CustomMySqlSecondsCommandString = settings.customseconds.command;
                cumulus.CustomMySqlSecondsEnabled       = settings.customseconds.enabled;
                cumulus.CustomMySqlSecondsInterval      = settings.customseconds.interval;
                // custom minutes
                cumulus.CustomMySqlMinutesCommandString = settings.customminutes.command;
                cumulus.CustomMySqlMinutesEnabled       = settings.customminutes.enabled;
                cumulus.CustomMySqlMinutesIntervalIndex = settings.customminutes.intervalindex;
                if (cumulus.CustomMySqlMinutesIntervalIndex >= 0 && cumulus.CustomMySqlMinutesIntervalIndex < cumulus.FactorsOf60.Length)
                {
                    cumulus.CustomMySqlMinutesInterval = cumulus.FactorsOf60[cumulus.CustomMySqlMinutesIntervalIndex];
                }
                else
                {
                    cumulus.CustomMySqlMinutesInterval = 10;
                }
                // custom rollover
                cumulus.CustomMySqlRolloverCommandString = settings.customrollover.command;
                cumulus.CustomMySqlRolloverEnabled       = settings.customrollover.enabled;

                // Save the settings
                cumulus.WriteIniFile();

                cumulus.MonthlyMySqlConn.Host     = cumulus.MySqlHost;
                cumulus.MonthlyMySqlConn.Port     = cumulus.MySqlPort;
                cumulus.MonthlyMySqlConn.UserId   = cumulus.MySqlUser;
                cumulus.MonthlyMySqlConn.Password = cumulus.MySqlPass;
                cumulus.MonthlyMySqlConn.Database = cumulus.MySqlDatabase;

                cumulus.SetMonthlySqlCreateString();
                cumulus.SetStartOfMonthlyInsertSQL();

                cumulus.SetDayfileSqlCreateString();
                cumulus.SetStartOfDayfileInsertSQL();

                cumulus.RealtimeSqlConn.Host     = cumulus.MySqlHost;
                cumulus.RealtimeSqlConn.Port     = cumulus.MySqlPort;
                cumulus.RealtimeSqlConn.UserId   = cumulus.MySqlUser;
                cumulus.RealtimeSqlConn.Password = cumulus.MySqlPass;
                cumulus.RealtimeSqlConn.Database = cumulus.MySqlDatabase;

                cumulus.SetRealtimeSqlCreateString();
                cumulus.SetStartOfRealtimeInsertSQL();

                cumulus.CustomMysqlSecondsConn.Host      = cumulus.MySqlHost;
                cumulus.CustomMysqlSecondsConn.Port      = cumulus.MySqlPort;
                cumulus.CustomMysqlSecondsConn.UserId    = cumulus.MySqlUser;
                cumulus.CustomMysqlSecondsConn.Password  = cumulus.MySqlPass;
                cumulus.CustomMysqlSecondsConn.Database  = cumulus.MySqlDatabase;
                cumulus.CustomMysqlSecondsTimer.Interval = cumulus.CustomMySqlSecondsInterval * 1000;
                cumulus.CustomMysqlSecondsTimer.Enabled  = cumulus.CustomMySqlSecondsEnabled;

                cumulus.CustomMysqlMinutesConn.Host     = cumulus.MySqlHost;
                cumulus.CustomMysqlMinutesConn.Port     = cumulus.MySqlPort;
                cumulus.CustomMysqlMinutesConn.UserId   = cumulus.MySqlUser;
                cumulus.CustomMysqlMinutesConn.Password = cumulus.MySqlPass;
                cumulus.CustomMysqlMinutesConn.Database = cumulus.MySqlDatabase;

                cumulus.CustomMysqlRolloverConn.Host     = cumulus.MySqlHost;
                cumulus.CustomMysqlRolloverConn.Port     = cumulus.MySqlPort;
                cumulus.CustomMysqlRolloverConn.UserId   = cumulus.MySqlUser;
                cumulus.CustomMysqlRolloverConn.Password = cumulus.MySqlPass;
                cumulus.CustomMysqlRolloverConn.Database = cumulus.MySqlDatabase;

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }