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
final DefaultTopologyService topologyService = new DefaultTopologyService();
topologyService.setServiceLocator(serviceLocatorMock);
this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(topologyService, 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, graphContainerMock));
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(OnmsSeverity.INDETERMINATE.getId());
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 getNotificationsWithCriterias.
/**
* Returns a list of notifications for a given list of nodes.
*
* @param rowCategories the row catgories
* @param colCategories the column categories
* @param customSeverity the custom severity mapping for notifications
* @param severity the severity for these nodes
* @param criterias the restrictions to use
* @return the list of notifications
*/
private List<OnmsNotification> getNotificationsWithCriterias(final Set<OnmsCategory> rowCategories, final Set<OnmsCategory> colCategories, final Map<OnmsNotification, String> customSeverity, final String severity, final Restriction... criterias) {
CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsNotification.class);
criteriaBuilder.alias("node", "node");
final List<String> parameters = new ArrayList<>(rowCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList()));
parameters.addAll(colCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList()));
final Type[] types = new Type[parameters.size()];
Arrays.fill(types, Type.STRING);
// Restrict on OnmsNotification.nodeId
criteriaBuilder.sql(createQuery("{alias}.nodeId", rowCategories, colCategories), parameters.toArray(new String[parameters.size()]), types);
criteriaBuilder.ne("node.type", "D");
criteriaBuilder.orderBy("pageTime", false);
Criteria myCriteria = criteriaBuilder.toCriteria();
for (Restriction criteria : criterias) {
myCriteria.addRestriction(criteria);
}
List<OnmsNotification> notifications = m_notificationDao.findMatching(myCriteria);
for (OnmsNotification onmsNotification : notifications) {
customSeverity.put(onmsNotification, severity);
}
return notifications;
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class DefaultProvisionService method saveOrUpdate.
@Transactional
private OnmsNode saveOrUpdate(final OnmsNode node) {
final Set<OnmsCategory> updatedCategories = new HashSet<>();
for (final Iterator<OnmsCategory> it = node.getCategories().iterator(); it.hasNext(); ) {
final OnmsCategory category = it.next();
if (category.getId() == null) {
it.remove();
updatedCategories.add(createCategoryIfNecessary(category.getName()));
}
}
node.getCategories().addAll(updatedCategories);
m_nodeDao.saveOrUpdate(node);
m_nodeDao.flush();
return node;
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class DefaultProvisionService method getRequisitionedNode.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public OnmsNode getRequisitionedNode(final String foreignSource, final String foreignId) throws ForeignSourceRepositoryException {
OnmsNodeRequisition nodeReq = null;
try {
nodeReq = m_foreignSourceRepository.getNodeRequisition(foreignSource, foreignId);
} catch (ForeignSourceRepositoryException e) {
// just fall through, nodeReq will be null
}
if (nodeReq == null) {
LOG.warn("nodeReq for node {}:{} cannot be null!", foreignSource, foreignId);
return null;
}
final OnmsNode node = nodeReq.constructOnmsNodeFromRequisition();
// fill in real database categories
final HashSet<OnmsCategory> dbCategories = new HashSet<>();
for (final OnmsCategory category : node.getCategories()) {
dbCategories.add(createCategoryIfNecessary(category.getName()));
}
node.setCategories(dbCategories);
if (node.getLocation() == null || Strings.isNullOrEmpty(node.getLocation().getLocationName())) {
node.setLocation(m_monitoringLocationDao.getDefaultLocation());
}
// fill in real service types
node.visit(new ServiceTypeFulfiller());
return node;
}
Aggregations