Skip to content

Align monitoring exit codes and about error handling#41

Open
c-kr wants to merge 1 commit intoConSol-Monitoring:mainfrom
c-kr:cli-return-codes-validation
Open

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

Conversation

@c-kr
Copy link
Copy Markdown

@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
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.

1 participant