Create k8s_failed_cronjobs.py - #49
Open
kkellerlbl wants to merge 1 commit into
Open
Conversation
Initial commit of script checking Jobs spawned by CronJobs.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Python MRPE/Nagios-style check that queries Kubernetes for CronJobs and their child Jobs (via ownerReferences) and reports failures via exit status.
Changes:
- Introduces
lakehouse/k8s_failed_cronjobs.pyto enumerate CronJobs/Jobs cluster-wide and compute an overall status. - Emits human-readable summary output intended for MRPE consumption.
Suppressed comments (3)
lakehouse/k8s_failed_cronjobs.py:72
len(failed_children) > 0is a global list across all CronJobs, so a failure in one CronJob can incorrectly downgrade a different CronJob to WARNING as soon as it has a successful Job. Track failures per CronJob when deciding whether to return WARNING vs OK for that CronJob.
elif any(c.type == "SuccessCriteriaMet" and c.status == "True" for c in conditions):
if (len(failed_children) > 0):
cronjobstatus=1
lakehouse/k8s_failed_cronjobs.py:87
- The script can print "all CronJobs OK" while returning exit status 3 (UNKNOWN), e.g. when there are no CronJobs or no child Jobs and
statusremains 3. Also, the "failed CronJobs" message is currently listing failed Job names. Make the output consistent with the exit code and label the list accurately.
if failed_children:
print(f"failed CronJobs: {', '.join(failed_children)} ; CronJobs checked: {', '.join(cronjob_names)}")
else:
# print(str(status) + f" ok {ns}/{name} ({len(children)} job(s))")
print(f"all CronJobs OK, CronJobs checked: {', '.join(cronjob_names)}")
lakehouse/k8s_failed_cronjobs.py:93
- Unhandled Kubernetes API/config exceptions will currently bubble up as a Python traceback, which is noisy for MRPE/local checks and may result in a non-Nagios exit status. Catch exceptions at the top-level and exit with UNKNOWN (3) and a single-line message.
if __name__ == "__main__":
sys.exit(main())
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| uid = cj.metadata.uid | ||
|
|
||
| cronjob_names.append(cj.metadata.namespace+'/'+cj.metadata.name) | ||
| children = jobs_by_cronjob_uid.get(uid, []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Initial commit of script checking Jobs spawned by CronJobs. Suitable for use as an MRPE check.