diff options
Diffstat (limited to 'ansible_collections/community/zabbix/tests/integration/targets')
11 files changed, 733 insertions, 0 deletions
diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_correlation/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_correlation/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_correlation/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_correlation/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_correlation/tasks/main.yml new file mode 100644 index 000000000..d893cbc34 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_correlation/tasks/main.yml @@ -0,0 +1,328 @@ +--- +- name: test - create simple correlation + community.zabbix.zabbix_correlation: + name: new event tag correlation + filter: + evaltype: and_or + conditions: + - type: new_event_tag + tag: ok + operations: + - type: close_old_events + register: zbxcorrelation_create + +- name: assert that correlation was created + ansible.builtin.assert: + that: + - zbxcorrelation_create.changed is sameas True + +- name: test - update simple correlation (without changes) + community.zabbix.zabbix_correlation: + name: new event tag correlation + filter: + evaltype: and_or + conditions: + - type: new_event_tag + tag: ok + operations: + - type: close_old_events + register: zbxcorrelation_create + +- name: assert that correlation was not updated + ansible.builtin.assert: + that: + - zbxcorrelation_create.changed is sameas False + +- name: test - update simple correlation + community.zabbix.zabbix_correlation: + name: new event tag correlation + filter: + evaltype: and_or + conditions: + - type: new_event_tag + tag: ng + operations: + - type: close_old_events + register: zbxcorrelation_create + +- name: assert that correlation was updated + ansible.builtin.assert: + that: + - zbxcorrelation_create.changed is sameas True + +- name: test - delete simple correlation + community.zabbix.zabbix_correlation: + name: new event tag correlation + state: absent + register: zbxcorrelation_delete + +- name: assert that correlation was deleted + ansible.builtin.assert: + that: + - zbxcorrelation_delete.changed is sameas True + +- name: prepare - create hostgroup + community.zabbix.zabbix_group: + host_groups: + - correlation_group_A + - correlation_group_B + state: present + register: zbxgroup_create + +- name: test - create custom_expression correlation + community.zabbix.zabbix_correlation: + name: new host group correlation + description: a custom description + filter: + evaltype: custom_expression + formula: A or B + conditions: + - type: new_event_host_group + hostgroup: correlation_group_A + operator: not_equal + formulaid: A + - type: new_event_host_group + hostgroup: correlation_group_B + operator: not_equal + formulaid: B + operations: + - type: close_old_events + register: zbxcorrelation_create + +- name: assert that correlation was created + ansible.builtin.assert: + that: + - zbxcorrelation_create.changed is sameas True + +- name: test - create custom_expression correlation (again) + community.zabbix.zabbix_correlation: + name: new host group correlation + description: a custom description + filter: + evaltype: custom_expression + formula: A or B + conditions: + - type: new_event_host_group + hostgroup: correlation_group_A + operator: not_equal + formulaid: A + - type: new_event_host_group + hostgroup: correlation_group_B + operator: not_equal + formulaid: B + operations: + - type: close_old_events + register: zbxcorrelation_create + +- name: assert that correlation was not updated + ansible.builtin.assert: + that: + - zbxcorrelation_create.changed is sameas False + +- name: test - delete custom_expression correlation + community.zabbix.zabbix_correlation: + name: new host group correlation + state: absent + register: zbxcorrelation_delete + +- name: assert that correlation was deleted + ansible.builtin.assert: + that: + - zbxcorrelation_delete.changed is sameas True + +- name: cleanup - delete hostgroup + community.zabbix.zabbix_group: + host_groups: + - correlation_group_A + - correlation_group_B + state: absent + register: zbxgroup_delete + +- name: test - create correlation with old_event_tag condition + community.zabbix.zabbix_correlation: + name: tag correlation + filter: + evaltype: and_or + conditions: + - type: old_event_tag + tag: old_tag + operations: + - type: close_old_events + - type: close_new_event + register: zbxcorrelation_create + +- name: assert that correlation was created + ansible.builtin.assert: + that: + - zbxcorrelation_create.changed is sameas True + +- name: test - update correlation with new_event_tag condition + community.zabbix.zabbix_correlation: + name: tag correlation + filter: + evaltype: and_or + conditions: + - type: new_event_tag + tag: new_tag + operations: + - type: close_old_events + - type: close_new_event + register: zbxcorrelation_update + +- name: assert that correlation was updated + ansible.builtin.assert: + that: + - zbxcorrelation_update.changed is sameas True + +- name: test - update correlation with event_tag_pair condition + community.zabbix.zabbix_correlation: + name: tag correlation + filter: + evaltype: and_or + conditions: + - type: event_tag_pair + oldtag: oldtag_pair + newtag: newtag_pair + operations: + - type: close_old_events + - type: close_new_event + register: zbxcorrelation_update + +- name: assert that correlation was updated + ansible.builtin.assert: + that: + - zbxcorrelation_update.changed is sameas True + +- name: test - update correlation with old_event_tag_value condition + community.zabbix.zabbix_correlation: + name: tag correlation + filter: + evaltype: and_or + conditions: + - type: old_event_tag_value + tag: old_tag_value + value: old + operator: equal + operations: + - type: close_old_events + - type: close_new_event + register: zbxcorrelation_update + +- name: assert that correlation was updated + ansible.builtin.assert: + that: + - zbxcorrelation_update.changed is sameas True + +- name: test - update correlation with new_event_tag_value condition + community.zabbix.zabbix_correlation: + name: tag correlation + filter: + evaltype: and_or + conditions: + - type: new_event_tag_value + tag: new_tag_value + value: new + operator: equal + operations: + - type: close_old_events + - type: close_new_event + register: zbxcorrelation_update + +- name: assert that correlation was updated + ansible.builtin.assert: + that: + - zbxcorrelation_update.changed is sameas True + +- name: test - delete tag correlation + community.zabbix.zabbix_correlation: + name: tag correlation + state: absent + register: zbxcorrelation_delete + +- name: assert that correlation was deleted + ansible.builtin.assert: + that: + - zbxcorrelation_delete.changed is sameas True + +- name: prepare - create hostgroup + community.zabbix.zabbix_group: + host_groups: + - correlation_group + state: present + register: zbxgroup_create + +- name: test - create host group correlation with wrong operator (like) + community.zabbix.zabbix_correlation: + name: new host group correlation + description: a custom description + filter: + evaltype: and_or + conditions: + - type: new_event_host_group + hostgroup: correlation_group + operator: like + operations: + - type: close_old_events + ignore_errors: yes + register: zbxcorrelation_create + +- name: assert that correlation was failed + ansible.builtin.assert: + that: + - zbxcorrelation_create is failed + +- name: test - create host group correlation with wrong operator (not_like) + community.zabbix.zabbix_correlation: + name: new host group correlation + description: a custom description + filter: + evaltype: and_or + conditions: + - type: new_event_host_group + hostgroup: correlation_group + operator: not_like + operations: + - type: close_old_events + ignore_errors: yes + register: zbxcorrelation_create + +- name: assert that correlation was failed + ansible.builtin.assert: + that: + - zbxcorrelation_create is failed + +- name: prepare - delete hostgroup + community.zabbix.zabbix_group: + host_groups: + - correlation_group + state: absent + register: zbxgroup_delete + +- name: test - create tag correlation with wrong formulaid + community.zabbix.zabbix_correlation: + name: new tag correlation + description: a custom description + filter: + evaltype: custom_expression + formula: a + conditions: + - type: new_event_tag_value + tag: new_tag_value + value: new + operator: equal + formulaid: a + operations: + - type: close_old_events + ignore_errors: yes + register: zbxcorrelation_create + +- name: assert that correlation was failed + ansible.builtin.assert: + that: + - zbxcorrelation_create is failed + +- name: test - delete custom_expression correlation + community.zabbix.zabbix_correlation: + name: new tag correlation + state: absent + register: zbxcorrelation_delete diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml index a4829a051..20246a16b 100644 --- a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml @@ -1348,6 +1348,78 @@ ansible.builtin.assert: that: zbx_host_create_interfaceless is not changed +- name: "test: attempt to delete host created earlier" + community.zabbix.zabbix_host: + host_name: ExampleHost + state: absent + register: zabbix_host1 + +- name: deleting a host is a change, right? + ansible.builtin.assert: + that: + - "zabbix_host1 is changed" + +- name: "test: create host with IPMI values" + community.zabbix.zabbix_host: + host_name: ExampleHost + host_groups: + - Linux servers + - Zabbix servers + ipmi_authtype: 1 + ipmi_privilege: 1 + ipmi_username: "test" + ipmi_password: "test" + register: zabbix_ipmi_host + +- name: expect to succeed and that things have changed + ansible.builtin.assert: + that: + - "zabbix_ipmi_host is changed" + +- name: "test: update inventory of the created host" + community.zabbix.zabbix_host: + host_name: ExampleHost + inventory_mode: manual + inventory_zabbix: + notes: "Update inventory" + register: zabbix_ipmi_host + +- name: expect to succeed and that things have changed + ansible.builtin.assert: + that: + - "zabbix_ipmi_host is changed" + +- name: "test: create host with IPMI values without changes" + community.zabbix.zabbix_host: + host_name: ExampleHost + ipmi_authtype: 1 + ipmi_privilege: 1 + ipmi_username: "test" + ipmi_password: "test" + register: zabbix_ipmi_host + +- name: expect to succeed and that things have not changed + ansible.builtin.assert: + that: + - "zabbix_ipmi_host is not changed" + +- name: "test: create host with host group(empty list)" + community.zabbix.zabbix_host: + host_name: ExampleHost + visible_name: ExampleName + description: My ExampleHost Description + host_groups: [] + status: disabled + state: present + ignore_errors: true + register: zbx_host_create_hostgroup_empty_list + +- name: expect to fail updating + ansible.builtin.assert: + that: + - zbx_host_create_hostgroup_empty_list is failed + - zbx_host_create_hostgroup_empty_list.msg == "host_groups must be not empty list." + - name: "cleanup" community.zabbix.zabbix_host: host_name: ExampleHost diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/tasks/main.yml index 1b9c6f6bd..86d511d36 100644 --- a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/tasks/main.yml +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/tasks/main.yml @@ -273,6 +273,56 @@ # that: # - update_maintenance_host_tags.changed is sameas false +- name: "test - Create maintenance with an active_since param" + community.zabbix.zabbix_maintenance: + name: maintenance + host_name: example + active_since: "1979-09-19" + state: present + register: create_maintenance_active_since_result + +- ansible.builtin.assert: + that: + - create_maintenance_active_since_result.changed is sameas true + +- name: "test - Create maintenance with a active_since param(again - expectations: false change will occur)" + community.zabbix.zabbix_maintenance: + name: maintenance + host_name: example + active_since: "1979-09-19" + state: present + register: create_maintenance_active_since_again_result + +- ansible.builtin.assert: + that: + - create_maintenance_active_since_again_result.changed is sameas false + +- name: "test - Create maintenance with an active_till param" + community.zabbix.zabbix_maintenance: + name: maintenance + host_name: example + active_since: "1979-09-19 00:00" + active_till: "1979-09-19 23:59" + state: present + register: create_maintenance_active_till_result + +- ansible.builtin.assert: + that: + - create_maintenance_active_till_result.changed is sameas true + +- name: "test - Create maintenance with a active_till param(again - expectations: false change will occur)" + community.zabbix.zabbix_maintenance: + name: maintenance + host_name: example + active_since: "1979-09-19 00:00" + active_till: "1979-09-19 23:59" + state: present + register: create_maintenance_active_till_again_result + +- ansible.builtin.assert: + that: + - create_maintenance_active_till_again_result.changed is sameas false + - name: "test - Delete maintenance" community.zabbix.zabbix_maintenance: name: maintenance diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/tasks/main.yml index a49166d37..1ba2f6669 100644 --- a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/tasks/main.yml +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/tasks/main.yml @@ -114,6 +114,29 @@ - ansible.builtin.assert: that: zbxmediatype_reset.changed is sameas True + - name: test - check email mediatype content_type for html default + community.zabbix.zabbix_mediatype: + content_type: "html" + register: zbxmediatype_verif + + - ansible.builtin.assert: + that: zbxmediatype_verif.changed is sameas False + + - name: test - update email mediatype content_type to plaintext + community.zabbix.zabbix_mediatype: + content_type: "plaintext" + register: zbxmediatype_verif + + - ansible.builtin.assert: + that: zbxmediatype_verif.changed is sameas True + + - name: test - reset email mediatype content_type to default + community.zabbix.zabbix_mediatype: + register: zbxmediatype_reset + + - ansible.builtin.assert: + that: zbxmediatype_reset.changed is sameas True + - name: test - update email mediatype concurrent settings community.zabbix.zabbix_mediatype: max_sessions: 99 diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service_info/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service_info/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service_info/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service_info/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service_info/tasks/main.yml new file mode 100644 index 000000000..77c244df8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service_info/tasks/main.yml @@ -0,0 +1,57 @@ +--- +- name: test - Create new Zabbix service + community.zabbix.zabbix_service: + name: ExampleService + description: ExampleService + sortorder: 0 + propagation_rule: as_is + propagation_value: not_classified + algorithm: most_crit_of_child_serv + register: create_service_result + +- ansible.builtin.assert: + that: + - create_service_result.changed is sameas true + +- name: test - Create new Zabbix child service + community.zabbix.zabbix_service: + name: ExampleChildService + description: ExampleChildService + sortorder: 0 + propagation_rule: as_is + propagation_value: not_classified + parents: ExampleService + problem_tags: + - tag: testtag + value: test + register: create_child_result + +- ansible.builtin.assert: + that: + - create_child_result.changed is sameas true + +- name: test - Get zabbix service information + community.zabbix.zabbix_service_info: + service_name: ExampleService + register: get_service_info_result + +- ansible.builtin.assert: + that: + - get_service_info_result["zabbix_service"].name == "ExampleService" + - get_service_info_result["zabbix_service"].children | length > 0 + - get_service_info_result["zabbix_service"].children[0].name == "ExampleChildService" + - get_service_info_result["zabbix_service"].propagation_rule == "0" + - get_service_info_result["zabbix_service"].propagation_value == "0" + - get_service_info_result["zabbix_service"].sortorder == "0" + +- name: test - cleanup test Zabbix child service + community.zabbix.zabbix_service: + state: absent + sortorder: 0 + name: ExampleChildService + +- name: test - cleanup test Zabbix service + community.zabbix.zabbix_service: + state: absent + sortorder: 0 + name: ExampleService diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template4_60_higher.json b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template4_60_higher.json new file mode 100644 index 000000000..7d4c37a52 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template4_60_higher.json @@ -0,0 +1,49 @@ +{ + "zabbix_export": { + "version": "6.0", + "date": "2024-01-04T18:26:37Z", + "groups": [ + { + "uuid": "7df96b18c230490a9a0a9e2307226338", + "name": "Templates" + }, + { + "uuid": "a571c0d144b14fd4a87a9d9b2aa9fcd6", + "name": "Templates/Applications" + } + ], + "templates": [ + { + "uuid": "cd837ef0edb14e4e875f409bc90af546", + "template": "ExampleTemplate", + "name": "ExampleTemplate", + "templates": [ + { + "name": "FTP Service" + }, + { + "name": "Zabbix proxy health" + } + ], + "groups": [ + { + "name": "Templates" + }, + { + "name": "Templates/Applications" + } + ], + "macros": [ + { + "macro": "{$EXAMPLE_MACRO1}", + "value": "1000" + }, + { + "macro": "{$EXAMPLE_MACRO2}", + "value": "text" + } + ] + } + ] + } +} diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template4_60_higher.xml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template4_60_higher.xml new file mode 100644 index 000000000..3d423c692 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template4_60_higher.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<zabbix_export> + <version>6.0</version> + <date>2024-01-04T18:26:29Z</date> + <groups> + <group> + <uuid>7df96b18c230490a9a0a9e2307226338</uuid> + <name>Templates</name> + </group> + <group> + <uuid>a571c0d144b14fd4a87a9d9b2aa9fcd6</uuid> + <name>Templates/Applications</name> + </group> + </groups> + <templates> + <template> + <uuid>cd837ef0edb14e4e875f409bc90af546</uuid> + <template>ExampleTemplate</template> + <name>ExampleTemplate</name> + <templates> + <template> + <name>FTP Service</name> + </template> + <template> + <name>Zabbix proxy health</name> + </template> + </templates> + <groups> + <group> + <name>Templates</name> + </group> + <group> + <name>Templates/Applications</name> + </group> + </groups> + <macros> + <macro> + <macro>{$EXAMPLE_MACRO1}</macro> + <value>1000</value> + </macro> + <macro> + <macro>{$EXAMPLE_MACRO2}</macro> + <value>text</value> + </macro> + </macros> + </template> + </templates> +</zabbix_export> diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template4_60_higher.yaml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template4_60_higher.yaml new file mode 100644 index 000000000..0112b1fc7 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template4_60_higher.yaml @@ -0,0 +1,23 @@ +zabbix_export: + version: '6.0' + date: '2024-01-04T18:26:17Z' + groups: + - uuid: 7df96b18c230490a9a0a9e2307226338 + name: Templates + - uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6 + name: Templates/Applications + templates: + - uuid: cd837ef0edb14e4e875f409bc90af546 + template: ExampleTemplate + name: ExampleTemplate + templates: + - name: 'FTP Service' + - name: 'Zabbix proxy health' + groups: + - name: Templates + - name: Templates/Applications + macros: + - macro: '{$EXAMPLE_MACRO1}' + value: '1000' + - macro: '{$EXAMPLE_MACRO2}' + value: text diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/main.yml index 69aabe6b0..ce02916ee 100644 --- a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/main.yml +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/main.yml @@ -370,6 +370,83 @@ - delete_zabbix_template_result.changed is sameas false # +# template_file_context parameter +# + +- name: Import Zabbix template from a file using configuration.importcompare api + block: + - name: Import Zabbix template from YAML file. + community.zabbix.zabbix_template: + template_yaml: "{{ lookup('file', 'template4_60_higher.yaml') }}" + state: present + register: import_template_yaml + + - ansible.builtin.assert: + that: + - import_template_xml.changed is sameas true + + - name: Import Zabbix same template from XML file. + community.zabbix.zabbix_template: + template_xml: "{{ lookup('file', 'template4_60_higher.xml') }}" + state: present + register: import_same_template_xml + + - ansible.builtin.assert: + that: + - import_same_template_xml.changed is sameas false + + - name: Delete Zabbix template. + community.zabbix.zabbix_template: + template_name: ExampleTemplate + state: absent + register: delete_zabbix_template_result + + - ansible.builtin.assert: + that: + - delete_zabbix_template_result.changed is sameas true + + - name: Import Zabbix same template from XML file (after deleting template). + community.zabbix.zabbix_template: + template_xml: "{{ lookup('file', 'template4_60_higher.xml') }}" + state: present + register: import_same_template_xml + + - ansible.builtin.assert: + that: + - import_same_template_xml.changed is sameas true + + - name: Import Zabbix same template from JSON file. + community.zabbix.zabbix_template: + template_json: "{{ lookup('file', 'template4_60_higher.json') }}" + state: present + register: import_same_template_json + + - ansible.builtin.assert: + that: + - import_same_template_json.changed is sameas false + + - name: Delete Zabbix template. + community.zabbix.zabbix_template: + template_name: ExampleTemplate + state: absent + register: delete_zabbix_template_result + + - ansible.builtin.assert: + that: + - delete_zabbix_template_result.changed is sameas true + + - name: Delete Zabbix template (idempotency check). + community.zabbix.zabbix_template: + template_name: ExampleTemplate + state: absent + register: delete_zabbix_template_result + + - ansible.builtin.assert: + that: + - delete_zabbix_template_result.changed is sameas false + + +# # Unicode stuff # |