We are trying to make a connection to a MongoDB database using a Linux/UNIX script component. The components are from a Solarwinds template that is written in PERL and it assumes that the DB is “wide open”.
So, it doesn’t pass an account or password. We are trying to get the command to execute with an account and password. Problem is we are DBAs and we suck at coding.
The script pairs run db.server.Status commands to get info out of MongoDB.
We can run this script from the Unix command line on the monitored target and it works.
/usr/bin/mongo admin -u cfoot -p cfoot123 --eval “printjson(db.serverStatus().globalLock.currentQueue.total)”
The component accepts two arguments from the command line:
- the path “/usr/bin/mongo” = $client_path
- the database named “admin” = $database
$client_path=$ARGV[0];
$database = $ARGV[1];
Then the command is executed:
$arg2 = "--eval \"printjson(db.serverStatus().globalLock.currentQueue.total)\"";
$cmd=${client_path}.' '.${$database}.' '.${arg2};
We are struggling with the syntax to pass the username and password in. Have any ideas on the syntax? We tried a bunch of different ways. But, none work - probably because we don't know what the syntax is to pass the username and password. Looked in the PERL and MongoDB manuals - not much headway.
Thanks in advance.