Disable notification IF host notification are disable

Hi,

Is there an easy way to disable notification IF host notifications are disabled ?

We are using the Apply method to apply service to host and will be nice if we can do something like :

IF host.notifications == 0 then enable_notifications = false

I would build this into your notifications script.

I currently use:

apply Notification “mail-host-notification” to Host {
command = “mail-host-notification”
import “mail-notification”
states = [ Up, Down ]
assign where host.vars.notification.mail
}

apply Notification “mail-service-notification” to Service {
command = “mail-service-notification”
import “mail-notification”
states = [ OK, Warning, Critical, Unknown ]
assign where host.vars.notification.mail
}

Simply change “assign where host.vars.notification.mail”
to “assign where host.vars.notification.mail and host.vars.notifications != 0”

Antony.

@Pooh

I think I didn’t write the right example.
I don’t want to use the variable notifications under hosts but disable services notifications IF enable_notifications = false UNDER the host…

Okay. Either I really didn’t understand you, or you didn’t look at both parts
of the configuration I posted.

If the below doesn’t help, please try to explain exactly why not:

apply Notification “mail-service-notification” to Service {
command = “mail-service-notification”
import “mail-notification”
states = [ OK, Warning, Critical, Unknown ]
assign where host.vars.notification.mail and host.vars.notifications != 0
}

Antony.

@Pooh
In my host I have

template Host "host-override-notification" {
  enable_notifications = 0
}

object Host "***********" {
  import "generic-host"
  import "******************"
  import "host-override-notification"

  check_command = "cluster-zone"
  vars.os = "Linux"
  vars.agent = true
  vars.hardware = "raspberry"

  vars.disks["/"] = {
    disk_partitions = "/"
    disk_units = "GB"
  }
}

You assign with

and host.vars.notifications != 0

it’s for a variable under the host and we are not having one, so using your “and” disable notification for all services for any hosts instead of for the host that have notification disable as our “template”

In that case I have misunderstood your requirement.

You originally said "will be nice if we can do something like :

IF host.notifications == 0 then enable_notifications = false"

So I was assuming that you did have a host variable named “notifications”.

Maybe you could try expressing again what host definitions you do have, and on
what basis you want to enable/disable notifications?

Thanks,

Antony.

We would need something that can check if enable_notifications = 0 under the host definition and then, do the same thing under “services”

Is there a way to know the status of the “enable_notifications” under a host?

We would need something that can check if enable_notifications = 0 under
the host definition and then, do the same thing under “services”

Those are exactly the examples I gave you.

Here are the first and last lines of each:

apply Notification “mail-host-notification” to Host {

assign where host.vars.notifications != 0
}

apply Notification “mail-service-notification” to Service {

assign where host.vars.notifications != 0
}

Is there a way to know the status of the “enable_notifications” under a
host?

Yes. Service checks can test host variables, as shown above.

Have you actually tried one of the examples I’ve given, and found a problem
with it, or do you just think it won’t do what you want (possibly because of a
misunderstanding on my part)?

Antony.

@Pooh

It’s seem to be working, my mistake was to check this:
image

Instead of

image