private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                SSHConnectionDetails sshConnection = sshConnectionDetails.Clone();
                sshConnection.ComputerName     = ApplyConfigVarsOnField(sshConnection.ComputerName);
                sshConnection.UserName         = ApplyConfigVarsOnField(sshConnection.UserName);
                sshConnection.Password         = ApplyConfigVarsOnField(sshConnection.Password);
                sshConnection.PrivateKeyFile   = ApplyConfigVarsOnField(sshConnection.PrivateKeyFile);
                sshConnection.PassPhrase       = ApplyConfigVarsOnField(sshConnection.PassPhrase);
                sshConnection.ConnectionName   = ApplyConfigVarsOnField(sshConnection.ConnectionName);
                sshConnection.ConnectionString = ApplyConfigVarsOnField(sshConnection.ConnectionString);

                if (lvwNICs.Items.Count > 0 && (MessageBox.Show("Clear all existing entries?", "Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No))
                {
                    return;
                }
                else
                {
                    lvwNICs.Items.Clear();
                    lvwNICs.Items.Add(new ListViewItem("Querying " + sshConnection.ComputerName + "..."));
                    Application.DoEvents();
                }

                Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(sshConnection);
                if (sshClient.IsConnected)
                {
                    lvwNICs.Items.Clear();
                    foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient))
                    {
                        NIXNICSubEntry dsse = new NIXNICSubEntry()
                        {
                            NICName = di.Name, WarningValueKB = (long)warningNumericUpDown.Value, ErrorValueKB = (long)errorNumericUpDown.Value
                        };
                        ListViewItem lvi = new ListViewItem()
                        {
                            Text = dsse.NICName
                        };
                        lvi.SubItems.Add(dsse.WarningValueKB.ToString());
                        lvi.SubItems.Add(dsse.ErrorValueKB.ToString());
                        lvi.Tag = dsse;
                        lvwNICs.Items.Add(lvi);
                    }
                }
                else
                {
                    lvwNICs.Items.Clear();
                    MessageBox.Show("Could not connect to computer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Esempio n. 2
0
        public List <NICState> GetNICInfos()
        {
            List <NICState> nicEntries = new List <NICState>();

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

            //First see if ANY subentry is for all
            bool addAll = (from LinuxNICSubEntry d in SubItems
                           where d.NICName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                LinuxNICSubEntry alertDef = (from LinuxNICSubEntry d in SubItems
                                             where d.NICName == "*"
                                             select d).FirstOrDefault();
                foreach (Linux.NicInfo ni in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    NICState nis = new NICState()
                    {
                        NICInfo = ni, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    nicEntries.Add(nis);
                }
            }
            else
            {
                foreach (Linux.NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    LinuxNICSubEntry alertDef = (from LinuxNICSubEntry d in SubItems
                                                 where d.NICName.ToLower() == di.Name.ToLower()
                                                 select d).FirstOrDefault();

                    if (alertDef != null)
                    {
                        if (!nicEntries.Any(f => f.NICInfo.Name.ToLower() == di.Name.ToLower()))
                        {
                            NICState dis = new NICState()
                            {
                                NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            nicEntries.Add(dis);
                        }
                    }
                }
                SSHConnection.CloseConnection();
            }
            return(nicEntries);
        }
Esempio n. 3
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 <NICInfoState> nicEntries = new List <NICInfoState>();
            //First see if ANY subentry is for all
            bool addAll = (from NIXNICSubEntry d in SubItems
                           where d.NICName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                NIXNICSubEntry alertDef = (from NIXNICSubEntry d in SubItems
                                           where d.NICName == "*"
                                           select d).FirstOrDefault();
                alertDef.PrimaryUIValue = false;
                foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    NICInfoState dis = new NICInfoState()
                    {
                        NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    nicEntries.Add(dis);
                }
            }
            else
            {
                foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    NIXNICSubEntry alertDef = (from NIXNICSubEntry d in SubItems
                                               where d.NICName.ToLower() == di.Name.ToLower()
                                               select d).FirstOrDefault();

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

            SSHConnection.CloseConnection();

            int    errors   = 0;
            int    warnings = 0;
            int    success  = 0;
            double average  = 0;
            foreach (NICInfoState dis in nicEntries)
            {
                average += dis.NICInfo.RTxBytesPerSec;
                if (dis.NICInfo.RTxBytesPerSec >= dis.AlertDefinition.ErrorValueKB * 1024)
                {
                    dis.State = CollectorState.Error;
                }
                else if (dis.NICInfo.RTxBytesPerSec >= dis.AlertDefinition.WarningValueKB * 1024)
                {
                    dis.State = CollectorState.Warning;
                }
                else
                {
                    dis.State = CollectorState.Good;
                    success++;
                }
                if (dis.AlertDefinition.PrimaryUIValue)
                {
                    currentState.CurrentValue     = dis.NICInfo.RTxBytesPerSec.ToString("0");
                    currentState.CurrentValueUnit = "Bytes/Sec";
                }

                MonitorState diskIOState = new MonitorState()
                {
                    ForAgent         = dis.NICInfo.Name,
                    State            = dis.State,
                    CurrentValue     = dis.NICInfo.RTxBytesPerSec.ToString("0"),
                    CurrentValueUnit = "Bytes/Sec",
                    PrimaryUIValue   = dis.AlertDefinition.PrimaryUIValue
                };
                currentState.ChildStates.Add(diskIOState);
            }
            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 = "Bytes/Sec (avg)";
            }

            return(currentState);
        }