Skip to content

Align monitoring exit codes and about error handling#41

Open
c-kr wants to merge 6 commits intoConSol-Monitoring:mainfrom
c-kr:cli-return-codes-validation
Open

Align monitoring exit codes and about error handling#41
c-kr wants to merge 6 commits intoConSol-Monitoring:mainfrom
c-kr:cli-return-codes-validation

Conversation

@c-kr
Copy link
Copy Markdown
Contributor

@c-kr c-kr commented Apr 18, 2026

Return Codes And CLI Validation

Summary

This patch aligns top-level CLI handling and parser exits with the Monitoring Plugins guidelines:

  • --help and "no command supplied" now return UNKNOWN (3) instead of OK (0).
  • argparse usage and invalid command-line arguments now return UNKNOWN (3).
  • ConnectionRefusedError now reports CRITICAL in both text and exit code.
  • about no longer maps unexpected plugin-internal exceptions to CRITICAL; normal check results stay unchanged, but unexpected internal failures now surface as UNKNOWN.

Reference:

The relevant guideline points are:

  • invalid command line arguments should return UNKNOWN (3)
  • --help / --version should return UNKNOWN (3)
  • plugin-internal failures should not be reported as CRITICAL

Files

  • checkvsphere/tools/cli.py
  • checkvsphere/cli.py
  • checkvsphere/vcmd/about.py

Quick Verification

export PYTHONPATH="$PWD"
export VC_HOST='vcenter.example.com'
export VC_USER='monitor@vsphere.local'
export VC_PASS='secret'

1. No command supplied

python -m checkvsphere.cli
echo $?

Expected before fix:

  • rc=0

Expected after fix:

  • rc=3

2. Subcommand help

python -m checkvsphere.cli host-runtime --help
echo $?

Expected before fix:

  • rc=0

Expected after fix:

  • rc=3

3. Connection refused text/code mismatch

python -m checkvsphere.cli datastores -s 127.0.0.1 -o 1 -u x -p x
echo $?

Expected before fix:

  • rc=2
  • output starts with UNKNOWN - Connection refused

Expected after fix:

  • rc=2
  • output starts with CRITICAL - Connection refused

4. about internal error classification

This check needs a reachable vCenter. Point --sessionfile to a directory so writing the session ID fails after login:

python -m checkvsphere.cli about -s "$VC_HOST" -u "$VC_USER" -p "$VC_PASS" --sessionfile /
echo $?

Expected before fix:

  • rc=2
  • generic runtime failures inside about are reported as CRITICAL

Expected after fix:

  • rc=3
  • the failure is reported as UNKNOWN

Assisted-by: Codex gpt-5.4 high

@c-kr c-kr changed the title fix(cli): align monitoring exit codes and about error handling Align monitoring exit codes and about error handling Apr 18, 2026
@c-kr c-kr force-pushed the cli-return-codes-validation branch from a753ee3 to 6177be0 Compare April 22, 2026 08:21
@c-kr c-kr marked this pull request as ready for review April 22, 2026 09:33
@KIBruh
Copy link
Copy Markdown
Contributor

KIBruh commented May 7, 2026

too much in one pr

@c-kr
Copy link
Copy Markdown
Contributor Author

c-kr commented May 7, 2026

The change in checkvsphere/vcmd/about.py looks big but is almost just indentation. If we take that one out there is just the return code handling and a typo left. Not sure how to shrink it. But I am open for feedback for further improvements.

@datamuc
Copy link
Copy Markdown
Collaborator

datamuc commented May 8, 2026

yeah, but in different areas,

  • --help and "no command supplied" now return UNKNOWN (3) instead of OK (0).
  • argparse usage and invalid command-line arguments now return UNKNOWN (3).
  • ConnectionRefusedError now reports CRITICAL in both text and exit code.
  • about no longer maps unexpected plugin-internal exceptions to CRITICAL; normal check results stay unchanged, but unexpected internal failures now surface as UNKNOWN.

every one of these should at least be a single commit, so i can judge about them one by one.

@c-kr c-kr marked this pull request as draft May 8, 2026 09:10
@c-kr c-kr force-pushed the cli-return-codes-validation branch from 6177be0 to 4a900f1 Compare May 8, 2026 09:16
@c-kr c-kr force-pushed the cli-return-codes-validation branch from 4a900f1 to 98004c0 Compare May 8, 2026 09:23
@c-kr c-kr marked this pull request as ready for review May 8, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants