Groovy Tips and Tricks
Last updated - 23 July, 2025
LogicMonitor’s Embedded Groovy Scripting engine provides a number of helper classes specifically selected to help get instrumentation data out of systems and devices. See the following tips & tricks:
Calling a Simple HTTP API
Many devices have their own HTTP APIs that you might need to access to get device performance data. For a simple example, see the following example, where we query a NetApp E-Series REST API for details about it’s flash cache:
In this case you’ll want to create a datapoint for each of the key-value pairs you care about, using the key-value post-processor to separate the values as necessary.
Running an External Process
Some devices require that you run a CLI tool or some compiled binary to extract data. To do this in Groovy we do something like this:
Interacting with DNS
The Collector includes the ability to allow scripting of DNS objects. This can be handy when you need to verify the operation of your local DNS resolvers.
Here’s a simple example that would allow you to verify the resolution of a specific DNS record:
You might use this in conjunction with a datapoint post-processor to look for the presence of a certain address and trigger an alert if it’s not found.
Support for Groovy Lib v2 and v4
In addition to Groovy lib v2, collector also supports Groovy lib v4. Starting with EA Collector 34.500, you can use both Groovy lib v2 and v4. The first line is added as a comment (//) to define the groovy version to run the script.
Groovy lib v2
//!/lib-groovy/v2
println "version=" + GroovySystem.versionGroovy lib v4
//!/lib-groovy/v4
println "version=" + GroovySystem.versionNote: If you do not define the version comment, by default the script uses Groovy lib v2.