Skip to content

Instantly share code, notes, and snippets.

@xorpaul
Last active May 18, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xorpaul/f6a6874b762f9e2ae2402e0a86abd351 to your computer and use it in GitHub Desktop.
Save xorpaul/f6a6874b762f9e2ae2402e0a86abd351 to your computer and use it in GitHub Desktop.
object CheckCommand "check_tcp_wild" {
        import "ipv4-or-ipv6"

        command = [ PluginDir + "/check_tcp " + "$tcp_args$" ]

        vars.tcp_args = "$tcp_args$"
}
apply Service "Puppet Server 8140" {
  import "generic-service"
  check_command = "check_tcp_wild"
  vars.tcp_args = "-H puppetserver.domain.tld -p 8140"
}

Edit: One solution I came up with is:

object CheckCommand "check_tcp_wild" {
        import "plugin-check-command"
        import "ipv4-or-ipv6"
        command = PluginDir + "/check_tcp" + " " + "$tcp_args$" 
        vars.tcp_args = "$tcp_args$"
}
apply Service "Puppet Server 8140" {
  import "generic-service"
  check_command = "check_tcp_wild"
  vars.tcp_args = ["-H", "puppetserver.domain.tld", "-p", "8140"]
}
@xorpaul
Copy link
Author

xorpaul commented May 16, 2017

Results in

execvpe(/usr/lib/nagios/plugins/check_tcp -H puppetserver.domain.tld -p 8140) failed: No such file or directory

@xorpaul
Copy link
Author

xorpaul commented May 17, 2017

Also tried

object CheckCommand "check_tcp_wild" {
        import "ipv4-or-ipv6"
        command = PluginDir + "/check_tcp " + "$tcp_args$"
        vars.tcp_args = "$tcp_args$"
}
apply Service "Puppet Server 8140" {
  import "generic-service"
  check_command = "check_tcp_wild"
  vars.tcp_args = "-H puppetserver.domain.tld -p 8140"
}

and the array method

object CheckCommand "check_tcp_wild" {
        import "ipv4-or-ipv6"
        command = [ PluginDir + "/check_tcp ", vars.tcp_args ]
}
apply Service "Puppet Server 8140" {
  import "generic-service"
  check_command = "check_tcp_wild"
  vars.tcp_args = ["-H",  "puppetserver.domain.tld", "-p", "8140" ]
}

@tobiasvdk
Copy link

As discussed in chat, it's not the way the config should look like.

I think this will also not work as "tcp_args" will be one string:

object CheckCommand "check_tcp_wild" {
        import "ipv4-or-ipv6"

        command = [ PluginDir + "/check_tcp ", "$tcp_args$" ]

        vars.tcp_args = "$tcp_args$"
}

Maybe this works:

object CheckCommand "check_tcp_wild" {
        import "ipv4-or-ipv6"

        command = [ PluginDir + "/check_tcp ", "$tcp_args$".split(" ") ]

        vars.tcp_args = "$tcp_args$"
}

@gunnarbeutner
Copy link

Untested, but this should work:

object CheckCommand "check_tcp_wild" {
        import "ipv4-or-ipv6"
        command = [ PluginDir + "/check_tcp ", "$tcp_args$" ]
}

apply Service "Puppet Server 8140" {
  import "generic-service"
  check_command = "check_tcp_wild"
  vars.tcp_args = ["-H",  "puppetserver.domain.tld", "-p", "8140" ]
}

@xorpaul
Copy link
Author

xorpaul commented May 18, 2017

@tobiasvdk The "$tcp_args$".split(" ") method fails with:

critical/config: Error: Validation failed for object 'check_tcp_wild' of type 'CheckCommand'; Attribute 'command' -> '1': Invalid type.

@gunnarbeutner Your version also works, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment