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

added possibility to set lower threshold for warn/crit #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions check_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
import pymongo.son as son


# should we check warn/crit thresholds for >= or <= ?. extremly useful for size checks
lower_check = False

#
# thanks to http://stackoverflow.com/a/1229667/72987
#
Expand Down Expand Up @@ -82,11 +85,12 @@ def numeric_type(param):


def check_levels(param, warning, critical, message, ok=[]):
global lower_check
if (numeric_type(critical) and numeric_type(warning)):
if param >= critical:
if lower_check != bool (param >= critical):
print "CRITICAL - " + message
sys.exit(2)
elif param >= warning:
elif lower_check != bool (param >= warning):
print "WARNING - " + message
sys.exit(1)
else:
Expand Down Expand Up @@ -126,6 +130,7 @@ def main(argv):
p.add_option('-P', '--port', action='store', type='int', dest='port', default=27017, help='The port mongodb is runnung on')
p.add_option('-u', '--user', action='store', type='string', dest='user', default=None, help='The username you want to login as')
p.add_option('-p', '--pass', action='store', type='string', dest='passwd', default=None, help='The password you want to use for that user')
p.add_option('-L', '--lower-check', action='store_true', dest='lower_check', default=False, help='Thresholds trigger warning/critical if value is lower')
p.add_option('-W', '--warning', action='store', dest='warning', default=None, help='The warning threshold we want to set')
p.add_option('-C', '--critical', action='store', dest='critical', default=None, help='The critical threshold we want to set')
p.add_option('-A', '--action', action='store', type='choice', dest='action', default='connect', help='The action you want to take',
Expand Down Expand Up @@ -160,6 +165,8 @@ def main(argv):
critical = float(options.critical or 0)

action = options.action
global lower_check
lower_check = options.lower_check
perf_data = options.perf_data
max_lag = options.max_lag
database = options.database
Expand Down