Skip to content

Commit

Permalink
add unit tests for itemprototype
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Lathrop committed May 7, 2024
1 parent b054f20 commit 35bb15b
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- setup_zabbix
30 changes: 30 additions & 0 deletions tests/integration/targets/test_zabbix_itemprototype/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: test - do not run tests for Zabbix < 6.4
meta: end_play
when: zabbix_version is version('6.4', '<')

- block:
# setup stuff
- include_tasks: zabbix_setup.yml

# zabbix_item module tests
- include_tasks: zabbix_tests.yml

# tear down stuff set up earlier
- include_tasks: zabbix_teardown.yml
always:
- name: "cleanup host item if tests failed"
community.zabbix.zabbix_itemprototype:
host_name: ExampleHost
discoveryrule_name: ExampleHostRule
name: TestItem
state: absent
ignore_errors: true

- name: "cleanup template item if tests failed"
community.zabbix.zabbix_itemprototype:
template_name: ExampleTemplate
discoveryrule_name: ExampleTemplateRule
name: TestItem
state: absent
ignore_errors: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---

- name: Create test template
community.zabbix.zabbix_template:
template_name: ExampleTemplate
template_groups:
- Templates

- name: Create test host
community.zabbix.zabbix_host:
host_name: ExampleHost
host_groups:
- Linux servers
- Zabbix servers
link_templates:
- ExampleTemplate
status: enabled
state: present
interfaces:
- type: 1
main: 1
useip: 1
ip: 10.1.1.1
dns: ""
port: "10050"

- name: Create new Zabbix discoveryrule on host
community.zabbix.zabbix_discoveryrule:
name: ExampleHostRule
host_name: ExampleHost
params:
type: zabbix_agent_active
key: 'vfs.fs.discovery'
interval: 1m
enabled: True
state: present
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: remove test host
community.zabbix.zabbix_host:
host_name: ExampleHost
state: absent

- name: remove test template
community.zabbix.zabbix_template:
template_name: ExampleTemplate
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
---

- name: test - create new Zabbix item on host with many options set
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: GB
interval: 1m
tags:
- tag: tag
value: value
state: present
register: zbxhostitem_new

- name: assert that item was created
ansible.builtin.assert:
that: zbxhostitem_new is changed

- name: test - create same Zabbix item group once again
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: GB
interval: 1m
tags:
- tag: tag
value: value
state: present
register: zbxhostitem_existing

- name: assert that nothing has been changed
ansible.builtin.assert:
that: not zbxhostitem_existing is changed

- name: test - update existing zabbix item
community.zabbix.zabbix_itemprototype:
name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}'
discoveryrule_name: ExampleHostRule
host_name: ExampleHost
params:
interval: 2m
state: present
register: zbxhostitem_changed

- name: expect to succeed and that things changed
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: remove host rule
community.zabbix.zabbix_discoveryrule:
name: ExampleHostRule
host_name: ExampleHost
state: absent

- name: Create new Zabbix discoveryrule on template
community.zabbix.zabbix_discoveryrule:
name: ExampleTemplateRule
template_name: ExampleTemplate
params:
type: zabbix_agent_active
key: 'vfs.fs.discovery'
interval: 1m
enabled: True
state: present

- name: test - create new Zabbix item on template with many options set
community.zabbix.zabbix_itemprototype:
name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}'
discoveryrule_name: ExampleTemplateRule
template_name: ExampleTemplate
params:
type: zabbix_agent_active
key: '{% raw %}vfs.fs.size[{#FSNAME},used]{% endraw %}'
value_type: numeric_unsigned
units: GB
interval: 1m
tags:
- tag: tag
value: value
state: present
register: zbxtempitem_new

- name: assert that item was created
ansible.builtin.assert:
that: zbxtempitem_new is changed

- name: test - create same Zabbix item group once again
community.zabbix.zabbix_itemprototype:
name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}'
discoveryrule_name: ExampleTemplateRule
template_name: ExampleTemplate
params:
type: zabbix_agent_active
key: '{% raw %}vfs.fs.size[{#FSNAME},used]{% endraw %}'
value_type: numeric_unsigned
units: GB
interval: 1m
tags:
- tag: tag
value: value
state: present
register: zbxtempitem_existing

- name: assert that nothing has been changed
ansible.builtin.assert:
that: not zbxtempitem_existing is changed

- name: test - update existing zabbix item
community.zabbix.zabbix_itemprototype:
name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}'
discoveryrule_name: ExampleTemplateRule
template_name: ExampleTemplate
params:
interval: 2m
state: present
register: zbxtempitem_changed

- name: expect to succeed and that things changed
ansible.builtin.assert:
that: zbxtempitem_changed is changed

- name: test - attempt to delete previously created zabbix item
community.zabbix.zabbix_itemprototype:
name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}'
discoveryrule_name: ExampleTemplateRule
template_name: ExampleTemplate
state: absent
register: zbxtempitem_existing_delete

- name: assert that item was deleted
ansible.builtin.assert:
that: zbxtempitem_existing_delete is changed

- name: test - attempt to delete non-existing zabbix item
community.zabbix.zabbix_itemprototype:
name: '{% raw %}{#FSNAME}:TestItemPrototype{% endraw %}'
discoveryrule_name: ExampleTemplateRule
template_name: ExampleTemplate
state: absent
register: zbxtempitem_missing_delete

- name: assert that nothing has been changed
ansible.builtin.assert:
that: not zbxtempitem_missing_delete is changed

0 comments on commit 35bb15b

Please sign in to comment.