

def check_members(self):
    '\n        Check MongoDB peers and their status\n        '
    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 (str(e) == "command SON([('replSetGetStatus', 1)]) failed: not running with --replSet"):
            return {
                'state': 'OK',
                'messages': {
                    'info': ['Mongo is not running clustered'],
                },
            }
        else:
            raise
    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']))
        if (member['state'] in [1, 2, 7]):
            members['messages']['info'].append(msg)
            if (members['state'] not in ['ERROR', 'WARN']):
                members['state'] = 'OK'
        elif (member['state'] in [0, 3, 5, 9]):
            members['messages']['warn'].append(msg)
            if (members['state'] != 'ERROR'):
                members['state'] = 'WARN'
        else:
            members['messages']['error'].append(msg)
            members['state'] = 'ERROR'
    return members

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