Hi,
Today I stumbled upon a setup where someone deactivated the notification
feature on both master nodes and forgot to reactivate it on one. So they ended up with one master sending notifications and the other one remaining silent.
So I thought about introducing (and if you like it, contributing) a check that checks whether a certain feature is enabled and active. I’m not very used to writing function so you might have a suggestion or two for what I’d be very thankful. Especially getting rid of the duplicated function would be something I’d like to see.
Thanks to @Al2Klimov for the initial idea of using DSL, not bash.
So here it is (Don’t mind the apply
rule, I just used copy and paste within my dev-environment)
apply Service "Notification" {
import "generic-service"
check_command = "feature"
command_endpoint = host.name
vars.component_type = "NotificationComponent"
vars.component_name = "notification"
assign where host.vars.os == "linux"
}
object CheckCommand "feature" {
import "dummy"
vars.dummy_text = {{
var comp_type = macro("$component_type$")
var comp_name = macro("$component_name$")
var res = "Object " + comp_name + " of type " + comp_type + " exists"
var mycomponent = get_object(comp_type,comp_name)
if ( mycomponent == null) {
res = "Object " + comp_name + " of type " + comp_type + " missing"
}
return res
}}
vars.dummy_state = {{
var comp_type = macro("$component_type$")
var comp_name = macro("$component_name$")
var restate = 0
var mycomponent = get_object(comp_type,comp_name)
if ( mycomponent == null) {
restate = 2
}
return restate
}}
}