use of org.springframework.core.io.Resource in project opennms by OpenNMS.
the class DroolsTicketerServiceLayerTest method setUp.
@Before
public void setUp() throws Exception {
m_eventIpcManager = new MockEventIpcManager();
EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
MockLogAppender.setupLogging();
ResourceLoader loader = new DefaultResourceLoader();
Resource resource = loader.getResource("classpath:/drools-ticketer-rules.drl");
m_easyMockUtils = new EasyMockUtils();
m_configDao = m_easyMockUtils.createMock(DroolsTicketerConfigDao.class);
EasyMock.expect(m_configDao.getRulesFile()).andReturn(resource.getFile()).times(1);
EasyMock.replay(m_configDao);
m_alarmDao = m_easyMockUtils.createMock(AlarmDao.class);
m_ticketerPlugin = m_easyMockUtils.createMock(Plugin.class);
m_droolsTicketerServiceLayer = new DroolsTicketerServiceLayer(m_configDao);
m_droolsTicketerServiceLayer.setAlarmDao(m_alarmDao);
m_droolsTicketerServiceLayer.setTicketerPlugin(m_ticketerPlugin);
EasyMock.reset(m_configDao);
m_alarm = new OnmsAlarm();
m_alarm.setId(1);
m_alarm.setLogMsg("Test Logmsg");
m_alarm.setDescription("Test Description");
m_alarm.setUei("uei.opennms.org/nodes/nodeDown");
m_ticket = new Ticket();
m_ticket.setId("4");
}
use of org.springframework.core.io.Resource in project opennms by OpenNMS.
the class OSReportPlugin method getEntries.
@Override
public Map<String, Resource> getEntries() {
final Map<String, Resource> map = new TreeMap<String, Resource>();
map.put("Name", getResourceFromProperty("os.name"));
map.put("Architecture", getResourceFromProperty("os.arch"));
map.put("Version", getResourceFromProperty("os.version"));
map.put("Distribution", map.get("Name"));
OperatingSystemMXBean osBean = getBean(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
if (osBean == null) {
LOG.info("falling back to local VM OperatingSystemMXBean");
osBean = ManagementFactory.getOperatingSystemMXBean();
}
LOG.trace("bean = {}", osBean);
addGetters(osBean, map);
File lsb = new File("/bin/lsb_release");
File solaris = new File("/var/sadm/softinfo/INST_RELEASE");
if (lsb.exists()) {
final String text = slurpCommand(new String[] { "/bin/lsb_release", "-a" });
final Map<String, String> distMap = splitMultilineString(": +", text);
for (final Map.Entry<String, String> entry : distMap.entrySet()) {
map.put("Distribution " + entry.getKey(), getResource(entry.getValue()));
}
} else if (solaris.exists()) {
map.put("Distribution OS", getResource("Solaris"));
final String solarisText = slurp(solaris);
final Map<String, String> distMap = splitMultilineString("=", solarisText);
for (final Map.Entry<String, String> entry : distMap.entrySet()) {
map.put("Distribution " + entry.getKey().toLowerCase().replaceFirst("^.", entry.getKey().substring(0, 1).toUpperCase()), getResource(entry.getValue()));
}
if (map.containsKey("Distribution OS")) {
map.put("Distribution", map.remove("Distribution OS"));
}
File isainfo = new File("/usr/bin/isainfo");
if (isainfo.exists()) {
final String arch = slurpCommand(new String[] { "/usr/bin/isainfo", "-n" });
if (arch != null) {
map.put("Instruction Set", getResource(arch));
}
}
} else {
for (final Map.Entry<String, String> entry : m_oses.entrySet()) {
final String description = slurp(new File(entry.getKey()));
if (description != null) {
map.put("Distribution", getResource(entry.getValue()));
map.put("Description", getResource(description.trim()));
}
}
}
if (map.containsKey("Distribution Distributor ID")) {
map.put("Distribution", map.remove("Distribution Distributor ID"));
}
if (map.containsKey("Distribution Description")) {
map.put("Description", map.remove("Distribution Description"));
}
return map;
}
use of org.springframework.core.io.Resource in project opennms by OpenNMS.
the class LogReportPlugin method getEntries.
@Override
public Map<String, Resource> getEntries() {
final TreeMap<String, Resource> map = new TreeMap<String, Resource>();
File f = new File(System.getProperty("opennms.home") + File.separator + "logs");
processFile(f, map);
return map;
}
use of org.springframework.core.io.Resource in project opennms by OpenNMS.
the class OpenNMSReportPlugin method getEntries.
@Override
public Map<String, Resource> getEntries() {
final TreeMap<String, Resource> map = new TreeMap<String, Resource>();
final InputStream is = this.getClass().getResourceAsStream("/version.properties");
if (is != null) {
Properties p = new Properties();
try {
p.load(is);
map.put("Version", getResource(p.getProperty("version.display")));
} catch (final IOException e) {
LOG.warn("Unable to load from version.properties", e);
}
}
if (m_nodeDao != null) {
map.put("Number of Nodes", getResource(Integer.toString(m_nodeDao.countAll())));
}
if (m_ipInterfaceDao != null) {
map.put("Number of IP Interfaces", getResource(Integer.toString(m_ipInterfaceDao.countAll())));
}
if (m_snmpInterfaceDao != null) {
map.put("Number of SNMP Interfaces", getResource(Integer.toString(m_snmpInterfaceDao.countAll())));
}
if (m_eventDao != null) {
map.put("Number of Events", getResource(Integer.toString(m_eventDao.countAll())));
}
if (m_alarmDao != null) {
map.put("Number of Alarms", getResource(Integer.toString(m_alarmDao.countAll())));
}
return map;
}
use of org.springframework.core.io.Resource in project opennms by OpenNMS.
the class XmlSystemReportFormatter method write.
@Override
public void write(final SystemReportPlugin plugin) {
if (!hasDisplayable(plugin))
return;
if (m_handler == null) {
try {
StreamResult streamResult = new StreamResult(getOutputStream());
SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
m_handler = tf.newTransformerHandler();
Transformer serializer = m_handler.getTransformer();
serializer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "entry");
m_handler.setResult(streamResult);
} catch (final Exception e) {
LOG.error("Unable to create XML stream writer.", e);
m_handler = null;
}
try {
m_handler.startDocument();
m_handler.startElement("", "", "systemReportPlugins", null);
} catch (final Exception e) {
LOG.warn("Unable to start document.", e);
m_handler = null;
}
}
if (m_handler == null) {
LOG.warn("Unable to write, no handler defined!");
return;
}
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "name", "CDATA", plugin.getName());
atts.addAttribute("", "", "description", "CDATA", plugin.getDescription());
m_handler.startElement("", "", "plugin", atts);
for (final Map.Entry<String, Resource> entry : plugin.getEntries().entrySet()) {
final boolean displayable = isDisplayable(entry.getValue());
atts = new AttributesImpl();
atts.addAttribute("", "", "key", "CDATA", entry.getKey());
if (!displayable) {
atts.addAttribute("", "", "skipped", "CDATA", "true");
}
m_handler.startElement("", "", "entry", atts);
if (displayable) {
final String value = getResourceText(entry.getValue());
if (value != null) {
m_handler.startCDATA();
m_handler.characters(value.toCharArray(), 0, value.length());
m_handler.endCDATA();
}
}
m_handler.endElement("", "", "entry");
}
m_handler.endElement("", "", "plugin");
} catch (final Exception e) {
LOG.warn("An error occurred while attempting to write XML data.", e);
}
}
Aggregations