-
Notifications
You must be signed in to change notification settings - Fork 81
Fixed check_ceph_osd for Ceph Octopus. #83
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
Open
HeroesLament
wants to merge
2
commits into
ceph:master
Choose a base branch
from
HeroesLament:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,9 +15,8 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # 1.5.2 (2019-06-16) Martin Seener: fixed regex to work with Ceph Nautilus (14.2.x) | ||
| # 1.6.0 (2022-05-02) Logan Skidmore: fixed regex to work with Ceph Octopus (15.x.x) | ||
|
|
||
| from __future__ import print_function | ||
| import argparse | ||
| import os | ||
| import re | ||
|
|
@@ -55,26 +54,26 @@ def main(): | |
| # validate args | ||
| ceph_exec = args.exe if args.exe else CEPH_COMMAND | ||
| if not os.path.exists(ceph_exec): | ||
| print("OSD ERROR: ceph executable '%s' doesn't exist" % ceph_exec) | ||
| print "OSD ERROR: ceph executable '%s' doesn't exist" % ceph_exec | ||
| return STATUS_UNKNOWN | ||
|
|
||
| if args.version: | ||
| print('version %s' % __version__) | ||
| print 'version %s' % __version__ | ||
| return STATUS_OK | ||
|
|
||
| if args.conf and not os.path.exists(args.conf): | ||
| print("OSD ERROR: ceph conf file '%s' doesn't exist" % args.conf) | ||
| print "OSD ERROR: ceph conf file '%s' doesn't exist" % args.conf | ||
| return STATUS_UNKNOWN | ||
|
|
||
| if args.keyring and not os.path.exists(args.keyring): | ||
| print("OSD ERROR: keyring file '%s' doesn't exist" % args.keyring) | ||
| print "OSD ERROR: keyring file '%s' doesn't exist" % args.keyring | ||
| return STATUS_UNKNOWN | ||
|
|
||
| if not args.osdid: | ||
| args.osdid = '[^ ]*' | ||
|
|
||
| if not args.host: | ||
| print("OSD ERROR: no OSD hostname given") | ||
| print "OSD ERROR: no OSD hostname given" | ||
| return STATUS_UNKNOWN | ||
|
|
||
| try: | ||
|
|
@@ -83,7 +82,7 @@ def main(): | |
| if addrinfo[0][0] == socket.AF_INET6: | ||
| args.host = "[%s]" % args.host | ||
| except: | ||
| print('OSD ERROR: could not resolve %s' % args.host) | ||
| print 'OSD ERROR: could not resolve %s' % args.host | ||
| return STATUS_UNKNOWN | ||
|
|
||
|
|
||
|
|
@@ -103,51 +102,46 @@ def main(): | |
| ceph_cmd.append(args.keyring) | ||
| ceph_cmd.append('osd') | ||
| ceph_cmd.append('dump') | ||
|
|
||
| # exec command | ||
| p = subprocess.Popen(ceph_cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) | ||
| output, err = p.communicate() | ||
| output = output.decode('utf8') | ||
|
|
||
| if err or not output: | ||
| print("OSD ERROR: %s" % err) | ||
| return STATUS_ERROR | ||
| # exec command | ||
| print ceph_cmd | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You just print the |
||
|
|
||
| # escape IPv4 host address | ||
| osd_host = args.host.replace('.', '\.') | ||
| # escape IPv6 host address | ||
| osd_host = osd_host.replace('[', '\[') | ||
| osd_host = osd_host.replace(']', '\]') | ||
| up = re.findall(r"^(osd\.%s) up.*%s:" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| print output | ||
| up = re.findall(r"^(osd\.%s) up.*(%s):" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| # print up | ||
| if args.out: | ||
| down = re.findall(r"^(osd\.%s) down.*%s:" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| down_in = re.findall(r"^(osd\.%s) down[ ]+in.*%s:" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| down_out = re.findall(r"^(osd\.%s) down[ ]+out.*%s:" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| down = re.findall(r"^(osd\.%s) down.*(%s):" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| down_in = re.findall(r"^(osd\.%s) down[ ]+in.*(%s):" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| down_out = re.findall(r"^(osd\.%s) down[ ]+out.*(%s):" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| else: | ||
| down = re.findall(r"^(osd\.%s) down[ ]+in.*%s:" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| down = re.findall(r"^(osd\.%s) down[ ]+in.*(%s):" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| down_in = down | ||
| down_out = re.findall(r"^(osd\.%s) down[ ]+out.*%s:" % (args.osdid, osd_host), output, re.MULTILINE) | ||
| down_out = re.findall(r"^(osd\.%s) down[ ]+out.*(%s):" % (args.osdid, osd_host), output, re.MULTILINE) | ||
|
|
||
| if down: | ||
| print("OSD %s: Down OSD%s on %s: %s" % ('CRITICAL' if len(down)>=args.crit else 'WARNING' ,'s' if len(down)>1 else '', args.host, " ".join(down))) | ||
| print("Up OSDs: " + " ".join(up)) | ||
| print("Down+In OSDs: " + " ".join(down_in)) | ||
| print("Down+Out OSDs: " + " ".join(down_out)) | ||
| print("| 'osd_up'=%d 'osd_down_in'=%d;;%d 'osd_down_out'=%d;;%d" % (len(up), len(down_in), args.crit, len(down_out), args.crit)) | ||
| print "OSD %s: Down OSD%s on %s: %s" % ('CRITICAL' if len(down)>=args.crit else 'WARNING' ,'s' if len(down)>1 else '', args.host, " ".join(down)) | ||
| print "Up OSDs: " + " ".join(str(i) for i in up) | ||
| print "Down+In OSDs: " + " ".join(str(i) for i in down_in) | ||
| print "Down+Out OSDs: " + " ".join(str(i) for i in down_out) | ||
| print "| 'osd_up'=%d 'osd_down_in'=%d;;%d 'osd_down_out'=%d;;%d" % (len(up), len(down_in), args.crit, len(down_out), args.crit) | ||
| if len(down)>=args.crit: | ||
| return STATUS_ERROR | ||
| else: | ||
| return STATUS_WARNING | ||
|
|
||
| if up: | ||
| print("OSD OK") | ||
| print("Up OSDs: " + " ".join(up)) | ||
| print("Down+In OSDs: " + " ".join(down_in)) | ||
| print("Down+Out OSDs: " + " ".join(down_out)) | ||
| print("| 'osd_up'=%d 'osd_down_in'=%d;;%d 'osd_down_out'=%d;;%d" % (len(up), len(down_in), args.crit, len(down_out), args.crit)) | ||
| print "OSD OK" | ||
| print "Up OSDs: " + " ".join(str(i) for i in up) | ||
| print "Down+In OSDs: " + " ".join(str(i) for i in down_in) | ||
| print "Down+Out OSDs: " + " ".join(str(i) for i in down_out) | ||
| print "| 'osd_up'=%d 'osd_down_in'=%d;;%d 'osd_down_out'=%d;;%d" % (len(up), len(down_in), args.crit, len(down_out), args.crit) | ||
| return STATUS_OK | ||
|
|
||
| print("OSD WARN: no OSD.%s found on host %s" % (args.osdid, args.host)) | ||
| print "OSD WARN: no OSD.%s found on host %s" % (args.osdid, args.host) | ||
| return STATUS_WARNING | ||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python3 print requires parentheses!