use of org.opennms.netmgt.model.OnmsServiceType in project opennms by OpenNMS.
the class OnmsAlarmOssjMapper method populateOnmsAlarmFromOssjAlarm.
// ****************
// Business methods
// ****************
/**
* This method maps an OSS/J AlarmValue to OpenNMS alarm
*
* @param onmsAlarm OnmsAlarm object to be populated
* @param alarmValue OSS/J AlarmValue data to use to populate OnmsAlarm
* @param almUpdateBehaviour - determines how to treat the node name of the new alarm must be of value;
* <code>USE_TYPE_INSTANCE</code> - populate nodeID with node having same asset type and instance data as alarm
* or <code>SPECIFY_OUTSTATION</code> - populate nodeID with node having same nodeLabel as defaultUpdateNodeLabel
* @param defaultUpdateNodeLabel name of node to be updated if almUpdateBehaviour==SPECIFY_OUTSTATION
* @return the OnmsAlarm populated with OSS/J NotifyNewAlarmEvent data
* @throws java.lang.IllegalArgumentException if any.
* @throws javax.oss.UnsupportedAttributeException if any.
*/
public OnmsAlarm populateOnmsAlarmFromOssjAlarm(OnmsAlarm onmsAlarm, AlarmValue alarmValue, Integer almUpdateBehaviour, String defaultUpdateNodeLabel) throws IllegalArgumentException, UnsupportedAttributeException {
String logheader = this.getClass().getSimpleName() + "populateOnmsAlarmFromOssjAlarm():";
try {
String ossPrimaryKey = alarmValue.getAlarmKey().getAlarmPrimaryKey();
String applicationDN = alarmValue.getAlarmKey().getApplicationDN();
LOG.debug("{} AlarmPrimaryKey: {} ApplictionDN: {} alarmRaisedTime: {}", logheader, ossPrimaryKey, applicationDN, alarmValue.getAlarmRaisedTime());
if ((applicationDN == null) || (applicationDN.equals("")) || (ossPrimaryKey == null) || (ossPrimaryKey.equals(""))) {
LOG.error("{} ApplicatioDN or PrimaryKey not set", logheader);
} else {
LOG.debug("{} trying to find existing alarm using getCurrentAlarmForUniqueKey", logheader);
onmsAlarm = ossDao.getCurrentAlarmForUniqueKey(applicationDN, ossPrimaryKey);
if (onmsAlarm != null) {
// already an alarm with this unique id - log error
LOG.error("{} Alarm Already exists with this Unique ID", logheader);
} else {
onmsAlarm = new OnmsAlarm();
onmsAlarm.setUei(ossjAlarmTypeToUei(alarmValue.getAlarmType()));
onmsAlarm.setX733AlarmType((alarmValue.getAlarmType() == null) ? "" : alarmValue.getAlarmType());
onmsAlarm.setX733ProbableCause(alarmValue.getProbableCause());
// needed?
onmsAlarm.setTTicketState(null);
// needed?
onmsAlarm.setTTicketId("");
onmsAlarm.setQosAlarmState("");
// needed?
onmsAlarm.setSuppressedUser("");
// needed?
onmsAlarm.setSuppressedUntil(new Date());
// needed?
onmsAlarm.setSuppressedTime(new Date());
OnmsSeverity onmsseverity;
try {
onmsseverity = ossjSeveritytoOnmsSeverity(alarmValue.getPerceivedSeverity());
} catch (IllegalArgumentException iae) {
LOG.error("{} problem setting severity used default:'WARNING'.", logheader, iae);
onmsseverity = OnmsSeverity.WARNING;
}
onmsAlarm.setSeverity(onmsseverity);
OnmsServiceType service = new OnmsServiceType();
service.setId(new Integer(-1));
// needed?
onmsAlarm.setServiceType(new OnmsServiceType());
onmsAlarm.setReductionKey(":managedObjectInstance:" + alarmValue.getManagedObjectInstance() + ":managedObjectType:" + alarmValue.getManagedObjectClass() + ":ossPrimaryKey:-" + ossPrimaryKey + ":applicationDN:-" + // must be unique because of alarm_reductionkey_idx
applicationDN);
onmsAlarm.setOssPrimaryKey(ossPrimaryKey);
onmsAlarm.setOperInstruct(alarmValue.getProposedRepairActions());
// defaultvalue if search fails - will update node with ID 1
// TODO remove ossDao.makeExtendedOnmsNode();
OnmsNode node = new OnmsNode();
// node id cannot be null
node.setId(new Integer(1));
//
onmsAlarm.setNode(node);
if (almUpdateBehaviour == null) {
LOG.error("{} This receiver's alarmUpdateBehaviour is not set: defaulting to update nodeID:1", logheader);
} else {
LOG.debug("{} alarmUpdateBehaviour:{} {}", logheader, almUpdateBehaviour, getAlarmUpdateBehaviourForInt(almUpdateBehaviour));
if (almUpdateBehaviour.equals(SPECIFY_OUTSTATION)) {
// this will look for first match of node label to callingAer.getName()
// and set node id to this value.
LOG.debug("{} SPECIFY_OUTSTATION looking for node with nodelabel:{}", logheader, defaultUpdateNodeLabel);
try {
// TODO temp remove ?
try {
node = ossDao.findNodeByLabel(defaultUpdateNodeLabel);
} catch (Throwable ex) {
LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node", logheader, ex);
}
if (node != null) {
LOG.debug("{} alarmUpdateBehaviour.equals(SPECIFY_OUTSTATION): NODE FOUND for this name:{} setting node id to NodeLabel:{} NodeID:{}", logheader, defaultUpdateNodeLabel, node.getLabel(), node.getId());
// maps into FIRST instance of node with the same managedObjectInstance and managedObjectType
onmsAlarm.setNode(node);
} else {
LOG.error("{} alarmUpdateBehaviour.equals(SPECIFY_OUTSTATION): NODE NOT FOUND for this name:{} setting node id to default NodeID: 1", logheader, defaultUpdateNodeLabel);
// TODO remove ossDao.makeExtendedOnmsNode();
node = new OnmsNode();
// node id cannot be null
node.setId(new Integer(1));
//
onmsAlarm.setNode(node);
}
} catch (Throwable ex) {
LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node for alarm Set to default nodeID:1", logheader, ex);
}
} else if (almUpdateBehaviour.equals(USE_TYPE_INSTANCE)) {
// this will look for first match of node Managed object Instance and Managed Object type
// and set node id to this value.
String managedObjectType = alarmValue.getManagedObjectClass();
String managedObjectInstance = alarmValue.getManagedObjectInstance();
LOG.debug("{} USE_TYPE_INSTANCE looking for node with managedObjectType:{} managedObjectInstance:{}", logheader, managedObjectType, managedObjectInstance);
try {
node = ossDao.findNodeByInstanceAndType(managedObjectInstance, managedObjectType);
if (node != null) {
LOG.debug("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE): NODE FOUND for this RX Name:{} setting node id to NodeLabel:{} NodeID:{}", logheader, defaultUpdateNodeLabel, node.getLabel(), node.getId());
// maps into FIRST instance of node with the same managedObjectInstance and managedObjectType
onmsAlarm.setNode(node);
} else {
LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE): NODE NOT FOUND for this managedObjectType:{} managedObjectInstance:{} setting node id to default NodeID: 1", logheader, managedObjectType, managedObjectInstance);
// TODO remove ossDao.makeExtendedOnmsNode();
node = new OnmsNode();
// node id cannot be null
node.setId(new Integer(1));
//
onmsAlarm.setNode(node);
}
} catch (Throwable ex) {
LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node for alarm Set to default nodeID:1", logheader, ex);
}
} else {
LOG.error("{} Invalid value for alarmUpdateBehaviour:{} {} defaulting to update nodeID:1", logheader, almUpdateBehaviour, getAlarmUpdateBehaviourForInt(almUpdateBehaviour));
}
}
// needed?
onmsAlarm.setMouseOverText("");
onmsAlarm.setManagedObjectType(alarmValue.getManagedObjectClass());
onmsAlarm.setManagedObjectInstance(alarmValue.getManagedObjectInstance());
onmsAlarm.setLogMsg(alarmValue.getSpecificProblem());
// NOTE - this has no effect here as .setLastEvent nulls value
// alarm.setLastEventTime(nnae.getEventTime());
// TODO REMOVED - DO NOT CREATE EVENT WITH HIBERNATE AlarmDAo
// OnmsEvent event= new OnmsEvent();
// //event.setId(new Integer(1)); // This is NOT set since unique constraint in alarms table on Events table
// onmsAlarm.setLastEvent(event);
// needed?
onmsAlarm.setIpAddr(InetAddressUtils.getLocalHostAddress());
// set null as updating alarm
onmsAlarm.setId(null);
onmsAlarm.setFirstEventTime(alarmValue.getAlarmRaisedTime());
onmsAlarm.setLastEventTime(alarmValue.getAlarmChangedTime());
onmsAlarm.setDistPoller(distPollerDao.whoami());
//TODO need Qosd Not to generate this if remote
onmsAlarm.setDescription(alarmValue.getAdditionalText());
onmsAlarm.setCounter(new Integer(1));
onmsAlarm.setApplicationDN(applicationDN);
// set to raise alarm
onmsAlarm.setAlarmType(new Integer(1));
//alarm.setAlarmAckUser(arg0);
//alarm.setAlarmAckTime(arg0);
LOG.debug("{} Creating Alarm", logheader);
}
}
} catch (Throwable e) {
LOG.error("{} Error : ", logheader, e);
}
return onmsAlarm;
}
use of org.opennms.netmgt.model.OnmsServiceType in project opennms by OpenNMS.
the class DefaultDistributedStatusServiceTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
Locale.setDefault(Locale.US);
m_service.setMonitoredServiceDao(m_monitoredServiceDao);
m_service.setMonitoringLocationDao(m_monitoringLocationDao);
m_service.setLocationMonitorDao(m_locationMonitorDao);
m_service.setApplicationDao(m_applicationDao);
m_service.setResourceDao(m_resourceDao);
m_service.setGraphDao(m_graphDao);
m_service.afterPropertiesSet();
m_locationDefinition1 = new OnmsMonitoringLocation("Raleigh", "OpenNMS NC", "raleigh");
m_locationDefinition2 = new OnmsMonitoringLocation("Durham", "OpenNMS NC", "durham");
m_locationDefinition3 = new OnmsMonitoringLocation("Columbus", "OpenNMS OH", "columbus");
m_application1 = new OnmsApplication();
m_application1.setName("Application 1");
m_application2 = new OnmsApplication();
m_application2.setName("Application 2");
m_locationMonitor1_1 = new OnmsLocationMonitor();
m_locationMonitor1_1.setId(LOCATION_MONITOR_ID_A);
m_locationMonitor1_1.setLastUpdated(new Date());
m_locationMonitor1_1.setLocation("Raleigh");
m_locationMonitor1_1.setStatus(MonitorStatus.STARTED);
assertEquals("location monitor 1.1 status", MonitorStatus.STARTED, m_locationMonitor1_1.getStatus());
m_locationMonitor2_1 = new OnmsLocationMonitor();
m_locationMonitor2_1.setId(LOCATION_MONITOR_ID_B);
m_locationMonitor2_1.setLastUpdated(new Date());
m_locationMonitor2_1.setLocation("Durham");
m_locationMonitor2_1.setStatus(MonitorStatus.STARTED);
assertEquals("location monitor 2.1 status", MonitorStatus.STARTED, m_locationMonitor2_1.getStatus());
m_locationMonitor2_2 = new OnmsLocationMonitor();
m_locationMonitor2_2.setId(LOCATION_MONITOR_ID_C);
m_locationMonitor2_2.setLocation("Durham");
m_locationMonitor2_2.setStatus(MonitorStatus.STARTED);
assertEquals("location monitor 2.2 status", MonitorStatus.STARTED, m_locationMonitor2_2.getStatus());
List<String> serviceNames = new ArrayList<String>();
serviceNames.add("ICMP");
serviceNames.add("DNS");
serviceNames.add("HTTP");
serviceNames.add("HTTPS");
// shuffle to test sorting
Collections.shuffle(serviceNames);
m_node = new OnmsNode();
m_ip = InetAddressUtils.addr("1.1.1.1");
m_node.setLabel("Node 1");
m_node.setId(1);
// Can't shuffle since it's a set
m_services = new HashSet<OnmsMonitoredService>();
m_services.add(new OnmsMonitoredService(new OnmsIpInterface(m_ip, m_node), new OnmsServiceType("ICMP")));
m_services.add(new OnmsMonitoredService(new OnmsIpInterface(m_ip, m_node), new OnmsServiceType("DNS")));
m_services.add(new OnmsMonitoredService(new OnmsIpInterface(m_ip, m_node), new OnmsServiceType("HTTP")));
m_services.add(new OnmsMonitoredService(new OnmsIpInterface(m_ip, m_node), new OnmsServiceType("HTTPS")));
// Can't shuffle since these since they are sets
m_applicationServices1 = new TreeSet<OnmsMonitoredService>();
m_applicationServices1.add(findMonitoredService(m_services, m_ip, "HTTP"));
m_applicationServices1.add(findMonitoredService(m_services, m_ip, "HTTPS"));
// m_application1.setMemberServices(applicationServices1);
m_applicationServices2 = new TreeSet<OnmsMonitoredService>();
m_applicationServices2.add(findMonitoredService(m_services, m_ip, "HTTPS"));
// m_application2.setMemberServices(applicationServices2);
/*
m_application2 = new OnmsApplication();
m_application2.setLabel("Application 2");
// XXX shuffle to verify sorting? create new list and do: Collections.shuffle(applicationServices2)
m_application2.setMemberServices(applicationServices1);
*/
}
use of org.opennms.netmgt.model.OnmsServiceType in project opennms by OpenNMS.
the class DefaultProvisionService method createServiceTypeIfNecessary.
/** {@inheritDoc} */
@Transactional
@Override
public OnmsServiceType createServiceTypeIfNecessary(final String serviceName) {
preloadExistingTypes();
OnmsServiceType type = m_typeCache.get().get(serviceName);
if (type == null) {
type = loadServiceType(serviceName);
m_typeCache.get().put(serviceName, type);
}
return type;
}
use of org.opennms.netmgt.model.OnmsServiceType in project opennms by OpenNMS.
the class ForeignSourceConfigRestService method getServices.
/**
* Gets the services.
* <p>It will include all the configured service monitors from poller-configuration.xml.</p>
* <p>If the groupName is not null, it will include the services defined on the foreign source.</p>
*
* @param groupName the group name
* @return the services
*/
@GET
@Path("services/{groupName}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public ElementList getServices(@PathParam("groupName") String groupName) {
ElementList elements = new ElementList(m_pollerConfig.getServiceMonitors().keySet());
m_collectdConfigFactory.getCollectdConfig().getCollectors().forEach(c -> {
if (!elements.contains(c.getService())) {
elements.add(c.getService());
}
});
if (groupName != null) {
final SortedSet<String> serviceNames = new TreeSet<>();
final ForeignSource pendingForeignSource = m_foreignSourceService.getForeignSource(groupName);
serviceNames.addAll(pendingForeignSource.getDetectorNames());
for (final OnmsServiceType type : m_serviceTypeDao.findAll()) {
serviceNames.add(type.getName());
}
// Include all of the service names defined in the poller configuration
if (m_pollerConfig != null && m_pollerConfig.getServiceMonitors() != null && !m_pollerConfig.getServiceMonitors().isEmpty()) {
serviceNames.addAll(m_pollerConfig.getServiceMonitors().keySet());
}
serviceNames.forEach(s -> {
if (!elements.contains(s)) {
elements.add(s);
}
});
}
return elements;
}
Aggregations