public override List <System.Data.DataTable> GetDetailDataTables()
        {
            List <System.Data.DataTable>   list          = new List <System.Data.DataTable>();
            SqlDatabaseSizeCollectorConfig currentConfig = (SqlDatabaseSizeCollectorConfig)AgentConfig;

            System.Data.DataTable dt = new System.Data.DataTable("Database Sizes");
            dt.Columns.Add(new System.Data.DataColumn("Database", typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn("Size (MB)", typeof(int)));
            foreach (SqlDatabaseSizeCollectorEntry entry in currentConfig.Entries)
            {
                dt.Rows.Add(entry.Database, entry.GetDBSize());
            }
            list.Add(dt);
            return(list);
        }
 public override void LoadDisplayData()
 {
     if (Collector != null && Collector.AgentConfig != null)
     {
         SqlDatabaseSizeCollectorConfig sqlQueryConfig = (SqlDatabaseSizeCollectorConfig)Collector.AgentConfig;
         lvwEntries.Items.Clear();
         foreach (SqlDatabaseSizeEntry dbSizeEntry in sqlQueryConfig.Entries)
         {
             ListViewItem lvi = new ListViewItem(dbSizeEntry.ToString());
             lvi.SubItems.Add("-");
             lvi.Tag = dbSizeEntry;
             lvwEntries.Items.Add(lvi);
         }
     }
     base.LoadDisplayData();
 }
        public override void OKClicked()
        {
            if (SelectedConfig == null)
            {
                SelectedConfig = new SqlDatabaseSizeCollectorConfig();
            }
            SqlDatabaseSizeCollectorConfig sqlDbSizeConfig = (SqlDatabaseSizeCollectorConfig)SelectedConfig;

            sqlDbSizeConfig.Entries.Clear();
            foreach (ListViewItem lvi in lvwEntries.Items)
            {
                SqlDatabaseSizeEntry sqlDBSizeEntry = (SqlDatabaseSizeEntry)lvi.Tag;
                sqlDbSizeConfig.Entries.Add(sqlDBSizeEntry);
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
 public override void LoadList()
 {
     if (SelectedConfig != null)
     {
         SqlDatabaseSizeCollectorConfig sqlDbSizeConfig = (SqlDatabaseSizeCollectorConfig)SelectedConfig;
         lvwEntries.Items.Clear();
         foreach (SqlDatabaseSizeEntry sqlDBSizeEntry in sqlDbSizeConfig.Entries)
         {
             ListViewItem lvi = new ListViewItem(sqlDBSizeEntry.ToString());
             lvi.SubItems.Add(sqlDBSizeEntry.WarningSizeMB.ToString());
             lvi.SubItems.Add(sqlDBSizeEntry.ErrorSizeMB.ToString());
             lvi.Tag = sqlDBSizeEntry;
             lvwEntries.Items.Add(lvi);
         }
     }
     base.LoadList();
 }
Beispiel #5
0
        public override MonitorState GetState()
        {
            MonitorState returnState = new MonitorState()
            {
                State = CollectorState.Good
            };
            StringBuilder plainTextDetails    = new StringBuilder();
            StringBuilder htmlTextTextDetails = new StringBuilder();
            string        lastAction          = "";
            int           errors     = 0;
            int           warnings   = 0;
            int           success    = 0;
            double        totalValue = 0;

            try
            {
                SqlDatabaseSizeCollectorConfig sqlDBSizeConfig = (SqlDatabaseSizeCollectorConfig)AgentConfig;
                plainTextDetails.AppendLine(string.Format("Database size(s)"));
                htmlTextTextDetails.AppendLine(string.Format("Database size(s)"));
                htmlTextTextDetails.AppendLine("<ul>");
                foreach (SqlDatabaseSizeEntry sqlDBSizeEntry in sqlDBSizeConfig.Entries)
                {
                    lastAction = string.Format("Getting database size for '{0}\\{1}'", sqlDBSizeEntry.SqlServer, sqlDBSizeEntry.Database);

                    long           size         = sqlDBSizeEntry.GetDBSize();
                    CollectorState currentstate = sqlDBSizeEntry.GetState(size);
                    totalValue += size;

                    if (currentstate == CollectorState.Error)
                    {
                        errors++;
                        plainTextDetails.AppendLine(string.Format("\t'{0}\\{1}' - value '{2}' - Error (trigger {3})", sqlDBSizeEntry.SqlServer, sqlDBSizeEntry.Database, size, sqlDBSizeEntry.ErrorSizeMB));
                        htmlTextTextDetails.AppendLine(string.Format("<li>'{0}\\{1}' - Value '{2}' - <b>Error</b> (trigger {3})</li>", sqlDBSizeEntry.SqlServer, sqlDBSizeEntry.Database, size, sqlDBSizeEntry.ErrorSizeMB));
                    }
                    else if (currentstate == CollectorState.Warning)
                    {
                        warnings++;
                        plainTextDetails.AppendLine(string.Format("\t'{0}\\{1}' - value '{2}' - Warning (trigger {3})", sqlDBSizeEntry.SqlServer, sqlDBSizeEntry.Database, size, sqlDBSizeEntry.WarningSizeMB));
                        htmlTextTextDetails.AppendLine(string.Format("<li>'{0}\\{1}' - Value '{2}' - <b>Warning</b> (trigger {3})</li>", sqlDBSizeEntry.SqlServer, sqlDBSizeEntry.Database, size, sqlDBSizeEntry.WarningSizeMB));
                    }
                    else
                    {
                        success++;
                        plainTextDetails.AppendLine(string.Format("\t'{0}\\{1}' - value '{2}'", sqlDBSizeEntry.SqlServer, sqlDBSizeEntry.Database, size));
                        htmlTextTextDetails.AppendLine(string.Format("<li>'{0}\\{1}' - Value '{2}'</li>", sqlDBSizeEntry.SqlServer, sqlDBSizeEntry.Database, size));
                    }
                }
                htmlTextTextDetails.AppendLine("</ul>");
                if (errors > 0 && warnings == 0)
                {
                    returnState.State = CollectorState.Error;
                }
                else if (warnings > 0)
                {
                    returnState.State = CollectorState.Warning;
                }
                returnState.RawDetails   = plainTextDetails.ToString().TrimEnd('\r', '\n');
                returnState.HtmlDetails  = htmlTextTextDetails.ToString();
                returnState.CurrentValue = totalValue;
            }
            catch (Exception ex)
            {
                returnState.RawDetails  = string.Format("Last step: '{0}\r\n{1}", lastAction, ex.Message);
                returnState.HtmlDetails = string.Format("<blockquote>Last step: '{0}<br />{1}</blockquote>", lastAction, ex.Message);
                returnState.State       = CollectorState.Error;
            }
            return(returnState);
        }
Beispiel #6
0
 public SqlDatabaseSizeCollector()
 {
     AgentConfig = new SqlDatabaseSizeCollectorConfig();
 }
        public override MonitorState RefreshState()
        {
            MonitorState returnState = new MonitorState();
            string       lastAction  = "";
            int          errors      = 0;
            int          warnings    = 0;
            int          success     = 0;
            double       totalValue  = 0;

            try
            {
                SqlDatabaseSizeCollectorConfig currentConfig = (SqlDatabaseSizeCollectorConfig)AgentConfig;

                returnState.RawDetails   = string.Format("Running {0} queries", currentConfig.Entries.Count);
                returnState.HtmlDetails  = string.Format("<b>Running {0} queries</b>", currentConfig.Entries.Count);
                returnState.CurrentValue = 0;
                foreach (SqlDatabaseSizeCollectorEntry entry in currentConfig.Entries)
                {
                    long           size         = entry.GetDBSize();
                    CollectorState currentState = entry.GetState(size);
                    totalValue += size;

                    if (currentState == CollectorState.Error)
                    {
                        errors++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            State        = CollectorState.Error,
                            ForAgent     = entry.Database,
                            CurrentValue = string.Format("{0} MB", size),
                            RawDetails   = string.Format("(Trigger '{0} MB')", entry.ErrorSizeMB)
                        });
                    }
                    else if (currentState == CollectorState.Warning)
                    {
                        warnings++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            State        = CollectorState.Warning,
                            ForAgent     = entry.Database,
                            CurrentValue = string.Format("{0} MB", size),
                            RawDetails   = string.Format("(Trigger '{0} MB')", entry.WarningSizeMB)
                        });
                    }
                    else
                    {
                        success++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            State        = CollectorState.Good,
                            ForAgent     = entry.Database,
                            CurrentValue = string.Format("{0} MB", size)
                        });
                    }
                }
                returnState.CurrentValue = totalValue;

                if (errors > 0 && warnings == 0 && success == 0) // any errors
                {
                    returnState.State = CollectorState.Error;
                }
                else if (errors > 0 || warnings > 0) //any warnings
                {
                    returnState.State = CollectorState.Warning;
                }
                else
                {
                    returnState.State = CollectorState.Good;
                }
            }
            catch (Exception ex)
            {
                returnState.RawDetails  = ex.Message;
                returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message);
                returnState.State       = CollectorState.Error;
            }
            return(returnState);
        }