Skip to content

Commit

Permalink
improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
oceanef committed Jan 24, 2017
1 parent 088021b commit 8d335a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions checks.d/http_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,19 @@ def send_status_down(loginfo, message):
if content_match:
# r.text is the response content decoded by `requests`, of type `unicode`
content = r.text if type(content_match) is unicode else r.content
if not reverse_content_match and re.search(content_match, content, re.UNICODE):
send_status_up("%s is found in return content" % content_match)
if re.search(content_match, content, re.UNICODE):
if reverse_content_match:
send_status_down("%s is found in return content with the reverse_content_match option" % content_match,
'Content "%s" found in response with the reverse_content_match' % content_match)
else:
send_status_up("%s is found in return content" % content_match)

elif reverse_content_match and not re.search(content_match, content, re.UNICODE):
send_status_up("%s is not found in return content with the reverse_content_match option" % content_match)

elif reverse_content_match:
send_status_down("%s is found in return content with the reverse_content_match option" % content_match,
'Content "%s" found in response with the reverse_content_match' % content_match)
else:
send_status_down("%s is not found in return content" % content_match,
'Content "%s" not found in response.' % content_match)
if reverse_content_match:
send_status_up("%s is not found in return content with the reverse_content_match option" % content_match)
else:
send_status_down("%s is not found in return content" % content_match,
'Content "%s" not found in response.' % content_match)

else:
send_status_up("%s is UP" % addr)
Expand Down
2 changes: 1 addition & 1 deletion conf.d/http_check.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ instances:

# The (optional) reverse_content_match parameter will allow the content_match
# to work the other way around. That means that the check will report
# as DOWN if the string is DOWN
# as DOWN if the string is found.
# reverse_content_match: false

# If your service uses basic authentication, you can optionally
Expand Down

0 comments on commit 8d335a1

Please sign in to comment.