From 53bc8fe36122e83157d0840241d24b1f5d69c2ba Mon Sep 17 00:00:00 2001 From: Brandon Diamond Date: Mon, 24 Oct 2011 18:11:17 -0400 Subject: SERVER-3641 SERVER-1458: mongostat uses auth with mongos/repsets --- tools/stat.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/stat.cpp b/tools/stat.cpp index e1eda8db3c1..8b1b5aab786 100644 --- a/tools/stat.cpp +++ b/tools/stat.cpp @@ -365,11 +365,6 @@ namespace mongo { } int run() { - if ( !(_username.empty() || _password.empty()) && isMongos()) { - cout << "You cannot use mongostat on a mongos running with authentication enabled" << endl; - return -1; - } - _sleep = getParam( "sleep" , _sleep ); _all = hasParam( "all" ); if ( _many ) @@ -480,6 +475,9 @@ namespace mongo { string error; bool mongos; + + string username; + string password; }; static void serverThread( shared_ptr state ) { @@ -489,8 +487,9 @@ namespace mongo { string errmsg; if ( ! conn.connect( state->host , errmsg ) ) state->error = errmsg; - long long cycleNumber = 0; + + conn.auth("admin", state->username, state->password, errmsg); while ( ++cycleNumber ) { try { @@ -549,6 +548,9 @@ namespace mongo { state.reset( new ServerState() ); state->host = host; state->thr.reset( new boost::thread( boost::bind( serverThread , state ) ) ); + state->username = _username; + state->password = _password; + return true; } @@ -605,7 +607,7 @@ namespace mongo { int runMany() { StateMap threads; - + { string orig = getParam( "host" ); if ( orig == "" ) -- cgit v1.2.1