Skip to content

Commit

Permalink
NMS-16986 : Updated changes and tests as per requirement provided in …
Browse files Browse the repository at this point in the history
…the ticket(NMS-16986).
  • Loading branch information
mwajahatabbasi committed Jan 14, 2025
1 parent 35ce305 commit 63c0d13
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public boolean getOutputsFiles() {
return false;
}

@Override
public boolean isVisible() { return false; }

protected ResourceLocator getResourceLocator() {
return m_resourceLocator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -230,14 +231,14 @@ public List<SystemReportPlugin> getPlugins() {
initializeSpring();
final List<SystemReportPlugin> plugins = new ArrayList<SystemReportPlugin>(m_serviceRegistry.findProviders(SystemReportPlugin.class));
Collections.sort(plugins);
return plugins;
return plugins.stream().filter(SystemReportPlugin::isVisible).collect(Collectors.toList());
}

public List<SystemReportFormatter> getFormatters() {
initializeSpring();
final List<SystemReportFormatter> formatters = new ArrayList<SystemReportFormatter>(m_serviceRegistry.findProviders(SystemReportFormatter.class));
Collections.sort(formatters);
return formatters;
return formatters.stream().filter(SystemReportFormatter::isVisible).collect(Collectors.toList());
}

private void initializeSpring() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@ public interface SystemReportFormatter extends Comparable<SystemReportFormatter>
*/
public boolean canStdout();


public boolean isVisible();

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ public interface SystemReportPlugin extends Comparable<SystemReportPlugin> {
public boolean getFullOutputOnly();

public boolean getOutputsFiles();

public boolean isVisible();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public boolean canStdout() {
return false;
}

@Override
public boolean isVisible() { return true; }

@Override
public void begin() {
super.begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public int getPriority() {
return 20;
}

@Override
public boolean isVisible() { return true; }

@Override
public boolean getFullOutputOnly() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public boolean getFullOutputOnly() {
return true;
}

@Override
public boolean isVisible() { return true; }

@Override
public boolean getOutputsFiles() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public int getPriority() {
return 4;
}

@Override
public boolean isVisible() { return true; }

@Override
public Map<String, Resource> getEntries() {
final TreeMap<String,Resource> map = new TreeMap<String,Resource>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public int getPriority() {
return 1;
}

@Override
public boolean isVisible() { return true; }

@Override
public Map<String, Resource> getEntries() {
final TreeMap<String,Resource> map = new TreeMap<String,Resource>();
Expand Down Expand Up @@ -88,28 +91,6 @@ public Map<String, Resource> getEntries() {

addGetters(classBean, map);

/* this stuff is really not giving us anything useful
List<GarbageCollectorMXBean> 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<String,Resource> temp = new TreeMap<String,Resource>();
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,6 +83,9 @@ public String getDescription() {
return "Kernel, OS, and Distribution";
}

@Override
public boolean isVisible() { return true; }

@Override
public int getPriority() {
return 2;
Expand Down Expand Up @@ -176,8 +178,6 @@ public Map<String, Resource> 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;
}
Expand All @@ -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(", "));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<bean name="osReportPlugin" class="org.opennms.systemreport.system.OSReportPlugin" />
<onmsgi:service id="osReportPluginService" ref="osReportPlugin" interface="org.opennms.systemreport.SystemReportPlugin" />

<!-- Hard Drive Capacity and Performance Details -->
<bean name="hardDriveReportPlugin" class="org.opennms.systemreport.system.HardDriveReportPlugin" />
<onmsgi:service id="hardDriveReportPluginService" ref="hardDriveReportPlugin" interface="org.opennms.systemreport.SystemReportPlugin" />


<!-- OpenNMS information -->
<bean name="opennmsReportPlugin" class="org.opennms.systemreport.opennms.OpenNMSReportPlugin" />
<onmsgi:service id="opennmsReportPluginService" ref="opennmsReportPlugin" interface="org.opennms.systemreport.SystemReportPlugin" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -62,6 +62,14 @@ public void testJavaReportPlugin() {

}

@Test
public void testHardDriveReportPlugin() {
final Map<String, org.springframework.core.io.Resource> 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());
Expand Down

0 comments on commit 63c0d13

Please sign in to comment.