Please take a look at this check, maybe it helps you at least understand how yield
can be used:
#!/usr/bin/env python
factory_settings['axing_default_levels'] = (60,70)
# inventory (check_mk will find these checks in the service discovery)
def inventory_axing_temp(info):
for line in info:
if line[0] == "TEMP":
yield line[0], "axing_default_levels"
def check_axing_temp(name, params, info):
warn, crit = params
status = 0
for line in info:
if name == line[0]:
item = line[0]
value = int(line[1])
infotext = "Temperature is %s°C" % (value)
perfdata = [("temp",value,warn,crit)]
if value >= warn:
status = 1
if value >= crit:
status = 2
yield status, infotext, perfdata
# some metadata for the check plugin, how the services are named, etc.
check_info["axing.temp"] = {
"check_function" : check_axing_temp,
"inventory_function" : inventory_axing_temp,
"service_description" : "Axing %s",
"default_levels_variable" : "axing_default_levels",
"has_perfdata" : True,
}
Hope this helps.
Regards
PS : I found the following text for yield:
Return sends a specified value back to its caller whereas Yield can produce a sequence of values. We should use yield when we want to iterate over a sequence, but don’t want to store the entire sequence in memory.