A Java OpenNMS client for creating events via ONMS eventd daemon.
A REST interface for creating events exists out-of-the-box since OpenNMS 17.1.1. You may want to use the REST interface in favor of the eventd daemon, if you are running 17.1.1 or a later version of OpenNMS.
This library is intended to support the developer when sending ONMS Events in Java. The library utilizes JAX-B to generate the XML message.
OpenNmsEventBuilder.create()
.host("host")
.source("source")
.time(new Date())
.service("service")
.description("description")
.uei("uei")
.send("my.opennms.server");
This section covers handling and setting Event properties
Following Event properties are supported by this project:
Note that the ONMS Event configuration of your OpenNMS Server may have restrictions on overriding event properties.
Following properties need to be set for most of the Event types in order to be processed by the eventd
daemon:
Make sure these properties are set before sending the event with send()
In some situations OpenNMS parm
entries need to be supplied in a specific order. To encapsulate this knowledge from the
user of the library, a custom Parameter Collection can be used.
A custom ParameterCollection
can look like this:
public class CustomParameterCollection extends ParameterCollection {
private final static String FIRST_PARAM = "firstParameter";
private final static String SECOND_PARAM = "secondParameter";
private String[] parameterOrder = { FIRST_PARAM, SECOND_PARAM };
public CustomParameterCollection() {
for (String parameterName : parameterOrder) {
this.configureParameter(parameterName);
}
}
@Override
protected void validate() throws ParameterValidationException {
}
public CustomParameterCollection setFirstParameter(String value) {
this.setValue(FIRST_PARAM, value);
return this;
}
public CustomParameterCollection setSecondParameter(Integer value) {
this.setValue(SECOND_PARAM, value);
return this;
}
}
After writing your custom ParameterCollection
class, setting parameters can for example look like this:
// Using a custom ParameterCollection
OpenNmsEventBuilder.create()
.parameter(
new CustomParameterCollection()
.setSecondParameter(2)
.setFirstParameter("1")
);
Keep in mind that the OpenNMS eventd
service does not return responses on success or error. You need to ensure your transmitted event data complies to the event schema you have configured on your OpenNMS server.
If you are running in any issues (e.g. events are not created) take a look into the eventd
service log file.
Using Maven
<dependency>
<groupId>com.github.error418.opennms</groupId>
<artifactId>event-client</artifactId>
<version>0.2.1</version>
</dependency>