bin/check-mongodb.py in sensu-plugins-mongodb-0.0.4 vs bin/check-mongodb.py in sensu-plugins-mongodb-0.0.6

- old
+ new

@@ -150,11 +150,11 @@ p.add_option('--max-lag', action='store_true', dest='max_lag', default=False, help='Get max replication lag (for replication_lag action only)') p.add_option('--mapped-memory', action='store_true', dest='mapped_memory', default=False, help='Get mapped memory instead of resident (if resident memory can not be read)') p.add_option('-D', '--perf-data', action='store_true', dest='perf_data', default=False, help='Enable output of Nagios performance data') p.add_option('-d', '--database', action='store', dest='database', default='admin', help='Specify the database to check') p.add_option('--all-databases', action='store_true', dest='all_databases', default=False, help='Check all databases (action database_size)') - p.add_option('-s', '--ssl', dest='ssl', default=False, action='callback', callback=optional_arg(True), help='Connect using SSL') + p.add_option('-s', '--ssl-enabled', dest='ssl_enabled', default=False, action='callback', callback=optional_arg(True), help='Connect using SSL') p.add_option('-r', '--replicaset', dest='replicaset', default=None, action='callback', callback=optional_arg(True), help='Connect to replicaset') p.add_option('-q', '--querytype', action='store', dest='query_type', default='query', help='The query type to check [query|insert|update|delete|getmore|command] from queries_per_second') p.add_option('-c', '--collection', action='store', dest='collection', default='admin', help='Specify the collection to check') p.add_option('-T', '--time', action='store', type='int', dest='sample_time', default=1, help='Time used to sample number of pages faults') @@ -175,11 +175,11 @@ action = options.action perf_data = options.perf_data max_lag = options.max_lag database = options.database - ssl = options.ssl + ssl_enabled = options.ssl_enabled replicaset = options.replicaset if action == 'replica_primary' and replicaset is None: return "replicaset must be passed in when using replica_primary check" elif not action == 'replica_primary' and replicaset: @@ -187,11 +187,11 @@ # # moving the login up here and passing in the connection # start = time.time() - err, con = mongo_connect(host, port, ssl, user, passwd, replicaset) + err, con = mongo_connect(host, port, ssl_enabled, user, passwd, replicaset) if err != 0: return err conn_time = time.time() - start conn_time = round(conn_time, 0) @@ -265,18 +265,18 @@ return check_replset_quorum(con, perf_data) else: return check_connect(host, port, warning, critical, perf_data, user, passwd, conn_time) -def mongo_connect(host=None, port=None, ssl=False, user=None, passwd=None, replica=None): +def mongo_connect(host=None, port=None, ssl_enabled=False, user=None, passwd=None, replica=None): try: # ssl connection for pymongo > 2.3 if pymongo.version >= "2.3": if replica is None: - con = pymongo.MongoClient(host, port, ssl=ssl) + con = pymongo.MongoClient(host, port, ssl=ssl_enabled) else: - con = pymongo.Connection(host, port, read_preference=pymongo.ReadPreference.SECONDARY, ssl=ssl, replicaSet=replica, network_timeout=10) + con = pymongo.Connection(host, port, read_preference=pymongo.ReadPreference.SECONDARY, ssl=ssl_enabled, replicaSet=replica, network_timeout=10) else: if replica is None: con = pymongo.Connection(host, port, slave_okay=True, network_timeout=10) else: con = pymongo.Connection(host, port, slave_okay=True, network_timeout=10) @@ -698,11 +698,11 @@ def check_replset_state(con, perf_data, warning="", critical=""): try: warning = [int(x) for x in warning.split(",")] except: - warning = [0, 3, 5] + warning = [0, 3, 5, 9] try: critical = [int(x) for x in critical.split(",")] except: critical = [8, 4, -1] @@ -733,9 +733,11 @@ message = "State: %i (Primary)" % state elif state == 2: message = "State: %i (Secondary)" % state elif state == 7: message = "State: %i (Arbiter)" % state + elif state == 9: + message = "State: %i (Rollback)" % state elif state == -1: message = "Not running with replSet" else: message = "State: %i (Unknown state)" % state message += performance_data(perf_data, [(state, "state")])