我正在与SCOM一起实施WCF休息服务。从服务我在客户端请求警报数据时建立与SCOM服务器的连接。 由于连接不可用,因此每隔2分钟发生警报请求就不希望建立连接,如果连接不可用则保持连接状态永不过期,则建立连接。这是示例代码。
public void SCOM_ConnectionSettings()
{
System.Security.SecureString ss = new System.Security.SecureString();
ss.AppendChar('x');
ss.AppendChar('x');
ss.AppendChar('x');
ss.AppendChar('d');
ss.AppendChar('x');
ss.AppendChar('x');
ManagementGroupConnectionSettings mgGroupConnection = new ManagementGroupConnectionSettings("xxx.xxx.xxx.xx");
mgGroupConnection.CacheMode = CacheMode.None;
mgGroupConnection.Domain = "IMTS.Test";
mgGroupConnection.UserName = "Azureuser";
mgGroupConnection.Password = ss;
mgGroup = new ManagementGroup(mgGroupConnection);
}
调用警报的主要方法
public List<MonitoringObject> GetNewAssetInformation()
{
SCOM_ConnectionSettings();
List<MonitoringObject> monitoringobjects = new List<MonitoringObject>();
AgentManagedComputerCriteria agentCriteria = new AgentManagedComputerCriteria("LastModified >= '" + new DateTime(2015, 5, 25).ToString("G") + "'");//LastModified >= '" + new DateTime(2006, 10, 25).ToString("G") + "'");
ManagementGroupAdministration administration = mgGroup.GetAdministration();
ReadOnlyCollection<AgentManagedComputer> agents = administration.GetAgentManagedComputers(agentCriteria);
if (agents.Count > 0)
{
foreach (AgentManagedComputer agentManagedComputer in agents)
{
if (agentManagedComputer.InstallTime >= DateTime.Now.AddMonths(-1))
{
monitoringobjects.Add(mgGroup.GetMonitoringObject(agentManagedComputer.Id));
}
}
return monitoringobjects;
}
return null;
}
感谢