예제 #1
0
        public void FromXml(string configurationString)
        {
            if (configurationString == null || configurationString.Length == 0)
            {
                return;
            }
            XmlDocument config = new XmlDocument();

            config.LoadXml(configurationString);
            XmlElement root = config.DocumentElement;

            Entries.Clear();

            foreach (XmlElement pcNode in root.SelectNodes("nixDiskSpaces"))
            {
                NIXDiskSpaceEntry entry = new NIXDiskSpaceEntry();
                entry.SSHConnection = SSHConnectionDetails.FromXmlElement(pcNode);
                entry.SubItems      = new List <ICollectorConfigSubEntry>();
                foreach (XmlElement fileSystemNode in pcNode.SelectNodes("fileSystem"))
                {
                    NIXDiskSpaceSubEntry fse = new NIXDiskSpaceSubEntry();
                    fse.FileSystemName = fileSystemNode.ReadXmlElementAttr("name", "");
                    fse.WarningValue   = fileSystemNode.ReadXmlElementAttr("warningValue", 10.0d);
                    fse.ErrorValue     = fileSystemNode.ReadXmlElementAttr("errorValue", 5.0d);
                    fse.PrimaryUIValue = fileSystemNode.ReadXmlElementAttr("primaryUIValue", false);
                    entry.SubItems.Add(fse);
                }
                Entries.Add(entry);
            }
        }
예제 #2
0
        public override MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent     = Description,
                State        = CollectorState.None,
                CurrentValue = ""
            };

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();

            #region Get Disk infos and states
            List <DiskSpaceInfoState> fileSystemEntries = new List <DiskSpaceInfoState>();
            //First see if ANY subentry is for all
            bool addAll = (from NIXDiskSpaceSubEntry d in SubItems
                           where d.FileSystemName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                NIXDiskSpaceSubEntry alertDef = (from NIXDiskSpaceSubEntry d in SubItems
                                                 where d.FileSystemName == "*"
                                                 select d).FirstOrDefault();
                alertDef.PrimaryUIValue = false;
                foreach (DiskInfo di in DiskInfo.FromDfTk(sshClient))
                {
                    DiskSpaceInfoState dis = new DiskSpaceInfoState()
                    {
                        FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    fileSystemEntries.Add(dis);
                }
            }
            else
            {
                foreach (DiskInfo di in DiskInfo.FromDfTk(sshClient))
                {
                    NIXDiskSpaceSubEntry alertDef = (from NIXDiskSpaceSubEntry d in SubItems
                                                     where d.FileSystemName.ToLower() == di.Name.ToLower()
                                                     select d).FirstOrDefault();

                    if (alertDef != null)
                    {
                        if (!fileSystemEntries.Any(f => f.FileSystemInfo.Name.ToLower() == di.Name.ToLower()))
                        {
                            DiskSpaceInfoState dis = new DiskSpaceInfoState()
                            {
                                FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            fileSystemEntries.Add(dis);
                        }
                    }
                }
            }
            #endregion

            SSHConnection.CloseConnection();

            int    errors   = 0;
            int    warnings = 0;
            int    success  = 0;
            double average  = 0;
            foreach (DiskSpaceInfoState dis in fileSystemEntries)
            {
                average += dis.FileSystemInfo.FreeSpacePerc;
                if (dis.FileSystemInfo.FreeSpacePerc <= dis.AlertDefinition.ErrorValue)
                {
                    dis.State = CollectorState.Error;
                    errors++;
                }
                else if (dis.FileSystemInfo.FreeSpacePerc <= dis.AlertDefinition.WarningValue)
                {
                    dis.State = CollectorState.Warning;
                    warnings++;
                }
                else
                {
                    dis.State = CollectorState.Good;
                    success++;
                }
                if (dis.AlertDefinition.PrimaryUIValue)
                {
                    currentState.CurrentValue     = dis.FileSystemInfo.FreeSpacePerc.ToString("0.0");
                    currentState.CurrentValueUnit = "%";
                }

                MonitorState fileSystemState = new MonitorState()
                {
                    ForAgent         = dis.FileSystemInfo.Name,
                    State            = dis.State,
                    CurrentValue     = dis.FileSystemInfo.FreeSpacePerc.ToString("0.0"),
                    CurrentValueUnit = "%",
                    PrimaryUIValue   = dis.AlertDefinition.PrimaryUIValue
                };
                currentState.ChildStates.Add(fileSystemState);
            }
            if (errors > 0 && warnings == 0 && success == 0) // any errors
            {
                currentState.State = CollectorState.Error;
            }
            else if (errors > 0 || warnings > 0) //any warnings
            {
                currentState.State = CollectorState.Warning;
            }
            else
            {
                currentState.State = CollectorState.Good;
            }

            if (currentState.CurrentValue.ToString() == "" && currentState.ChildStates.Count > 0)
            {
                currentState.CurrentValue     = (average / currentState.ChildStates.Count).ToString("0.0");
                currentState.CurrentValueUnit = "% (avg)";
            }

            return(currentState);
        }