Different plugindir for a single host no root

  • Example where I assign a service for several hosts but there is a server to which I do not have root access and the address of the plugins can not be the same as the others

    In constants.conf set PluginDir to / usr / lib / nagios / plugins /

    But in this case I need a different dir to monitor a single hosts to which I do not have access to root

    Sorry my english is not very good ^^
    I hope I have explained ^^

    services.conf-

    apply Service "checkswap" {

    import "generic-service"


    check_command = "checkbyssh"


    vars.by_ssh_command = PluginDir + "/check_swap -w $swap_warn$ -c $swap_crit$"


    vars.swap_warn = "90%"

    vars.swap_crit = "85%"


    assign where (host.address || host.address6) && host.vars.os == "LinuxOS"


    }



    host.conf-

    object Host "host.page.net" {

    /* Import the default host template defined in `templates.conf`. */

    import "generic-host"


    address = "10.80.0.6"

    address6 = ""

    vars.by_ssh_address = "10.80.0.6"

    vars.by_ssh_port = "22"

    vars.by_ssh_logname = "usernoroot"


    }


    commands.conf-


    object CheckCommand "checkbyssh" {

    import "plugin-check-command"

    import "ipv4-or-ipv6"


    command = [ PluginDir + "/check_by_ssh" ]


    arguments = {

    "-H" = "$by_ssh_address$"

    "-p" = "$by_ssh_port$"

    "-C" = "$by_ssh_command$"

    "-l" = "$by_ssh_logname$"

    "-i" = "$by_ssh_identity$"

    "-q" = {

    set_if = "$by_ssh_quiet$"

    }

    "-w" = "$by_ssh_warn$"

    "-c" = "$by_ssh_crit$"

    "-t" = "$by_ssh_timeout$"

    "-o" = "StrictHostKeyChecking=no"

    }


    vars.by_ssh_address = "$check_address$"

    vars.by_ssh_quiet = false

    }

  • Please use the code tags </> to format your configuration snippets.


    If you do need a different path for your plugin called via check_by_ssh, drop PluginDir from its configuration and use a different constant or the entire absolute path.


    Code
    1. vim /etc/icinga2/constants.conf
    2. const OtherLinuxPluginDir = "/opt/plugins"


    Code
    1. vars.by_ssh_command = OtherLinuxPluginDir + "/check_swap -w $swap_warn$ -c $swap_crit$"
  • if but how to define it so that it only applies to a hosts and that all the others use the one that is by default, without having to define another service more for that host that has different PluginDir


    could you apply a for or filter in templates.conf?


    or in services.conf?

  • If you happen to have an on-demand host custom attribute, you could also go for that.


    Code
    1. if (host.vars.custom_plugin_path) {
    2. vars.by_ssh_command = host.vars.custom_plugin_path + "/check_swap -w $swap_warn$ -c $swap_crit$"
    3. } else {
    4. vars.by_ssh_command = PluginDir + "/check_swap -w $swap_warn$ -c $swap_crit$"
    5. }



    PS: Please use shorter sentences and illustrate what you mean. I had to re-read it five times to get an idea.