private void UpdateFileSystem()
 {
     if (txtFileSystem.Text.Trim().Length > 0 && !fileSystemUpdated)
     {
         if (lvwFileSystems.SelectedItems.Count == 1)
         {
             ListViewItem           lvi  = lvwFileSystems.SelectedItems[0];
             LinuxDiskSpaceSubEntry dsse = (LinuxDiskSpaceSubEntry)lvwFileSystems.SelectedItems[0].Tag;
             dsse.FileSystemName  = txtFileSystem.Text;
             dsse.WarningValue    = (double)warningNumericUpDown.Value;
             dsse.ErrorValue      = (double)errorNumericUpDown.Value;
             lvi.Text             = txtFileSystem.Text;
             lvi.SubItems[1].Text = warningNumericUpDown.Value.ToString();
             lvi.SubItems[2].Text = errorNumericUpDown.Value.ToString();
         }
         else
         {
             LinuxDiskSpaceSubEntry dsse = new LinuxDiskSpaceSubEntry()
             {
                 FileSystemName = txtFileSystem.Text, WarningValue = (double)warningNumericUpDown.Value, ErrorValue = (double)errorNumericUpDown.Value
             };
             ListViewItem lvi = new ListViewItem()
             {
                 Text = dsse.FileSystemName
             };
             lvi.SubItems.Add(dsse.WarningValue.ToString());
             lvi.SubItems.Add(dsse.ErrorValue.ToString());
             lvi.Tag = dsse;
             lvwFileSystems.Items.Add(lvi);
             lvwFileSystems.SelectedItems.Clear();
             lvi.Selected = true;
         }
     }
 }
Esempio n. 2
0
        public List <DiskInfoState> GetDiskInfos()
        {
            List <DiskInfoState> fileSystemEntries = new List <DiskInfoState>();

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


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

            if (addAll)
            {
                LinuxDiskSpaceSubEntry alertDef = (from LinuxDiskSpaceSubEntry d in SubItems
                                                   where d.FileSystemName == "*"
                                                   select d).FirstOrDefault();
                foreach (Linux.DiskInfo di in DiskInfo.FromDfTk(sshClient))
                {
                    DiskInfoState dis = new DiskInfoState()
                    {
                        FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    fileSystemEntries.Add(dis);
                }
            }
            else
            {
                foreach (Linux.DiskInfo di in DiskInfo.FromDfTk(sshClient))
                {
                    LinuxDiskSpaceSubEntry alertDef = (from LinuxDiskSpaceSubEntry 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()))
                        {
                            DiskInfoState dis = new DiskInfoState()
                            {
                                FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            fileSystemEntries.Add(dis);
                        }
                    }
                }
            }
            SSHConnection.CloseConnection();
            return(fileSystemEntries);
        }
 private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     try
     {
         if (lvwFileSystems.Items.Count > 0 && (MessageBox.Show("Clear all existing entries?", "Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No))
         {
             return;
         }
         else
         {
             lvwFileSystems.Items.Clear();
             lvwFileSystems.Items.Add(new ListViewItem("Querying " + sshConnectionDetails.ComputerName + "..."));
             Application.DoEvents();
         }
         Renci.SshNet.SshClient sshClient = QuickMon.Linux.SshClientTools.GetSSHConnection(sshConnectionDetails);
         if (sshClient.IsConnected)
         {
             lvwFileSystems.Items.Clear();
             foreach (Linux.DiskInfo di in QuickMon.Linux.DiskInfo.FromDfTk(sshClient))
             {
                 LinuxDiskSpaceSubEntry dsse = new LinuxDiskSpaceSubEntry()
                 {
                     FileSystemName = di.Name, WarningValue = (double)warningNumericUpDown.Value, ErrorValue = (double)errorNumericUpDown.Value
                 };
                 ListViewItem lvi = new ListViewItem()
                 {
                     Text = dsse.FileSystemName
                 };
                 lvi.SubItems.Add(dsse.WarningValue.ToString());
                 lvi.SubItems.Add(dsse.ErrorValue.ToString());
                 lvi.Tag = dsse;
                 lvwFileSystems.Items.Add(lvi);
             }
         }
         else
         {
             lvwFileSystems.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);
     }
 }
 private void lvwFileSystems_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lvwFileSystems.SelectedItems.Count == 1)
     {
         fileSystemUpdated = true;
         LinuxDiskSpaceSubEntry dsse = (LinuxDiskSpaceSubEntry)lvwFileSystems.SelectedItems[0].Tag;
         warningNumericUpDown.SaveValueSet((decimal)dsse.WarningValue);
         errorNumericUpDown.SaveValueSet((decimal)dsse.ErrorValue);
         txtFileSystem.Text = dsse.FileSystemName;
         fileSystemUpdated  = false;
     }
     else if (lvwFileSystems.SelectedItems.Count == 0)
     {
         fileSystemUpdated  = true;
         txtFileSystem.Text = "";
         fileSystemUpdated  = false;
     }
 }
        private void cmdOK_Click(object sender, EventArgs e)
        {
            LinuxDiskSpaceEntry selectedEntry;

            if (SelectedEntry == null)
            {
                SelectedEntry = new LinuxDiskSpaceEntry();
            }
            selectedEntry = (LinuxDiskSpaceEntry)SelectedEntry;
            selectedEntry.SSHConnection = sshConnectionDetails;
            selectedEntry.SubItems      = new List <ICollectorConfigSubEntry>();

            foreach (ListViewItem lvi in lvwFileSystems.Items)
            {
                LinuxDiskSpaceSubEntry dsse = (LinuxDiskSpaceSubEntry)lvi.Tag;
                selectedEntry.SubItems.Add(dsse);
            }


            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
Esempio n. 6
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("linux/diskSpace"))
            {
                LinuxDiskSpaceEntry entry = new LinuxDiskSpaceEntry();
                entry.SSHConnection = SSHConnectionDetails.FromXmlElement(pcNode);

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

                entry.SubItems = new List <ICollectorConfigSubEntry>();
                foreach (XmlElement fileSystemNode in pcNode.SelectNodes("fileSystem"))
                {
                    LinuxDiskSpaceSubEntry fse = new LinuxDiskSpaceSubEntry();
                    fse.FileSystemName = fileSystemNode.ReadXmlElementAttr("name", "");
                    fse.WarningValue   = fileSystemNode.ReadXmlElementAttr("warningValue", 10.0d);
                    fse.ErrorValue     = fileSystemNode.ReadXmlElementAttr("errorValue", 5.0d);
                    entry.SubItems.Add(fse);
                }
                Entries.Add(entry);
            }
        }