There’s vars.numericoffset as host custom var, setting a function object as value (likely not intended).
There’s also globals.numericoffset registering a function.
globals.notification_interval_function() is not defined anywhere.
Aside from that, var node_name is a pure string and the len() call just returns the string length.
There’s no macro resolution in place.
Question remains, what’s the purpose of vars.numericoffset and where would you want to access that? Based on that answer we may recommend possible solutions.
vars.my_desired_variable = 11 #the length off the string “$host.name$”
instead of my desired:
vars.my_desired_variable = 26 #the length off the object Host
I only got the right question, about if there’s any attribute from already imported templates/ or even the object name, available for using either as a function parameter or within the global function during the update/generation of the object in icinga
< I understand, the marco is not availabla unless at runtime , but i need it at object-generation time
The macro function can be used to resolve runtime macro strings into their values. The returned value depends on the attribute value which is resolved from the specified runtime macro.
I just want to know the purpose of this calculated value. If you for example say that you want its value being used inside the Grafana module for some calculations, we need a different route.
If you want to use it for functionality inside the objects themselves, another approach might be applicable.
The more ideas you share, the better answers you get. Right now, I don’t know what would fit here.
I’m using A calculated value, to “randomly spread notifications” in time, as to avoid icinga getting OOM killed/stalled due to excessive notifications being sent simultaneously.
Actual function:
globals.notification_interval_function=function(base_notification_interval,randon_notification_delay_range) {
var b=Math.ceil(randon_notification_delay_range*Math.random())
return (base_notification_interval+b)
}
Is used to set the notification interval; in example:
apply Notification "service-prod" to Service {
import "z"
interval = globals.notification_interval_function(PRODUCTION_NOTIFICATION_FREQUENCY, PRODUCTION_MAX_NOTIFICATION_DELAY)
users = [ "x" ]
assign where host.vars.production
ignore where service.vars.disable_notifications
}
That way, I prevent All notifications being sent at once, this however causes the following issue:
upon configuration reload/update, Icinga sends nearly 15 minutes of inserts/deletes commands to mysql backend, causing the ido_mysql queues to skyrocket from avg 1000 items in queue up to 2.1 M items in queue. Issue is that notifications, and state information will only catch up in nearly after 45 minutes (that is 45 minutes without alerting !!!)
Since I suspect the variation of this value during configuration updates is somehow being persisted on the database, I was trying to migrate the function to something based on the “host” vars; i.e. “address” or “host.name” so that the function can be updated to some hashing value (like len of host.name or 10xsqrt(host.name)) and the performance hit is fully removed; but this in turn needs the object attributes and/or vars to be available during object creation (not really on api timing).
At the begining of the post; the function was addes as host.vars.notification_frequency; at the moment is being added to the notification object instead…
Do you think the problem has stated in a better manner now?
Is this notification.interval value trully being persisted somehow to database backend?
Hi, I have just made the notification interval inmutable for each notification object, fixing the time required by database to update the field notification_interval on services and hosts table.
I’ll be closing the ticket.
Now, Is it possible to provide a hashmode function,
i.e
math.hashmod (some_string, modulus)
where given a string to hash, the outcome is a to the modulus of a hash of the said string, between 0 and the modulus integer? pretty much like prometheus “hashmod” function ?