I think you need a step back a bit a get a better understanding of how Script and BatchScript DataSources works. I suggest watching some of the videos in LM Academy like https://academy.logicmonitor.com/introduction-to-datasources and reading over the docs like https://www.logicmonitor.com/support/logicmodules/datasources/data-collection-methods/scripted-data-collection-overview and https://www.logicmonitor.com/support/logicmodules/datasources/data-collection-methods/batchscript-data-collection and https://www.logicmonitor.com/support/logicmodules/datasources/data-collection-methods/scripted-data-collection-overview. Also highly suggest you look at existing DataSources to understand how it works like Microsoft_DHCP_IPv4Scopes. Look at the examples at https://www.logicmonitor.com/support/terminology-syntax/scripting-support/embedded-powershell-scripting
Suggest working out answers to questions like:
- What is the difference between a Script and BatchScript DataSource?
- How do I know what device/resource LogicMonitor wants data on?
For example LogicMonitor will tell you what device it wants information on, you don't tell it.
Here is an example of a BatchScript DataSource, if you wanted to implement getting disk usage of all the drives on a device.
ActiveDiscovery: Get the name of the device from LM by looking at ##SYSTEM.HOSTNAME## and sent a query to that device asking for the list of all drives. Output something like this:
C##C Drive
D##D Drive
Collection: Get the name of the device from LM by looking at ##SYSTEM.HOSTNAME## and send a query to that device asking for the list of all drives along with the usage information. Output something like this:
C.totalspace=1000
C.freespace=10
C.usedspace=900
D.totalspace=2000
D.freespace=50
D.usedspace=1950
When LM later on wants to get the information for the free space of the D: drive, it will set the ##WILDVALUE## to "D" and extract all the lines that start with "D." then pull the totalspace, freespace, and usedspace.
Your script should only provide output for the device that LM is requesting data on. You would get that information from a line like this:
#Get the hostname the LM wants data on
$Hostname = '##SYSTEM.HOSTNAME##';