Hi beloved community !
As in Icinga statusdata is deprecated, and we rely on this to check multiple Services (check_multi),
I had to come up with a new way to that.
But I am not sure, what I have done is really a good idea. (but it works)
As I would like to avoid a rewrite, I would like to know what I wrote is considered OK, or is it a bad idea,
particularly passing a function from Service to a Checkcommand.
Thank you for your response : ) (I hope i am not offtopic with this.)
These are the results:
object CheckCommand "multi_check" {
import "plugin-check-command"
command = {{
var arrCommand = [PluginDir + "/check_dummy" ]
var strHostFilter = macro("$service.vars.hostfilter$")
var strServiceFilter = macro("$service.vars.servicefilter$")
var dictStatus = {}
functFilterfunction = macro("$service.vars.filterfunction$")
var strReturnstring = "\n"
var intReturncode = 0
for (var objService in (get_objects(Service))){
if (match(strHostFilter,objService.host.name) && match(strServiceFilter,objService.name)){
strReturnstring+=objService.host.name +" --> "+objService.last_check_result.output + "\n"
if ( objService.last_check_result.state == 0 ){
dictStatus["OK"]["Count"] +=1
dictStatus["OK"][objService.host.name][objService.name] = 1
}else if( objService.last_check_result.state == 1 ){
dictStatus["WARNING"]["Count"] +=1
dictStatus["WARNING"][objService.host.name][objService.name] = 1
}else if ( objService.last_check_result.state == 2 ){
dictStatus["ERROR"]["Count"] +=1
dictStatus["ERROR"][objService.host.name][objService.name] = 1
}else if( objService.last_check_result.state == 3 ){
dictStatus["UNKNOWN"]["Count"] +=1
dictStatus["UNKNOWN"][objService.host.name][objService.name] =1
}
}
}
intReturncode=functFilterfunction(dictStatus)
arrCommand+=[intReturncode,strReturnstring + dictStatus.to_string() + intReturncode ]
return arrCommand
}}
}
apply Service "multi_service" {
import "generic-service"
check_command = "multi_check"
vars.servicefilter = "*pudding*"
vars.hostfilter = "*pizza*"
vars.filterfunction = {{
function(status){
if (status["OK"]["Count"] < 4 ){
return 1
}
}
}}
assign where host.vars.os == "ilovecookies"
}