Ejemplo n.º 1
0
 private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     try
     {
         if (lvwDisks.Items.Count > 0 && (MessageBox.Show("Clear all existing entries?", "Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No))
         {
             return;
         }
         else
         {
             lvwDisks.Items.Clear();
             lvwDisks.Items.Add(new ListViewItem("Querying " + sshConnectionDetails.ComputerName + "..."));
             Application.DoEvents();
         }
         Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(sshConnectionDetails);
         if (sshClient.IsConnected)
         {
             lvwDisks.Items.Clear();
             foreach (DiskIOInfo di in DiskIOInfo.GetCurrentDiskStats(sshClient))
             {
                 NIXDiskIOSubEntry dsse = new NIXDiskIOSubEntry()
                 {
                     DiskName = di.Name, WarningValue = (double)warningNumericUpDown.Value, ErrorValue = (double)errorNumericUpDown.Value
                 };
                 ListViewItem lvi = new ListViewItem()
                 {
                     Text = dsse.DiskName
                 };
                 lvi.SubItems.Add(dsse.WarningValue.ToString());
                 lvi.SubItems.Add(dsse.ErrorValue.ToString());
                 lvi.Tag = dsse;
                 lvwDisks.Items.Add(lvi);
             }
         }
         else
         {
             lvwDisks.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);
     }
 }
Ejemplo n.º 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 <DiskIOInfoState> diskEntries = new List <DiskIOInfoState>();
            //First see if ANY subentry is for all
            bool addAll = (from NIXDiskIOSubEntry d in SubItems
                           where d.DiskName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                NIXDiskIOSubEntry alertDef = (from NIXDiskIOSubEntry d in SubItems
                                              where d.DiskName == "*"
                                              select d).FirstOrDefault();
                alertDef.PrimaryUIValue = false;
                foreach (DiskIOInfo di in DiskIOInfo.GetCurrentDiskStats(sshClient, 250))
                {
                    DiskIOInfoState dis = new DiskIOInfoState()
                    {
                        DiskInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    diskEntries.Add(dis);
                }
            }
            else
            {
                foreach (DiskIOInfo di in DiskIOInfo.GetCurrentDiskStats(sshClient, 250))
                {
                    NIXDiskIOSubEntry alertDef = (from NIXDiskIOSubEntry d in SubItems
                                                  where d.DiskName.ToLower() == di.Name.ToLower()
                                                  select d).FirstOrDefault();

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

            SSHConnection.CloseConnection();

            int    errors   = 0;
            int    warnings = 0;
            int    success  = 0;
            double average  = 0;
            foreach (DiskIOInfoState dis in diskEntries)
            {
                average += dis.DiskInfo.BytesReadWritePerSec;
                if (dis.DiskInfo.BytesReadWritePerSec >= dis.AlertDefinition.ErrorValue)
                {
                    dis.State = CollectorState.Error;
                }
                else if (dis.DiskInfo.BytesReadWritePerSec >= dis.AlertDefinition.WarningValue)
                {
                    dis.State = CollectorState.Warning;
                }
                else
                {
                    dis.State = CollectorState.Good;
                    success++;
                }
                if (dis.AlertDefinition.PrimaryUIValue)
                {
                    currentState.CurrentValue     = dis.DiskInfo.BytesReadWritePerSec.ToString("0.0");
                    currentState.CurrentValueUnit = "Bytes/Sec";
                }

                MonitorState diskIOState = new MonitorState()
                {
                    ForAgent         = dis.DiskInfo.Name,
                    State            = dis.State,
                    CurrentValue     = dis.DiskInfo.BytesReadWritePerSec.ToString("0.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);
        }