get_zabbix_problems.yml 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ---
  2. - name: 'Get current hosts who have triggers that are alerting by trigger description'
  3. hosts: localhost
  4. gather_facts: no
  5. roles:
  6. - os_zabbix
  7. post_tasks:
  8. - assert:
  9. that: oo_desc is defined
  10. - zbxapi:
  11. server: https://noc2.ops.rhcloud.com/zabbix/api_jsonrpc.php
  12. zbx_class: Trigger
  13. action: get
  14. params:
  15. only_true: true
  16. output: extend
  17. selectHosts: extend
  18. searchWildCardsEnabled: 1
  19. search:
  20. description: "{{ oo_desc }}"
  21. register: problems
  22. - debug: var=problems
  23. - set_fact:
  24. problem_hosts: "{{ problems.results | oo_collect(attribute='hosts') | oo_flatten | oo_collect(attribute='host') | difference(['aggregates']) }}"
  25. - debug: var=problem_hosts
  26. - add_host:
  27. name: "{{ item }}"
  28. groups: problem_hosts_group
  29. with_items: problem_hosts
  30. - name: "Run on problem hosts"
  31. hosts: problem_hosts_group
  32. gather_facts: no
  33. tasks:
  34. - command: "{{ oo_cmd }}"
  35. when: oo_cmd is defined