Since we already can have custom SQL-queries in alerting, I’d really like the idea of having this also at hand for creating dynamic groups.
This would be handy to solve tasks like requested here: Dynamic group based on group membership
Something just like this, maybe the code could be re-used: