How to use "+=" operator creating service over API

I’m adding services to hosts over API. This works fine, but I need to use vars for one of the services and I’d like to add some vars to the dict instead of overriding all vars - something that can be achieved in config by “+=”.

Is there a way to use this operator over API? I just have json like

{"templates": [ "generic-service" ],
                "attrs": {
                    "display_name": self.passive_check_name,
                    "check_command" : "check_monit",
                    "check_interval": "600",
                    "vars": { "include_regexp": self.passive_check_name}

which results in default values from CheckCommand definition being overridden.

Hello Marcin!

Try "vars.include_regexp": ...


@Al2Klimov - thanks for reading and your reply. Both approaches - the one I’ve used and your formatting vars.include_regexp and "vars": { "include_regexp": ...} work consistent. They both result in the whole vars dictionary being overwritten and I just want to add one specific veriable creating the service.

Ah, you mean Service#vars contains only include_regexp while CheckCommand#vars contains foo, bar, …?

I have command defined like:

object CheckCommand "check_monit" {
  command = [ PluginDir + "/" ] //constants.conf -> const PluginDir

  arguments = {
    "-H" = {
                required = true
                value = "$check_host$"
    "-p" = "$check_port$"
    "-u" = {

When I create a service using the JSON above the command execution fails, because it’s missing -H. If I remove vars from the JSON creating service it works fine, but… for some cases I’d like to have additional argument passed to command.

I assume check_host is defined in generic-service, right?

1 Like

I was totaly wrong thinking that it’s kind of built-in, defined per host. I realized in services where it works I just have it defined per service. I just replaced it with ‘$host.address$’ and I can confirm it’s not overriden by API call from the first post.
Thanks for your time!
(Edit) The thread can be closed, but I’m not sure if I should mark anything a solution - it’s kind of “invalid ticket” from the beginning.