public void SSHConfigTest() { string mconfig = "<collectorHost uniqueId=\"SSHTest\" dependOnParentId=\"\" name=\"SSH Test\" enabled=\"True\" expandOnStart=\"Auto\" " + " childCheckBehaviour=\"OnlyRunOnSuccess\" runAsEnabled=\"False\" runAs=\"\">" + " <collectorAgents agentCheckSequence=\"All\">" + " <collectorAgent name=\"SSH Test\" type=\"QuickMon.Collectors.SSHCommandCollector\" enabled=\"True\">" + "<config>" + "<carvcesEntries>" + "<carvceEntry>" + "<dataSource name=\"SSH Test\" sshSecOpt=\"password\" machine=\"hostName\" sshPort=\"22\" userName=\"user\" password=\"pwd\" privateKeyFile=\"\" passPhrase=\"\" persistent=\"False\">" + "<stateQuery>grep ^Version= /usr/lib/firefox/application.ini</stateQuery>" + "</dataSource>" + "<testConditions testSequence=\"GWE\">" + "<success testType=\"contains\">Version=53.0</success>" + "<warning testType=\"match\">[any]</warning>" + "<error testType=\"match\">[null]</error>" + "</testConditions>" + "</carvceEntry>" + "</carvcesEntries>" + "</config>" + " </collectorAgent>" + " </collectorAgents>" + " </collectorHost>"; CollectorHost ch = CollectorHost.FromXml(mconfig); Assert.AreEqual("SSH Test", ch.Name, "Collector host name not set"); Assert.AreEqual(1, ch.CollectorAgents.Count, "1 Collector agent expected"); Assert.AreEqual("SSH Test", ch.CollectorAgents[0].Name, "Agent name not set"); Assert.IsInstanceOfType(ch.CollectorAgents[0], typeof(Collectors.SSHCommandCollector)); Collectors.SSHCommandCollector sshCollector = (Collectors.SSHCommandCollector)ch.CollectorAgents[0]; Assert.AreEqual(1, ((Collectors.SSHCommandCollectorConfig)sshCollector.AgentConfig).Entries.Count, "1 SSH Command expected"); Collectors.SSHCommandCollectorConfigEntry sshEntry = (Collectors.SSHCommandCollectorConfigEntry)(((Collectors.SSHCommandCollectorConfig)sshCollector.AgentConfig).Entries[0]); Assert.AreEqual("hostName", sshEntry.SSHConnection.ComputerName, "SSH server name not found!"); Assert.AreEqual("Version=53.0", sshEntry.GoodValue, "Good value does not match"); string savedConfig = ch.ToXml(); ch = CollectorHost.FromXml(savedConfig); Assert.AreEqual("SSH Test", ch.Name, "Collector host name not set (reload)"); Assert.AreEqual(1, ch.CollectorAgents.Count, "1 Collector agent expected (reload)"); Assert.AreEqual("SSH Test", ch.CollectorAgents[0].Name, "Agent name not set (reload)"); //string testValue = sshEntry.ExecuteCommand(); //MonitorState testState = ch.RefreshCurrentState(); }
private void button1_Click(object sender, EventArgs e) { string configXml = txtConfig.Text; MonitorPack m = new MonitorPack(); m.LoadXml(configXml); if (m.CollectorHosts.Count > 0) { EditCollectorHost editCollectorHost = new EditCollectorHost(); editCollectorHost.SelectedConfig = m.CollectorHosts[0].ToXml(); if (editCollectorHost.ShowDialog() == System.Windows.Forms.DialogResult.OK) { m.CollectorHosts[0] = CollectorHost.FromXml(XmlFormattingUtils.NormalizeXML(editCollectorHost.SelectedConfig), null, false); txtConfig.Text = m.ToXml(); } } }
public System.Data.DataSet GetCollectorHostDetails(QuickMon.RemoteCollectorHost entry) { StringBuilder consoleOutPut = new StringBuilder(); System.Data.DataSet result = new System.Data.DataSet(); try { Console.WriteLine("{0}: Getting collector host data set: {1}\r\n{2}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name, new string('*', 79)); CollectorHost ch = CollectorHost.FromXml(entry.ToCollectorHostXml()); result = ch.GetAllAgentDetails(); consoleOutPut.AppendFormat("{0}: Results for collector host: {1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name); consoleOutPut.AppendFormat(" Data set request received: {0}\r\n", entry.Name); if (result != null) { consoleOutPut.AppendFormat(" Tables: {0}\r\n", result.Tables.Count); for (int i = 0; i < result.Tables.Count; i++) { consoleOutPut.AppendFormat(" Table[{0}]: {1} row(s)\r\n", i, result.Tables[i].Rows.Count); } } else { consoleOutPut.AppendFormat(" Warning! Data set is empty!\r\n"); } } catch (Exception ex) { consoleOutPut.AppendFormat(" Error: {0}\r\n", ex); System.Data.DataTable dt = new System.Data.DataTable("Exception"); dt.Columns.Add(new System.Data.DataColumn("Text", typeof(string))); dt.Rows.Add(ex.ToString()); result.Tables.Add(dt); } consoleOutPut.AppendLine(new string('*', 79)); Console.WriteLine(consoleOutPut.ToString()); return(result); }
public void CollectorAgentTestPing() { string mconfig = "<collectorHost uniqueId=\"123\" dependOnParentId=\"\" name=\"Ping\" enabled=\"True\" expandOnStart=\"Auto\" " + " childCheckBehaviour=\"OnlyRunOnSuccess\" runAsEnabled=\"False\" runAs=\"\">" + " <collectorAgents agentCheckSequence=\"All\">" + " <collectorAgent name=\"Ping localhost\" type=\"QuickMon.Collectors.PingCollector\" enabled=\"True\">" + " <config>" + " <entries>" + " <entry pingMethod=\"Ping\" address=\"localhost\" description=\"\" maxTimeMS=\"1000\" timeOutMS=\"5000\" httpHeaderUser=\"\" httpHeaderPwd=\"\" httpProxyServer=\"\" httpProxyUser=\"\" httpProxyPwd=\"\" socketPort=\"23\" receiveTimeoutMS=\"30000\" sendTimeoutMS=\"30000\" useTelnetLogin=\"False\" userName=\"\" password=\"\" ignoreInvalidHTTPSCerts=\"False\" />" + " <entry pingMethod=\"HTTP\" address=\"http://localhost\" description=\"\" maxTimeMS=\"1000\" timeOutMS=\"5000\" httpHeaderUser=\"\" httpHeaderPwd=\"\" httpProxyServer=\"\" httpProxyUser=\"\" httpProxyPwd=\"\" socketPort=\"23\" receiveTimeoutMS=\"30000\" sendTimeoutMS=\"30000\" useTelnetLogin=\"False\" userName=\"\" password=\"\" ignoreInvalidHTTPSCerts=\"False\" />" + " <entry pingMethod=\"SOCKET\" address=\"127.0.0.1\" description=\"\" maxTimeMS=\"1000\" timeOutMS=\"5000\" httpHeaderUser=\"\" httpHeaderPwd=\"\" httpProxyServer=\"\" httpProxyUser=\"\" httpProxyPwd=\"\" socketPort=\"80\" receiveTimeoutMS=\"30000\" sendTimeoutMS=\"30000\" useTelnetLogin=\"False\" userName=\"\" password=\"\" ignoreInvalidHTTPSCerts=\"False\" />" + " </entries>" + " </config>" + " </collectorAgent>" + " </collectorAgents>" + " </collectorHost>"; CollectorHost ch = CollectorHost.FromXml(mconfig); Assert.IsNotNull(ch, "Monitor pack is null"); Assert.AreEqual("Ping", ch.Name, "Collector host name not set"); Assert.AreEqual("123", ch.UniqueId, "Collector host UniqueId not set"); Assert.AreEqual(true, ch.Enabled, "Collector host Enabled property not set"); Assert.AreEqual(false, ch.RunAsEnabled, "Run As enabled!"); Assert.AreEqual("", ch.RunAs, "Run As set up incorrectly!"); Assert.AreEqual("", ch.ParentCollectorId, "Collector host ParentCollectorId property not set"); Assert.AreEqual(AgentCheckSequence.All, ch.AgentCheckSequence, "Collector host AgentCheckSequence property not set"); Assert.AreEqual(ChildCheckBehaviour.OnlyRunOnSuccess, ch.ChildCheckBehaviour, "Collector host ChildCheckBehaviour property not set"); Assert.AreEqual(1, ch.CollectorAgents.Count, "1 Collector agent expected"); Assert.AreEqual(0, ch.ConfigVariables.Count, "No config variables expected"); Assert.AreEqual(0, ch.RefreshCount, "No refreshes expected yet"); MonitorState testState = ch.RefreshCurrentState(); Assert.AreEqual(1, ch.RefreshCount, "1 refresh expected"); Assert.AreEqual(CollectorState.Good, testState.State, "Cannot ping self"); }