Forum Discussion

SmokinIndo's avatar
4 years ago

Need help trying to figure out this DataSource I found online.

Hey everyone. I found this DataSource online that monitors if an SFTP connection is working. The source is here: blog.mikesuding.com/2017/04/08/monitor-sftp-site-connection-and-login/

Unfortunately, I haven't been able to get the groovy script working. There's not much documentation that comes with the script. The only info it provides says to set the sftp.site = wowie.us, sftp-user = mike, sftp-pass = ***.  Now, I'm sure that I'm supposed to using my OWN sftp site, my OWN sftp user, and my OWN sftp pass, but I could be wrong. The other thing I'm confused about is where In the groovy script I'm supposed to change these properties. Inside the "Applies To" textfield, it's automatically populated with sftp.site && sftp.user && sftp.pass, but isn't this field supposed to be for the device that you want the datasource attached to? If it's asking me to substitute the variables here, then how do I do that? I'm unsure of the syntax.

There's also a few function calls in the groovy script.

def host = hostProps.get("sftp.site")
def user = hostProps.get("sftp.user")
def pass = hostProps.get("sftp.pass")
def port = hostProps.get("port") ?: '22'; 

It seems reasonable that this is where I want substitute my own sftp credentials. Of course, when I do this and run it, I return a error that says "Host cannot be NULL". Something is breaking, and I don't know what it is.

 

7 Replies

  • The strings are host properties, so set them on the collector you want to run this from.  Those would have to be bound to a collector host.  As written, that supports only a single remote SFTP test.  If you wanted to do more, you would need to rewrite that to handle instances either manual or active discovery.  I do the latter often even with a manual property list as it is the only way to define automatic instance properties.

    It may be possible to do this via an internal "website" check, but I have not tried going full groovy on those yet :).  Even then, each would be a separate copy of code, so better to use this and perhaps extend to support multiple checks.

  • Hi mnagel. I set the host properties on the collector, and when I test the script, I return the following: com.jcraft.jsch.JSchException: java.net.UnknownHostException: sftp://********  

    That sftp site is what I'm using for the sftp.site host property. That's the host I always use to connect to my sftp site, but it looks like it's not working. For science, I checked to make sure that I could connect to the sftp site directly from my collector host, and I successfully able to.

  • On 7/31/2020 at 3:12 PM, mnagel said:

    The strings are host properties, so set them on the collector you want to run this from.  Those would have to be bound to a collector host.  As written, that supports only a single remote SFTP test.  If you wanted to do more, you would need to rewrite that to handle instances either manual or active discovery.  I do the latter often even with a manual property list as it is the only way to define automatic instance properties.

    It may be possible to do this via an internal "website" check, but I have not tried going full groovy on those yet :).  Even then, each would be a separate copy of code, so better to use this and perhaps extend to support multiple checks.

    Hi mnagel. I set the host properties on the collector, and when I test the script, I return the following: com.jcraft.jsch.JSchException: java.net.UnknownHostException: sftp://********  

    That sftp site is what I'm using for the sftp.site host property. That's the host I always use to connect to my sftp site, but it looks like it's not working. For science, I checked to make sure that I could connect to the sftp site directly from my collector host, and I successfully able to.

  • 32 minutes ago, SmokinIndo said:

    Hi mnagel. I set the host properties on the collector, and when I test the script, I return the following: com.jcraft.jsch.JSchException: java.net.UnknownHostException: sftp://********  

    That sftp site is what I'm using for the sftp.site host property. That's the host I always use to connect to my sftp site, but it looks like it's not working. For science, I checked to make sure that I could connect to the sftp site directly from my collector host, and I successfully able to.

    If that is literally what came out of the script, it sounds like the hostname is being confused with the password.  If that is not the issue, I would add debugging statements to the code and exit 1 to ensure they are printed when you run Poll Now.

  • 2 hours ago, mnagel said:

    If that is literally what came out of the script, it sounds like the hostname is being confused with the password.  If that is not the issue, I would add debugging statements to the code and exit 1 to ensure they are printed when you run Poll Now.

    I just used the asterisks to hide the name of my sftp site. What it actually printed out was the name of the sftp site that I used for the host property. I tried debugging with print statements, and it looks like the code fails at session.connect(). Am I supposed to be using an IP address for the host? Or the actual name? Do I need to make sure something is installed on my collector for the script to make the sftp connection? THanks for your help. 

  • 9 minutes ago, SmokinIndo said:

    I just used the asterisks to hide the name of my sftp site. What it actually printed out was the name of the sftp site that I used for the host property. I tried debugging with print statements, and it looks like the code fails at session.connect(). Am I supposed to be using an IP address for the host? Or the actual name? Do I need to make sure something is installed on my collector for the script to make the sftp connection? THanks for your help. 

    It will use whatever you provide.  If it is a name and the collector can resolve the name, then it should work.  I just looked at the code and I don't see where it would have emitted sftp:// at all -- that is a URL format and it wants just the hostname (or IP).  If you included sftp:// in the hostname, please remove it :).

        def session = jsch.getSession(user, host, port.toInteger()); // Get a session
        session.setPassword(pass) // Set the password to use for the session
  • 2 hours ago, mnagel said:

    It will use whatever you provide.  If it is a name and the collector can resolve the name, then it should work.  I just looked at the code and I don't see where it would have emitted sftp:// at all -- that is a URL format and it wants just the hostname (or IP).  If you included sftp:// in the hostname, please remove it :).

    
        def session = jsch.getSession(user, host, port.toInteger()); // Get a session
        session.setPassword(pass) // Set the password to use for the session

    Thank you so much. I was able to script to connect to the sftp site.