• 0
Roland Banks

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

Question

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?

Thanks,

Roland.

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
    client.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
client.logout()
client.disconnect()

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

return 0;

Hope that helps!

Cheers,

Kerry

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.