public void TestAddMonitorDataToDatabase() { // Get Agents before adding data for clean up string sysDescOld = string.Empty; string sysNameOld = string.Empty; string sysUptimeOld = string.Empty; List <AgentDataModel> agents = databaseConnection.GetAgentsFromDatabase(); foreach (AgentDataModel agent in agents) { if (agent.AgentNr == 1) { sysDescOld = agent.SysDescription; sysNameOld = agent.SysName; sysUptimeOld = agent.SysUptime; } } // Set new data string sysDescNew = "Test-SysDesc: windows 2008 Server R2"; string sysNameNew = "Test-SysName: testserver"; string sysUptimeNew = "Test-SysUptime: 2d 3h 5m"; List <KeyValuePair <string, string> > monitorData = new List <KeyValuePair <string, string> >(); monitorData.Add(new KeyValuePair <string, string>("1.3.6.1.2.1.1.1", sysDescNew)); monitorData.Add(new KeyValuePair <string, string>("1.3.6.1.2.1.1.5", sysNameNew)); monitorData.Add(new KeyValuePair <string, string>("1.3.6.1.2.1.25.1.1", sysUptimeNew)); databaseConnection.AddMonitorDataToDatabase(1, monitorData); // Check new data List <AgentDataModel> agentsNew = databaseConnection.GetAgentsFromDatabase(); foreach (AgentDataModel agent in agentsNew) { if (agent.AgentNr == 1) { Assert.AreEqual(sysDescNew, agent.SysDescription); Assert.AreEqual(sysNameNew, agent.SysName); Assert.AreEqual(sysUptimeNew, agent.SysUptime); } } //CLean up List <KeyValuePair <string, string> > monitorDataOld = new List <KeyValuePair <string, string> >(); monitorData.Add(new KeyValuePair <string, string>("1.3.6.1.2.1.1.1", sysDescOld)); monitorData.Add(new KeyValuePair <string, string>("1.3.6.1.2.1.1.5", sysNameOld)); monitorData.Add(new KeyValuePair <string, string>("1.3.6.1.2.1.25.1.1", sysUptimeOld)); databaseConnection.AddMonitorDataToDatabase(1, monitorData); }
private void WalkThroughOid(UdpTarget target, DatabaseConnectionManager connection, AgentDataModel agent) { List <MonitoringTypeDataModel> MonitoringTypeList = connection.GetMonitoringTypesForAgentForCheckFromDatabase(agent.AgentNr); if (MonitoringTypeList.Count > 0) { List <KeyValuePair <string, string> > resultList = new List <KeyValuePair <string, string> >(); foreach (MonitoringTypeDataModel type in MonitoringTypeList) { SNMPWalk walk = new SNMPWalk(target, type.ObjectID); JObject results = walk.Walk(); resultList.Add(new KeyValuePair <string, string>(type.ObjectID, results.ToString())); } connection.AddMonitorDataToDatabase(agent.AgentNr, resultList); connection.UpdateStatusOfAgent(agent.AgentNr, 1); } }