Come join our live training webinar every other Wednesday at 11am PST and hear LogicMonitor experts explain best practices and answer common questions. We understand these are uncertain times, and we are here to help!
LogicMonitor supports embedded scripting throughout our product using the Groovy programming language. Groovy can be used in DataSources for Scripted Active Discovery, Scripted Data Collection, and Complex Datapoint Post-Processing; in Scripted EventSources; ConfigSources; and Netscan Policies.
We favor Groovy primarily because—as an extension of Java—it is run entirely within the LogicMonitor Collector, so we can guarantee that it will run the same way across all collectors regardless of underlying OS platform and version. Also, we’ve bundled into our Collector a wide variety of helper classes specifically selected to help get instrumentation data out of systems and devices.
Another advantage of Groovy is that we support the use of any device or instance property within your script. In other languages we can pass in device properties but not instance properties.
The following methods support ingest of properties.
name = hostProps.get("system.hostname")
instance = instanceProps.get("wildvalue")
speed=taskProps.get("speed")
Note: The taskProps.get() and instanceProps.get() methods should not be used when BatchScript data collection method is specified (as opposed to the Script data collection method) because BatchScript context spans multiple instances and there is no way to indicate which instance for which you want to set the instance level property.
taskProps.get()
instanceProps.get()
The following is sample Groovy code used to perform scripted Active Discovery. In scripted Active Discovery, the goal is to return instance data of the form:
instance_id##instance_name
This particular script is used to discover power source instances on a Palo Alto firewall:
import com.santaba.agent.groovyapi.http.*; apikey = hostProps.get("paloalto.apikey.pass") host = hostProps.get("system.hostname") command = java.net.URLEncoder.encode("") url = "https://${host}/api/?type=op&key=${apikey}&cmd=${command}" def response = new XmlSlurper().parseText(HTTP.body(url)) // loop through slots response.result.power.children().each { slot -> slot_name = slot.name() // loop through each slot's components slot.entry.each { entry -> entry_desc = entry.description.text() instance_name = slot_name + '/' + entry_desc println "${instance_name}##${instance_name}" } } return(0)
See Groovy Tips & Tricks and Groovy/Expect Text-Based Interaction for more examples and sample code.
In This Article