public void TestStatusUpdate() { List <AgentDataModel> agents = databaseConnection.GetAgentsFromDatabase(); int oldStatus = 0; foreach (AgentDataModel agent in agents) { if (agent.AgentNr == 1) { oldStatus = agent.Status; } } Assert.AreEqual(1, oldStatus); databaseConnection.UpdateStatusOfAgent(1, 3); List <AgentDataModel> agentsUpdated = databaseConnection.GetAgentsFromDatabase(); int newStatus = 0; foreach (AgentDataModel agent in agentsUpdated) { if (agent.AgentNr == 1) { newStatus = agent.Status; } } Assert.AreEqual(3, newStatus); // Clean up databaseConnection.UpdateStatusOfAgent(1, oldStatus); }
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); } }
private void GetSNMPDataFromSingleAgent(AgentDataModel agent) { try { DatabaseConnectionManager connection = new DatabaseConnectionManager(_connectionString); OctetString community = new OctetString("public"); AgentParameters param = new AgentParameters(community); param.Version = SnmpVersion.Ver2; IpAddress agentIpAddress = new IpAddress(agent.IPAddress); UdpTarget target = new UdpTarget((IPAddress)agentIpAddress, agent.Port, 2000, 1); try { this.WalkThroughOid(target, connection, agent); } finally { target.Close(); } } catch (SnmpException e) { DatabaseConnectionManager connection = new DatabaseConnectionManager(_connectionString); connection.UpdateStatusOfAgent(agent.AgentNr, 3); ExceptionCore.HandleException(ExceptionCategory.Low, e); } catch (SqlException e) { ExceptionCore.HandleException(ExceptionCategory.Fatal, e); } catch (Exception e) { ExceptionCore.HandleException(ExceptionCategory.Normal, e); } }