use of org.opennms.netmgt.xml.event.Logmsg in project opennms by OpenNMS.
the class SyslogEventForwarderTest method testForwardEvent.
/**
* Test forward event.
*
* @throws Exception the exception
*/
@Test
public void testForwardEvent() throws Exception {
SyslogEventForwarder forwarder = new SyslogEventForwarder();
forwarder.initialize("localTest1");
OnmsNode node = new OnmsNode();
node.setForeignSource("TestGroup");
node.setForeignId("1");
node.setId(1);
node.setLabel("p-brane");
Event event = new Event();
event.setUei("uei.opennms.org/junit/testEvent");
event.setNodeid(1l);
event.setDbid(100);
event.setLogmsg(new Logmsg());
event.getLogmsg().setContent("something is wrong");
Parm param = new Parm();
param.setParmName("forwardEventToActivitySyslog");
Value value = new Value();
value.setContent("true");
param.setValue(value);
event.setParmCollection(new ArrayList<Parm>());
event.getParmCollection().add(param);
event.setSeverity("Major");
forwarder.forward(event, node);
Thread.sleep(100);
BufferedReader r = new BufferedReader(new StringReader(m_logStream.readStream()));
List<String> messages = new LinkedList<String>();
String line = null;
while ((line = r.readLine()) != null) {
messages.add(line);
Thread.sleep(10);
}
Assert.assertTrue("Log messages sent: 1, Log messages received: " + messages.size(), 1 == messages.size());
messages.forEach(System.out::println);
Assert.assertTrue(messages.get(0).contains("EVENT 100 FOR NODE p-brane IN TestGroup: something is wrong"));
forwarder.reload();
forwarder.shutdown();
}
use of org.opennms.netmgt.xml.event.Logmsg in project opennms by OpenNMS.
the class AlarmEventSynchronization method getXMLEvent.
private Event getXMLEvent(OnmsAlarm alarm) {
Event event = new Event();
event.setDbid(alarm.getLastEvent().getId());
//UEI
if (alarm.getUei() != null) {
event.setUei(alarm.getUei());
} else {
return null;
}
// Source
if (alarm.getLastEvent().getEventSource() != null) {
event.setSource(alarm.getLastEvent().getEventSource());
}
//nodeid
if (alarm.getNode() != null) {
event.setNodeid(alarm.getNode().getId().longValue());
}
// alarm creation time
if (alarm.getFirstEventTime() != null) {
// TODO: This is incorrect. The creation time represents
// the time that the event was stored in the database, not
// the original timestamp of the event.
event.setCreationTime(alarm.getFirstEventTime());
}
// last event timestamp
if (alarm.getLastEventTime() != null) {
event.setTime(alarm.getLastEventTime());
}
// host
if (alarm.getLastEvent().getEventHost() != null) {
event.setHost(alarm.getLastEvent().getEventHost());
}
// interface
if (alarm.getIpAddr() != null) {
event.setInterfaceAddress(alarm.getIpAddr());
}
// Service Name
if (alarm.getServiceType() != null) {
event.setService(alarm.getServiceType().getName());
}
// Description
if (alarm.getDescription() != null) {
event.setDescr(alarm.getDescription());
}
// Log message
if (alarm.getLogMsg() != null) {
Logmsg msg = new Logmsg();
msg.setContent(alarm.getLogMsg());
event.setLogmsg(msg);
}
// severity
if (alarm.getSeverity() != null) {
event.setSeverity((alarm.getSeverity()).getLabel());
}
// operator Instruction
if (alarm.getOperInstruct() != null) {
event.setOperinstruct(alarm.getOperInstruct());
}
AlarmData ad = new AlarmData();
ad.setReductionKey(alarm.getReductionKey());
ad.setAlarmType(alarm.getAlarmType());
if (alarm.getClearKey() != null)
ad.setClearKey(alarm.getClearKey());
event.setAlarmData(ad);
return event;
}
use of org.opennms.netmgt.xml.event.Logmsg in project opennms by OpenNMS.
the class InsSession method getXMLEvent.
private Event getXMLEvent(final OnmsEvent ev) {
final Integer id = ev.getId();
LOG.info("Working on XML Event for id: {}", id);
LOG.debug("Setting Event id: {}", id);
final Event e = new Event();
e.setDbid(id);
//UEI
final String uei = ev.getEventUei();
if (uei != null) {
LOG.debug("Setting Event uei: {}", uei);
e.setUei(uei);
} else {
LOG.warn("No Event uei found: skipping event....");
return null;
}
// Source
final String source = ev.getEventSource();
if (source != null) {
LOG.debug("Setting Event source: {}", source);
e.setSource(source);
} else {
LOG.info("No Event source found.");
}
//nodeid
final Integer nodeid = ev.getNode().getId();
if (ev.getNode() != null && nodeid != null) {
LOG.debug("Setting Event nodeid: {}", nodeid);
e.setNodeid(nodeid.longValue());
} else {
LOG.info("No Event node found.");
}
// timestamp
final Date time = ev.getEventTime();
if (time != null) {
LOG.debug("Setting event date timestamp to (GMT): {}", time);
e.setTime(time);
} else {
LOG.info("No Event time found.");
}
// host
final String host = ev.getEventHost();
if (host != null) {
LOG.debug("Setting Event Host: {}", host);
e.setHost(host);
} else {
LOG.info("No Event host found.");
}
// interface
final InetAddress ipAddr = ev.getIpAddr();
if (ipAddr != null) {
LOG.debug("Setting Event Interface/ipaddress: {}", ipAddr);
e.setInterfaceAddress(ipAddr);
} else {
LOG.info("No Event ip address found.");
}
// Service Name
if (ev.getServiceType() != null) {
final String serviceName = ev.getServiceType().getName();
LOG.debug("Setting Event Service Name: {}", serviceName);
e.setService(serviceName);
} else {
LOG.info("No Event service name found.");
}
// Description
final String descr = ev.getEventDescr();
if (descr != null) {
LOG.debug("Setting Event Description: {}", descr);
e.setDescr(descr);
} else {
LOG.info("No Event ip address found.");
}
// Log message
final String logmsg = ev.getEventLogMsg();
if (logmsg != null) {
final Logmsg msg = new Logmsg();
LOG.debug("Setting Event Log Message: {}", logmsg);
msg.setContent(logmsg);
e.setLogmsg(msg);
} else {
LOG.info("No Event log Message found.");
}
// severity
final Integer severity = ev.getEventSeverity();
if (severity != null) {
LOG.debug("Setting Event Severity: {}", severity);
e.setSeverity(OnmsSeverity.get(severity).getLabel());
} else {
LOG.info("No Event severity found.");
}
final Integer ifIndex = ev.getIfIndex();
if (ifIndex != null && ifIndex > 0) {
e.setIfIndex(ifIndex);
e.setIfAlias(getIfAlias(nodeid, ifIndex));
} else {
e.setIfIndex(-1);
e.setIfAlias("-1");
}
// operator Instruction
final String operInstruct = ev.getEventOperInstruct();
if (operInstruct != null) {
LOG.debug("Setting Event Operator Instruction: {}", operInstruct);
e.setOperinstruct(operInstruct);
} else {
LOG.info("No Event operator Instruction found.");
}
// parms
final String eventParms = ev.getEventParms();
if (eventParms != null) {
LOG.debug("Setting Event Parms: {}", eventParms);
final List<Parm> parms = EventParameterUtils.decode(eventParms);
if (parms != null)
e.setParmCollection(parms);
} else {
LOG.info("No Event parms found.");
}
final AlarmData ad = new AlarmData();
final OnmsAlarm onmsAlarm = ev.getAlarm();
try {
if (onmsAlarm != null) {
ad.setReductionKey(onmsAlarm.getReductionKey());
ad.setAlarmType(onmsAlarm.getAlarmType());
ad.setClearKey(onmsAlarm.getClearKey());
e.setAlarmData(ad);
}
} catch (final ObjectNotFoundException e1) {
LOG.warn("Correlated alarm data not found.", e1);
}
LOG.info("Returning event with id: {}", id);
return e;
}
use of org.opennms.netmgt.xml.event.Logmsg 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<Parm>();
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.xml.event.Logmsg in project opennms by OpenNMS.
the class PassiveStatusKeeperIT method createEventWithParms.
private Event createEventWithParms(String uei, List<Parm> parms) {
Event e = MockEventUtil.createEventBuilder("Test", uei).getEvent();
e.setHost("localhost");
e.setParmCollection(parms);
Logmsg logmsg = new Logmsg();
logmsg.setContent("Testing Passive Status Keeper with down status");
e.setLogmsg(logmsg);
return e;
}
Aggregations