private void UpdateFileSystem() { if (txtNIC.Text.Trim().Length > 0 && !fileSystemUpdated) { if (lvwNICs.SelectedItems.Count == 1) { ListViewItem lvi = lvwNICs.SelectedItems[0]; LinuxNICSubEntry dsse = (LinuxNICSubEntry)lvwNICs.SelectedItems[0].Tag; dsse.NICName = txtNIC.Text; dsse.WarningValueKB = (long)warningNumericUpDown.Value; dsse.ErrorValueKB = (long)errorNumericUpDown.Value; lvi.Text = txtNIC.Text; lvi.SubItems[1].Text = warningNumericUpDown.Value.ToString(); lvi.SubItems[2].Text = errorNumericUpDown.Value.ToString(); } else { LinuxNICSubEntry dsse = new LinuxNICSubEntry() { NICName = txtNIC.Text, 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); lvwNICs.SelectedItems.Clear(); lvi.Selected = true; } } }
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); }
private void lblAutoAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { 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 " + sshConnectionDetails.ComputerName + "...")); Application.DoEvents(); } Renci.SshNet.SshClient sshClient = QuickMon.Linux.SshClientTools.GetSSHConnection(sshConnectionDetails); if (sshClient.IsConnected) { lvwNICs.Items.Clear(); foreach (Linux.NicInfo di in QuickMon.Linux.NicInfo.GetCurrentNicStats(sshClient)) { LinuxNICSubEntry dsse = new LinuxNICSubEntry() { 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); } }
private void lvwFileSystems_SelectedIndexChanged(object sender, EventArgs e) { if (lvwNICs.SelectedItems.Count == 1) { fileSystemUpdated = true; LinuxNICSubEntry dsse = (LinuxNICSubEntry)lvwNICs.SelectedItems[0].Tag; warningNumericUpDown.SaveValueSet((decimal)dsse.WarningValueKB); errorNumericUpDown.SaveValueSet((decimal)dsse.ErrorValueKB); txtNIC.Text = dsse.NICName; fileSystemUpdated = false; } else if (lvwNICs.SelectedItems.Count == 0) { fileSystemUpdated = true; txtNIC.Text = ""; fileSystemUpdated = false; } }
private void cmdOK_Click(object sender, EventArgs e) { LinuxNICEntry selectedEntry; if (SelectedEntry == null) { SelectedEntry = new LinuxNICEntry(); } selectedEntry = (LinuxNICEntry)SelectedEntry; selectedEntry.SSHConnection = sshConnectionDetails; selectedEntry.SubItems = new List <ICollectorConfigSubEntry>(); foreach (ListViewItem lvi in lvwNICs.Items) { LinuxNICSubEntry dsse = (LinuxNICSubEntry)lvi.Tag; selectedEntry.SubItems.Add(dsse); } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); }
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/nics")) { LinuxNICEntry entry = new LinuxNICEntry(); 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("nic")) { LinuxNICSubEntry fse = new LinuxNICSubEntry(); fse.NICName = fileSystemNode.ReadXmlElementAttr("name", ""); fse.WarningValueKB = fileSystemNode.ReadXmlElementAttr("warningValueKB", 1024); fse.ErrorValueKB = fileSystemNode.ReadXmlElementAttr("errorValueKB", 5120); entry.SubItems.Add(fse); } Entries.Add(entry); } }