use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.
the class SshMonitorIT method testPollWithRegexpBanner.
@Test
public void testPollWithRegexpBanner() throws UnknownHostException {
ServiceMonitor sm = new SshMonitor();
MonitoredService svc = new MockMonitoredService(1, "Router", InetAddressUtils.addr(HOST_TO_TEST), "SSH");
Map<String, Object> parms = new HashMap<String, Object>();
parms.put("banner", "^SSH");
PollStatus ps = sm.poll(svc, parms);
assertTrue(createAssertMessage(ps, "Up"), ps.isUp());
assertFalse(createAssertMessage(ps, "not Down"), ps.isDown());
}
use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testSimple.
@Test
public void testSimple() throws Exception {
setPageSequenceParam("localhost");
PollStatus googleStatus = m_monitor.poll(getHttpService("localhost"), m_params);
assertTrue("Expected available but was " + googleStatus + ": reason = " + googleStatus.getReason(), googleStatus.isAvailable());
assertTrue("Expected a DS called 'response-time' but did not find one", googleStatus.getProperties().containsKey(PollStatus.PROPERTY_RESPONSE_TIME));
}
use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.
the class PollerBackEndTest method setUp.
@Override
protected void setUp() throws Exception {
System.setProperty("opennms.home", "src/test/test-configurations/PollerBackEndTest-home");
m_monitoringLocationDao = m_mocks.createMock(MonitoringLocationDao.class);
m_locMonDao = m_mocks.createMock(LocationMonitorDao.class);
m_scanReportDao = m_mocks.createMock(ScanReportDao.class);
m_monSvcDao = m_mocks.createMock(MonitoredServiceDao.class);
m_pollerConfig = m_mocks.createMock(PollerConfig.class);
m_timeKeeper = m_mocks.createMock(TimeKeeper.class);
m_eventIpcManager = new MockEventIpcManager();
m_backEnd = new DefaultPollerBackEnd();
m_backEnd.setMonitoringLocationDao(m_monitoringLocationDao);
m_backEnd.setLocationMonitorDao(m_locMonDao);
m_backEnd.setScanReportDao(m_scanReportDao);
m_backEnd.setMonitoredServiceDao(m_monSvcDao);
m_backEnd.setPollerConfig(m_pollerConfig);
m_backEnd.setTimeKeeper(m_timeKeeper);
m_backEnd.setEventIpcManager(m_eventIpcManager);
m_backEnd.setDisconnectedTimeout(DISCONNECTED_TIMEOUT);
m_backEnd.setPersisterFactory(new MockPersisterFactory());
m_startTime = new Date(System.currentTimeMillis() - 600000);
expect(m_timeKeeper.getCurrentDate()).andReturn(m_startTime);
replay(m_timeKeeper);
m_backEnd.afterPropertiesSet();
verify(m_timeKeeper);
reset(m_timeKeeper);
// set up some objects that can be used to mock up the tests
// the location definition
m_locationDefinition = new OnmsMonitoringLocation();
m_locationDefinition.setMonitoringArea("Oakland");
m_locationDefinition.setLocationName("OAK");
m_locationDefinition.setPollingPackageNames(Collections.singletonList("OAKPackage"));
m_package = createPackage("OAKPackage", "ipaddr = '192.168.1.1'");
m_serviceSelector = new ServiceSelector(m_package.getFilter().getContent(), Arrays.asList(new String[] { "HTTP", "DNS" }));
m_httpSvcConfig = addService(m_package, "HTTP", 1234, "url", "http://www.opennms.org");
m_dnsSvcConfig = addService(m_package, "DNS", 5678, "hostname", "www.opennms.org");
m_locationMonitor = new OnmsLocationMonitor();
m_locationMonitor.setId(LOCATION_MONITOR_ID);
m_locationMonitor.setLocation(m_locationDefinition.getLocationName());
OnmsApplication application = new OnmsApplication();
application.setName(APPLICATION_NAME);
NetworkBuilder builder = new NetworkBuilder();
builder.addNode("testNode").setId(1);
builder.addInterface("192.168.1.1").setId(1);
m_httpService = builder.addService(new OnmsServiceType("HTTP"));
m_httpService.setId(1);
m_httpService.setApplications(Collections.singleton(application));
m_dnsService = builder.addService(new OnmsServiceType("DNS"));
m_dnsService.setId(2);
m_dnsService.setApplications(Collections.singleton(application));
m_monServices = new OnmsMonitoredService[] { m_httpService, m_dnsService };
long now = System.currentTimeMillis();
PollStatus httpResult = PollStatus.available(1000.0);
httpResult.setTimestamp(new Date(now - 300000));
m_httpCurrentStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_httpService, httpResult);
m_httpCurrentStatus.setId(1);
PollStatus dnsResult = PollStatus.unavailable("Non responsive");
dnsResult.setTimestamp(new Date(now - 300000));
m_dnsCurrentStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_dnsService, dnsResult);
m_dnsCurrentStatus.setId(2);
m_pollerDetails = new HashMap<String, String>();
m_pollerDetails.put("os.name", "WonkaOS");
m_pollerDetails.put("os.version", "1.2.3");
}
use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.
the class DefaultPollerBackEnd method processStatusChange.
private void processStatusChange(final OnmsLocationSpecificStatus currentStatus, final OnmsLocationSpecificStatus newStatus) {
if (databaseStatusChanged(currentStatus, newStatus)) {
m_locMonDao.saveStatusChange(newStatus);
final PollStatus pollResult = newStatus.getPollResult();
// if we don't know the current status only send an event if it is not up
if (logicalStatusChanged(currentStatus, newStatus)) {
sendRegainedOrLostServiceEvent(newStatus, pollResult);
}
}
}
use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.
the class Test method doExecute.
@Override
protected Object doExecute() throws Exception {
// Parse/validate the IP address
final InetAddress addr = InetAddressUtils.addr(ipAddress);
if (addr == null) {
throw new IllegalStateException("Error getting InetAddress object for " + ipAddress);
}
final Map<String, Object> parameters = Poll.parse(serviceParameters);
final MonitoredService monSvc = transactionTemplate.execute(new TransactionCallback<MonitoredService>() {
@Override
public MonitoredService doInTransaction(TransactionStatus status) {
final List<OnmsIpInterface> ips = ipInterfaceDao.findByIpAddress(ipAddress);
if (ips == null || ips.size() == 0) {
System.err.printf("Error: Can't find the IP address %s on the database\n", ipAddress);
return null;
}
if (ips.size() > 1) {
System.out.printf("Warning: there are several IP interface objects associated with the IP address %s (picking the first one)\n", ipAddress);
}
OnmsNode n = ips.get(0).getNode();
return new SimpleMonitoredService(addr, n.getId(), n.getLabel(), serviceName);
}
});
if (monSvc == null) {
// in which case we already printed an error message above
return null;
}
// Read a fresh copy of poller-configuration.xml
final PollerConfig pollerConfig = ReadOnlyPollerConfigManager.create();
System.out.printf("Checking service %s on IP %s%n", serviceName, ipAddress);
final org.opennms.netmgt.config.poller.Package pkg = packageName == null ? pollerConfig.getFirstLocalPackageMatch(ipAddress) : pollerConfig.getPackage(packageName);
if (pkg == null) {
System.err.printf("Error: Package %s doesn't exist%n", packageName);
return null;
}
System.out.printf("Package: %s%n", pkg.getName());
final Service svc = pollerConfig.getServiceInPackage(serviceName, pkg);
if (svc == null) {
System.err.printf("Error: Service %s not defined on package %s%n", serviceName, packageName);
return null;
}
ServiceMonitor monitor = null;
if (monitorClass == null) {
monitor = pollerConfig.getServiceMonitor(serviceName);
if (monitor == null) {
System.err.printf("Error: Service %s doesn't have a monitor class defined%n", serviceName);
return null;
}
} else {
monitor = registry.getMonitorByClassName(monitorClass);
System.err.printf("Error: No monitor found with class name %s\n", monitorClass);
if (monitor == null) {
return null;
}
}
System.out.printf("Monitor: %s%n", monitor.getClass().getName());
if (pollerConfig.isPolledLocally(ipAddress, serviceName)) {
for (Parameter p : svc.getParameters()) {
if (!parameters.containsKey(p.getKey())) {
String value = p.getValue();
if (value == null) {
try {
value = JaxbUtils.marshal(p.getAnyObject());
} catch (Exception e) {
}
}
parameters.put(p.getKey(), value);
}
}
for (Entry<String, Object> e : parameters.entrySet()) {
System.out.printf("Parameter %s : %s%n", e.getKey(), e.getValue());
}
try {
PollStatus status = monitor.poll(monSvc, parameters);
System.out.printf("Available ? %s (status %s[%s])%n", status.isAvailable(), status.getStatusName(), status.getStatusCode());
if (status.isAvailable()) {
System.out.printf("Response time: %s%n", status.getResponseTime());
} else {
if (status.getReason() != null) {
System.out.printf("Reason: %s%n", status.getReason());
}
}
} catch (Exception e) {
System.err.println("Error: Can't execute the monitor. " + e.getMessage());
return null;
}
} else {
System.err.printf("Error: Polling is not enabled for service %s using IP %s%n", serviceName, ipAddress);
}
return null;
}
Aggregations