Passing SSH flags to Icinga2 by_ssh plugin

I’m following this guide to use by_ssh on icinga2 instead of NRPE:

https://wiki.icinga.org/display/howtos/Using+SSH+as+remote+client+for+Icinga2

The problem I have this that when executing a nagios plugin remotely over SSH i’m getting ‘stdin: is not a tty’ returned, which icinga2 is erroring on.

I can stop this on the command line with passing ssh -t, eg:

ssh -t icinga2@myserver.com "ls -l"

However, i can’t seem to get -t into the by_ssh module. I thought using the by_ssh_argument attribute would do this. My icinga2 config looks like this:

object CheckCommand "disks" {
    import "by_ssh"
    vars.by_ssh_logname = "root"
    vars.by_ssh_port = "4873"
    vars.by_ssh_argument = { "-t" = null }
    vars.by_ssh_command = [ "/usr/lib64/nagios/plugins/check_disk", "-w", "$by_ssh_disk_warn$", "-c", "$by_ssh_disk_crit$" ]
   vars.by_ssh_disk_warn = "5%"
   vars.by_ssh_disk_crit = "2%"
}

I’ve also tried inverting, putting { 0 = “-t” } or equivalent. Neither way is getting passed into the ssh command correctly.

I’m either not going about this the correct way at all, or it’s not possible and i need to make my own by_ssh plugin?

Answer

I’ve found a solution, whether this is the best way or doing it or not i’m unsure.

I found that passing -E to the nagios check_by_ssh plugin stops the tty error. I couldn’t see a way to pass -E in from the by_ssh plugin, so I’ve created my own icinga2 plugin for this:

object CheckCommand "by_ssh_extended" {
    import "plugin-check-command"
    import "ipv4-or-ipv6"

    command = [ PluginDir + "/check_by_ssh" ]

    arguments = {
            "-H" = "$by_ssh_address$"
            "-p" = "$by_ssh_port$"
            "-C" = {{
                    var command = macro("$by_ssh_command$")
                    var arguments = macro("$by_ssh_arguments$")

                    if (typeof(command) == String && !arguments) {
                            return command
                    }

                    var escaped_args = []
                    for (arg in resolve_arguments(command, arguments)) {
                            escaped_args.add(escape_shell_arg(arg))
                    }
                    return escaped_args.join(" ")
            }}
            "-l" = "$by_ssh_logname$"
            "-i" = "$by_ssh_identity$"
            "-q" = {
                    set_if = "$by_ssh_quiet$"
            }
            "-E" = {
                    set_if = "$by_ssh_e$"
            }
            "-w" = "$by_ssh_warn$"
            "-c" = "$by_ssh_crit$"
            "-t" = "$by_ssh_timeout$"
            "-o" = {
                    value = "$by_ssh_options$"
                    description = "Provide ssh options (may be repeated)"
            }
    }

    vars.by_ssh_address = "$check_address$"
    vars.by_ssh_quiet = false
}

Attribution
Source : Link , Question Author : elliotp , Answer Author : Eduardo Cuomo

Leave a Comment