Forum Discussion

Roland_Banks's avatar
6 years ago

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?

Thanks,

Roland.

1 Reply

Replies have been turned off for this discussion
  • 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