{"id":5782,"sha1":"84e9353510601feccb8fc811a036424b61d38b98","playbook":{"id":3662,"items":{"plays":1,"tasks":10,"results":10,"hosts":1,"files":1,"records":0},"arguments":{"version":null,"verbosity":2,"private_key_file":"/home/ssh-gateway/.ssh/id_rsa","remote_user":"root","connection":"ssh","timeout":null,"ssh_common_args":null,"sftp_extra_args":null,"scp_extra_args":null,"ssh_extra_args":null,"ask_pass":false,"connection_password_file":null,"force_handlers":false,"flush_cache":false,"become":false,"become_method":"sudo","become_user":null,"become_ask_pass":false,"become_password_file":null,"tags":["all"],"skip_tags":[],"check":false,"diff":false,"inventory":["/home/ssh-gateway/ansible/kuly/bash-kvm-inventory-prod.sh"],"listhosts":false,"subset":"versatile-chipmunk.man-1.vm.plesk-server.com","extra_vars":"Not saved by ARA as configured by 'ignored_arguments'","vault_ids":[],"ask_vault_pass":false,"vault_password_files":[],"forks":20,"module_path":null,"syntax":false,"listtasks":false,"listtags":false,"step":false,"start_at_task":null,"args":["validate_provider_metrics_output.yaml"]},"labels":[{"id":1,"name":"remote_user:root"},{"id":2,"name":"check:False"},{"id":3,"name":"tags:all"},{"id":80,"name":"subset:versatile-chipmunk.man-1.vm.plesk-server.com"}],"started":"2025-09-11T11:17:21.247812+01:00","ended":"2025-09-11T11:17:27.282729+01:00","duration":"00:00:06.034917","name":null,"ansible_version":"2.16.11","client_version":"1.7.3","python_version":"3.10.10","server_version":"1.7.3","status":"completed","path":"/home/ssh-gateway/ansible/kuly/validate_provider_metrics_output.yaml","controller":"ssh-gw-4.layershift.com","user":"root"},"content":"---\n- name: Validate provider_metrics output from agent360 (using clean shell filter)\n  hosts: all\n  gather_facts: false\n  vars:\n    expected_types:\n      firewall_up: int\n      http_response_code: int\n      http_response_time_ms: float\n      imunify360_and_fail2ban: int\n      imunify360_license: int\n      imunify360_services: int\n      imunify360_underlicensed: int\n      iptables_entries: int\n      kcare_status: int\n      litespeed_nginx_parallel: int\n      litespeed_running_ok: int\n      monitoring360_ip_dropped: int\n      mysql_free_connections: int\n      mysql_iptables_drop: int\n      mysql_response_time_ms: float\n      oom_kills_since_reboot: int\n      queue_size: int\n      ram_upgrade_required: int\n      recent_oom_kills: int\n      smtp_response_time_ms: float\n      ssh_port_checksum_ok: int\n      time_sync_enabled: int\n\n  tasks:\n    - name: Run agent360 test provider_metrics and clean output\n      ansible.builtin.shell: |\n        /usr/local/bin/agent360 test provider_metrics 2>/dev/null | egrep -v \"provider_metrics:|#\"\n      register: metrics_output\n      changed_when: false\n\n    - name: DEBUG - Show cleaned output\n      ansible.builtin.debug:\n        var: metrics_output.stdout\n\n    - name: Fail if stdout is empty after filtering\n      ansible.builtin.fail:\n        msg: |\n          \u274c No JSON output after filtering. Command may have failed or output format changed.\n          Try running manually on host:\n          /usr/bin/agent360 test provider_metrics 2>/dev/null | egrep -v \"provider_metrics:|#\"\n      when: metrics_output.stdout | trim == \"\"\n\n    - name: Parse JSON output\n      ansible.builtin.set_fact:\n        metrics_json: \"{{ metrics_output.stdout | trim | from_json }}\"\n      ignore_errors: yes\n      register: parse_result\n\n    - name: Fail if JSON parsing failed\n      ansible.builtin.fail:\n        msg: |\n          \u274c Output is not valid JSON:\n          {{ metrics_output.stdout | trim }}\n      when: parse_result is failed\n\n    - name: Initialize list for type mismatches\n      ansible.builtin.set_fact:\n        type_mismatches: []\n\n    - name: Check each key against expected type\n      ansible.builtin.set_fact:\n        type_mismatches: >-\n          {{\n            type_mismatches + [{\n              'key': item,\n              'expected': expected_types[item],\n              'actual_type': metrics_json[item] | type_debug,\n              'actual_value': metrics_json[item]\n            }]\n          }}\n      when:\n        - metrics_json[item] is defined\n        - (expected_types[item] == 'int' and metrics_json[item] | type_debug != 'int') or\n          (expected_types[item] == 'float' and metrics_json[item] | type_debug not in ['float', 'int'])\n      loop: \"{{ expected_types.keys() | list }}\"\n\n    - name: Display mismatches if any\n      ansible.builtin.debug:\n        msg: |\n          \u26a0\ufe0f Type mismatch found:\n          Key: {{ item.key }}\n          Expected: {{ item.expected }}\n          Actual Type: {{ item.actual_type }}\n          Actual Value: {{ item.actual_value | to_nice_json }}\n      loop: \"{{ type_mismatches }}\"\n      when: type_mismatches | length > 0\n      loop_control:\n        label: \"{{ item.key }}\"\n\n    - name: Fail if any mismatches found\n      ansible.builtin.fail:\n        msg: \"\u274c Found {{ type_mismatches | length }} type mismatch(es) in provider_metrics output.\"\n      when: type_mismatches | length > 0\n\n    - name: Success message if all OK\n      ansible.builtin.debug:\n        msg: \"\u2705 All metrics have correct types. Output is valid.\"\n      when: type_mismatches | length == 0\n","created":"2025-09-11T11:17:21.262679+01:00","updated":"2025-09-11T11:17:21.262700+01:00","path":"/home/ssh-gateway/ansible/kuly/validate_provider_metrics_output.yaml"}