use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.
the class SyslogdImplementationsIT method loadSyslogConfiguration.
private void loadSyslogConfiguration(final String configuration) throws IOException {
InputStream stream = null;
try {
stream = ConfigurationTestUtils.getInputStreamForResource(this, configuration);
m_config = new SyslogdConfigFactory(stream);
} finally {
if (stream != null) {
IOUtils.closeQuietly(stream);
}
}
}
use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.
the class ConvertToEventTest method testCiscoEventConversion.
@Test
public void testCiscoEventConversion() throws IOException {
InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-cisco-configuration.xml");
SyslogdConfig config = new SyslogdConfigFactory(stream);
try {
ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, InetAddressUtils.ONE_TWENTY_SEVEN, 9999, SyslogdTestUtils.toByteBuffer("<190>Mar 11 08:35:17 aaa_host 30128311: Mar 11 08:35:16.844 CST: %SEC-6-IPACCESSLOGP: list in110 denied tcp 192.168.10.100(63923) -> 192.168.11.128(1521), 1 packet"), config);
LOG.info("Generated event: {}", convertToEvent.getEvent().toString());
} catch (MessageDiscardedException e) {
LOG.error("Message Parsing failed", e);
fail("Message Parsing failed: " + e.getMessage());
}
}
use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.
the class ConvertToEventTest method testConvertToEvent.
/**
* Test method which calls the ConvertToEvent constructor.
*
* @throws IOException
*/
@Test
public void testConvertToEvent() throws IOException {
InterfaceToNodeCacheDaoImpl.setInstance(new MockInterfaceToNodeCache());
// 10000 sample syslogmessages from xml file are taken and passed as
// Inputstream to create syslogdconfiguration
InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-loadtest-configuration.xml");
SyslogdConfig config = new SyslogdConfigFactory(stream);
// Sample message which is embedded in packet and passed as parameter
// to
// ConvertToEvent constructor
byte[] bytes = "<34> 2010-08-19 localhost foo10000: load test 10000 on tty1".getBytes(StandardCharsets.US_ASCII);
// Datagram packet which is passed as parameter for ConvertToEvent
// constructor
DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, InetAddress.getLocalHost(), SyslogClient.PORT);
ByteBuffer data = ByteBuffer.wrap(pkt.getData());
// @param len The length of the XML data in the buffer
try {
ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, pkt.getAddress(), pkt.getPort(), data, config);
LOG.info("Generated event: {}", convertToEvent.getEvent().toString());
} catch (MessageDiscardedException e) {
LOG.error("Message Parsing failed", e);
fail("Message Parsing failed: " + e.getMessage());
}
}
use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.
the class SyslogMessageTest method testCustomParserNms5242.
@Test
public void testCustomParserNms5242() throws Exception {
final Locale startLocale = Locale.getDefault();
try {
Locale.setDefault(Locale.FRANCE);
final InputStream stream = new ByteArrayInputStream(("<?xml version=\"1.0\"?>\n" + "<syslogd-configuration>\n" + " <configuration\n" + " syslog-port=\"10514\"\n" + " new-suspect-on-message=\"false\"\n" + " parser=\"org.opennms.netmgt.syslogd.CustomSyslogParser\"\n" + " forwarding-regexp=\"^((.+?) (.*))\\n?$\"\n" + " matching-group-host=\"2\"\n" + " matching-group-message=\"3\"\n" + " discard-uei=\"DISCARD-MATCHING-MESSAGES\"\n" + " />\n" + "\n" + " <hideMessage>\n" + " <hideMatch>\n" + " <match type=\"substr\" expression=\"TEST\"/>\n" + " </hideMatch>\n" + " </hideMessage>\n" + "</syslogd-configuration>\n").getBytes());
final SyslogdConfigFactory config = new SyslogdConfigFactory(stream);
final SyslogParser parser = new CustomSyslogParser(config, SyslogdTestUtils.toByteBuffer("<0>Mar 14 17:10:25 petrus sudo: cyrille : user NOT in sudoers ; TTY=pts/2 ; PWD=/home/cyrille ; USER=root ; COMMAND=/usr/bin/vi /etc/aliases"));
assertTrue(parser.find());
final SyslogMessage message = parser.parse();
LOG.debug("message = {}", message);
final Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, ZonedDateTimeBuilder.getBestYearForMonth(Month.MARCH.getValue()));
cal.set(Calendar.MONTH, Calendar.MARCH);
cal.set(Calendar.DAY_OF_MONTH, 14);
cal.set(Calendar.HOUR_OF_DAY, 17);
cal.set(Calendar.MINUTE, 10);
cal.set(Calendar.SECOND, 25);
cal.set(Calendar.MILLISECOND, 0);
assertEquals(SyslogFacility.KERNEL, message.getFacility());
assertEquals(SyslogSeverity.EMERGENCY, message.getSeverity());
assertNull(message.getMessageID());
assertEquals(cal.getTime(), message.getDate());
assertEquals("petrus", message.getHostName());
assertEquals("sudo", message.getProcessName());
assertEquals(null, message.getProcessId());
assertEquals("cyrille : user NOT in sudoers ; TTY=pts/2 ; PWD=/home/cyrille ; USER=root ; COMMAND=/usr/bin/vi /etc/aliases", message.getMessage());
} finally {
Locale.setDefault(startLocale);
}
}
use of org.opennms.netmgt.config.SyslogdConfigFactory in project opennms by OpenNMS.
the class SyslogdIT method setUp.
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging();
MockLogAppender.resetState();
InputStream stream = null;
try {
stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-configuration.xml");
m_config = new SyslogdConfigFactory(stream);
} finally {
if (stream != null) {
IOUtils.closeQuietly(stream);
}
}
// Verify that the test syslogd-configuration.xml file was loaded
boolean foundBeer = false;
boolean foundMalt = false;
assertEquals(10514, m_config.getSyslogPort());
for (final UeiMatch match : m_config.getUeiList()) {
if (match.getProcessMatch().isPresent()) {
final ProcessMatch processMatch = match.getProcessMatch().get();
if (!foundBeer && "beerd".equals(processMatch.getExpression())) {
foundBeer = true;
} else if (!foundMalt && "maltd".equals(processMatch.getExpression())) {
foundMalt = true;
}
}
}
assertTrue(foundBeer);
assertTrue(foundMalt);
m_syslogSinkConsumer = new SyslogSinkConsumer(new MetricRegistry());
m_syslogSinkConsumer.setDistPollerDao(m_distPollerDao);
m_syslogSinkConsumer.setSyslogdConfig(m_config);
m_syslogSinkConsumer.setEventForwarder(m_eventIpcManager);
m_syslogSinkModule = m_syslogSinkConsumer.getModule();
m_messageDispatcherFactory.setConsumer(m_syslogSinkConsumer);
SyslogReceiverJavaNetImpl receiver = new SyslogReceiverJavaNetImpl(m_config);
receiver.setDistPollerDao(m_distPollerDao);
receiver.setMessageDispatcherFactory(m_messageDispatcherFactory);
m_syslogd.setSyslogReceiver(receiver);
m_syslogd.init();
SyslogdTestUtils.startSyslogdGracefully(m_syslogd);
}
Aggregations