Execution
Date
11 Sep 2025 11:22:06 +0100
Duration
00:12:15.26
Controller
ssh-gw-4.layershift.com
User
root
Versions
Ansible
2.16.11
ara
1.7.3 / 1.7.3
Python
3.10.10
Summary
399
Hosts
13
Tasks
5103
Results
1
Plays
1
Files
0
Records
File: /home/ssh-gateway/ansible/kuly/validate_provider_metrics_output.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | --- - name: Validate provider_metrics output from agent360 (Plesk servers only) hosts: all gather_facts: false tasks: - name: Check system information with plesk_info plesk_info: register: si - name: Skip non-Plesk servers ansible.builtin.debug: msg: "⏭️ Skipping — not a Plesk server." when: not si.plesk_found changed_when: false - name: Run agent360 test provider_metrics and clean output ansible.builtin.shell: | set -o pipefail /usr/local/bin/agent360 test provider_metrics 2>/dev/null | egrep -v "provider_metrics:|#" register: metrics_output changed_when: false when: si.plesk_found - name: DEBUG - Show cleaned output ansible.builtin.debug: var: metrics_output.stdout when: si.plesk_found - name: Fail if stdout is empty after filtering ansible.builtin.fail: msg: | ❌ No JSON output after filtering. Command may have failed or output format changed. Try running manually on host: /usr/bin/agent360 test provider_metrics 2>/dev/null | egrep -v "provider_metrics:|#" when: - si.plesk_found - metrics_output.stdout | trim == "" - name: Parse JSON output ansible.builtin.set_fact: metrics_json: "{{ metrics_output.stdout | trim | from_json }}" ignore_errors: true register: parse_result when: si.plesk_found - name: Fail if JSON parsing failed ansible.builtin.fail: msg: | ❌ Output is not valid JSON: {{ metrics_output.stdout | trim }} when: - si.plesk_found - parse_result is failed # Define expected types — only needed if we proceed to validation - name: Define expected field types ansible.builtin.set_fact: expected_types: firewall_up: int http_response_code: int http_response_time_ms: float imunify360_and_fail2ban: int imunify360_license: int imunify360_services: int imunify360_underlicensed: int iptables_entries: int kcare_status: int litespeed_nginx_parallel: int litespeed_running_ok: int monitoring360_ip_dropped: int mysql_free_connections: int mysql_iptables_drop: int mysql_response_time_ms: float oom_kills_since_reboot: int queue_size: int ram_upgrade_required: int recent_oom_kills: int smtp_response_time_ms: float ssh_port_checksum_ok: int time_sync_enabled: int when: si.plesk_found - name: Initialize list for type mismatches ansible.builtin.set_fact: type_mismatches: [] when: si.plesk_found - name: Check each key against expected type ansible.builtin.set_fact: type_mismatches: >- {{ type_mismatches + [{ 'key': item, 'expected': expected_types[item], 'actual_type': metrics_json[item] | type_debug, 'actual_value': metrics_json[item] }] }} when: - si.plesk_found - metrics_json[item] is defined - (expected_types[item] == 'int' and metrics_json[item] | type_debug != 'int') or (expected_types[item] == 'float' and metrics_json[item] | type_debug not in ['float', 'int']) loop: "{{ expected_types.keys() | list }}" - name: Display mismatches if any ansible.builtin.debug: msg: | ⚠️ Type mismatch found: Key: {{ item.key }} Expected: {{ item.expected }} Actual Type: {{ item.actual_type }} Actual Value: {{ item.actual_value | to_nice_json }} loop: "{{ type_mismatches }}" when: - si.plesk_found - type_mismatches | length > 0 loop_control: label: "{{ item.key }}" - name: Fail if any mismatches found ansible.builtin.fail: msg: "❌ Found {{ type_mismatches | length }} type mismatch(es) in provider_metrics output." when: - si.plesk_found - type_mismatches | length > 0 - name: Success message if all OK ansible.builtin.debug: msg: "✅ All metrics have correct types. Output is valid." when: - si.plesk_found - type_mismatches | length == 0 |