# Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. --- # Testcase OMNIA_1.2_Grafana_TC_005 # Test case to Validate syslog.log on grafana loki - name: OMNIA_1.2_Grafana_TC_005 hosts: localhost connection: local tags: TC_005 gather_subset: - 'min' vars_files: - ../input_params/base_vars.yml - test_vars/test_grafana_vars.yml tasks: - name: Check login_vars file is encrypted command: cat {{ login_vars_path }} changed_when: false register: config_content no_log: true tags: always - name: Validate login file is encypted or not assert: that: "'$ANSIBLE_VAULT;' in config_content.stdout" fail_msg: "{{ login_vars_fail_msg }}" success_msg: "{{ login_vars_success_msg }}" - name: Installing jq (JSON Query) package: name: "{{ test_package }}" state: present - name: Decrpyt login_vars.yml command: >- ansible-vault decrypt {{ login_vars_path }} --vault-password-file {{ login_vars_vault_path }} changed_when: false when: "'$ANSIBLE_VAULT;' in config_content.stdout" no_log: true tags: always - name: Include variable file login_vars.yml include_vars: "{{ login_vars_path }}" no_log: true tags: always - name: Get auth string shell: echo -n {{ grafana_username }}_{{ grafana_password }} | sha256sum register: auth_string_output changed_when: false failed_when: false no_log: true tags: always - name: Set the grafana username and password set_fact: grafana_username: "{{ grafana_username }}" grafana_password: "{{ grafana_password }}" auth_string: "{{ auth_string_output }}" no_log: true tags: always - name: Encypt login file command: >- ansible-vault encrypt {{ login_vars_path }} --vault-password-file {{ login_vars_vault_path }} changed_when: false no_log: true tags: always - name: Fetch Grafana Cluster IP shell: | kubectl get svc -n grafana -o json | jq '.items[] | select(.metadata.name == "loki") | "\(.spec.clusterIP)"' register: grafanaloki_ip_info - name: Ping the grafana device to validate connectivity command: ping -c1 {{ grafanaloki_ip_info.stdout[1:-1] }} register: validate_grafanaloki changed_when: false failed_when: false - name: Validate the Grafana Loki connectivity assert: that: - "'ping' in validate_grafanaloki.stdout" success_msg: "{{ connectivity_success_msg }}" fail_msg: "{{ connectivity_failure_msg }}" # Testcase OMNIA_1.2_Grafana_TC_005 # Test case to Validate syslog.log on grafana loki - name: Execute get syslog shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="syslog"}' | jq register: syslog_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if syslog status is success or not assert: that: - syslog_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ syslog_success_msg }}" fail_msg: "{{ syslog_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_006 # Test case to Validate Grafana omnia.log - name: Execute get job is omnia shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="Omnia"}' | jq register: omnia_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if omnia log status is success or not assert: that: - omnia_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ omnia_success_msg }}" fail_msg: "{{ omnia_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_007(-) # Test case to Validate Rocky OS package log - name: Execute get job is Package Rocky shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="Package Rocky.log"}' | jq register: package_rocky_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if Package Rocky log status is success or not assert: that: - package_rocky_info.stdout.status | regex_search( "{{ success }}" ) - package_rocky_info.stdout.data.result != None success_msg: "{{ package_rocky_success_msg }}" fail_msg: "{{ package_rocky_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_007 # Test case to Validate Rocky OS package log - name: Execute get job is Package Rocky shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="Package Rocky"}' | jq register: package_rocky_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if Package Rocky log status is success or not assert: that: - package_rocky_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ package_rocky_success_msg }}" fail_msg: "{{ package_rocky_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_008 # Test case to Validate K8s pods log - name: Execute get job is K8s pods shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="K8s pods"}' | jq register: k8s_pods_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if k8s pods log status is success or not assert: that: - k8s_pods_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ k8s_pods_success_msg }}" fail_msg: "{{ k8s_pods_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_009 # Test case to Validate cron log - name: Execute get job is cron logs shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="cron"}' | jq register: cron_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if cron log status is success or not assert: that: - cron_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ cron_success_msg }}" fail_msg: "{{ cron_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_010 # Test case to Validate Vars log - name: Execute get job is var logs shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="varlogs"}' | jq register: varlogs_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if var log status is success or not assert: that: - varlogs_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ varlogs_success_msg }}" fail_msg: "{{ varlogs_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_011 # Test case to Validate Secure log - name: Execute get job is secure logs shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="secure"}' | jq register: secure_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if secure log status is success or not assert: that: - secure_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ secure_success_msg }}" fail_msg: "{{ secure_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_012 # Test case to Validate audit log - name: Execute get job is audit logs shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="audit"}' | jq register: audit_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if audit log status is success or not assert: that: - audit_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ audit_success_msg }}" fail_msg: "{{ audit_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_013 # Test case to Validate sssd log - name: Execute get job is sssd logs shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="sssd"}' | jq register: sssd_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if sssd log status is success or not assert: that: - sssd_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ sssd_success_msg }}" fail_msg: "{{ sssd_fail_msg }}" # Testcase OMNIA_1.2_Grafana_TC_014 # Test case to Validate Grafana - /var/log/omnia.log - name: Execute get job is Grafana - /var/log/omnia.log logs shell: | curl -G -s "http://{{ grafanaloki_ip_info.stdout[1:-1] }}:{{ grafana_loki_port }}/loki/api/v1/query" --data-urlencode 'query={job="varlogs",filename="/var/log/omnia.log"}' | jq register: varlog_omnia_info when: "'ping' in validate_grafanaloki.stdout" - name: Verify if varlog for file omnio.log status is success or not assert: that: - varlog_omnia_info.stdout.status | regex_search( "{{ success }}" ) success_msg: "{{ varlog_omnia_success_msg }}" fail_msg: "{{ varlog_omnia_fail_msg }}"