diff --git a/changelogs/fragments/pr_1234.yml b/changelogs/fragments/pr_1234.yml new file mode 100644 index 000000000..f5239f331 --- /dev/null +++ b/changelogs/fragments/pr_1234.yml @@ -0,0 +1,3 @@ +minor_changes: + - zabbix_item - add support for setting master items by name + - zabbix_itemprototype - add support for setting master items by name diff --git a/plugins/modules/zabbix_item.py b/plugins/modules/zabbix_item.py index 8684b5709..2d6bb95eb 100644 --- a/plugins/modules/zabbix_item.py +++ b/plugins/modules/zabbix_item.py @@ -283,6 +283,36 @@ value: application state: present +- name: create a dependent item + # set task level variables as we change ansible_connection plugin here + vars: + ansible_network_os: community.zabbix.zabbix + ansible_connection: httpapi + ansible_httpapi_port: 443 + ansible_httpapi_use_ssl: true + ansible_httpapi_validate_certs: false + ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http:///zabbixeu + ansible_host: zabbix-example-fqdn.org + community.zabbix.zabbix_item: + name: depend_item + host_name: example_host + params: + type: dependent_item + key: vfs.fs.pused + value_type: numeric_float + units: '%' + master_item: + item_name: example_item + host_name: example_host + preprocessing: + - type: jsonpath + params: '$[?(@.fstype == "ext4")]' + error_handler: zabbix_server + - type: jsonpath + params: "$[*].['bytes', 'inodes'].pused.max()" + error_handler: zabbix_server + state: present + - name: Delete Zabbix item # set task level variables as we change ansible_connection plugin here vars: diff --git a/plugins/modules/zabbix_itemprototype.py b/plugins/modules/zabbix_itemprototype.py index 7f5616320..1fe5b9560 100644 --- a/plugins/modules/zabbix_itemprototype.py +++ b/plugins/modules/zabbix_itemprototype.py @@ -300,6 +300,35 @@ value: application state: present +- name: create dependent item + # set task level variables as we change ansible_connection plugin here + vars: + ansible_network_os: community.zabbix.zabbix + ansible_connection: httpapi + ansible_httpapi_port: 443 + ansible_httpapi_use_ssl: true + ansible_httpapi_validate_certs: false + ansible_zabbix_url_path: 'zabbixeu' # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http:///zabbixeu + ansible_host: zabbix-example-fqdn.org + community.zabbix.zabbix_itemprototype: + name: '{% raw %}{#FSNAME}:example_depend_item_prototype{% endraw %}' + discoveryrule_name: example_rule + host_name: example_host + params: + type: dependent_item + key: '{% raw %}vfs.fs.size.half[{#FSNAME}]{% endraw %}' + value_type: numeric_float + units: B + master_item: + item_name: '{% raw %}{#FSNAME}:example_item_prototype{% endraw %}' + discoveryrule_name: example_rule + host_name: example_host + preprocessing: + - type: javascript + params: 'return value / 2;' + error_handler: zabbix_server + state: present + - name: Delete Zabbix item prototype # set task level variables as we change ansible_connection plugin here vars: diff --git a/tests/integration/targets/test_zabbix_item/tasks/zabbix_tests.yml b/tests/integration/targets/test_zabbix_item/tasks/zabbix_tests.yml index f0924dde0..86767a716 100644 --- a/tests/integration/targets/test_zabbix_item/tasks/zabbix_tests.yml +++ b/tests/integration/targets/test_zabbix_item/tasks/zabbix_tests.yml @@ -7,8 +7,16 @@ params: type: zabbix_agent_active key: vfs.fs.get - value_type: text + value_type: numeric_float + units: '%' interval: 1m + preprocessing: + - type: jsonpath + params: '$[?(@.fstype == "ext4")]' + error_handler: zabbix_server + - type: jsonpath + params: "$[*].['bytes', 'inodes'].pused.max()" + error_handler: zabbix_server tags: - tag: tag value: value @@ -19,15 +27,23 @@ ansible.builtin.assert: that: zbxhostitem_new is changed -- name: test - create same Zabbix item once again +- name: test - create same Zabbix item group once again community.zabbix.zabbix_item: name: TestItem host_name: ExampleHost params: type: zabbix_agent_active key: vfs.fs.get - value_type: text + value_type: numeric_float + units: '%' interval: 1m + preprocessing: + - type: jsonpath + params: '$[?(@.fstype == "ext4")]' + error_handler: zabbix_server + - type: jsonpath + params: "$[*].['bytes', 'inodes'].pused.max()" + error_handler: zabbix_server tags: - tag: tag value: value @@ -51,6 +67,47 @@ ansible.builtin.assert: that: zbxhostitem_changed is changed +- name: test - attempt to delete previously created zabbix item + community.zabbix.zabbix_item: + name: TestItem + host_name: ExampleHost + state: absent + register: zbxhostitem_existing_delete + +- name: assert that item was deleted + ansible.builtin.assert: + that: zbxhostitem_existing_delete is changed + +- name: test - attempt to delete non-existing zabbix item + community.zabbix.zabbix_item: + name: TestItem + host_name: ExampleHost + state: absent + register: zbxhostitem_missing_delete + +- name: assert that nothing has been changed + ansible.builtin.assert: + that: not zbxhostitem_missing_delete is changed + +- name: test - create new Zabbix master item on host + community.zabbix.zabbix_item: + name: TestItem + host_name: ExampleHost + params: + type: zabbix_agent_active + key: vfs.fs.get + value_type: text + interval: 1m + tags: + - tag: tag + value: value + state: present + register: zbxhostmstitem_new + +- name: assert that item was created + ansible.builtin.assert: + that: zbxhostmstitem_new is changed + - name: create dependent item community.zabbix.zabbix_item: name: TestDependItem @@ -77,16 +134,16 @@ ansible.builtin.assert: that: zbxhostdependitem_new is changed -- name: test - attempt to delete previously created zabbix item +- name: test - attempt to delete previously created zabbix master item community.zabbix.zabbix_item: name: TestItem host_name: ExampleHost state: absent - register: zbxhostitem_existing_delete + register: zbxhostmstitem_existing_delete - name: assert that item was deleted ansible.builtin.assert: - that: zbxhostitem_existing_delete is changed + that: zbxhostmstitem_existing_delete is changed - name: test - attempt to delete dependent item community.zabbix.zabbix_item: @@ -99,17 +156,6 @@ ansible.builtin.assert: that: not zbxhostdependitem_delete is changed -- name: test - attempt to delete non-existing zabbix item - community.zabbix.zabbix_item: - name: TestItem - host_name: ExampleHost - state: absent - register: zbxhostitem_missing_delete - -- name: assert that nothing has been changed - ansible.builtin.assert: - that: not zbxhostitem_missing_delete is changed - - name: test - create new Zabbix item on template with many options set community.zabbix.zabbix_item: name: TestItem diff --git a/tests/integration/targets/test_zabbix_itemprototype/tasks/zabbix_tests.yml b/tests/integration/targets/test_zabbix_itemprototype/tasks/zabbix_tests.yml index 47b696b43..604ecf4d4 100644 --- a/tests/integration/targets/test_zabbix_itemprototype/tasks/zabbix_tests.yml +++ b/tests/integration/targets/test_zabbix_itemprototype/tasks/zabbix_tests.yml @@ -9,7 +9,7 @@ type: zabbix_agent_active key: '{% raw %}vfs.fs.size[{#FSNAME},used]{% endraw %}' value_type: numeric_unsigned - units: B + units: GB interval: 1m tags: - tag: tag @@ -30,7 +30,7 @@ type: zabbix_agent_active key: '{% raw %}vfs.fs.size[{#FSNAME},used]{% endraw %}' value_type: numeric_unsigned - units: B + units: GB interval: 1m tags: - tag: tag @@ -56,6 +56,51 @@ ansible.builtin.assert: that: zbxhostitem_changed is changed +- name: test - attempt to delete previously created zabbix item + community.zabbix.zabbix_itemprototype: + name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}' + discoveryrule_name: ExampleHostRule + host_name: ExampleHost + state: absent + register: zbxhostitem_existing_delete + +- name: assert that item was deleted + ansible.builtin.assert: + that: zbxhostitem_existing_delete is changed + +- name: test - attempt to delete non-existing zabbix item + community.zabbix.zabbix_itemprototype: + name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}' + discoveryrule_name: ExampleHostRule + host_name: ExampleHost + state: absent + register: zbxhostitem_missing_delete + +- name: assert that nothing has been changed + ansible.builtin.assert: + that: not zbxhostitem_missing_delete is changed + +- name: test - create new Zabbix master item on host + community.zabbix.zabbix_itemprototype: + name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}' + discoveryrule_name: ExampleHostRule + host_name: ExampleHost + params: + type: zabbix_agent_active + key: '{% raw %}vfs.fs.size[{#FSNAME},used]{% endraw %}' + value_type: numeric_unsigned + units: B + interval: 1m + tags: + - tag: tag + value: value + state: present + register: zbxhostmstitem_new + +- name: assert that item was created + ansible.builtin.assert: + that: zbxhostmstitem_new is changed + - name: create dependent item community.zabbix.zabbix_itemprototype: name: '{% raw %}{#FSNAME}:TestDependItemPrototype{% endraw %}' @@ -87,11 +132,11 @@ discoveryrule_name: ExampleHostRule host_name: ExampleHost state: absent - register: zbxhostitem_existing_delete + register: zbxhostmstitem_existing_delete - name: assert that item was deleted ansible.builtin.assert: - that: zbxhostitem_existing_delete is changed + that: zbxhostmstitem_existing_delete is changed - name: test - attempt to delete dependent item community.zabbix.zabbix_itemprototype: @@ -105,18 +150,6 @@ ansible.builtin.assert: that: not zbxhostdependitem_delete is changed -- name: test - attempt to delete non-existing zabbix item - community.zabbix.zabbix_itemprototype: - name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}' - discoveryrule_name: ExampleHostRule - host_name: ExampleHost - state: absent - register: zbxhostitem_missing_delete - -- name: assert that nothing has been changed - ansible.builtin.assert: - that: not zbxhostitem_missing_delete is changed - - name: remove host rule community.zabbix.zabbix_discoveryrule: name: ExampleHostRule