use of org.opennms.netmgt.events.api.EventProxy in project opennms by OpenNMS.
the class SyslogdLoadIT method testEventd.
@Test
@Transactional
public void testEventd() throws Exception {
m_eventd.start();
EventProxy ep = createEventProxy();
Log eventLog = new Log();
Events events = new Events();
eventLog.setEvents(events);
int eventCount = 10000;
m_eventCounter.setAnticipated(eventCount);
for (int i = 0; i < eventCount; i++) {
int eventNum = Double.valueOf(Math.random() * 300).intValue();
String expectedUei = "uei.example.org/syslog/loadTest/foo" + eventNum;
final EventBuilder eb = new EventBuilder(expectedUei, "SyslogdLoadTest");
Event thisEvent = eb.setInterface(addr("127.0.0.1")).setLogDest("logndisplay").setLogMessage("A load test has been received as a Syslog Message").getEvent();
// LOG.debug("event = {}", thisEvent);
events.addEvent(thisEvent);
}
long start = System.currentTimeMillis();
ep.send(eventLog);
long mid = System.currentTimeMillis();
// wait up to 2 minutes for the events to come through
m_eventCounter.waitForFinish(120000);
long end = System.currentTimeMillis();
assertEquals(eventCount, m_eventCounter.getCount());
m_eventd.stop();
final long total = (end - start);
final double eventsPerSecond = (eventCount * 1000.0 / total);
System.err.println(String.format("total time: %d, wait time: %d, events per second: %8.4f", total, (end - mid), eventsPerSecond));
}
use of org.opennms.netmgt.events.api.EventProxy in project opennms by OpenNMS.
the class SnmpCollector method collect.
/**
* {@inheritDoc}
*
* Perform data collection.
*/
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException {
try {
final ServiceParameters params = new ServiceParameters(parameters);
params.logIfAliasConfig();
if (m_client == null) {
m_client = BeanUtils.getBean("daoContext", "locationAwareSnmpClient", LocationAwareSnmpClient.class);
}
OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection((SnmpCollectionAgent) agent, params, m_client);
final EventProxy eventProxy = EventIpcManagerFactory.getIpcManager();
final ForceRescanState forceRescanState = new ForceRescanState(agent, eventProxy);
SnmpCollectionSet collectionSet = snmpCollection.createCollectionSet((SnmpCollectionAgent) agent);
collectionSet.setCollectionTimestamp(new Date());
if (!collectionSet.hasDataToCollect()) {
LOG.info("agent {} defines no data to collect. Skipping.", agent);
// should we return here?
}
collectionSet.collect();
/*
* FIXME: Should we even be doing this? I say we get rid of this force rescan thingie
* {@see http://issues.opennms.org/browse/NMS-1057}
*/
if (System.getProperty("org.opennms.netmgt.collectd.SnmpCollector.forceRescan", "false").equalsIgnoreCase("true") && collectionSet.rescanNeeded()) {
/*
* TODO: the behavior of this object may have been re-factored away.
* Verify that this is correct and remove this unused object if it
* is no longer needed. My gut thinks this should be investigated.
*/
forceRescanState.rescanIndicated();
} else {
collectionSet.checkForSystemRestart();
}
return collectionSet;
} catch (CollectionException e) {
throw e;
} catch (Throwable t) {
throw new CollectionException("Unexpected error during node SNMP collection for: " + agent.getHostAddress(), t);
}
}
use of org.opennms.netmgt.events.api.EventProxy in project opennms by OpenNMS.
the class Util method createEventProxy.
/**
* <p>createEventProxy</p>
*
* @deprecated Use dependency injection to wire in an instance of the {@link EventProxy} instead
*
* @return a {@link org.opennms.netmgt.events.api.EventProxy} object.
*/
public static EventProxy createEventProxy() {
/*
* Rather than defaulting to localhost all the time, give an option in properties
*/
final String vaultHost = Vault.getProperty("opennms.rtc.event.proxy.host");
final String vaultPort = Vault.getProperty("opennms.rtc.event.proxy.port");
final String vaultTimeout = Vault.getProperty("opennms.rtc.event.proxy.timeout");
final String proxyHostName = vaultHost == null ? "127.0.0.1" : vaultHost;
final String proxyHostPort = vaultPort == null ? Integer.toString(TcpEventProxy.DEFAULT_PORT) : vaultPort;
final String proxyHostTimeout = vaultTimeout == null ? Integer.toString(TcpEventProxy.DEFAULT_TIMEOUT) : vaultTimeout;
InetAddress proxyAddr = null;
EventProxy proxy = null;
proxyAddr = InetAddressUtils.addr(proxyHostName);
if (proxyAddr == null) {
try {
proxy = new TcpEventProxy();
} catch (final UnknownHostException e) {
// XXX Ewwww! We should just let the first UnknownException bubble up.
throw new UndeclaredThrowableException(e);
}
} else {
proxy = new TcpEventProxy(new InetSocketAddress(proxyAddr, Integer.parseInt(proxyHostPort)), Integer.parseInt(proxyHostTimeout));
}
return proxy;
}
use of org.opennms.netmgt.events.api.EventProxy in project opennms by OpenNMS.
the class FinishPollerConfigServlet method doPost.
/**
* {@inheritDoc}
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
EventBuilder bldr = new EventBuilder("uei.opennms.org/internal/reloadPollerConfig", "webUI");
try {
EventProxy eventProxy = Util.createEventProxy();
if (eventProxy != null) {
eventProxy.send(bldr.getEvent());
} else {
throw new ServletException("Event proxy object is null, unable to send event " + bldr.getEvent().getUei());
}
} catch (Throwable e) {
throw new ServletException("Could not send event " + bldr.getEvent().getUei(), e);
}
// forward the request for proper display
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/index.jsp");
dispatcher.forward(request, response);
}
use of org.opennms.netmgt.events.api.EventProxy in project opennms by OpenNMS.
the class ActionDiscoveryServlet method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
LOG.info("Loading Discovery configuration.");
HttpSession sess = request.getSession(true);
DiscoveryConfiguration config = (DiscoveryConfiguration) sess.getAttribute(ATTRIBUTE_DISCOVERY_CONFIGURATION);
if (config == null) {
config = getDiscoveryConfig();
sess.setAttribute(ATTRIBUTE_DISCOVERY_CONFIGURATION, config);
}
// Update general settings from the incoming request parameters
config = GeneralSettingsLoader.load(request, config);
String action = request.getParameter("action");
LOG.debug("action: {}", action);
// add a Specific
if (action.equals(addSpecificAction)) {
LOG.debug("Adding Specific");
String ipAddr = request.getParameter("specificipaddress");
String timeout = request.getParameter("specifictimeout");
String retries = request.getParameter("specificretries");
String foreignSource = request.getParameter("specificforeignsource");
String location = request.getParameter("specificlocation");
Specific newSpecific = new Specific();
newSpecific.setAddress(ipAddr);
if (timeout != null && !"".equals(timeout.trim()) && !timeout.equals(String.valueOf(config.getTimeout().orElse(null)))) {
newSpecific.setTimeout(WebSecurityUtils.safeParseLong(timeout));
}
if (retries != null && !"".equals(retries.trim()) && !retries.equals(String.valueOf(config.getRetries().orElse(null)))) {
newSpecific.setRetries(WebSecurityUtils.safeParseInt(retries));
}
if (foreignSource != null && !"".equals(foreignSource.trim()) && !foreignSource.equals(config.getForeignSource().orElse(null))) {
newSpecific.setForeignSource(foreignSource);
}
if (location != null && !"".equals(location.trim()) && !location.equals(config.getLocation().orElse(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID))) {
newSpecific.setLocation(location);
}
config.addSpecific(newSpecific);
}
// remove 'Specific' from configuration
if (action.equals(removeSpecificAction)) {
LOG.debug("Removing Specific");
String specificIndex = request.getParameter("index");
int index = WebSecurityUtils.safeParseInt(specificIndex);
final int index1 = index;
Specific spec = config.getSpecifics().get(index1);
boolean result = config.removeSpecific(spec);
LOG.debug("Removing Specific result = {}", result);
}
// add an 'Include Range'
if (action.equals(addIncludeRangeAction)) {
LOG.debug("Adding Include Range");
String ipAddrBase = request.getParameter("irbase");
String ipAddrEnd = request.getParameter("irend");
String timeout = request.getParameter("irtimeout");
String retries = request.getParameter("irretries");
String foreignSource = request.getParameter("irforeignsource");
String location = request.getParameter("irlocation");
IncludeRange newIR = new IncludeRange();
newIR.setBegin(ipAddrBase);
newIR.setEnd(ipAddrEnd);
if (timeout != null && !"".equals(timeout.trim()) && !timeout.equals(String.valueOf(config.getTimeout().orElse(null)))) {
newIR.setTimeout(WebSecurityUtils.safeParseLong(timeout));
}
if (retries != null && !"".equals(retries.trim()) && !retries.equals(String.valueOf(config.getRetries().orElse(null)))) {
newIR.setRetries(WebSecurityUtils.safeParseInt(retries));
}
if (foreignSource != null && !"".equals(foreignSource.trim()) && !foreignSource.equals(config.getForeignSource().orElse(null))) {
newIR.setForeignSource(foreignSource);
}
if (location != null && !"".equals(location.trim()) && !location.equals(config.getLocation().orElse(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID))) {
newIR.setLocation(location);
}
config.addIncludeRange(newIR);
}
// remove 'Include Range' from configuration
if (action.equals(removeIncludeRangeAction)) {
LOG.debug("Removing Include Range");
String specificIndex = request.getParameter("index");
int index = WebSecurityUtils.safeParseInt(specificIndex);
final int index1 = index;
IncludeRange ir = config.getIncludeRanges().get(index1);
boolean result = config.removeIncludeRange(ir);
LOG.debug("Removing Include Range result = {}", result);
}
// add an 'Include URL'
if (action.equals(addIncludeUrlAction)) {
LOG.debug("Adding Include URL");
String url = request.getParameter("iuurl");
String timeout = request.getParameter("iutimeout");
String retries = request.getParameter("iuretries");
String foreignSource = request.getParameter("iuforeignsource");
String location = request.getParameter("iulocation");
IncludeUrl iu = new IncludeUrl();
iu.setUrl(url);
if (timeout != null && !"".equals(timeout.trim()) && !timeout.equals(String.valueOf(config.getTimeout().orElse(null)))) {
iu.setTimeout(WebSecurityUtils.safeParseLong(timeout));
}
if (retries != null && !"".equals(retries.trim()) && !retries.equals(String.valueOf(config.getRetries().orElse(null)))) {
iu.setRetries(WebSecurityUtils.safeParseInt(retries));
}
if (foreignSource != null && !"".equals(foreignSource.trim()) && !foreignSource.equals(config.getForeignSource().orElse(null))) {
iu.setForeignSource(foreignSource);
}
if (location != null && !"".equals(location.trim()) && !location.equals(config.getLocation().orElse(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID))) {
iu.setLocation(location);
}
config.addIncludeUrl(iu);
}
// remove 'Include URL' from configuration
if (action.equals(removeIncludeUrlAction)) {
LOG.debug("Removing Include URL");
String specificIndex = request.getParameter("index");
int index = WebSecurityUtils.safeParseInt(specificIndex);
final int index1 = index;
IncludeUrl iu = config.getIncludeUrls().get(index1);
boolean result = config.removeIncludeUrl(iu);
LOG.debug("Removing Include URL result = {}", result);
}
// add an 'Exclude Range'
if (action.equals(addExcludeRangeAction)) {
LOG.debug("Adding Exclude Range");
String ipAddrBegin = request.getParameter("erbegin");
String ipAddrEnd = request.getParameter("erend");
ExcludeRange newER = new ExcludeRange();
newER.setBegin(ipAddrBegin);
newER.setEnd(ipAddrEnd);
config.addExcludeRange(newER);
}
// remove 'Exclude Range' from configuration
if (action.equals(removeExcludeRangeAction)) {
LOG.debug("Removing Exclude Range");
String specificIndex = request.getParameter("index");
int index = WebSecurityUtils.safeParseInt(specificIndex);
final int index1 = index;
ExcludeRange er = config.getExcludeRanges().get(index1);
boolean result = config.removeExcludeRange(er);
LOG.debug("Removing Exclude Range result = {}", result);
}
// save configuration and restart discovery service
if (action.equals(saveAndRestartAction)) {
DiscoveryConfigFactory dcf = null;
try {
StringWriter configString = new StringWriter();
JaxbUtils.marshal(config, configString);
LOG.debug(configString.toString().trim());
dcf = DiscoveryConfigFactory.getInstance();
dcf.saveConfiguration(config);
} catch (Throwable ex) {
LOG.error("Error while saving configuration. {}", ex);
throw new ServletException(ex);
}
EventProxy proxy = null;
try {
proxy = Util.createEventProxy();
} catch (Throwable me) {
LOG.error(me.getMessage());
}
EventBuilder bldr = new EventBuilder(EventConstants.DISCOVERYCONFIG_CHANGED_EVENT_UEI, "ActionDiscoveryServlet");
bldr.setHost("host");
try {
proxy.send(bldr.getEvent());
} catch (Throwable me) {
LOG.error(me.getMessage());
}
LOG.info("Restart Discovery requested!");
sess.removeAttribute(ATTRIBUTE_DISCOVERY_CONFIGURATION);
response.sendRedirect(Util.calculateUrlBase(request, "admin/discovery/config-done.jsp"));
return;
}
sess.setAttribute(ATTRIBUTE_DISCOVERY_CONFIGURATION, config);
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/discovery/edit-config.jsp");
dispatcher.forward(request, response);
}
Aggregations