use of org.opennms.netmgt.model.OnmsNode 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;
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class PollerRpcTimeoutIT method setUp.
@Before
public void setUp() throws Exception {
MockUtil.println("------------ Begin Test --------------------------");
MockLogAppender.setupLogging();
m_network = new MockNetwork();
m_network.setCriticalService("ICMP");
m_network.addNode(1, "Router");
m_network.addInterface(str(InetAddressUtils.UNPINGABLE_ADDRESS));
m_network.addService("ICMP");
m_network.addService("HTTP");
m_db.populate(m_network);
DataSourceFactory.setInstance(m_db);
// Add a location that no systems are monitoring
OnmsMonitoringLocation location = new OnmsMonitoringLocation(NONEXISTENT_LOCATION, "Nullsville");
m_monitoringLocationDao.save(location);
// Update all of the nodes to have the nonexistent location
for (OnmsNode node : m_nodeDao.findAll()) {
node.setLocation(location);
m_nodeDao.save(node);
}
InputStream is = new FileInputStream(new File("src/test/resources/etc/rpctimeout-poller-configuration.xml"));
PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
PollerConfigFactory.setInstance(factory);
IOUtils.closeQuietly(is);
// Sanity check the config
ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("HTTP");
Assert.assertNotNull(monitor);
Package pkg = PollerConfigFactory.getInstance().getPackage("PollerRpcTimeoutIT");
Assert.assertNotNull(pkg);
Service svc = pkg.getServices().iterator().next();
Assert.assertEquals("HTTP", svc.getName());
DefaultPollContext pollContext = new DefaultPollContext();
pollContext.setEventManager(m_eventMgr);
pollContext.setLocalHostName("localhost");
pollContext.setName("Test.DefaultPollContext");
pollContext.setPollerConfig(factory);
pollContext.setQueryManager(m_queryManager);
pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
PollableNetwork network = new PollableNetwork(pollContext);
m_poller = new Poller();
m_poller.setMonitoredServiceDao(m_monitoredServiceDao);
m_poller.setOutageDao(m_outageDao);
m_poller.setTransactionTemplate(m_transactionTemplate);
m_poller.setEventIpcManager(m_eventMgr);
m_poller.setNetwork(network);
m_poller.setQueryManager(m_queryManager);
m_poller.setPollerConfig(factory);
m_poller.setPollOutagesConfig(m_pollOutagesConfig);
m_poller.setLocationAwarePollerClient(m_locationAwarePollerClient);
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class DemandPollServiceTest method testPollMonitoredService.
public void testPollMonitoredService() throws EventProxyException {
final int expectedResultId = m_pollStore.getExpectedId();
// anticipate a call to the dao save with a pollResult
m_demandPollDao.save(isA(DemandPoll.class));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
DemandPoll poll = (DemandPoll) getCurrentArguments()[0];
m_pollStore.save(poll);
return null;
}
});
OnmsServiceType svcType = new OnmsServiceType();
svcType.setId(3);
svcType.setName("HTTP");
OnmsNode node = new OnmsNode();
node.setId(1);
OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
iface.setSnmpInterface(snmpIface);
OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
expect(m_monitoredServiceDao.get(1, addr("192.168.1.1"), 1, 3)).andReturn(monSvc);
m_pollerService.poll(monSvc, expectedResultId);
replay(m_demandPollDao);
replay(m_monitoredServiceDao);
replay(m_pollerService);
DemandPoll result = m_demandPollService.pollMonitoredService(1, addr("192.168.1.1"), 1, 3);
verify(m_demandPollDao);
verify(m_monitoredServiceDao);
verify(m_pollerService);
assertNotNull("Null is an invalid response from pollMonitoredService", result);
assertEquals("Expected Id to be set by dao", expectedResultId, result.getId().intValue());
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class GenericInfoPanelItemProvider method createVertexContext.
public Map<String, Object> createVertexContext(final VertexRef vertex) {
final Map<String, Object> context = Maps.newHashMap();
if (vertex instanceof AbstractVertex) {
final AbstractVertex abstractVertex = (AbstractVertex) vertex;
if (abstractVertex.getNodeID() != null) {
final OnmsNode node = this.nodeDao.get(abstractVertex.getNodeID());
if (node != null) {
context.put("node", node);
}
}
}
context.put("vertex", vertex);
return context;
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class RrdDashletConfigurationWindow method setRrdGraphEntryFromKscReportGraph.
private void setRrdGraphEntryFromKscReportGraph(RrdGraphEntry rrdGraphEntry, Graph graph) {
String graphLabel, graphId, graphUrl, nodeId, nodeLabel, resourceLabel, resourceTypeId, resourceTypeLabel;
String[] graphTypeArr = graph.getGraphtype().split("\\.");
String[] resourceIdArr = graph.getResourceId().orElse("").split("\\.");
nodeId = resourceIdArr[0].split("[\\[\\]]")[1];
String resourceTypeName = resourceIdArr[1].split("[\\[\\]]")[0];
OnmsNode onmsNode = m_nodeDao.get(nodeId);
nodeLabel = onmsNode.getLabel();
Map<OnmsResourceType, List<OnmsResource>> resourceTypeListMap = m_rrdGraphHelper.getResourceTypeMapForNodeId(nodeId);
for (Map.Entry<OnmsResourceType, List<OnmsResource>> entry : resourceTypeListMap.entrySet()) {
OnmsResourceType onmsResourceType = entry.getKey();
if (resourceTypeName.equals(onmsResourceType.getName())) {
resourceTypeId = "node[" + nodeId + "]." + resourceTypeName;
resourceTypeLabel = onmsResourceType.getLabel();
List<OnmsResource> onmsResourceList = entry.getValue();
for (OnmsResource onmsResource : onmsResourceList) {
String onmsResourceId = onmsResource.getId().toString();
if (onmsResourceId.equals(graph.getResourceId())) {
resourceLabel = onmsResource.getLabel();
Map<String, String> resultsMap = m_rrdGraphHelper.getGraphResultsForResourceId(onmsResource.getId());
Map<String, String> nameTitleMapping = m_rrdGraphHelper.getGraphNameTitleMappingForResourceId(onmsResource.getId());
graphId = onmsResourceId + "." + nameTitleMapping.get(graph.getGraphtype());
graphLabel = nameTitleMapping.get(graph.getGraphtype());
graphUrl = resultsMap.get(graph.getGraphtype());
rrdGraphEntry.setNodeId(nodeId);
rrdGraphEntry.setNodeLabel(nodeLabel);
rrdGraphEntry.setResourceTypeId(resourceTypeId);
rrdGraphEntry.setResourceTypeLabel(resourceTypeLabel);
rrdGraphEntry.setResourceId(onmsResourceId);
rrdGraphEntry.setResourceLabel(resourceLabel);
rrdGraphEntry.setGraphId(graphId);
rrdGraphEntry.setGraphLabel(graphLabel);
rrdGraphEntry.setGraphUrl(graphUrl);
break;
}
}
break;
}
}
}
Aggregations