Forum Discussion
Anonymous
3 years agoShould be a pretty easy one to do with SSH. https://megamorf.gitlab.io/2019/06/10/check-if-reboot-is-required-after-installing-linux-updates/ I'd suggest doing it as a property source so you can just put them into a group based on the property. Something like this (not extensively tested).
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 { def command = 'test -f /var/run/reboot-required && echo needed' def command_output = getCommandOutput(command) println("pending.reboot=" + command_output) return 0 } catch (Exception e) {println "Unexpected Exception : " + e;return 1;} /** * Helper method which handles creating JSCH session and executing commands * @return */ def getCommandOutput(String input_command) { try { // instantiate JSCH object. jsch = new JSch() // do we have an user and no pass ? if (user && !pass) { // Yes, so lets try connecting via cert. jsch.addIdentity(cert) } // create session. session = jsch.getSession(user, host, port) // given we are running non-interactively, we will automatically accept new host keys. session.setConfig("StrictHostKeyChecking", "no"); String authMethod = Settings.getSetting(Settings.SSH_PREFEREDAUTHENTICATION, Settings.DEFAULT_SSH_PREFEREDAUTHENTICATION); session.setConfig("PreferredAuthentications", authMethod); // set session timeout, in milliseconds. session.setTimeout(timeout) // is host configured with a user & password? if (pass) { // set password. session.setPassword(pass); } // connect session.connect() // execute command. channel = session.openChannel("exec") channel.setCommand(input_command) // collect command output. def commandOutput = channel.getInputStream() channel.connect() def output = commandOutput.text; // disconnect channel.disconnect() return output } catch (Exception e) {e.printStackTrace()} // ensure we disconnect the session. finally {session.disconnect()} }
If you want alerts, you could alert off this property pretty easily with a companion datasource that looks like this:
return 0
With an appliesto like this:
auto.pending.reboot == "needed"
Related Content
- 2 years agoAnonymous