Forum Discussion

Billy_Yuliadi's avatar
8 years ago

Using PropertySources for Reporting

PropertySources are one of the recent additions to LogicModules, they were introduced in v.83 (https://www.logicmonitor.com/release-notes/v-83-scriptable-properties-dashboards-report-two-factor-authentication/). They are a very powerful feature and you can use them for many other purposes other than just showing a Cisco Serial Number which is a common use case for this feature.

I am going to focus this post on using PropertySources to improve a Device Inventory Report. For example, you have hundreds or thousands of SNMP devices being monitored and you want to know if any of the devices are having an issue collecting data through SNMP. It is not a viable solution to go through the device one by one and check if LogicMonitor collects data from them. 

Fortunately, there is an easy way on how to get this information using Device Inventory Report and PropertySources. The idea is to create a property source that can add a host property to a device if SNMP is not working, then we can create a device inventory report to show this property. 

Here is a sample of PropertySource that go through all SNMP devices and adds a host property called auto.snmp.working=no if SNMP is not working on a device. 

// import the logicmonitor snmp helper class
import com.santaba.agent.groovyapi.snmp.Snmp;
// getthesnmp host from the device properties
def host = hostProps.get('system.hostname');
// retrieve the value for the specified OID
try 
{
    oid_value = Snmp.get(host, ".1.3.6.1.2.1.1.1.0");
    println "snmp.working=yes"
}
catch (Exception ex)
{
    println "snmp.working=no";
}
return (0);

Then we can easily create a Device Inventory Reports and add this specific host property. Here is how the report looks like

Another use case would be to build a device inventory report that shows a piece of basic information, such as the number of CPU cores or system memory of a Windows server. Some information such as system.totalmemory is available by default, so we should be able to pull this information directly from the devices. To get a number of CPU cores on a Windows server, here is a sample property source that pulls that information. You can easily add other information such as total memory or even processor type and so on.

// This script counts the total number of processor cores across all processors on a device
import com.santaba.agent.groovyapi.win32.WMI;
def hostname = hostProps.get("system.hostname");
try {
    def wmiResponse = WMI.queryAll(hostname, "select NUMBEROFCORES from Win32_Processor");
    def totalcores = 0;
    wmiResponse.each
    { corecount ->
        totalcores += (corecount.get('NUMBEROFCORES')).toInteger();
    }
    println "Windows_CPUcorecount=" + totalcores;
} 
// Catch any exceptions that may have occurred
catch (Exception e)
{
        //print exception out and return non- zero
        println e;
        return 1;
}
//Exit by returning zero
return 0;

Here is a sample of Device Inventory report with the PropertySources added.

This is just of one of the things that you can do using PropertySources. You can also use PropertySources as applies to field in Datasources or even Alert Rules.