Groovy Tips & Tricks
Last updated on 20 March, 2023LogicMonitor’s Embedded Groovy Scripting engine provides a number of helper classes specifically selected to help get instrumentation data out of systems & 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.
See http://dnsjava.org/dnsjava-current/doc/ for complete documentation of this class.