use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class EventDaoIT method testSave.
@Test
@Transactional
public void testSave() {
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventCreateTime(new Date());
event.setEventDescr("event dao test");
event.setEventHost("localhost");
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogGroup("event dao test log group");
event.setEventLogMsg("event dao test log msg");
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventSource("EventDaoTest");
event.setEventTime(new Date());
event.setEventUei("uei://org/opennms/test/EventDaoTest");
OnmsNode node = (OnmsNode) m_nodeDao.findAll().iterator().next();
OnmsIpInterface iface = (OnmsIpInterface) node.getIpInterfaces().iterator().next();
OnmsMonitoredService service = (OnmsMonitoredService) iface.getMonitoredServices().iterator().next();
event.setNode(node);
event.setServiceType(service.getServiceType());
OnmsAlarm alarm = new OnmsAlarm();
event.setAlarm(alarm);
event.setIpAddr(iface.getIpAddress());
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "label", "node", "string"), new OnmsEventParameter(event, "ds", "(memAvailReal + memCached) / memTotalReal * 100.0", "string"), new OnmsEventParameter(event, "description", "(memAvailReal + memCached) / memTotalReal * 100.0", "string"), new OnmsEventParameter(event, "value", "4.7", "string"), new OnmsEventParameter(event, "instance", "node", "string"), new OnmsEventParameter(event, "instanceLabel", "node", "string"), new OnmsEventParameter(event, "resourceId", "node[70].nodeSnmp[]", "string"), new OnmsEventParameter(event, "threshold", "5.0", "string"), new OnmsEventParameter(event, "trigger", "2", "string"), new OnmsEventParameter(event, "rearm", "10.0", "string")));
m_eventDao.save(event);
OnmsEvent newEvent = m_eventDao.load(event.getId());
assertEquals("uei://org/opennms/test/EventDaoTest", newEvent.getEventUei());
assertNotNull(newEvent.getServiceType());
assertEquals(service.getNodeId(), newEvent.getNode().getId());
assertEquals(event.getIpAddr(), newEvent.getIpAddr());
System.err.println(JaxbUtils.marshal(event));
}
use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class NCSNorthbounderIT method alarm.
private NorthboundAlarm alarm(int alarmId) {
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "componentType", "Service", "string"), new OnmsEventParameter(event, "componentName", "NAM" + alarmId, "string"), new OnmsEventParameter(event, "componentForeignSource", "FS", "string"), new OnmsEventParameter(event, "componentForeignId", "" + alarmId, "string"), new OnmsEventParameter(event, "cause", "17", "string")));
OnmsAlarm alarm = new OnmsAlarm();
alarm.setId(alarmId);
alarm.setUei("uei.opennms.org/test/httpNorthBounder");
alarm.setLastEvent(event);
alarm.setAlarmType((alarmId + 1) % 2 + 1);
return new NorthboundAlarm(alarm);
}
use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class OnmsRestEventsClient method toEvent.
public Event toEvent(OnmsEvent onmsEvent) {
Event event = new Event();
if (onmsEvent.getId() != null)
event.setDbid(onmsEvent.getId());
if (onmsEvent.getEventUei() != null)
event.setUei(onmsEvent.getEventUei());
if (onmsEvent.getEventCreateTime() != null)
event.setCreationTime(onmsEvent.getEventCreateTime());
// event.setService()
if (onmsEvent.getSeverityLabel() != null)
event.setSeverity(onmsEvent.getSeverityLabel());
if (onmsEvent.getEventDescr() != null)
event.setDescr(onmsEvent.getEventDescr());
if (onmsEvent.getEventHost() != null)
event.setHost(onmsEvent.getEventHost());
List<Parm> parmColl = new ArrayList<>();
if (onmsEvent.getEventParameters() != null) {
List<OnmsEventParameter> params = onmsEvent.getEventParameters();
for (OnmsEventParameter onmsEventParameter : params) {
String parmName = onmsEventParameter.getName();
String type = onmsEventParameter.getType();
String value = onmsEventParameter.getValue();
Parm parm = new Parm();
parm.setParmName(parmName);
Value parmvalue = new Value();
parmvalue.setType(type);
parmvalue.setContent(value);
parm.setValue(parmvalue);
parmColl.add(parm);
}
}
// add node label as param
if (onmsEvent.getNodeLabel() != null) {
Parm parm = new Parm();
parm.setParmName(NODE_LABEL);
Value parmValue = new Value();
parm.setValue(parmValue);
parmValue.setType("string");
parmValue.setEncoding("text");
parmValue.setContent(onmsEvent.getNodeLabel());
parmColl.add(parm);
}
event.setParmCollection(parmColl);
if (onmsEvent.getEventLogMsg() != null) {
Logmsg logmsg = new Logmsg();
logmsg.setContent(onmsEvent.getEventLogMsg());
event.setLogmsg(logmsg);
}
if (onmsEvent.getNodeId() != null) {
Integer i = onmsEvent.getNodeId();
Long l = Long.valueOf(i.longValue());
event.setNodeid(l);
}
return event;
}
use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class HypericAckProcessorIT method testParseMethods.
@Test
public void testParseMethods() throws Exception {
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "platform.id", "10001", "string"), new OnmsEventParameter(event, "platform.commentText", "", "string"), new OnmsEventParameter(event, "platform.platformType.os", "null", "string"), new OnmsEventParameter(event, "platform.platformType.osVersion", "null", "string"), new OnmsEventParameter(event, "platform.platformType.arch", "null(", "tring"), new OnmsEventParameter(event, "platform.agent.address", "192.0.2.143", "string"), new OnmsEventParameter(event, "platform.agent.port", "2144", "string"), new OnmsEventParameter(event, "platform.fqdn", "192.0.2.143", "string"), new OnmsEventParameter(event, "platform.name", "delta", "string"), new OnmsEventParameter(event, "platform.description", "Fedora 12", "string"), new OnmsEventParameter(event, "platform.location", "", "string"), new OnmsEventParameter(event, "alert.id", "11757", "string"), new OnmsEventParameter(event, "alert.fixed", "false", "string"), new OnmsEventParameter(event, "alert.ctime", "1267219500000", "string"), new OnmsEventParameter(event, "alert.timestamp", "1267219500000", "string"), new OnmsEventParameter(event, "alert.ackedBy", "null", "string"), new OnmsEventParameter(event, "alert.stateId", "null", "string"), new OnmsEventParameter(event, "alert.url", "http://192.168.0.5:7080/alerts/Alerts.do?mode%61viewAlert&eid%611:10001&a%6111757", "string"), new OnmsEventParameter(event, "alert.baseURL", "http://192.168.0.5:7080", "string"), new OnmsEventParameter(event, "alert.source", "HQ", "string"), new OnmsEventParameter(event, "alertDef.id", "10002", "string"), new OnmsEventParameter(event, "alertDef.name", "Load Above 2", "string"), new OnmsEventParameter(event, "alertDef.description", "", "string"), new OnmsEventParameter(event, "alertDef.priority", "2", "string"), new OnmsEventParameter(event, "alertDef.appdefType", "1", "string"), new OnmsEventParameter(event, "alertDef.appdefId", "10001", "string"), new OnmsEventParameter(event, "alertDef.notifyFiltered", "false", "string"), new OnmsEventParameter(event, "action.shortReason", "Load Above 2 delta Load Average 5 Minutes (1.4)", "string"), new OnmsEventParameter(event, "action.longReason", "If Load Average 5 Minutes > 0.5 (actual value %61 1.4)", "string"), new OnmsEventParameter(event, "resource.instanceId", "10001", "string"), new OnmsEventParameter(event, "resource.name", "delta", "string"), new OnmsEventParameter(event, "resource.url", "http://192.168.0.5:7080/Resource.do?eid%611:10001", "string"), new OnmsEventParameter(event, "resource.resourceType.name", "covalentEAMPlatform", "string")));
OnmsAlarm alarm = new OnmsAlarm();
alarm.setLastEvent(event);
/*
OnmsAlarm alarm = createMock(OnmsAlarm.class);
expect(alarm.getEventParms()).andReturn(
"platform.id=10001(string,text);platform.commentText=(string,text);platform.platformType.os=null(string,text);platform.platformType.osVersion=null(string,text);platform.platformType.arch=null(string,text);platform.agent.address=192.0.2.143(string,text);platform.agent.port=2144(string,text);platform.fqdn=192.0.2.143(string,text);platform.name=delta(string,text);platform.description=Fedora 12(string,text);platform.location=(string,text);alert.id=11757(string,text);alert.fixed=false(string,text);alert.ctime=1267219500000(string,text);alert.timestamp=1267219500000(string,text);alert.ackedBy=null(string,text);alert.stateId=null(string,text);alert.url=http://192.168.0.5:7080/alerts/Alerts.do?mode%61viewAlert&eid%611:10001&a%6111757(string,text);alert.baseURL=http://192.168.0.5:7080(string,text);alert.source=HQ(string,text);alertDef.id=10002(string,text);alertDef.name=Load Above 2(string,text);alertDef.description=(string,text);alertDef.priority=2(string,text);alertDef.appdefType=1(string,text);alertDef.appdefId=10001(string,text);alertDef.notifyFiltered=false(string,text);action.shortReason=Load Above 2 delta Load Average 5 Minutes (1.4)(string,text);action.longReason=If Load Average 5 Minutes > 0.5 (actual value %61 1.4)(string,text);resource.instanceId=10001(string,text);resource.name=delta(string,text);resource.url=http://192.168.0.5:7080/Resource.do?eid%611:10001(string,text);resource.resourceType.name=covalentEAMPlatform(string,text)"
).times(2);
replay(alarm);
*/
assertEquals("Alert source not parsed properly", "HQ", HypericAckProcessor.getAlertSourceParmValue(alarm));
assertEquals("Alert ID not parsed properly", "11757", HypericAckProcessor.getAlertIdParmValue(alarm));
}
use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class AbstractNorthbounder method buildParmMappingXml.
/**
* Builds an XML representation of parameter mappings.
* @param alarm the alarm
* @param mapping the mapping
*/
private void buildParmMappingXml(final NorthboundAlarm alarm, final Map<String, Object> mapping) {
List<OnmsEventParameter> parms = alarm.getEventParametersCollection();
EventParms eventParms = new EventParms(parms);
try {
JAXBElement<EventParms> rootElement = new JAXBElement<EventParms>(new QName("eventParms"), EventParms.class, eventParms);
StringWriter sw = new StringWriter();
Marshaller marshaller = ONMS_EVENT_PARM_CONTEXT.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
marshaller.marshal(rootElement, sw);
LOG.debug("Adding eventParmsXML mapping with contents {}.", sw);
mapping.put("eventParmsXml", sw);
} catch (JAXBException e) {
LOG.error("Error marshalling event params to XML for alarm ID: {}", alarm.getId(), e);
}
}
Aggregations