Exemple #1
0
        private void cmdTest_Click(object sender, EventArgs e)
        {
            LinuxProcessEntry testEntry = new LinuxProcessEntry();

            testEntry.SSHConnection       = sshConnectionDetails;
            testEntry.Name                = txtName.Text;
            testEntry.ProcessCheckOption  = (ProcessCheckOption)cboProcessCheckOption.SelectedIndex;
            testEntry.TopProcessCount     = (int)topProcessCountUpDown.Value;
            testEntry.CPUPercWarningValue = (int)topXCPUPercWarnNumericUpDown.Value;
            testEntry.CPUPercErrorValue   = (int)topXCPUPercErrNumericUpDown.Value;
            testEntry.MemPercWarningValue = (int)topXMemPercWarnNumericUpDown.Value;
            testEntry.MemPercErrorValue   = (int)topXMemPercErrNumericUpDown.Value;
            testEntry.SubItems.Clear();

            foreach (ListViewItem lvi in lvwProcesses.Items)
            {
                LinuxProcessSubEntry dsse = (LinuxProcessSubEntry)lvi.Tag;
                testEntry.SubItems.Add(dsse);
            }

            try
            {
                List <ProcessInfoState> states = testEntry.GetStates();
                MessageBox.Show(string.Format("Test succeeded!\r\nGood: {0}\r\nWarning: {1}\r\nError: {2}",
                                              states.Count <ProcessInfoState>(s => s.State == CollectorState.Good),
                                              states.Count <ProcessInfoState>(s => s.State == CollectorState.Warning),
                                              states.Count <ProcessInfoState>(s => s.State == CollectorState.Error)
                                              )
                                , "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Test failed!\r\n" + ex.Message, "Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemple #2
0
        private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            LinuxProcessViewer pviewer = new LinuxProcessViewer();

            pviewer.SSHConnectionDetails = sshConnectionDetails;
            if (pviewer.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (Linux.ProcessInfo pi in pviewer.SelectedProcesses)
                {
                    if ((from ListViewItem l in lvwProcesses.Items
                         where l.Text.ToLower() == pi.ProcessName.ToLower()
                         select l).Count() == 0)
                    {
                        LinuxProcessSubEntry dsse = new LinuxProcessSubEntry()
                        {
                            ProcessName         = pi.ProcessName,
                            CPUPercWarningValue = (int)cpuPercWarnNumericUpDown.Value,
                            CPUPercErrorValue   = (int)cpuPercErrNumericUpDown.Value,
                            MemPercWarningValue = (int)memPercWarnNumericUpDown.Value,
                            MemPercErrorValue   = (int)memPercErrNumericUpDown.Value
                        };
                        ListViewItem lvi = new ListViewItem()
                        {
                            Text = dsse.ProcessName
                        };
                        lvi.SubItems.Add(dsse.CPUPercWarningValue.ToString());
                        lvi.SubItems.Add(dsse.CPUPercErrorValue.ToString());
                        lvi.SubItems.Add(dsse.MemPercWarningValue.ToString());
                        lvi.SubItems.Add(dsse.MemPercErrorValue.ToString());
                        lvi.Tag = dsse;
                        lvwProcesses.Items.Add(lvi);
                    }
                }
            }
        }
Exemple #3
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            LinuxProcessEntry selectedEntry;

            if (SelectedEntry == null)
            {
                SelectedEntry = new LinuxProcessEntry();
            }
            selectedEntry = (LinuxProcessEntry)SelectedEntry;
            selectedEntry.SSHConnection       = sshConnectionDetails;
            selectedEntry.Name                = txtName.Text;
            selectedEntry.ProcessCheckOption  = (ProcessCheckOption)cboProcessCheckOption.SelectedIndex;
            selectedEntry.TopProcessCount     = (int)topProcessCountUpDown.Value;
            selectedEntry.CPUPercWarningValue = (int)topXCPUPercWarnNumericUpDown.Value;
            selectedEntry.CPUPercErrorValue   = (int)topXCPUPercErrNumericUpDown.Value;
            selectedEntry.MemPercWarningValue = (int)topXMemPercWarnNumericUpDown.Value;
            selectedEntry.MemPercErrorValue   = (int)topXMemPercErrNumericUpDown.Value;
            selectedEntry.SubItems.Clear();

            foreach (ListViewItem lvi in lvwProcesses.Items)
            {
                LinuxProcessSubEntry dsse = (LinuxProcessSubEntry)lvi.Tag;
                selectedEntry.SubItems.Add(dsse);
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
Exemple #4
0
        public List <ProcessInfoState> GetStates()
        {
            List <ProcessInfoState> processEntries = new List <ProcessInfoState>();

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

            LinuxProcessSubEntry globalAlertDef = new LinuxProcessSubEntry();

            globalAlertDef.CPUPercWarningValue = CPUPercWarningValue;
            globalAlertDef.CPUPercErrorValue   = CPUPercErrorValue;
            globalAlertDef.MemPercWarningValue = MemPercWarningValue;
            globalAlertDef.MemPercErrorValue   = MemPercErrorValue;

            List <ProcessInfo> runningProcesses = ProcessInfo.FromPsAux(sshClient);

            if (ProcessCheckOption == ProcessCheckOption.TopXByCPU)
            {
                foreach (ProcessInfo p in (from p in runningProcesses
                                           orderby p.percCPU descending
                                           select p).Take(TopProcessCount))
                {
                    processEntries.Add(new ProcessInfoState()
                    {
                        ProcessInfo = p, AlertDefinition = globalAlertDef
                    });
                }
            }
            else if (ProcessCheckOption == ProcessCheckOption.TopXByMem)
            {
                foreach (ProcessInfo p in (from p in runningProcesses
                                           orderby p.percMEM descending
                                           select p).Take(TopProcessCount))
                {
                    processEntries.Add(new ProcessInfoState()
                    {
                        ProcessInfo = p, AlertDefinition = globalAlertDef
                    });
                }
            }
            else
            {
                foreach (ProcessInfo p in runningProcesses)
                {
                    LinuxProcessSubEntry se = (from LinuxProcessSubEntry sdef in SubItems
                                               where FileNameMatch(p.ProcessName, sdef.ProcessName)
                                               select sdef).FirstOrDefault();
                    if (se != null)
                    {
                        processEntries.Add(new ProcessInfoState()
                        {
                            ProcessInfo = p, AlertDefinition = se
                        });
                    }
                }
            }
            SSHConnection.CloseConnection();
            return(processEntries);
        }
Exemple #5
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 procNode in root.SelectNodes("linuxProcess"))
            {
                LinuxProcessEntry entry = new LinuxProcessEntry();
                entry.SSHConnection = SSHConnectionDetails.FromXmlElement(procNode);

                //entry.SSHConnection.SSHSecurityOption = SSHSecurityOptionTypeConverter.FromString(procNode.ReadXmlElementAttr("sshSecOpt", "password"));
                //entry.SSHConnection.ComputerName = procNode.ReadXmlElementAttr("machine", ".");
                //entry.SSHConnection.SSHPort = procNode.ReadXmlElementAttr("sshPort", 22);
                //entry.SSHConnection.UserName = procNode.ReadXmlElementAttr("userName", "");
                //entry.SSHConnection.Password = procNode.ReadXmlElementAttr("password", "");
                //entry.SSHConnection.PrivateKeyFile = procNode.ReadXmlElementAttr("privateKeyFile", "");
                //entry.SSHConnection.PassPhrase = procNode.ReadXmlElementAttr("passPhrase", "");

                entry.Name = procNode.ReadXmlElementAttr("name", "");
                entry.ProcessCheckOption  = ProcessCheckOptionTypeConverter.FromString(procNode.ReadXmlElementAttr("processCheckOption", ""));
                entry.TopProcessCount     = procNode.ReadXmlElementAttr("topProcessCount", 10);
                entry.CPUPercWarningValue = procNode.ReadXmlElementAttr("cpuPercWarningValue", 80);
                entry.CPUPercErrorValue   = procNode.ReadXmlElementAttr("cpuPercErrorValue", 90);
                entry.MemPercWarningValue = procNode.ReadXmlElementAttr("memPercWarningValue", 80);
                entry.MemPercErrorValue   = procNode.ReadXmlElementAttr("memPercErrorValue", 90);

                entry.SubItems = new List <ICollectorConfigSubEntry>();
                foreach (XmlElement fileSystemNode in procNode.SelectNodes("specificEntry"))
                {
                    LinuxProcessSubEntry fse = new LinuxProcessSubEntry();
                    fse.ProcessName         = fileSystemNode.ReadXmlElementAttr("name", "");
                    fse.CPUPercWarningValue = fileSystemNode.ReadXmlElementAttr("cpuPercWarningValue", 80);
                    fse.CPUPercErrorValue   = fileSystemNode.ReadXmlElementAttr("cpuPercErrorValue", 90);
                    fse.MemPercWarningValue = fileSystemNode.ReadXmlElementAttr("memPercWarningValue", 80);
                    fse.MemPercErrorValue   = fileSystemNode.ReadXmlElementAttr("memPercErrorValue", 90);

                    entry.SubItems.Add(fse);
                }
                Entries.Add(entry);
            }
        }
Exemple #6
0
 private void UpdateSpecificProcess()
 {
     if (txtProcessName.Text.Trim().Length > 0 && !specificProcessUpdated)
     {
         if (lvwProcesses.SelectedItems.Count == 1)
         {
             ListViewItem         lvi  = lvwProcesses.SelectedItems[0];
             LinuxProcessSubEntry dsse = (LinuxProcessSubEntry)lvwProcesses.SelectedItems[0].Tag;
             dsse.ProcessName         = txtProcessName.Text;
             dsse.CPUPercWarningValue = (int)cpuPercWarnNumericUpDown.Value;
             dsse.CPUPercErrorValue   = (int)cpuPercErrNumericUpDown.Value;
             dsse.MemPercWarningValue = (int)memPercWarnNumericUpDown.Value;
             dsse.MemPercErrorValue   = (int)memPercErrNumericUpDown.Value;
             lvi.Text             = txtProcessName.Text;
             lvi.SubItems[1].Text = cpuPercWarnNumericUpDown.Value.ToString();
             lvi.SubItems[2].Text = cpuPercErrNumericUpDown.Value.ToString();
             lvi.SubItems[3].Text = memPercWarnNumericUpDown.Value.ToString();
             lvi.SubItems[4].Text = memPercErrNumericUpDown.Value.ToString();
         }
         else
         {
             LinuxProcessSubEntry dsse = new LinuxProcessSubEntry()
             {
                 ProcessName         = txtProcessName.Text,
                 CPUPercWarningValue = (int)cpuPercWarnNumericUpDown.Value,
                 CPUPercErrorValue   = (int)cpuPercErrNumericUpDown.Value,
                 MemPercWarningValue = (int)memPercWarnNumericUpDown.Value,
                 MemPercErrorValue   = (int)memPercErrNumericUpDown.Value
             };
             ListViewItem lvi = new ListViewItem()
             {
                 Text = dsse.ProcessName
             };
             lvi.SubItems.Add(dsse.CPUPercWarningValue.ToString());
             lvi.SubItems.Add(dsse.CPUPercErrorValue.ToString());
             lvi.SubItems.Add(dsse.MemPercWarningValue.ToString());
             lvi.SubItems.Add(dsse.MemPercErrorValue.ToString());
             lvi.Tag = dsse;
             lvwProcesses.Items.Add(lvi);
             lvwProcesses.SelectedItems.Clear();
             lvi.Selected = true;
         }
     }
 }
Exemple #7
0
 private void lvwProcesses_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lvwProcesses.SelectedItems.Count == 1)
     {
         specificProcessUpdated = true;
         LinuxProcessSubEntry dsse = (LinuxProcessSubEntry)lvwProcesses.SelectedItems[0].Tag;
         txtProcessName.Text = dsse.ProcessName;
         cpuPercWarnNumericUpDown.SaveValueSet(dsse.CPUPercWarningValue);
         cpuPercErrNumericUpDown.SaveValueSet(dsse.CPUPercErrorValue);
         memPercWarnNumericUpDown.SaveValueSet(dsse.MemPercWarningValue);
         memPercErrNumericUpDown.SaveValueSet(dsse.MemPercErrorValue);
         specificProcessUpdated = false;
     }
     else if (lvwProcesses.SelectedItems.Count == 0)
     {
         specificProcessUpdated = true;
         txtProcessName.Text    = "";
         specificProcessUpdated = false;
     }
 }