Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#236) agent_state_summary: Count nodes without report as unhealthy #238

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ The plan `pe_status_check::agent_state_summary` provides you a hash with all nod
"failed": [ ],
"changed": [ "student2.local" ],
"unresponsive": [ "student3.local", "student4.local", "student1.local", "login.local" ],
"no_report": [ "newnode.with.report.local" ],
"responsive": [ "pe.bastelfreak.local"],
"unhealthy": [ "student2.local", "student3.local", "student4.local", "student1.local", "login.local" ],
"unhealthy_counter": 5,
Expand All @@ -181,6 +182,7 @@ The plan `pe_status_check::agent_state_summary` provides you a hash with all nod
* `failed`: The last catalog couldn't be compiled or catalog application raised an error
* `changed`: A node reported a change
* `unresponsive`: Last report is older than 30 minutes (can be configured via the `runinterval` parameter)
* `no_report`: The node exists in PuppetDB but has no reports
* `corrective_changes`: A node reported corrective changes
* `used_cached_catalog`: The node didn't apply a new catalog but used a cached version
* `unhealthy`: List of nodes that are in any of the above categories
Expand Down
16 changes: 11 additions & 5 deletions plans/agent_state_summary.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@
$nodes = puppetdb_query('nodes[certname,latest_report_noop,latest_report_corrective_change,cached_catalog_status,latest_report_status,report_timestamp]{}')
$fqdns = $nodes.map |$node| { $node['certname'] }

# check if the last catalog is older than X minutes
# check if the node has a report
# `report_timestamp` will be undef, or null, if no report exists
$no_report_nodes = $nodes.filter |$node| { $node['report_timestamp'] =~ Undef }
$no_report = $no_report_nodes.map |$node| { $node['certname'] }

# 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.map |$node| {
$unresponsive = ($nodes - $no_report_nodes).map |$node| {
$old_timestamp = Integer(Timestamp($node['report_timestamp']).strftime('%s'))
if ($current_timestamp - $old_timestamp) >= $runinterval_seconds {
$node['certname']
$node
}
}.filter |$node| { $node =~ NotUndef }

# all nodes that delivered a report in time
$responsive = $fqdns - $unresponsive
$responsive = $fqdns - $unresponsive - $no_report

# all nodes that used noop for the last catalog
$noop = $nodes.map |$node| { if ($node['latest_report_noop'] == true){ $node['certname'] } }.filter |$node| { $node =~ NotUndef }
Expand All @@ -45,7 +50,7 @@
$changed = $nodes.map |$node| { if ($node['latest_report_status'] == 'changed'){ $node['certname'] } }.filter |$node| { $node =~ NotUndef }

# all nodes that aren't healthy in any form
$unhealthy = [$noop, $corrective_changes, $used_cached_catalog, $failed, $changed, $unresponsive].flatten.unique
$unhealthy = [$noop, $corrective_changes, $used_cached_catalog, $failed, $changed, $unresponsive, $no_report].flatten.unique

# all healthy nodes
$healthy = $fqdns - $unhealthy
Expand All @@ -58,6 +63,7 @@
'failed' => $failed,
'changed' => $changed,
'unresponsive' => $unresponsive,
'no_report' => $no_report,
'responsive' => $responsive,
'unhealthy' => $unhealthy,
'unhealthy_counter' => $unhealthy.count,
Expand Down
Loading