• 0
Roland Banks

Internal web check with request/response Groovy script to check external FTP site


Is it possible to check an FTP site using an internal web check, and using Groovy script in the request / response?

This URL (https://www.logicmonitor.com/support/services/adding-managing-services/executing-internal-web-checks-via-groovy-scripts/) seems to indicate the commands that can be used, as if it's limited in some way.

I can't think of another way to check the alive-ness of an FTP site somewhere on the web via LogicMonitor, if the device isn't in LogicMonitor itself.

Any ideas?



Share this post

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hey @Roland Banks,

That should be possible - the commands listed there are mostly Groovy methods that have been added on by LogicMonitor, which doesn't necessarily mean we're locking down Groovy capabilities in other ways. If you happen to own the LM Config add-on, there's an example of a Groovy script logging in via FTP and pulling the contents of a file:

import org.apache.commons.net.ftp.FTPClient
import org.apache.commons.net.ftp.FTPReply

def host = hostProps.get("system.hostname");
def port = hostProps.get("ftp.port") ?: '21';

def user = hostProps.get("ftp.user");
def pass = hostProps.get("ftp.pass");

def client = new FTPClient()
client.connect(host, port.toInteger())

// After connection attempt, you should check the reply code to verify
// success.
def reply = client.getReplyCode();

// Did we get a positive completion reply?
if (!FTPReply.isPositiveCompletion(reply))
    // no, disconnect
    println "FTP server refused connection.";
    return 1;

// Connection looks good, login
client.login(user, pass)

// Create a BAOS to store the file contents
ByteArrayOutputStream baos = new ByteArrayOutputStream()

// Retreive the file
client.retrieveFile("##WILDVALUE##", baos)

// Log out and disconnection from the server

// Print the contents of the file from the BAOS.
println baos

return 0;

Hope that helps!



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now