use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class NotificationManagerIT method setUp.
@Before
public void setUp() throws Exception {
// Initialize Filter DAO
DatabaseSchemaConfigFactory.init();
JdbcFilterDao jdbcFilterDao = new JdbcFilterDao();
jdbcFilterDao.setDataSource(m_dataSource);
jdbcFilterDao.setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory.getInstance());
jdbcFilterDao.afterPropertiesSet();
FilterDaoFactory.setInstance(jdbcFilterDao);
m_configManager = new MockNotifdConfigManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifd-configuration.xml"));
m_notificationManager = new NotificationManagerImpl(m_configManager, m_dataSource);
OnmsNode node;
OnmsIpInterface ipInterface;
OnmsMonitoredService service;
OnmsServiceType serviceType;
OnmsCategory category1 = new OnmsCategory("CategoryOne");
m_categoryDao.save(category1);
OnmsCategory category2 = new OnmsCategory("CategoryTwo");
m_categoryDao.save(category2);
OnmsCategory category3 = new OnmsCategory("CategoryThree");
m_categoryDao.save(category3);
OnmsCategory category4 = new OnmsCategory("CategoryFour");
m_categoryDao.save(category4);
m_categoryDao.flush();
// node 1
serviceType = new OnmsServiceType("HTTP");
m_serviceTypeDao.save(serviceType);
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 1");
node.addCategory(category1);
node.addCategory(category2);
node.addCategory(category3);
ipInterface = new OnmsIpInterface(addr("192.168.1.1"), node);
service = new OnmsMonitoredService(ipInterface, serviceType);
m_nodeDao.save(node);
// node 2
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 2");
node.addCategory(category1);
node.addCategory(category2);
node.addCategory(category4);
m_nodeDao.save(node);
ipInterface = new OnmsIpInterface(addr("192.168.1.1"), node);
m_ipInterfaceDao.save(ipInterface);
service = new OnmsMonitoredService(ipInterface, serviceType);
m_serviceDao.save(service);
ipInterface = new OnmsIpInterface(addr("0.0.0.0"), node);
m_ipInterfaceDao.save(ipInterface);
// node 3
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 3");
m_nodeDao.save(node);
ipInterface = new OnmsIpInterface(addr("192.168.1.2"), node);
m_ipInterfaceDao.save(ipInterface);
service = new OnmsMonitoredService(ipInterface, serviceType);
m_serviceDao.save(service);
// node 4 has an interface, but no services
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 4");
m_nodeDao.save(node);
ipInterface = new OnmsIpInterface(addr("192.168.1.3"), node);
m_ipInterfaceDao.save(ipInterface);
// node 5 has no interfaces
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 5");
m_nodeDao.save(node);
m_nodeDao.flush();
m_ipInterfaceDao.flush();
m_serviceDao.flush();
m_serviceTypeDao.flush();
m_categoryDao.flush();
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class BundleContextHistoryManagerTest method initProvidersAndCriteria.
/**
* In this method all starting {@link SearchCriteria} and {@link SearchProvider} objects are initialized
*/
private void initProvidersAndCriteria() {
// Preparing SearchProviders
CategoryProvider vertexProvider = new CategoryProvider() {
@Override
public Collection<OnmsCategory> getAllCategories() {
return Lists.newArrayList(findCategoryByName("somename"));
}
@Override
public OnmsCategory findCategoryByName(String m_categoryName) {
OnmsCategory cat = new OnmsCategory("test", "test");
cat.setId(Integer.valueOf(idCategory));
return cat;
}
@Override
public List<OnmsNode> findNodesForCategory(OnmsCategory category) {
return new ArrayList<>();
}
};
IpInterfaceProvider ipInterfaceProvider = new IpInterfaceProvider() {
@Override
public List<OnmsIpInterface> findMatching(org.opennms.core.criteria.Criteria criteria) {
OnmsNode node = new OnmsNode();
node.setId(Integer.valueOf(idIpLike));
String ipAddr = "127.0.0.1";
OnmsIpInterface ipInterface = new OnmsIpInterface(ipAddr, node);
return Lists.newArrayList(ipInterface);
}
};
AlarmProvider alarmProvider = new AlarmProvider() {
@Override
public List<OnmsAlarm> findMatchingAlarms(org.opennms.core.criteria.Criteria criteria) {
Date eventTime = new Date();
OnmsDistPoller distPoller = new OnmsDistPoller("pollerID");
OnmsEvent event = new OnmsEvent();
OnmsAlarm alarm = new OnmsAlarm(Integer.valueOf(idAlarm), "eventUI", distPoller, 2, 3, eventTime, event);
return Lists.newArrayList(alarm);
}
};
// Creating SearchResults to be used in testing
SearchResult sResultCategory = new SearchResult(CategoryHopCriteria.NAMESPACE, idCategory, labelCategory, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
SearchResult sResultAlarm = new SearchResult(AlarmHopCriteria.NAMESPACE, idAlarm, labelAlarm, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
SearchResult sResultIpLike = new SearchResult(IpLikeHopCriteria.NAMESPACE, idIpLike, labelIpLike, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
this.startingSearchResults.put(CriteriaTypes.alarm, sResultAlarm);
this.startingSearchResults.put(CriteriaTypes.ipLike, sResultIpLike);
this.startingSearchResults.put(CriteriaTypes.category, sResultCategory);
// Initializing available (initial) SearchProviders
this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(vertexProvider));
this.startingProviders.put(CriteriaTypes.ipLike, new IpLikeSearchProvider(ipInterfaceProvider));
this.startingProviders.put(CriteriaTypes.alarm, new AlarmSearchProvider(alarmProvider));
// Initializing available (initial) Criteria
this.startingCriteria.put(CriteriaTypes.category, new CategoryHopCriteria(sResultCategory, vertexProvider));
this.startingCriteria.put(CriteriaTypes.ipLike, new IpLikeHopCriteria(sResultIpLike, ipInterfaceProvider));
this.startingCriteria.put(CriteriaTypes.alarm, new AlarmHopCriteria(new AlarmSearchProvider(alarmProvider).new AlarmSearchResult(sResultAlarm), alarmProvider));
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class AvailabilityDatabasePopulator method populateDatabase.
public void populateDatabase() {
OnmsCategory ac = getCategory("DEV_AC");
OnmsCategory mid = getCategory("IMP_mid");
OnmsCategory ops = getCategory("OPS_Online");
OnmsCategory catRouter = getCategory("Routers");
@SuppressWarnings("unused") OnmsCategory catSwitches = getCategory("Switches");
OnmsCategory catServers = getCategory("Servers");
getCategory("Production");
getCategory("Test");
getCategory("Development");
getServiceType("ICMP");
getServiceType("SNMP");
getServiceType("HTTP");
// m_db.update("insert into node (nodeID, nodelabel, nodeCreateTime, nodeType) values (1,'test1.availability.opennms.org','2004-03-01 09:00:00','A')");
// m_db.update("insert into node (nodeID, nodelabel, nodeCreateTime, nodeType) values (2,'test2.availability.opennms.org','2004-03-01 09:00:00','A')");
//
// m_db.update("insert into service (serviceid, servicename) values\n"
// + "(1, 'ICMP');");
// m_db.update("insert into service (serviceid, servicename) values\n"
// + "(2, 'HTTP');");
// m_db.update("insert into service (serviceid, servicename) values\n"
// + "(3, 'SNMP');");
//
// m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n"
// + "(1, 1,'192.168.100.1','M');");
// m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n"
// + "(2, 2,'192.168.100.2','M');");
// m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n"
// + "(3, 2,'192.168.100.3','M');");
//
// m_db.update("insert into ifservices (nodeid, ipaddr, serviceid, status, ipInterfaceId) values "
// + "(1,'192.168.100.1',1,'A', 1);");
// m_db.update("insert into ifservices (nodeid, ipaddr, serviceid, status, ipInterfaceId) values "
// + "(2,'192.168.100.2',1,'A', 2);");
// /*
// * m_db.update("insert into ifservices (nodeid, ipaddr, serviceid,
// * status, ipInterfaceId) values " + "(2,'192.168.100.2',2,'A', 2);");
// */
// m_db.update("insert into ifservices (nodeid, ipaddr, serviceid, status, ipInterfaceId) values "
// + "(2,'192.168.100.3',1,'A', 3);");
NetworkBuilder builder = new NetworkBuilder();
setNode1(builder.addNode("test1.availability.opennms.org").setId(1).setType(NodeType.ACTIVE).getNode());
Assert.assertNotNull("newly built node 1 should not be null", getNode1());
builder.addCategory(ac);
builder.addCategory(mid);
builder.addCategory(ops);
builder.addCategory(catRouter);
builder.setBuilding("HQ");
builder.addInterface("192.168.100.1").setIsManaged("M");
//getNodeDao().save(builder.getCurrentNode());
//getNodeDao().flush();
builder.addService(getServiceType("ICMP")).setStatus("A");
getNodeDao().save(builder.getCurrentNode());
getNodeDao().flush();
builder.addNode("test2.availability.opennms.org").setId(2).setType(NodeType.ACTIVE);
builder.addCategory(mid);
builder.addCategory(catServers);
builder.setBuilding("HQ");
builder.addInterface("192.168.100.2").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(getServiceType("ICMP")).setStatus("A");
//builder.addService(getServiceType("SNMP")).setStatus("A");;
builder.addInterface("192.168.100.3").setIsManaged("M");
builder.addService(getServiceType("ICMP")).setStatus("A");
//builder.addService(getServiceType("HTTP")).setStatus("A");
getNodeDao().save(builder.getCurrentNode());
getNodeDao().flush();
OnmsEvent event = new OnmsEvent();
event.setDistPoller(builder.getDistPoller());
event.setEventUei("uei.opennms.org/test");
event.setEventTime(new Date());
event.setEventSource("test");
event.setEventCreateTime(new Date());
event.setEventSeverity(1);
event.setEventLog("Y");
event.setEventDisplay("Y");
getEventDao().save(event);
getEventDao().flush();
// + "(2,2,'192.168.100.2',1,'2005-05-01 10:00:00','2005-05-02 10:00:00');");
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
OnmsMonitoredService node1If1Svc1 = getMonitoredServiceDao().get(1, InetAddressUtils.addr("192.168.100.1"), "ICMP");
OnmsMonitoredService node2If1Svc1 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.2"), "ICMP");
@SuppressWarnings("unused") OnmsMonitoredService node2If1Svc2 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.2"), "SNMP");
OnmsMonitoredService node2If2Svc1 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.3"), "ICMP");
@SuppressWarnings("unused") OnmsMonitoredService node2If2Svc2 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.3"), "HTTP");
OnmsOutage outage1 = new OnmsOutage(df.parse("2005-05-01 09:00:00"), df.parse("2005-05-01 09:30:00"), event, event, node1If1Svc1, null, null);
getOutageDao().save(outage1);
getOutageDao().flush();
OnmsOutage outage2 = new OnmsOutage(df.parse("2005-05-01 10:00:00"), df.parse("2005-05-02 10:00:00"), event, event, node2If1Svc1, null, null);
getOutageDao().save(outage2);
getOutageDao().flush();
// test data for LastMonthsDailyAvailability report
// // insert 30 minute outage on one node - 99.3056% availability
// m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
// + "(3,1,'192.168.100.1',1,'2005-04-02 10:00:00','2005-04-02 10:30:00');");
OnmsOutage outage3 = new OnmsOutage(df.parse("2005-04-02 10:00:00"), df.parse("2005-04-02 10:30:00"), event, event, node1If1Svc1, null, null);
getOutageDao().save(outage3);
getOutageDao().flush();
// // insert 60 minute outage on one interface and 59 minute outages on
// // another - 97.2454
// m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
// + "(4,1,'192.168.100.1',1,'2005-04-03 11:30:00','2005-04-03 12:30:00');");
OnmsOutage outage4 = new OnmsOutage(df.parse("2005-04-03 11:30:00"), df.parse("2005-04-03 12:30:00"), event, event, node1If1Svc1, null, null);
getOutageDao().save(outage4);
getOutageDao().flush();
// m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
// + "(5,2,'192.168.100.2',1,'2005-04-03 23:00:00','2005-04-03 23:59:00');");
OnmsOutage outage5 = new OnmsOutage(df.parse("2005-04-03 23:00:00"), df.parse("2005-04-03 23:59:00"), event, event, node2If1Svc1, null, null);
getOutageDao().save(outage5);
getOutageDao().flush();
// // test an outage that spans 60 minutes across midnight - 99.3056% on
// // each day, well, not exactly
// // its 29 minutes 99.3059 on the fist day and 31 minutes 99.3052 on
// // the second.
// m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
// + "(6,2,'192.168.100.3',1,'2005-04-04 23:30:00','2005-04-05 00:30:00');");
OnmsOutage outage6 = new OnmsOutage(df.parse("2005-04-04 23:30:00"), df.parse("2005-04-05 00:30:00"), event, event, node2If2Svc1, null, null);
getOutageDao().save(outage6);
getOutageDao().flush();
} catch (final ParseException e) {
LOG.warn("populating database failed", e);
}
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class DefaultSurveillanceViewService method createQuery.
/**
* Creates a SQL query string for filtering on categories.
*
* @param rowCategories the row categories
* @param colCategories the column categories
* @return the SQL query string
*/
private static String createQuery(final String nodeIdProperty, final Set<OnmsCategory> rowCategories, final Set<OnmsCategory> colCategories) {
StringBuffer stringBuffer = new StringBuffer();
boolean first = true;
stringBuffer.append(nodeIdProperty + " in (select distinct cn.nodeId from category_node cn join categories c on cn.categoryId = c.categoryId where c.categoryName in (");
for (OnmsCategory onmsCategory : rowCategories) {
if (first) {
stringBuffer.append("'");
first = false;
} else {
stringBuffer.append(",'");
}
stringBuffer.append(onmsCategory.getName());
stringBuffer.append("'");
}
stringBuffer.append("))");
first = true;
stringBuffer.append("and " + nodeIdProperty + " in (select distinct cn.nodeId from category_node cn join categories c on cn.categoryId = c.categoryId where c.categoryName in (");
for (OnmsCategory onmsCategory : colCategories) {
if (first) {
stringBuffer.append("'");
first = false;
} else {
stringBuffer.append(",'");
}
stringBuffer.append(onmsCategory.getName());
stringBuffer.append("'");
}
stringBuffer.append("))");
return stringBuffer.toString();
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class DatabasePopulator method getCategory.
private OnmsCategory getCategory(final String categoryName) {
OnmsCategory cat = m_categoryDao.findByName(categoryName, true);
if (cat == null) {
cat = new OnmsCategory(categoryName);
m_categoryDao.save(cat);
m_categoryDao.flush();
}
return cat;
}
Aggregations