private void cmdTest_Click(object sender, EventArgs e)
        {
            try
            {
                LinuxSSHCommandEntry testEntry = new LinuxSSHCommandEntry()
                {
                    SSHConnection = sshConnectionDetails
                };
                testEntry.CommandString = txtCommandText.Text;

                testEntry.ValueReturnCheckSequence = optEWG.Checked ? CollectorAgentReturnValueCheckSequence.EWG : CollectorAgentReturnValueCheckSequence.GWE;
                testEntry.ValueReturnType          = (SSHCommandValueReturnType)cboReturnType.SelectedIndex;
                testEntry.SuccessMatchType         = (CollectorAgentReturnValueCompareMatchType )cboSuccessMatchType.SelectedIndex;
                testEntry.SuccessValueOrMacro      = txtGoodValueOrMacro.Text;
                testEntry.WarningMatchType         = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex;
                testEntry.WarningValueOrMacro      = txtWarningValueOrMacro.Text;
                testEntry.ErrorMatchType           = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex;
                testEntry.ErrorValueOrMacro        = txtErrorValueOrMacro.Text;

                string         value        = testEntry.ExecuteCommand();
                CollectorState currentState = CollectorAgentReturnValueCompareEngine.GetState(testEntry.ValueReturnCheckSequence, testEntry.SuccessMatchType, testEntry.SuccessValueOrMacro,
                                                                                              testEntry.WarningMatchType, testEntry.WarningValueOrMacro, testEntry.ErrorMatchType, testEntry.ErrorValueOrMacro, value);

                MessageBox.Show(string.Format("Returned state: {0}\r\nOutput: {1}", currentState, value), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
示例#2
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 cmndNode in root.SelectNodes("linux/sshCommand"))
            {
                LinuxSSHCommandEntry entry = new LinuxSSHCommandEntry();
                entry.SSHConnection = SSHConnectionDetails.FromXmlElement(cmndNode);

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

                entry.Name = cmndNode.ReadXmlElementAttr("name", "");

                XmlNode commandStringNode = cmndNode.SelectSingleNode("commandString");
                entry.CommandString = cmndNode.InnerText;

                XmlNode alertTriggersNode = cmndNode.SelectSingleNode("alertTriggers");
                entry.ValueReturnType          = SSHCommandValueReturnTypeConverter.FromString(alertTriggersNode.ReadXmlElementAttr("valueReturnType", "RawValue"));
                entry.ValueReturnCheckSequence = CollectorAgentReturnValueCompareEngine.CheckSequenceTypeFromString(alertTriggersNode.ReadXmlElementAttr("checkSequence", "EWG"));

                XmlNode successNode = alertTriggersNode.SelectSingleNode("success");
                entry.SuccessMatchType    = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(successNode.ReadXmlElementAttr("matchType", "Match"));
                entry.SuccessValueOrMacro = successNode.ReadXmlElementAttr("value", "[any]");

                XmlNode warningNode = alertTriggersNode.SelectSingleNode("warning");
                entry.WarningMatchType    = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(warningNode.ReadXmlElementAttr("matchType", "Match"));
                entry.WarningValueOrMacro = warningNode.ReadXmlElementAttr("value", "0");

                XmlNode errorNode = alertTriggersNode.SelectSingleNode("error");
                entry.ErrorMatchType    = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(errorNode.ReadXmlElementAttr("matchType", "Match"));
                entry.ErrorValueOrMacro = errorNode.ReadXmlElementAttr("value", "[null]");

                Entries.Add(entry);
            }
        }
        private void LoadEntryDetails()
        {
            LinuxSSHCommandEntry currentEntry = (LinuxSSHCommandEntry)SelectedEntry;

            if (currentEntry == null)
            {
                currentEntry = new LinuxSSHCommandEntry();
            }
            sshConnectionDetails  = currentEntry.SSHConnection;
            txtSSHConnection.Text = Linux.SSHConnectionDetails.FormatSSHConnection(sshConnectionDetails);

            txtName.Text                      = currentEntry.Name;
            txtCommandText.Text               = currentEntry.CommandString;
            optEWG.Checked                    = currentEntry.ValueReturnCheckSequence == CollectorAgentReturnValueCheckSequence.EWG;
            cboReturnType.SelectedIndex       = (int)currentEntry.ValueReturnType;
            cboSuccessMatchType.SelectedIndex = (int)currentEntry.SuccessMatchType;
            txtGoodValueOrMacro.Text          = currentEntry.SuccessValueOrMacro;
            cboWarningMatchType.SelectedIndex = (int)currentEntry.WarningMatchType;
            txtWarningValueOrMacro.Text       = currentEntry.WarningValueOrMacro;
            cboErrorMatchType.SelectedIndex   = (int)currentEntry.ErrorMatchType;
            txtErrorValueOrMacro.Text         = currentEntry.ErrorValueOrMacro;
        }