Forum Discussion
- Anonymous
Should 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"
Yeah, it's easy with SSH, we already have a bash script that can check reboot status of a Linux machine, but we'd like to avoid using SSH as we only use SNMP right now.
Quite a lot of work to set up SSH on all devices just to have this ekstra reboot pending check- Mike_MonizProfessor
You can extend snmpd to run custom script but that would still require modifying each server's snmpd config.
https://net-snmp.sourceforge.io/wiki/index.php/Tut:Extending_snmpd_using_shell_scripts
- Anonymous
Enabling ssh would get you much more than just this one custom datasource. Worth looking into IMO.
- 2 minutes ago, Stuart Weenig said:
Enabling ssh would get you much more than just this one custom datasource. Worth looking into IMO.
From what I've understood there is more broad monitoring with SNMP on Linux machines with LogicMonitor?
Is there something particular with the SSH monitoring that is superior than the SNMP monitoring (talking out of the box in LogicMonitor)
- Anonymous
Yes, many of the SSH datasources available out of the box provide superior monitoring and detail vs. the SNMP data that is pollable.
25 minutes ago, spiritie said:From what I've understood there is more broad monitoring with SNMP on Linux machines with LogicMonitor?
Almost. There's more SNMP monitoring that happens on Linux than Windows, because Windows has WMI that, like SSH, provides richer monitoring data.
Also, just because you enable SSH monitoring, doesn't mean you're necessarily disabling SNMP monitoring. Do both.
- On 2/1/2022 at 5:13 PM, Stuart Weenig said:
Yes, many of the SSH datasources available out of the box provide superior monitoring and detail vs. the SNMP data that is pollable.
Almost. There's more SNMP monitoring that happens on Linux than Windows, because Windows has WMI that, like SSH, provides richer monitoring data.
Also, just because you enable SSH monitoring, doesn't mean you're necessarily disabling SNMP monitoring. Do both.
Hi Stuart
Thanks for your insight :)/emoticons/smile@2x.png 2x" title=":)" width="20" />
I think we will wait with the SSH monitoring, we have a lot of machines where we disable SSH as a security measure and only enabled it during maintenance.
We want to try go the OpenMetrics way instead :)/emoticons/smile@2x.png 2x" title=":)" width="20" />
Related Content
- 10 months ago