shinken-monitoring / mod-livestatus

Shinken module for presenting data with a MK/Livestatus comptabile interface
GNU Affero General Public License v3.0
15 stars 20 forks source link

Filtering hosts by host_groups causes unsorted output. #22

Closed andrewmcgilvray closed 10 years ago

andrewmcgilvray commented 10 years ago

I first noticed this issue in Thruk but have reproduced it with "pynag livestatus".

When listing all hosts they are returned sorted alphabetically. If an output limit is used the behaviour stays the same.

But when listing hosts and Filtering by host_group the output is unsorted. This behaviour is an issue for tools like Thruk because when it displays '100 per page' a seemingly random assortment of hosts are returned on each page because they are re-sorted to be alphabetical. On page 2 of 100 thruk will limit to 200 results, sort them and then display the second 100 results.

This causes behavior like when moving from page to page you will see hosts missing on early pages and other hosts reappearing on later pages.

This seems to be caused by the gen_filtered generator called at https://github.com/shinken-monitoring/mod-livestatus/blob/master/module/livestatus_query.py#L393 or the cs.filter_func that is passed to it.

I don't have the python skills to work this out but it seems that the output of the filter generator needs to be sorted before the limit generator is used.

Contrived example: GET hosts Filter: host_groups >= linux Limit: 5

host8 host4 host7 host10 host2

Contrived example: GET hosts Filter: host_groups >= linux Limit: 10

host8 host4 host7 host10 host2 host45 host24 host98 host65

andrewmcgilvray commented 10 years ago

An extra note ... when thruk is asked to sort the results by another field (like Duration or Status) it does not seem to use the 'limit' option and will grab the entire result set, sort it and page the results itself.

Thruk seems to be relying on the original mk_livestatus behaviour of the natural alphabetical sort when a filter is used or not.

andrewmcgilvray commented 10 years ago

Sorry for the spam .. This also affects services when they are filtered by host_groups.

andrewmcgilvray commented 10 years ago

created pull request https://github.com/shinken-monitoring/mod-livestatus/pull/23

olivierHa commented 10 years ago

I will try to test it soon. If someone can test this patch before, go :)

andrewmcgilvray commented 10 years ago

I updated the pull request with sorting for the services by servicegroup and services by hostgroup.

andrewmcgilvray commented 10 years ago

Any news on this? I have been running with this patch in production and have not run into any issues. It really does fix a real problem.