<div dir="ltr">I am writing a python plugin that checks the number of available upgrades and security upgrades on Debian servers (based on apt-check tool).<div><br></div><div>The thing is that I want this check to be executed once every day unless there are upgrades available in which case I want to reduce the interval to a lower value. Once the upgrades are installed I want the interval to change back to once a day.</div>
<div><br></div><div>This is what I tried in my plugin:</div><div><br></div><div><div>def read_callback():</div><div>    global callback_id</div><div><br></div><div>    res = apt_check()</div><div>    upgrades = collectd.Values(plugin=NAME, type='apt')</div>
<div>    upgrades.values = [ res[0], res[1] ]</div><div>    upgrades.dispatch()</div><div><br></div><div>    #<a href="http://collectd.info">collectd.info</a>("Apt-Check %s %s " % (res[0], res[1]))</div><div><br>
</div><div>    if(res[0] > 0 or res[1] > 0):</div><div>      collectd.unregister_read(callback_id)<br></div><div>      callback_id = collectd.register_read(read_callback, SHORT_INTERVAL)</div><div>    else:</div><div>
      collectd.unregister_read(callback_id)<br></div><div>      callback_id = collectd.register_read(read_callback, INTERVAL)</div></div><div><br></div><div>In my read callback, after I get the number of upgrades, if there are upgrades (res[0] or res[1] > 0) I unregister the read callback and register it again with a shorter iterval. If there are no upgrades I register it with a large interval (e.g. 24 hours).</div>
<div><br></div><div><br></div><div>My questions are:</div><div><br></div><div>- Is is necessary to unregister the callback each time? or is the register_read method indemponent and can be called multiple times without causing memory leaks?</div>
<div><br></div><div>- It seems that the interval variable in the register_read method is ignored. If I un-comment the info call I can see the read callback is invoked at increasing intervals starting from 3 secs. No matter what are the values of INTERVAL and SHORT_INTERVAL.</div>
<div><br></div><div>- Is there a better way in collectd to support dynamic intervals that depend on the values being monitored?</div><div><br></div><div><br></div><div>regards,</div><div>Horacio </div></div>