summaryrefslogtreecommitdiffstats
path: root/playbooks/adhoc/noc/get_zabbix_problems.yml
blob: 32fc7ce6809cdbd8207d5efa3531bcc753d84fab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
- name: 'Get current hosts who have triggers that are alerting by trigger description'
  hosts: localhost
  connection: local
  become: no
  gather_facts: no
  roles:
    - os_zabbix
  post_tasks:
    - assert:
        that: oo_desc is defined

    - zbxapi:
        server: https://noc2.ops.rhcloud.com/zabbix/api_jsonrpc.php
        zbx_class: Trigger
        state: list
        params:
          only_true: true
          output: extend
          selectHosts: extend
          searchWildCardsEnabled: 1
          search:
            description: "{{ oo_desc }}"
      register: problems

    - debug: var=problems

    - set_fact:
        problem_hosts: "{{ problems.results | oo_collect(attribute='hosts') | oo_flatten | oo_collect(attribute='host') | difference(['aggregates']) }}"

    - debug: var=problem_hosts

    - add_host:
        name: "{{ item }}"
        groups: problem_hosts_group
      with_items: "{{ problem_hosts }}"

- name: "Run on problem hosts"
  hosts: problem_hosts_group
  gather_facts: no
  tasks:
    - command: "{{ oo_cmd }}"
      when: oo_cmd is defined