Forum Discussion

a_techie's avatar
2 years ago
Solved

Test Groovy script on a device

Hello All,

Newbie here!

Can anyone please tell me how to test a groovy script in a particular device? I have found that there is a debug command  option for the collector. But how I do set the device name in the debugger?

7 Replies

  • You can use the chrome extension here:
    https://chrome.google.com/webstore/detail/logicmonitor-script-debug/ijojgoccfeggejpbhdahmeijjhpdjklf
    It adds additional functionality to the !groovy debug function, one of those being a drop down on the top right side that allows you to specify the host you are running the script against.  As Mike mentioned above, the source will be the collector you have opened the collector debug facility from.

    I actually don’t like this extension as it confuses what is happening and is also no longer maintained by the original author.

    Example script 1. Example script 2.

    When you run `!groovy` in the collector debug window, it will pop up a window that will prompt you for the device name and the script. Just put the device name. It won’t work if your datasource is script and has active discovery because the instance is not selectable. Perhaps that’s where the extension will help, though I’ve never really had an issue just doing it right in the DS editor.

  • Groovy scripts, actually any scripts, DataSources, PropertySources, etc LogicMonitor uses will always run on the collector itself. You need to write the script in such a way to have it connect to the other system and collect the data remotely. That might be using snmp, wmi, rest api, etc. In some cases you can have the script remotely run commands/scripts like PowerShell’s Invoke-Command or PSRemote.

  • By any chance do you have an example script for getting data from a network device by SSH?

  • By any chance do you have an example script for getting data from a network device by SSH?

    You can look at any of the Linux_SSH_* DataSources as an example. It will connect to a server, run some commands, and process the output. I believe there are several LM Config examples also.

    The “Using Groovy in LogicMonitor” academy course has a section called “Groovy, Expect, and LM Config” that seems to cover using SSH in groovy in more detail.

  • When you run `!groovy` in the collector debug window, it will pop up a window that will prompt you for the device name and the script. Just put the device name. It won’t work if your datasource is script and has active discovery because the instance is not selectable.

    I never understood what the Device dropdown does in debug. Does it set an environment var or something? I mostly use Firefox and never used the chrome plugin.