diff --git a/features/system-report/src/main/java/org/opennms/systemreport/AbstractSystemReportPlugin.java b/features/system-report/src/main/java/org/opennms/systemreport/AbstractSystemReportPlugin.java index 4c7f3cc9028d..e534f5131834 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/AbstractSystemReportPlugin.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/AbstractSystemReportPlugin.java @@ -88,6 +88,9 @@ public boolean getOutputsFiles() { return false; } + @Override + public boolean isVisible() { return false; } + protected ResourceLocator getResourceLocator() { return m_resourceLocator; } diff --git a/features/system-report/src/main/java/org/opennms/systemreport/SystemReport.java b/features/system-report/src/main/java/org/opennms/systemreport/SystemReport.java index 15d1f077c121..a54aba849f65 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/SystemReport.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/SystemReport.java @@ -35,6 +35,7 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; @@ -230,14 +231,14 @@ public List getPlugins() { initializeSpring(); final List plugins = new ArrayList(m_serviceRegistry.findProviders(SystemReportPlugin.class)); Collections.sort(plugins); - return plugins; + return plugins.stream().filter(SystemReportPlugin::isVisible).collect(Collectors.toList()); } public List getFormatters() { initializeSpring(); final List formatters = new ArrayList(m_serviceRegistry.findProviders(SystemReportFormatter.class)); Collections.sort(formatters); - return formatters; + return formatters.stream().filter(SystemReportFormatter::isVisible).collect(Collectors.toList()); } private void initializeSpring() { diff --git a/features/system-report/src/main/java/org/opennms/systemreport/SystemReportFormatter.java b/features/system-report/src/main/java/org/opennms/systemreport/SystemReportFormatter.java index 915e53b5fc21..0b751b529df4 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/SystemReportFormatter.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/SystemReportFormatter.java @@ -89,4 +89,7 @@ public interface SystemReportFormatter extends Comparable */ public boolean canStdout(); + + public boolean isVisible(); + } diff --git a/features/system-report/src/main/java/org/opennms/systemreport/SystemReportPlugin.java b/features/system-report/src/main/java/org/opennms/systemreport/SystemReportPlugin.java index 365891d47a37..9e68851923bf 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/SystemReportPlugin.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/SystemReportPlugin.java @@ -57,4 +57,6 @@ public interface SystemReportPlugin extends Comparable { public boolean getFullOutputOnly(); public boolean getOutputsFiles(); + + public boolean isVisible(); } diff --git a/features/system-report/src/main/java/org/opennms/systemreport/formatters/AbstractSystemReportFormatter.java b/features/system-report/src/main/java/org/opennms/systemreport/formatters/AbstractSystemReportFormatter.java index 49aa54332e5c..691553db9d48 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/formatters/AbstractSystemReportFormatter.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/formatters/AbstractSystemReportFormatter.java @@ -95,6 +95,9 @@ public void begin() { @Override public void end() { } + + @Override + public boolean isVisible() { return false; } @Override public final int compareTo(final SystemReportFormatter o) { diff --git a/features/system-report/src/main/java/org/opennms/systemreport/formatters/ZipSystemReportFormatter.java b/features/system-report/src/main/java/org/opennms/systemreport/formatters/ZipSystemReportFormatter.java index 9e828b5ad2e0..0abfb1ee36a3 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/formatters/ZipSystemReportFormatter.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/formatters/ZipSystemReportFormatter.java @@ -81,6 +81,9 @@ public boolean canStdout() { return false; } + @Override + public boolean isVisible() { return true; } + @Override public void begin() { super.begin(); diff --git a/features/system-report/src/main/java/org/opennms/systemreport/opennms/ConfigurationReportPlugin.java b/features/system-report/src/main/java/org/opennms/systemreport/opennms/ConfigurationReportPlugin.java index d8fab4f4d3b6..533505265b43 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/opennms/ConfigurationReportPlugin.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/opennms/ConfigurationReportPlugin.java @@ -50,6 +50,9 @@ public int getPriority() { return 20; } + @Override + public boolean isVisible() { return true; } + @Override public boolean getFullOutputOnly() { return true; diff --git a/features/system-report/src/main/java/org/opennms/systemreport/opennms/LogReportPlugin.java b/features/system-report/src/main/java/org/opennms/systemreport/opennms/LogReportPlugin.java index aa876ef78259..3410efd08e98 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/opennms/LogReportPlugin.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/opennms/LogReportPlugin.java @@ -51,6 +51,9 @@ public boolean getFullOutputOnly() { return true; } + @Override + public boolean isVisible() { return true; } + @Override public boolean getOutputsFiles() { return true; diff --git a/features/system-report/src/main/java/org/opennms/systemreport/opennms/OpenNMSReportPlugin.java b/features/system-report/src/main/java/org/opennms/systemreport/opennms/OpenNMSReportPlugin.java index a5011d481d86..2dd3156c3f25 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/opennms/OpenNMSReportPlugin.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/opennms/OpenNMSReportPlugin.java @@ -76,6 +76,10 @@ public String getDescription() { return "OpenNMS core information, version, and basic configuration"; } + + @Override + public boolean isVisible() { return true; } + @Override public int getPriority() { return 3; diff --git a/features/system-report/src/main/java/org/opennms/systemreport/opennms/TopEventReportPlugin.java b/features/system-report/src/main/java/org/opennms/systemreport/opennms/TopEventReportPlugin.java index c06caae07b25..67f1466f951a 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/opennms/TopEventReportPlugin.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/opennms/TopEventReportPlugin.java @@ -58,6 +58,9 @@ public int getPriority() { return 4; } + @Override + public boolean isVisible() { return true; } + @Override public Map getEntries() { final TreeMap map = new TreeMap(); diff --git a/features/system-report/src/main/java/org/opennms/systemreport/system/JavaReportPlugin.java b/features/system-report/src/main/java/org/opennms/systemreport/system/JavaReportPlugin.java index f7332da2b2e2..bac39d42c395 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/system/JavaReportPlugin.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/system/JavaReportPlugin.java @@ -51,6 +51,9 @@ public int getPriority() { return 1; } + @Override + public boolean isVisible() { return true; } + @Override public Map getEntries() { final TreeMap map = new TreeMap(); @@ -88,28 +91,6 @@ public Map getEntries() { addGetters(classBean, map); - /* this stuff is really not giving us anything useful - List beans = getBeans(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, GarbageCollectorMXBean.class); - if (beans == null || beans.size() == 0) { - LOG.info("falling back to local VM MemoryMXBean"); - beans = ManagementFactory.getGarbageCollectorMXBeans(); - } - - LOG.trace("beans = {}", beans); - int collectorNum = 1; - for (final GarbageCollectorMXBean bean : beans) { - final Map temp = new TreeMap(); - addGetters(bean, map); - - final StringBuilder sb = new StringBuilder(); - for (final String s : temp.keySet()) { - sb.append(s).append(": ").append(temp.get(s)).append("\n"); - } - if (sb.length() > 0) sb.deleteCharAt(sb.length()); - map.put("Garbage Collector " + collectorNum, getResource(sb.toString())); - } - */ - return map; } } diff --git a/features/system-report/src/main/java/org/opennms/systemreport/system/OSReportPlugin.java b/features/system-report/src/main/java/org/opennms/systemreport/system/OSReportPlugin.java index a1ca3f3ff69e..e867877204cf 100644 --- a/features/system-report/src/main/java/org/opennms/systemreport/system/OSReportPlugin.java +++ b/features/system-report/src/main/java/org/opennms/systemreport/system/OSReportPlugin.java @@ -28,7 +28,6 @@ import java.util.Map; import java.util.TreeMap; import java.util.stream.Collectors; -import java.util.stream.IntStream; import org.opennms.core.resource.Vault; import org.opennms.netmgt.dao.api.IpInterfaceDao; import org.opennms.netmgt.model.OnmsIpInterface; @@ -84,6 +83,9 @@ public String getDescription() { return "Kernel, OS, and Distribution"; } + @Override + public boolean isVisible() { return true; } + @Override public int getPriority() { return 2; @@ -176,8 +178,6 @@ public Map getEntries() { map.put("Total System RAM",getResource(String.valueOf(totalPhysicalMemSize))); map.put("Used System RAM",getResource(String.valueOf((totalPhysicalMemSize-freePhysicalMemSize)))); - map.put("Hard Drive Capacity",getResource(getHardDriveCapacity())); - return map; } @@ -200,19 +200,5 @@ private Object getJmxAttribute(String objectName, String attributeName) { } - private String getHardDriveCapacity(){ - /*Unix command for retrieving the hard disk capacity here command will only return headers and total of hard disk capacity values*/ - String[] command = {"bash", "-c", "df -h --total | grep -E 'Filesystem|total'"}; - /* disCapComdOutput is Output of Disk Capcity Comand */ - String disCapComdOutput = slurpCommand(command); - - String[] hdStats = disCapComdOutput.trim().split("\n"); // Splitting the lines in hdStats Array of Strings - String [] headers = hdStats[0].split("\\s+"); // at zero index there are headers - String [] values = hdStats[1].split("\\s+"); // at 1 index there are values for disk capacity - - return IntStream.range(1, headers.length-1) // Stream over the indices of headers array and skipping the ist and last header as well as values. - .mapToObj(i -> headers[i] + ": " + values[i]) // Format each header-value pair - .collect(Collectors.joining(", ")); - } } diff --git a/features/system-report/src/main/resources/META-INF/opennms/applicationContext-systemReport.xml b/features/system-report/src/main/resources/META-INF/opennms/applicationContext-systemReport.xml index b560d3a4813f..8561abe4278f 100644 --- a/features/system-report/src/main/resources/META-INF/opennms/applicationContext-systemReport.xml +++ b/features/system-report/src/main/resources/META-INF/opennms/applicationContext-systemReport.xml @@ -22,6 +22,11 @@ + + + + + diff --git a/features/system-report/src/test/java/org/opennms/systemreport/system/SystemReportPluginIT.java b/features/system-report/src/test/java/org/opennms/systemreport/system/SystemReportPluginIT.java index ef94fb1cae98..3ddf5def8f7d 100644 --- a/features/system-report/src/test/java/org/opennms/systemreport/system/SystemReportPluginIT.java +++ b/features/system-report/src/test/java/org/opennms/systemreport/system/SystemReportPluginIT.java @@ -41,7 +41,7 @@ public class SystemReportPluginIT { private SystemReportPlugin m_javaReportPlugin = new JavaReportPlugin(); private SystemReportPlugin m_osReportPlugin = new OSReportPlugin(); private SystemReportPlugin m_onmsReportPlugin = new OpenNMSReportPlugin(); - + private SystemReportPlugin m_hardDriveReportPlugin=new HardDriveReportPlugin(); public SystemReportPluginIT() { MockLogAppender.setupLogging(false, "ERROR"); @@ -62,6 +62,14 @@ public void testJavaReportPlugin() { } + @Test + public void testHardDriveReportPlugin() { + final Map entries = m_hardDriveReportPlugin.getEntries(); + assertTrue(entries.containsKey("Hard Drive Capacity")); + assertTrue(entries.containsKey("Hard Drive Performance")); + } + + @Test public void testOpenNMSReportPlugin() { ReflectionTestUtils.setField(m_onmsReportPlugin,"m_nodeDao",new MockNodeDao());