Skip to content

Commit

Permalink
add changelog fragment, fix unit tests, add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Lathrop committed May 28, 2024
1 parent c2f314f commit 5450709
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 33 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/pr_1234.yml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions plugins/modules/zabbix_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://<FQDN>/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:
Expand Down
29 changes: 29 additions & 0 deletions plugins/modules/zabbix_itemprototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://<FQDN>/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:
Expand Down
80 changes: 63 additions & 17 deletions tests/integration/targets/test_zabbix_item/tasks/zabbix_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 %}'
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 5450709

Please sign in to comment.