public override void LoadList()
        {
            try
            {
                if (SelectedConfig != null)
                {
                    FileSystemCollectorConfig fscc = (FileSystemCollectorConfig)SelectedConfig;
                    foreach (FileSystemDirectoryFilterEntry de in fscc.Entries)
                    {
                        ListViewItem lvi = new ListViewItem(de.FilterFullPath);
                        lvi.SubItems.Add(de.CountWarningIndicator.ToString());
                        lvi.SubItems.Add(de.CountErrorIndicator.ToString());
                        lvi.SubItems.Add(de.SizeKBWarningIndicator.ToString());
                        lvi.SubItems.Add(de.SizeKBErrorIndicator.ToString());
                        lvi.SubItems.Add(de.FileMinAgeSec.ToString());
                        lvi.SubItems.Add(de.FileMaxAgeSec.ToString());
                        lvi.SubItems.Add(de.FileMinSizeKB.ToString());
                        lvi.SubItems.Add(de.FileMaxSizeKB.ToString());
                        lvi.Tag = de;

                        lvwEntries.Items.Add(lvi);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            base.LoadList();
        }
        public override void OKClicked()
        {
            if (SelectedConfig != null)
            {
                SelectedConfig = new FileSystemCollectorConfig();
            }
            FileSystemCollectorConfig fscc = (FileSystemCollectorConfig)SelectedConfig;

            fscc.Entries.Clear();
            foreach (ListViewItem lvi in lvwEntries.Items)
            {
                FileSystemDirectoryFilterEntry de = (FileSystemDirectoryFilterEntry)lvi.Tag;
                fscc.Entries.Add(de);
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
Пример #3
0
        public override List <System.Data.DataTable> GetDetailDataTables()
        {
            List <System.Data.DataTable> tables = new List <System.Data.DataTable>();

            System.Data.DataTable dt = new System.Data.DataTable();
            try
            {
                dt.Columns.Add(new System.Data.DataColumn("Path", typeof(string)));
                dt.Columns.Add(new System.Data.DataColumn("Details", typeof(string)));

                FileSystemCollectorConfig currentConfig = (FileSystemCollectorConfig)AgentConfig;
                foreach (FileSystemDirectoryFilterEntry directoryFilter in currentConfig.Entries)
                {
                    DirectoryFileInfo directoryFileInfo = directoryFilter.GetFileListByFilters();
                    string            details           = "";
                    try
                    {
                        if (!directoryFileInfo.DirectoryExists)
                        {
                            details = "Directory does not exists";
                        }
                        else if (directoryFilter.DirectoryExistOnly)
                        {
                            details = "Directory exists";
                        }
                        else
                        {
                            details = directoryFileInfo.DirectoryExists ? directoryFileInfo.FileCount.ToString() + " file(s), " + FormatUtils.FormatFileSize(directoryFileInfo.TotalFileSize) : "Directory does not exists";
                        }
                    }
                    catch (Exception ex)
                    {
                        details = ex.Message;
                    }
                    dt.Rows.Add(directoryFilter.Description, details);
                }
            }
            catch (Exception ex)
            {
                dt = new System.Data.DataTable("Exception");
                dt.Columns.Add(new System.Data.DataColumn("Text", typeof(string)));
                dt.Rows.Add(ex.ToString());
            }
            tables.Add(dt);
            return(tables);
        }
Пример #4
0
        public override void LoadDisplayData()
        {
            if (Collector != null && Collector.AgentConfig != null && ((FileSystemCollectorConfig)Collector.AgentConfig).Entries != null)
            {
                FileSystemCollectorConfig fscc = (FileSystemCollectorConfig)Collector.AgentConfig;
                lvwEntries.Items.Clear();
                foreach (FileSystemDirectoryFilterEntry directoryFilterEntry in fscc.Entries)
                {
                    ListViewItem lvwi = new ListViewItem(directoryFilterEntry.FilterFullPath);
                    if (directoryFilterEntry.DirectoryExistOnly)
                    {
                        lvwi.Text += " (Exists only)";
                    }
                    lvwi.SubItems.Add("-");
                    lvwi.SubItems.Add("-");
                    lvwi.Tag = directoryFilterEntry;

                    lvwEntries.Items.Add(lvwi);
                }
            }
        }
Пример #5
0
        public override MonitorState GetState()
        {
            MonitorState  returnState         = new MonitorState();
            StringBuilder plainTextDetails    = new StringBuilder();
            StringBuilder htmlTextTextDetails = new StringBuilder();
            int           errorCount          = 0;
            int           warningCount        = 0;
            int           okCount             = 0;
            int           totalFileCount      = 0;
            int           totalEntryCount     = 0;

            try
            {
                htmlTextTextDetails.AppendLine("<ul>");
                FileSystemCollectorConfig currentConfig = (FileSystemCollectorConfig)AgentConfig;
                foreach (FileSystemDirectoryFilterEntry directoryFilter in currentConfig.Entries)
                {
                    DirectoryFileInfo directoryFileInfo = directoryFilter.GetDirFileInfo();
                    CollectorState    currentState      = directoryFilter.GetState(directoryFileInfo);
                    totalEntryCount++;

                    if (directoryFilter.DirectoryExistOnly && currentState != CollectorState.Good)
                    {
                        errorCount++;
                        plainTextDetails.AppendLine(directoryFilter.LastErrorMsg);
                        htmlTextTextDetails.AppendLine("<li>" + directoryFilter.LastErrorMsg + "</li>");
                    }
                    else if (!directoryFilter.DirectoryExistOnly)
                    {
                        if (directoryFileInfo.FileCount == -1)
                        {
                            errorCount++;
                            plainTextDetails.AppendLine(string.Format("An error occured while accessing '{0}'\r\n\t{1}", directoryFilter.FilterFullPath, directoryFilter.LastErrorMsg));
                            htmlTextTextDetails.AppendLine(string.Format("<li>'{0}' - Error accessing files<blockquote>{1}</blockquote></li>", directoryFilter.FilterFullPath, directoryFilter.LastErrorMsg));
                        }
                        else
                        {
                            totalFileCount += directoryFileInfo.FileCount;
                            if (directoryFileInfo.FileCount > 0)
                            {
                                htmlTextTextDetails.AppendLine("<li>");
                                if (directoryFilter.LastErrorMsg.Length > 0)
                                {
                                    plainTextDetails.AppendLine(directoryFilter.LastErrorMsg);
                                    htmlTextTextDetails.AppendLine(directoryFilter.LastErrorMsg);
                                }

                                plainTextDetails.AppendLine(GetTop10FileInfos(directoryFileInfo.FileInfos));
                                htmlTextTextDetails.AppendLine("<blockquote>");
                                htmlTextTextDetails.AppendLine(GetTop10FileInfos(directoryFileInfo.FileInfos).Replace("\r\n", "<br/>"));
                                htmlTextTextDetails.AppendLine("</blockquote></li>");
                            }
                            else
                            {
                                plainTextDetails.AppendLine(string.Format("No files found '{0}'", directoryFilter.FilterFullPath));
                                htmlTextTextDetails.AppendLine(string.Format("<li>'{0}' - No files found</li>", directoryFilter.FilterFullPath));
                            }
                            if (currentState == CollectorState.Warning)
                            {
                                warningCount++;
                            }
                            else if (currentState == CollectorState.Error)
                            {
                                errorCount++;
                            }
                            else
                            {
                                okCount++;
                            }
                        }
                    }
                    else
                    {
                        okCount++;
                    }
                }
                htmlTextTextDetails.AppendLine("</ul>");
                if (errorCount > 0 && totalEntryCount == errorCount) // any errors
                {
                    returnState.State = CollectorState.Error;
                }
                else if (okCount != totalEntryCount) //any warnings
                {
                    returnState.State = CollectorState.Warning;
                }
                else
                {
                    returnState.State = CollectorState.Good;
                }

                returnState.RawDetails   = plainTextDetails.ToString().TrimEnd('\r', '\n');
                returnState.HtmlDetails  = htmlTextTextDetails.ToString();
                returnState.CurrentValue = totalFileCount;
            }
            catch (Exception ex)
            {
                //LastError = 1;
                //LastErrorMsg = ex.Message;
                returnState.RawDetails  = ex.Message;
                returnState.HtmlDetails = ex.Message;
                returnState.State       = CollectorState.Error;
            }

            return(returnState);
        }
Пример #6
0
 public FileSystemCollector()
 {
     AgentConfig = new FileSystemCollectorConfig();
 }
Пример #7
0
        public override MonitorState RefreshState()
        {
            MonitorState returnState     = new MonitorState();
            int          errorCount      = 0;
            int          warningCount    = 0;
            int          okCount         = 0;
            int          totalFileCount  = 0;
            int          totalEntryCount = 0;

            try
            {
                FileSystemCollectorConfig currentConfig = (FileSystemCollectorConfig)AgentConfig;
                foreach (FileSystemDirectoryFilterEntry directoryFilter in currentConfig.Entries)
                {
                    DirectoryFileInfo directoryFileInfo = directoryFilter.GetFileListByFilters();
                    CollectorState    currentState      = directoryFilter.GetState(directoryFileInfo);
                    totalEntryCount++;

                    if (directoryFilter.DirectoryExistOnly && currentState != CollectorState.Good)
                    {
                        errorCount++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            ForAgent     = directoryFilter.DirectoryPath,
                            State        = CollectorState.Error,
                            CurrentValue = directoryFilter.LastErrorMsg
                        });
                    }
                    else if (directoryFilter.DirectoryExistOnly)
                    {
                        okCount++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            ForAgent     = directoryFilter.DirectoryPath,
                            State        = currentState,
                            CurrentValue = directoryFilter.LastErrorMsg
                        });
                    }
                    else
                    {
                        if (directoryFileInfo.FileCount == -1)
                        {
                            errorCount++;
                            returnState.ChildStates.Add(
                                new MonitorState()
                            {
                                ForAgent     = directoryFilter.DirectoryPath,
                                State        = CollectorState.Error,
                                CurrentValue = directoryFilter.LastErrorMsg
                            });
                        }
                        else
                        {
                            totalFileCount += directoryFileInfo.FileCount;
                            if (directoryFileInfo.FileCount > 0)
                            {
                                if (directoryFilter.LastErrorMsg.Length > 0)
                                {
                                    returnState.ChildStates.Add(
                                        new MonitorState()
                                    {
                                        ForAgent     = directoryFilter.DirectoryPath,
                                        State        = currentState,
                                        CurrentValue = string.Format("{0} file(s), {1}", directoryFileInfo.FileCount, FormatUtils.FormatFileSize(directoryFileInfo.TotalFileSize))
                                    });
                                }
                                else
                                {
                                    returnState.ChildStates.Add(
                                        new MonitorState()
                                    {
                                        ForAgent     = directoryFilter.DirectoryPath,
                                        State        = currentState,
                                        CurrentValue = string.Format("{0} file(s) found", directoryFileInfo.FileInfos.Count)
                                    });

                                    if (directoryFilter.ShowFilenamesInDetails)
                                    {
                                        int topCount = 10;
                                        for (int i = 0; i < topCount && i < directoryFileInfo.FileInfos.Count; i++)
                                        {
                                            FileInfo fi = directoryFileInfo.FileInfos[i];
                                            returnState.ChildStates.Add(
                                                new MonitorState()
                                            {
                                                ForAgent     = fi.Name,
                                                State        = currentState,
                                                CurrentValue = string.Format("{0}", FormatUtils.FormatFileSize(fi.Length))
                                            });
                                        }
                                    }
                                }
                            }
                            else
                            {
                                returnState.ChildStates.Add(
                                    new MonitorState()
                                {
                                    ForAgent     = directoryFilter.DirectoryPath,
                                    State        = currentState,
                                    CurrentValue = "No files found"
                                });
                            }
                            if (currentState == CollectorState.Warning)
                            {
                                warningCount++;
                            }
                            else if (currentState == CollectorState.Error)
                            {
                                errorCount++;
                            }
                            else
                            {
                                okCount++;
                            }
                        }
                    }
                }
                if (errorCount > 0 && totalEntryCount == errorCount) // any errors
                {
                    returnState.State = CollectorState.Error;
                }
                else if (okCount != totalEntryCount) //any warnings
                {
                    returnState.State = CollectorState.Warning;
                }
                else
                {
                    returnState.State = CollectorState.Good;
                }

                returnState.CurrentValue = totalFileCount;
            }
            catch (Exception ex)
            {
                returnState.RawDetails  = ex.Message;
                returnState.HtmlDetails = ex.Message;
                returnState.State       = CollectorState.Error;
            }

            return(returnState);
        }