def check_members(self):
        """
        Check MongoDB peers and their status
        """
        if not self.connection:
            raise Exception('Not connected')

        db_admin = self.connection.admin

        try:
            status = db_admin.command('replSetGetStatus')
        except pymongo.errors.OperationFailure as e:
            # If Mongo isn't running clustered, return WARN, otherwise raise exception
            if str(e) == '''command SON([('replSetGetStatus', 1)]) failed: not running with --replSet''':
                return {
                    'state' : 'OK',
                    'messages' : {
                        'info' : ['Mongo is not running clustered']
                    }
                }
            else:
                raise

        # Check status of Mongo peers
        members = {
            'state' : None,
            'messages' : {
                'info' : [],
                'error': [],
                'warn' : [],
            }
        }

        for member in status['members']:
            if member.has_key('errmsg'):
                msg = 'Member %s is %s: %s' % (member['name'], member['stateStr'], member['errmsg'])
            else:
                msg = 'Member %s is %s' % (member['name'], member['stateStr'])

            # Check member state
            #
            #   0  WARN   Starting up, phase 1 (parsing configuration)
            #   1  OK     Primary
            #   2  OK     Secondary
            #   3  WARN   Recovering (initial syncing, post-rollback, stale members)
            #   4  ERROR  Fatal error
            #   5  WARN   Starting up, phase 2 (forking threads)
            #   6  ERROR  Unknown state (the set has never connected to the member)
            #   7  OK     Arbiter
            #   8  ERROR  Down
            #   9  WARN   Rollback
            #  10  ERROR  Removed
            if member['state'] in [1, 2, 7]:
                # Member is PRIMARY or SECONDARY
                members['messages']['info'].append(msg)

                if members['state'] not in ['ERROR', 'WARN']:
                    members['state'] = 'OK'
            elif member['state'] in [0, 3, 5, 9]:
                # Warning only
                members['messages']['warn'].append(msg)

                if members['state'] != 'ERROR':
                    members['state'] = 'WARN'
            else:
                # Error
                members['messages']['error'].append(msg)
                members['state'] = 'ERROR'

        return members
dataset/ETHPy150Open gooddata/smoker/smoker/server/plugins/mongo.py/Plugin.check_members/original