use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class LatencyStoringServiceMonitorAdaptorPersistenceTest method persistAndVerifyLatencySamples.
private void persistAndVerifyLatencySamples(String locationName, Path pathToResourceInResponseTime) throws Exception {
PollStatus pollStatus = PollStatus.get(PollStatus.SERVICE_AVAILABLE, 42.1);
// For the purposes of this test, it's important the attributes are not added in lexicographical order
Map<String, Number> props = new LinkedHashMap<String, Number>(pollStatus.getProperties());
props.put("ping1", Integer.valueOf(1));
props.put("loss", Integer.valueOf(2));
props.put("median", Integer.valueOf(3));
pollStatus.setProperties(props);
ServiceMonitor serviceMonitor = new FixedServiceMonitor(pollStatus);
Package pkg = new Package();
MockNetwork mockNetwork = new MockNetwork();
mockNetwork.createStandardNetwork();
MockPollerConfig pollerConfig = new MockPollerConfig(mockNetwork);
pollerConfig.setRRAList(pkg, Lists.newArrayList("RRA:AVERAGE:0.5:1:2016"));
LatencyStoringServiceMonitorAdaptor lssma = new LatencyStoringServiceMonitorAdaptor(pollerConfig, pkg, m_persisterFactory, m_resourceStorageDao);
MonitoredService monitoredService = new MockMonitoredService(3, "Firewall", locationName, InetAddress.getByName("192.168.1.5"), "SMTP");
Map<String, Object> params = Maps.newHashMap();
params.put("rrd-repository", getResponseTimeRoot().getAbsolutePath());
params.put("rrd-base-name", "smtp-base");
EasyMock.expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".jrb").atLeastOnce();
m_rrdStrategy.createDefinition(EasyMock.eq("192.168.1.5"), EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime).toString()), EasyMock.eq("smtp-base"), EasyMock.anyInt(), EasyMock.anyObject(), EasyMock.anyObject());
EasyMock.expectLastCall().andReturn(null).once();
m_rrdStrategy.createFile(EasyMock.anyObject());
EasyMock.expectLastCall().once();
m_rrdStrategy.openFile(EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime.resolve("smtp-base.jrb")).toString()));
EasyMock.expectLastCall().andReturn(null).once();
// This is the important bit, the order of the values should match the order there were inserted above
m_rrdStrategy.updateFile(EasyMock.isNull(), EasyMock.eq("192.168.1.5"), EasyMock.endsWith(":42.1:1:2:3"));
EasyMock.expectLastCall().once();
EasyMock.replay(m_rrdStrategy);
// Trigger the poll
lssma.handlePollResult(monitoredService, params, serviceMonitor.poll(monitoredService, params));
// Verify
EasyMock.verify(m_rrdStrategy);
// Reset
EasyMock.reset(m_rrdStrategy);
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class SSLCertMonitorIT method testExpiredDateForCertificate.
@Test
@JUnitHttpServer(port = 10342, https = true)
public void testExpiredDateForCertificate() throws UnknownHostException {
SSLCertMonitor monitor = new SSLCertMonitor() {
@Override
protected Calendar getCalendarInstance() {
final Calendar cal = GregorianCalendar.getInstance();
cal.setTimeInMillis(EXPIRE_DATE - 86400000 * -1);
return cal;
}
};
Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
parameters.put("port", "10342");
parameters.put("retry", "0");
parameters.put("timeout", "500");
parameters.put("verbose", "true");
parameters.put("days", "5");
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
PollStatus status = monitor.poll(svc, parameters);
assertTrue(status.isUnavailable());
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class SSLCertMonitorIT method testHostNameVerificationFails.
@Test
@JUnitHttpServer(port = 10342, https = true)
public void testHostNameVerificationFails() throws UnknownHostException {
SSLCertMonitor monitor = new SSLCertMonitor() {
@Override
protected Calendar getCalendarInstance() {
final Calendar cal = GregorianCalendar.getInstance();
cal.setTimeInMillis(EXPIRE_DATE - 86400000 * 5);
return cal;
}
};
Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
parameters.put("port", "10342");
parameters.put("retry", "0");
parameters.put("timeout", "500");
parameters.put("verbose", "true");
parameters.put("days", "5");
parameters.put("server-name", "klatschmohnwiese");
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
PollStatus status = monitor.poll(svc, parameters);
assertTrue(status.isUnavailable());
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class SSLCertMonitorIT method testInternetWebsite.
@Test
@Ignore
public void testInternetWebsite() throws UnknownHostException {
SSLCertMonitor monitor = new SSLCertMonitor();
Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
parameters.put("port", "443");
parameters.put("retry", "0");
parameters.put("timeout", "500");
parameters.put("verbose", "true");
parameters.put("days", "5");
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "www.google.com", DnsUtils.resolveHostname("www.google.com", false), "SSLCert");
PollStatus status = monitor.poll(svc, parameters);
assertTrue(status.isAvailable());
}
use of org.opennms.netmgt.poller.MonitoredService in project opennms by OpenNMS.
the class SmtpMonitorIT method testPollSvrStatus554.
@Test
public void testPollSvrStatus554() throws UnknownHostException, InterruptedException {
m_serverThread = new Thread(new Runnable() {
@Override
public void run() {
try {
m_serverSocket.setSoTimeout(1000);
Socket s = m_serverSocket.accept();
System.out.println("S: 554 localhost.localdomain ESMTP bogon");
s.getOutputStream().write("554 localhost.localdomain ESMTP bogon\r\n".getBytes());
BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
String command = r.readLine();
System.out.println("C: " + command);
if (command.equals("QUIT")) {
System.out.println("S: 221-Goodbye, friend.");
s.getOutputStream().write("221-Goodbye, friend.\r\n".getBytes());
System.out.println("S: 221 See ya");
s.getOutputStream().write("221 See ya\r\n".getBytes());
}
} catch (Throwable e) {
throw new UndeclaredThrowableException(e);
}
}
});
m_serverThread.start();
ServiceMonitor sm = new SmtpMonitor();
MonitoredService svc = new MockMonitoredService(1, "Node One", InetAddressUtils.addr("127.0.0.1"), "SMTP");
Map<String, Object> parms = new HashMap<String, Object>();
parms.put("port", m_serverSocket.getLocalPort());
PollStatus ps = sm.poll(svc, parms);
assertTrue(ps.isUnavailable());
assertFalse(ps.isUp());
}
Aggregations