use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class VacuumdIT method setUp.
/**
* Sets up the test.
*
* @throws Exception the exception
*/
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging();
m_ancitipator = ((MockEventIpcManager) m_eventProxy).getEventAnticipator();
m_location = new OnmsMonitoringLocation("Default", "Default");
m_distPoller = new OnmsDistPoller("00000000-0000-0000-0000-000000000000");
m_distPoller.setLabel("localhost");
m_distPoller.setLocation("Default");
m_distPoller.setType(OnmsMonitoringSystem.TYPE_OPENNMS);
OnmsNode node = createNode();
m_down = new NorthboundAlarm(createDownAlarm(node, new Date()));
System.err.println(JaxbUtils.marshal(m_down));
m_up = new NorthboundAlarm(createUpAlarm(node, new Date(m_down.getLastOccurrence().getTime() + DELAY)));
System.err.println(JaxbUtils.marshal(m_up));
// Setup the Drools northbounder configuration DAO
DroolsNorthbounderConfigDao configDao = new DroolsNorthbounderConfigDao();
configDao.setConfigResource(new FileSystemResource(new File("src/test/resources/etc/vacuumd/drools-northbounder-configuration.xml")));
configDao.afterPropertiesSet();
Assert.assertNotNull(configDao.getConfig().getEngine("Vacuumd"));
// Setup the northbounder
nbi = new DroolsNorthbounder(m_appContext, configDao, m_eventProxy, "Vacuumd");
nbi.afterPropertiesSet();
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class SyslogConfigDaoTest method testFiltersAndReload.
/**
* Test filters and reload.
*
* @throws Exception the exception
*/
@Test
public void testFiltersAndReload() throws Exception {
File configFile = new File("target/syslog-northbounder-test.xml");
FileWriter writer = new FileWriter(configFile);
writer.write(xmlWithFilters);
writer.close();
Resource resource = new FileSystemResource(configFile);
SyslogNorthbounderConfigDao dao = new SyslogNorthbounderConfigDao();
dao.setConfigResource(resource);
dao.afterPropertiesSet();
assertNotNull(dao.getConfig());
SyslogDestination dst = dao.getConfig().getSyslogDestination("test-host");
assertNotNull(dst);
assertEquals(2, dst.getFilters().size());
assertEquals(true, dst.getFilters().get(0).isEnabled());
assertEquals(false, dst.getFilters().get(1).isEnabled());
writer = new FileWriter(configFile);
writer.write(xmlNoUeis);
writer.close();
dao.reload();
dst = dao.getConfig().getSyslogDestination("test-host");
assertNotNull(dst);
assertTrue(dst.getFilters().isEmpty());
configFile.delete();
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class SnmpDataCollectionTest method verifySnmpCollectionIncludeOrder.
/**
* Verify that the order of the includes in the default 'datacollection-config.xml'
* file are listed in alphabetical order, with the exception of MIB2 which should
* always come first.
*
* See https://issues.opennms.org/browse/NMS-9643
*/
@Test
public void verifySnmpCollectionIncludeOrder() {
final DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, new FileSystemResource(ConfigurationTestUtils.getFileForConfigFile("datacollection-config.xml")));
final SnmpCollection snmpCollection = config.getSnmpCollection("default");
assertNotNull("'default' snmp-collection should exist.", snmpCollection);
// Current order
final List<String> includesInOrderSpecified = snmpCollection.getIncludeCollections().stream().map(inc -> inc.getDataCollectionGroup().toLowerCase()).collect(Collectors.toList());
// Exepected order
final List<String> includesInNaturalOrder = snmpCollection.getIncludeCollections().stream().map(inc -> inc.getDataCollectionGroup().toLowerCase()).sorted(Comparator.naturalOrder()).collect(Collectors.toList());
// Special handling for the "MIB2" include, if present
if (includesInOrderSpecified.indexOf("mib2") == 0) {
includesInNaturalOrder.remove("mib2");
includesInNaturalOrder.add(0, "mib2");
}
assertEquals("One or more SNMP data collections included in the default configuration are not listed in alphabetical order." + " Please sort and try again.", includesInNaturalOrder, includesInOrderSpecified);
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class PropertiesGraphDaoIT method testPrefabConfigDirectoryMixedSingleAndMultiReports.
/**
* Test that properties files in an included directory with
* multiple graphs defined in some, and single graphs in others, are loaded correctly
*/
@Test
public void testPrefabConfigDirectoryMixedSingleAndMultiReports() throws IOException {
File rootFile = m_fileAnticipator.tempFile("snmp-graph.properties");
File graphDirectory = m_fileAnticipator.tempDir("snmp-graph.properties.d");
File multiFile = m_fileAnticipator.tempFile(graphDirectory, "mib2-1.properties");
File graphBits = m_fileAnticipator.tempFile(graphDirectory, "mib2.bits.properties");
File graphHCbits = m_fileAnticipator.tempFile(graphDirectory, "mib2.HCbits.properties");
m_outputStream = new FileOutputStream(rootFile);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_baseIncludePrefab);
m_writer.close();
m_outputStream.close();
graphDirectory.mkdir();
m_outputStream = new FileOutputStream(graphBits);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_separateBitsGraph);
m_writer.close();
m_outputStream.close();
m_outputStream = new FileOutputStream(graphHCbits);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_separateHCBitsGraph);
m_writer.close();
m_outputStream.close();
graphDirectory.mkdir();
m_outputStream = new FileOutputStream(multiFile);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_includedMultiGraph1);
m_writer.close();
m_outputStream.close();
HashMap<String, Resource> prefabConfigs = new HashMap<String, Resource>();
prefabConfigs.put("performance", new FileSystemResource(rootFile));
PropertiesGraphDao dao = createPropertiesGraphDao(prefabConfigs, s_emptyMap);
// Check the graphs, basically ensuring that a handful of unique but easily checkable
// bits are uniquely what they should be.
// We check all 4 graphs
PrefabGraph mib2Bits = dao.getPrefabGraph("mib2.bits");
assertNotNull(mib2Bits);
assertEquals("mib2.bits", mib2Bits.getName());
assertEquals("Bits In/Out", mib2Bits.getTitle());
String[] columns1 = { "ifInOctets", "ifOutOctets" };
Assert.assertArrayEquals(columns1, mib2Bits.getColumns());
PrefabGraph mib2HCBits = dao.getPrefabGraph("mib2.HCbits");
assertNotNull(mib2HCBits);
assertEquals("mib2.HCbits", mib2HCBits.getName());
assertEquals("Bits In/Out", mib2HCBits.getTitle());
String[] columns2 = { "ifHCInOctets", "ifHCOutOctets" };
Assert.assertArrayEquals(columns2, mib2HCBits.getColumns());
PrefabGraph mib2Discards = dao.getPrefabGraph("mib2.discards");
assertNotNull(mib2Discards);
assertEquals("mib2.discards", mib2Discards.getName());
assertEquals("Discards In/Out", mib2Discards.getTitle());
String[] columns3 = { "ifInDiscards", "ifOutDiscards" };
Assert.assertArrayEquals(columns3, mib2Discards.getColumns());
PrefabGraph mib2Errors = dao.getPrefabGraph("mib2.errors");
assertNotNull(mib2Errors);
assertEquals("mib2.errors", mib2Errors.getName());
assertEquals("Errors In/Out", mib2Errors.getTitle());
String[] columns4 = { "ifInErrors", "ifOutErrors" };
Assert.assertArrayEquals(columns4, mib2Errors.getColumns());
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class PropertiesGraphDaoIT method testIncludeDirectoryIncludeMissingReportId.
@Test
public void testIncludeDirectoryIncludeMissingReportId() throws Exception {
// We're expecting an ERROR log, and will be most disappointed if
// we don't get it. Turn off the default check in runTest
m_testSpecificLoggingTest = true;
File rootFile = m_fileAnticipator.tempFile("snmp-graph.properties");
File graphDirectory = m_fileAnticipator.tempDir("snmp-graph.properties.d");
File graphBits = m_fileAnticipator.tempFile(graphDirectory, "mib2.bits.properties");
m_outputStream = new FileOutputStream(rootFile);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_baseIncludePrefab);
m_writer.close();
m_outputStream.close();
graphDirectory.mkdir();
m_outputStream = new FileOutputStream(graphBits);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_separateBitsGraph.replace("report.id", "report.noid"));
m_writer.close();
m_outputStream.close();
HashMap<String, Resource> perfConfig = new HashMap<String, Resource>();
perfConfig.put("performance", new FileSystemResource(rootFile));
PropertiesGraphDao dao = createPropertiesGraphDao(perfConfig, s_emptyMap);
try {
PrefabGraph graph = dao.getPrefabGraph("mib2.bits");
fail("Shouldn't have gotten here; expecting an exception fetching " + graph);
} catch (ObjectRetrievalFailureException e) {
// Expected; no such graph
}
}
Aggregations