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...
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()
}