{"id":5771,"sha1":"2334f864e192f3b973fe5dc554c22be3c908cbfc","playbook":{"id":3651,"items":{"plays":1,"tasks":1,"results":0,"hosts":0,"files":1,"records":0},"arguments":{"version":null,"verbosity":0,"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/hosts"],"listhosts":false,"subset":null,"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"}],"started":"2025-09-11T10:59:24.538994+01:00","ended":"2025-09-11T10:59:24.921838+01:00","duration":"00:00:00.382844","name":null,"ansible_version":"2.16.11","client_version":"1.7.3","python_version":"3.10.10","server_version":"1.7.3","status":"expired","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\n  hosts: all\n  gather_facts: no\n  vars:\n    # Define expected types for each key\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          # NOT list\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      command: agent360 test provider_metrics\n      register: metrics_output\n      changed_when: false\n\n    - name: Parse JSON output\n      set_fact:\n        metrics_json: \"{{ metrics_output.stdout | from_json }}\"\n\n    - name: Initialize list for type mismatches\n      set_fact:\n        type_mismatches: []\n\n    - name: Check each key against expected type\n      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\n      loop: \"{{ expected_types.keys() | list }}\"\n\n    - name: Display mismatches if any\n      debug:\n        msg: |\n          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 (optional)\n      fail:\n        msg: \"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      debug:\n        msg: \"\u2705 All metrics have correct types.\"\n      when: type_mismatches | length == 0\n","created":"2025-09-11T10:59:24.558062+01:00","updated":"2025-09-11T10:59:24.558083+01:00","path":"/home/ssh-gateway/ansible/kuly/validate_provider_metrics_output.yaml"}