Hey Dirk,

I don't know if this helps you any but this is how I have it implemented in
my shop and maybe there's something here that will put you on the right
track. I remember having issues with this check too until I stumbled upon
the -l and -o switches arguments, which made things much easier. Another
thing that was tripping me up, and wasn't obvious, were servers that were
configured MOTD/banners and worked around this by suppress them using the
LogLevel=Error setting.

Good luck and hope this helps some!

object CheckCommand "check_health" {

        import "by_ssh"

        vars.by_ssh_command = "sudo /usr/lib64/nagios/plugins/check_health"

        timeout = 60


        arguments += {

                "-l" = "icinga"

                "-o" = "StrictHostKeyChecking=no"

                "-o" = "LogLevel=Error"

        }

}


object EventCommand "event_by_ssh" {

        import "plugin-event-command"

        command = [ PluginDir + "/check_by_ssh" ]


        arguments = {

                "-H" = "$event_by_ssh_address$"

                "-p" = "$event_by_ssh_port$"

                "-C" = "$event_by_ssh_command$"

                "-l" = "$event_by_ssh_logname$"

                "-i" = "$event_by_ssh_identity$"

                "-q" = {

                        set_if = "$event_by_ssh_quiet$"

                }

                "-w" = "$event_by_ssh_warn$"

                "-c" = "$event_by_ssh_crit$"

                "-t" = "$event_by_ssh_timeout$"

        }


        vars.event_by_ssh_address = "$address$"

        vars.event_by_ssh_quiet = false

}

On September 16, 2016 at 6:08:23 AM, dirk@roeder.rocks (dirk@roeder.rocks)
wrote:

Hello together,
I'm having some problems with getting by_ssh running.
We are enforcing SSH Commands through ssh keys, this works fine wenn called
manually (So key exchange and so on is working).


-bash-4.2$ /usr/lib64/nagios/plugins/check_by_ssh -H localhost -l icinga -C
'uptimeTest 1 2 3'
uptimeTest 1 2 3 | uptimeTest 1 2 3


I followed the wiki
https://wiki.icinga.org/display/howtos/Using+SSH+as+remote+client+for+Icinga2
and created a small config file:


object CheckCommand "ssh_enforce" {
import "by_ssh"

vars.by_ssh_login = "icinga"
vars.by_ssh_command = [ "$command$", "$param1$", "$param2$", "$param3$" ]

}

apply Service "ssh_enforce_uptime" {
import "generic-service"

check_command = "ssh_enforce"

vars.command = "uptimeTest"
vars.param1 = "1"
vars.param2 = "2"


assign where host.vars.os == "Linux"
}

apply Service "ssh_enforce_updates" {
import "generic-service"

check_command = "ssh_enforce"

vars.command = "updates"


assign where host.vars.os == "Linux"
}

I found Icinga trying to run the commands uptimeTest and updates running
locally and not via ssh.

Plugin Output
Remote command execution failed: bash: uptimeTest: command not found

I'm running icinga2-2.5.4-1 on latest CentOS from the official repositories.

>From what I can see within the configuration all arguments are parsed fine:

icinga2 object list
Check Command:

Object 'ssh_enforce' of type 'CheckCommand':
% declared in '/etc/icinga2/conf.d/test.conf', lines 1:0-1:32
* __name = "ssh_enforce"
* arguments
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
1646:2-1683:2
* -4
* description = "Use IPv4 only"
* set_if = "$by_ssh_ipv4$"
* -6
* description = "Use IPv6 only"
* set_if = "$by_ssh_ipv6$"
* -C
* type = "Function"
* -H = "$by_ssh_address$"
* -c = "$by_ssh_crit$"
* -i = "$by_ssh_identity$"
* -l = "$by_ssh_logname$"
* -o
* description = "Provide ssh options (may be repeated)"
* value = "$by_ssh_options$"
* -p = "$by_ssh_port$"
* -q
* set_if = "$by_ssh_quiet$"
* -t = "$by_ssh_timeout$"
* -w = "$by_ssh_warn$"
* command = [ "/usr/lib64/nagios/plugins/check_by_ssh" ]
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
1644:2-1644:42
* env = null
* execute
% = modified in 'methods-itl.conf', lines 36:3-36:33
* type = "Function"
* name = "ssh_enforce"
* package = "_etc"
* templates = [ "ssh_enforce", "by_ssh", "plugin-check-command",
"ipv4-or-ipv6" ]
% = modified in '/etc/icinga2/conf.d/test.conf', lines 1:0-1:32
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
1640:1-1640:28
% = modified in 'methods-itl.conf', lines 35:2-35:61
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
20:1-20:36
* timeout = 60
* type = "CheckCommand"
* vars
* by_ssh_address = "$check_address$"
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
1685:2-1685:40
* by_ssh_command = [ "$command$", "$param1$", "$param2$", "$param3$" ]
% = modified in '/etc/icinga2/conf.d/test.conf', lines 5:5-5:77
* by_ssh_login = "icinga"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 4:5-4:36
* by_ssh_quiet = false
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
1686:2-1686:26
* check_address
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
21:2-30:3
* type = "Function"
* check_ipv4 = "$by_ssh_ipv4$"
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
32:2-32:24
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
1687:2-1687:34
* check_ipv6 = "$by_ssh_ipv6$"
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
33:2-33:24
% = modified in '/usr/share/icinga2/include/command-plugins.conf', lines
1688:2-1688:34
* zone = ""


Object 'localhost!ssh_enforce_updates' of type 'Service':
% declared in '/etc/icinga2/conf.d/test.conf', lines 22:1-22:35
* __name = "localhost!ssh_enforce_updates"
* action_url = ""
* check_command = "ssh_enforce"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 25:5-25:33
* check_interval = 60
% = modified in '/etc/icinga2/conf.d/templates.d/templates.conf', lines
28:3-28:21
* check_period = ""
* check_timeout = null
* command_endpoint = ""
* display_name = "ssh_enforce_updates"
* enable_active_checks = true
* enable_event_handler = true
* enable_flapping = false
* enable_notifications = true
* enable_passive_checks = true
* enable_perfdata = true
* event_command = ""
* flapping_threshold = 30
* groups = [ ]
* host_name = "localhost"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 22:1-22:35
* icon_image = ""
* icon_image_alt = ""
* max_check_attempts = 5
% = modified in '/etc/icinga2/conf.d/templates.d/templates.conf', lines
27:3-27:24
* name = "ssh_enforce_updates"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 22:1-22:35
* notes = ""
* notes_url = ""
* package = "_etc"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 22:1-22:35
* retry_interval = 30
% = modified in '/etc/icinga2/conf.d/templates.d/templates.conf', lines
29:3-29:22
* templates = [ "ssh_enforce_updates", "generic-service" ]
% = modified in '/etc/icinga2/conf.d/test.conf', lines 22:1-22:35
% = modified in '/etc/icinga2/conf.d/templates.d/templates.conf', lines
26:1-26:34
* type = "Service"
* vars
* command = "updates"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 27:5-27:28
* volatile = false
* zone = ""


Object 'localhost!ssh_enforce_uptime' of type 'Service':
% declared in '/etc/icinga2/conf.d/test.conf', lines 9:1-9:34
* __name = "localhost!ssh_enforce_uptime"
* action_url = ""
* check_command = "ssh_enforce"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 12:5-12:33
* check_interval = 60
% = modified in '/etc/icinga2/conf.d/templates.d/templates.conf', lines
28:3-28:21
* check_period = ""
* check_timeout = null
* command_endpoint = ""
* display_name = "ssh_enforce_uptime"
* enable_active_checks = true
* enable_event_handler = true
* enable_flapping = false
* enable_notifications = true
* enable_passive_checks = true
* enable_perfdata = true
* event_command = ""
* flapping_threshold = 30
* groups = [ ]
* host_name = "localhost"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 9:1-9:34
* icon_image = ""
* icon_image_alt = ""
* max_check_attempts = 5
% = modified in '/etc/icinga2/conf.d/templates.d/templates.conf', lines
27:3-27:24
* name = "ssh_enforce_uptime"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 9:1-9:34
* notes = ""
* notes_url = ""
* package = "_etc"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 9:1-9:34
* retry_interval = 30
% = modified in '/etc/icinga2/conf.d/templates.d/templates.conf', lines
29:3-29:22
* templates = [ "ssh_enforce_uptime", "generic-service" ]
% = modified in '/etc/icinga2/conf.d/test.conf', lines 9:1-9:34
% = modified in '/etc/icinga2/conf.d/templates.d/templates.conf', lines
26:1-26:34
* type = "Service"
* vars
* command = "uptimeTest"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 14:5-14:31
* param1 = "1"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 15:5-15:21
* param2 = "2"
% = modified in '/etc/icinga2/conf.d/test.conf', lines 16:5-16:21
* volatile = false
* zone = ""


_______________________________________________
icinga-users mailing list
icinga-users@lists.icinga.org
https://lists.icinga.org/mailman/listinfo/icinga-users
_______________________________________________
icinga-users mailing list
icinga-users@lists.icinga.org
https://lists.icinga.org/mailman/listinfo/icinga-users

Reply via email to