Python 3 compatibility fixes and two new features#95
Open
xorpaul wants to merge 4 commits into
Open
Conversation
Update all scripts to use `#!/usr/bin/env python3`. In Python 3 `subprocess.communicate()` returns stderr as bytes, so any string operation on it (split, format, %s interpolation) either crashes with TypeError or silently prints the b'' representation. Decode stderr with `.decode('utf-8', errors='replace')` before use in all affected scripts.
Scripts with the crash-on-split bug (TypeError: a bytes-like object is required, not 'str'):
- check_ceph_df
- check_ceph_health
- check_ceph_osd_df
Scripts printing raw bytes repr in error messages:
- check_ceph_mgr
- check_ceph_mon
Shebang-only fix (no stderr usage):
- check_ceph_osd_db
- check_ceph_rgw_api
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The previous approach resolved the OSD host's DNS name to an IP and then regex-searched that IP in `ceph osd dump` output. This fails on clusters with separate storage networks where the DNS name resolves to a management IP that never appears in the OSD dump (the OSDs bind to storage network addresses instead). Replace with `ceph osd tree --format json` which maps CRUSH host bucket names to OSD IDs directly — no IP matching needed. Host lookup tries the FQDN first, then the short hostname, so CRUSH bucket names (typically short) are matched correctly even when `-H` receives an FQDN. Other improvements: - Remove the socket/DNS resolution code and the invalid escape sequence workarounds (\. \[ \]) that triggered SyntaxWarning in Python 3.12+ - --osdid now matches against the numeric OSD ID rather than the full osd.N name - OSD in/out status is read from the reweight field in the tree JSON Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
radosgw-admin accepts --keyring like all other Ceph tools but the plugin had no way to pass it, forcing users to rely on a keyring in the default search path. Add -k/--keyring with the same validation and command-line wiring used by the other plugins in this collection. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…emon count check cephadm-managed clusters assign ephemeral random suffixes to MDS daemon names (e.g. m01.mds2.fezsws), so the existing --name mode cannot be used for stable Nagios service checks — the name changes every time a daemon restarts. Add -A/--min-active <N>: instead of checking a specific named daemon, verify that the filesystem has at least N non-laggy daemons in up:active state. Warns if any daemon is laggy, crits if the active count falls below the threshold. --name remains fully functional for environments with stable MDS names. Exactly one of --name or --min-active must be provided. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
#!/usr/bin/env pythonshebang andstderrbytes-decoding bugs across all ten scripts; without these fixes the plugins either crash withTypeErroror silently printb'...'byte-string representations in Nagios output on Python 3.12+check_ceph_osdrewrite — replace the broken IP-basedceph osd dumpapproach withceph osd tree --format json; the old code failed on clusters with separate storage networks where the DNS name resolves to a management IP that never appears in the OSD dumpcheck_ceph_rgw: add--keyring—radosgw-adminaccepts--keyringlike all other Ceph tools but the plugin had no way to pass itcheck_ceph_mds: add--min-active— cephadm-managed clusters assign ephemeral random suffixes to MDS daemon names, making the existing--namemode unusable for stable Nagios checks; the new mode checks that a filesystem has at least N active daemons insteadDetailed changes
Python 3 compatibility (all scripts)
All scripts updated to
#!/usr/bin/env python3.subprocess.communicate()returnsstderrasbytesin Python 3. Three scripts called.split('\n')directly on the bytes object, crashing withTypeErrorwhenever Ceph writes to stderr:src/check_ceph_dfsrc/check_ceph_healthsrc/check_ceph_osd_dfThree more scripts printed
errvia%s/.format()without decoding, causing error messages to include the rawb''wrapper:src/check_ceph_mgrsrc/check_ceph_monsrc/check_ceph_rgw(also fixed in the--keyringcommit)All fixed with
.decode('utf-8', errors='replace')before any string operation.check_ceph_osd— switch fromceph osd dumptoceph osd tree --format jsonThe previous implementation resolved the host argument via DNS, then regex-searched the resulting IP in
ceph osd dumptext output. This fails on any cluster where the management/DNS IP differs from the storage-network IP the OSD daemons actually bind to — a common production setup.The new implementation uses
ceph osd tree --format json, which encodes the CRUSH host-to-OSD mapping directly. The host lookup tries the FQDN first, then the short hostname, so CRUSH bucket names (typically short, e.g.osd2) are matched correctly even when-Hreceives an FQDN likeosd2.example.com.Additional fixes in the same script:
socket/ DNS resolution code — no longer needed'\.','\[','\]'insrc/check_ceph_osdthat triggeredSyntaxWarningin Python 3.12+--osdidnow matches the numeric OSD ID (e.g.--osdid 3) rather than requiring theosd.3prefixcheck_ceph_rgw— add--keyringAdd
-k/--keyringwith the same existence-check validation and command-line wiring used by all other plugins in the collection. Without this, users on hosts without a default keyring had no way to authenticate.check_ceph_mds— add--min-activeWith cephadm, MDS daemon names include ephemeral random IDs (format:
<fs>.<host>.<random>, e.g.m01.mds2.fezsws). These change on every daemon restart, making the--namemode unsuitable for permanent Nagios service definitions.The new
-A/--min-active <N>mode checks that the given filesystem has at least N daemons inup:activestate without a laggy flag. Behaviour:--nameis unchanged and still works for environments with stable MDS names. Exactly one of--nameor--min-activemust be provided.Testing
Verified against a Pacific/Quincy cluster with 12 CephFS filesystems, 96 OSDs across 4 hosts, and separate management / storage networks: