Markus,

That’s brilliant! I’m going to need some time to digest and test it but this 
looks like it is the solution I am looking for.

On September 13, 2016 at 3:35:47 AM, Joosten, Markus (markus.joos...@plumbe.de) 
wrote:

On 2016-09-12 19:23, Rob DeSanno wrote:  
> The challenge presented to me was to somehow configure notifications  
> to be sent only when a certain percentage of hosts experience critical  
> alerts.  
>  
> For example, instead of sending out a notification when every host  
> fails a ping check, only send one out if 10%, or more, hosts fail.  
>  
> We want something a little more complicated than that but the basic  
> theory should be the same, assuming its possible. Anyone have any  
> experience or thoughts on how to go about doing this?  
I have implemented something like this using check_dummy and Icinga2's  
runtime macros.  
Behold the following template (the basic idea is borrowed somewhere  
else, can't remember where):  

template Host "dummy-cluster" {  
import "generic-host"  
check_command = "dummy"  
vars.cluster_nodes = [ ]  

vars.dummy_state = {{  
var up_count = 0  
var down_count = 0  
var cluster_nodes = macro("$cluster_nodes$")  

for (node in cluster_nodes) {  
if (get_host(node).state > 0) {  
down_count += 1  
} else {  
up_count += 1  
}  
}  
if (up_count >= 1 ) {  
return 0 //at least one host responded  
} else {  
return 2 //no host answered  
}  
}}  
vars.dummy_text = {{  
var output = "Cluster hosts:\n"  
var cluster_nodes = macro("$cluster_nodes$")  

for (node in cluster_nodes) {  
output += node + ": " + get_host(node).last_check_result.output +  
"\n"  
}  

return output  
}}  
}  

As you can see, the vars.dummy_state is always evaluated at runtime and  
takes the last state of all host objects stored in vars.cluster_nodes  
into account.  
My template always returns UP as long as one host in vars.cluster_nodes  
is UP.  
You could introduce an additional var where you can define which  
percentage at which everything should be considered "UP".  

I instantiate the template as follows:  

object Host "ClusterA" {  
import "dummy-cluster"  

vars.cluster_nodes = [ "HostA", "HostB", "HostC", "HostD" ]  
}  

Kind regards,  
Markus  

> _______________________________________________  
> icinga-users mailing list  
> icinga-users@lists.icinga.org  
> https://lists.icinga.org/mailman/listinfo/icinga-users  
_______________________________________________  
icinga-users mailing list  
icinga-users@lists.icinga.org  
https://lists.icinga.org/mailman/listinfo/icinga-users  
_______________________________________________
icinga-users mailing list
icinga-users@lists.icinga.org
https://lists.icinga.org/mailman/listinfo/icinga-users

Reply via email to