-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Lathrop
committed
May 7, 2024
1 parent
b054f20
commit 35bb15b
Showing
5 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
tests/integration/targets/test_zabbix_itemprototype/meta/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
dependencies: | ||
- setup_zabbix |
30 changes: 30 additions & 0 deletions
30
tests/integration/targets/test_zabbix_itemprototype/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
36 changes: 36 additions & 0 deletions
36
tests/integration/targets/test_zabbix_itemprototype/tasks/zabbix_setup.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
9 changes: 9 additions & 0 deletions
9
tests/integration/targets/test_zabbix_itemprototype/tasks/zabbix_teardown.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
178 changes: 178 additions & 0 deletions
178
tests/integration/targets/test_zabbix_itemprototype/tasks/zabbix_tests.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |