Forum Discussion

usnishguha's avatar
3 years ago

Linux SSH ID Monitoring

Hi All,

 We have observed in our environment sometimes the ID that we use for monitoring gets locked resulting in "No Data" for that particular datasource. We do have "No Data" alerts on, but as "No Data" situation can occur due to multiple reasons (server down, network disconnection etc. and SSH ID being locked) we wanted a more meaningful alert for the SSH ID being in locked status. 
Can anyone please let me know if there's any datasource available for this purpose?

Thanks,
Usnish

5 Replies

  • Anonymous's avatar
    Anonymous

    You could put the whole thing around a try block and in the exception, you could output a datapoint that indicates failure to login.

  • @Stuart Weenig, thanks. Are you referring to something like below?

    if (user && pass)
    {
        // Both user and pass exist, try to auth and if we get an invalid login error, warn the user
        try
        {
            def jsch = new JSch()
            session = jsch.getSession(user, host, port)
            session.connect()
        }
            catch(Exception e) {
                System.out.println(e);
            } 
    }

  • Anonymous's avatar
    Anonymous

    Something like that. It could be a standalone datasource that returns 0 if the session connects and returns 1 if it doesn't. You should probably add a finally block to make sure the session disconnects.

  • Pardon my ignorance, but I am fairly new to groovy. Can you please tell me if this looks ok?

     

    import com.jcraft.jsch.JSch
    import com.santaba.agent.util.Settings

    host = hostProps.get("system.hostname")
    user = hostProps.get("ssh.user")
    pass = hostProps.get("ssh.pass")
    port = hostProps.get("ssh.port")?.toInteger() ?: 22
    //cert = hostProps.get("ssh.cert") ?: '~/.ssh/id_rsa'
    timeout = 15000 // timeout in milliseconds
    try {
            
            jsch = new JSch()
            session = jsch.getSession(user, host, port)
            session.setConfig("StrictHostKeyChecking", "no");
            String authMethod = Settings.getSetting(Settings.SSH_PREFEREDAUTHENTICATION, Settings.DEFAULT_SSH_PREFEREDAUTHENTICATION);
            session.setConfig("PreferredAuthentications", authMethod);
            if (user && pass)
              { session.connect() }
    }        
        catch(Exception e) {
        System.out.println(e);
        }
        
        finally {
            session.disconnect()
        }
        

  • Anonymous's avatar
    Anonymous

    Yep, something like that. I'd have to run it to make sure it's workable, but that's the general strategy.