On 6 April 2016 at 11:40, Sam Ruby <[email protected]> wrote: > On Tue, Apr 5, 2016 at 5:43 PM, sebb <[email protected]> wrote: >> I've started looking into how to quieten down the warnings without >> losing all the info. >> >> The monitors are called very fequently (maybe once or twice per minute) >> So it's vital that sending an e-mail is not needlessly repeated. >> >> I was hoping to use the previous_status hash which is passed in. >> >> I tried comparing hashes, but this shows differences, for example: >> >> previous >> {"ldap-services"=>{"href"=>"../logs/public-ldap-services", >> "mtime"=>"2016-04-05 00:15:43 +0100", "level"=>"warning", >> "data"=>"Last updated: 2016-04-05 00:15:43 +0100 (more than 1.5 hours >> old)"}} >> >> current >> {"ldap-services"=>{:href=>"../logs/public-ldap-services", >> :mtime=>2016-04-05 00:15:43 +0100, :level=>"warning", :data=>"Last >> updated: 2016-04-05 00:15:43 +0100 (more than 1.5 hours old)"}} >> >> The difference is that the input hash uses strings as hash keys, >> whereas the output hash uses symbols. >> >> It looks like monitor.rb is using mainly strings, whereas >> public_json.rb mainly uses symbols. >> This makes it harder to detect actual changes. >> >> Is there any reason not to use symbols for hash keys throughout? > > No. :-)
I discovered a slight snag: The JSON file of course uses strings only. And when parsed, the keys default to strings. However although one can tell the parser to convert all keys to symbols, there are some key names which are accessed using string variables - e.g. the method name and the file name. The original code bypassed this by converting the response to strings, so it did not matter what the scripts under monitors used. However that caused the problem noted above when comparing against the previous status. The updated code uses symbolic keys throughout. Turns out there were other changes to the status hash made by the main class (e.g. harmonisation of mtime format). These have to be fixed in any monitors that want to quickly compare status hashes. > Feel free to make it consistent. > > - Sam Ruby
