Skip to content
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

Enabled regex testing for content_match #1326

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion checks.d/http_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import socket
import ssl
import time
import re
from urlparse import urlparse

# 3rd party
Expand Down Expand Up @@ -120,7 +121,7 @@ def _check(self, instance):
self.gauge('network.http.response_time', running_time, tags=tags_list)

if content_match and int(resp.status) == 200:
if content_match in content:
if re.search(content_match, content):
self.log.debug("%s is found in return content" % content_match)
else:
self.log.info("%s not found in content" % content_match)
Expand Down
13 changes: 11 additions & 2 deletions conf.d/http_check.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ instances:

# The (optional) content_match parameter will allow the check
# to look for a particular string within the response. The check
# will report as DOWN if the string is not found
# content_match: '"status": "green"'
# will report as DOWN if the string is not found.
#
# content_match uses Python regular expressions which means that
# you will have to escape the following "special" characters with
# a backslash (\) if you're trying to match them in your content:
# . ^ $ * + ? { } [ ] \ | ( )
#
# Examples:
# content_match: 'In Stock'
# content_match: '^(Bread|Apples|Very small rocks|Cider|Gravy|Cherries|Mud|Churches|Lead) float(s)? in water'
# content_match: '"status": "green"'

# If your service uses basic authentication, you can optionally
# specify a username and password that will be used in the check.
Expand Down