Skip to content

Commit

Permalink
agent_state_summary: Properly handle nodes without reports/responses
Browse files Browse the repository at this point in the history
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
}
```
  • Loading branch information
bastelfreak committed Jan 30, 2025
1 parent c75424e commit f0c2d2d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions plans/agent_state_summary.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit f0c2d2d

Please sign in to comment.