From b9327aa3515f5ca206330d7350d32fcd8c762ed4 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Thu, 5 Dec 2024 13:09:42 +0100 Subject: [PATCH] agent_state_summary: Properly handle nodes without reports/responses previously, when running `pe_status_check::agent_state_summary`, the result didn't only contain the certnames, but also additional data:` without this patch (one unresponsive node, one without reports at all): ```json { "noop": [ ], "corrective_changes": [ ], "used_cached_catalog": [ ], "failed": [ ], "changed": [ ], "unresponsive": [ { "certname": "pe.tim", "latest_report_noop": false, "latest_report_corrective_change": false, "cached_catalog_status": "not_used", "latest_report_status": "unchanged", "report_timestamp": "2024-12-05T13:41:55.483Z" } ], "no_report": [ "agent.tim" ], "responsive": [ "pe.tim" ], "unhealthy": [ { "certname": "pe.tim", "latest_report_noop": false, "latest_report_corrective_change": false, "cached_catalog_status": "not_used", "latest_report_status": "unchanged", "report_timestamp": "2024-12-05T13:41:55.483Z" }, "agent.tim" ], "unhealthy_counter": 2, "healthy_counter": 1, "total_counter": 2 } ``` To reproduce, do on the agent: ``` puppet ssl submit_request puppet ssl download_cert puppet facts upload ``` Now on the puppetserver: ``` puppet query nodes[certname,report_timestamp]{} ``` gives you: ```json [ { "certname": "pe.tim", "report_timestamp": "2024-12-05T13:11:55.884Z" }, { "certname": "agent.tim", "report_timestamp": null } ] ``` with this patch: ```json { "noop": [ ], "corrective_changes": [ ], "used_cached_catalog": [ ], "failed": [ ], "changed": [ ], "unresponsive": [ "pe.tim" ], "no_report": [ "agent.tim" ], "responsive": [ ], "unhealthy": [ "pe.tim", "agent.tim" ], "unhealthy_counter": 2, "healthy_counter": 0, "total_counter": 2 } ``` --- plans/agent_state_summary.pp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plans/agent_state_summary.pp b/plans/agent_state_summary.pp index c575e1cd..bab59197 100644 --- a/plans/agent_state_summary.pp +++ b/plans/agent_state_summary.pp @@ -24,10 +24,12 @@ # check if the last report is older than X minutes, for all nodes that have a report $current_timestamp = Integer(Timestamp().strftime('%s')) $runinterval_seconds = $runinterval * 60 - $unresponsive = ($nodes - $no_report_nodes).map |$node| { - $old_timestamp = Integer(Timestamp($node['report_timestamp']).strftime('%s')) - if ($current_timestamp - $old_timestamp) >= $runinterval_seconds { - $node + $unresponsive = $nodes.map |$node| { + if $node['report_timestamp'] { + $old_timestamp = Integer(Timestamp($node['report_timestamp']).strftime('%s')) + if ($current_timestamp - $old_timestamp) >= $runinterval_seconds { + $node['certname'] + } } }.filter |$node| { $node =~ NotUndef }