Apply rule: check_generic and escape chars **resolved**

icinga2

(Denny Fuchs) #1

hi,

I want to use check_generic to execute a command, like apt-mark showhold :

./check_generic -n check_mongo_packages -e 'apt-mark showhold mongodb-org-mongos' -c '!~/mongodb-org/' -d /tmp/ 
check_mongo_packages OK - result:mongodb-org-mongos match:none 

I would create in Icingaweb2 director an array with packages to check:

apply Serice "MongoDB package hold: " for (package in host.vars.debian_packages) {
  check_command = "check-generic"
  display_name = "Debian package on hold: " + package
  **vars.generic_execute_cmd = "apt-mark showhold" + package**
  ...
  command_endpoint = host.vars.client_endpoint
  assign where host.vars.client_endpoint && host.vars.role == "mongodb"
}

My problem is now, how to get the $package name in the vars.generic_execute_cmd … ? Because the command requires escape chars around the command …

any suggestions ?

cu denny


(Nicolai) #2

Just escape the command in your argument definition:

object CheckCommand "check_generic" {
        // [...]
        arguments = {
               // [...]
                "-e" = {
                        value = "'$generic_execute_cmd$'"
                }
        }
}

(Denny Fuchs) #3

hi @nicolaiB,

it wasn’t needed :slight_smile:
check-generic-command.conf

object CheckCommand "check-generic"  {
  import "plugin-check-command"

  command = [ PluginDir + "/3dparty/check_generic", ]
  arguments = {
    "-e" = {
      value = "$generic_execute_cmd$"
    }
    "-u" = {
      value = "$generic_unknown_expr$"
    }
    "-w" = {
      value = "$generic_warning_expr$"
    }
    "-c" = {
      value = "$generic_critical_expr$"
    }
    "-o" = {
      value = "$generic_ok_expr$"
    }
    "-f" = {
      value = "$generic_false_expr$"
    }
    "-y" = "$generic_data_type$"
    "-i" = "$generic_ignore_rc$"
    "-n" = "$generic_name$"
    "-t" = "$generic_timeout$"
    "-d" = "$generic_tmpdir$"
    "-v" = "$generic_verbose$"
  }
  vars.generic_tmpdir = "/tmp/"
}

service_check_mongodb.conf

apply Service "MongoDB package hold: " for (package in host.vars.debian_packages) {
  check_command = "check-generic"
  display_name = "Debian package on hold: " + package
  vars.generic_name = "Package check " + package
  vars.generic_critical_expr = "!~/" + package + "/"
  vars.cmd = "apt-mark showhold " + package
  vars.generic_execute_cmd = vars.cmd
  command_endpoint = host.vars.client_endpoint
  assign where host.vars.client_endpoint && host.vars.role == "mongodb"
}

Thanks :slight_smile: