{"id":5777,"sha1":"cc1589d6d3cd8f578d2f09c714a48e50d1cbc2a6","playbook":{"id":3657,"items":{"plays":1,"tasks":1,"results":1,"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:11:50.043761+01:00","ended":"2025-09-11T11:11:51.152775+01:00","duration":"00:00:01.109014","name":null,"ansible_version":"2.16.11","client_version":"1.7.3","python_version":"3.10.10","server_version":"1.7.3","status":"failed","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 (extracting JSON from noisy output)\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\n      ansible.builtin.shell: |\n        /usr/bin/agent360 test provider_metrics 2>&1\n      register: metrics_output\n      changed_when: false\n\n    - name: DEBUG - Show raw command output\n      ansible.builtin.debug:\n        var: metrics_output.stdout\n\n    - name: Extract JSON blob from output \u2014 robust multiline extraction\n      ansible.builtin.set_fact:\n        json_blob: >-\n          {{\n            (\n              (\n                metrics_output.stdout |\n                regex_replace('^\\\\s+', '', multiline=True) |\n                regex_search('(?s)\\\\{.*\\\\}') |\n                first | trim\n              ) if (\n                metrics_output.stdout |\n                regex_search('(?s)\\\\{.*\\\\}')\n              ) else ''\n            )\n          }}\n\n    - name: DEBUG - Extracted JSON blob (may be empty)\n      ansible.builtin.debug:\n        var: json_blob\n\n    - name: Fail if no JSON blob found\n      ansible.builtin.fail:\n        msg: |\n          \u274c No JSON object found in agent360 output. Command may have failed or output format changed.\n          Raw output:\n          {{ metrics_output.stdout | indent(10) }}\n      when: json_blob == \"\"\n\n    - name: Parse extracted JSON\n      ansible.builtin.set_fact:\n        metrics_json: \"{{ json_blob | 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 Extracted blob is not valid JSON:\n          {{ json_blob }}\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:11:50.062132+01:00","updated":"2025-09-11T11:11:50.062165+01:00","path":"/home/ssh-gateway/ansible/kuly/validate_provider_metrics_output.yaml"}