/* $Id$ */ #include string manPageKeys[] = {"ALL", "NAME", "SYNOPSIS", "DESCRIPTION", "ENVIRONMENT", "EXAMPLES", "COPYRIGHT" }; string manPageLocation =""; string presetFileName =""; const string sshPrivateKeyFilename = "perfstat_sshkey/perfstat_privkey"; const string sshPublicKeyFilename = "perfstat_sshkey/perfstat_pubkey"; const string sshKeyPath = "perfstat_sshkey"; // BURT 541708 const string version = "perfstat v8.4 (20160831_133824)"; bool CLIHandler::bcleanUpFlag = true; CLIHandler::CLIHandler() { manPageLocation =""; presetFileName =""; outputFileName.append("perfstat_"); outputFileName.append(generateDateString()); } void CLIHandler::readManPageFile(int key) { size_t found; perfstatMan* manpage = new perfstatMan(version); if(key == 0) { vector vecMan = (*manpage).getPerfstatMan(); for(int i=0; i<(int)vecMan.size(); i++) { cout << vecMan[i] ; } } else { vector vecMan = (*manpage).getPerfstatMan(); bool firstKeyDone= false; for(int i=0; i<(int)vecMan.size(); i++) { if(!firstKeyDone) { found=vecMan[i].find(manPageKeys[key]); if(int(found)==-1) continue; else firstKeyDone = true; } else { found=vecMan[i].find(manPageKeys[key+1]); if(int(found)==-1) { cout < data; data.push_back("default"); data.push_back(boost::lexical_cast(sampleTime)); CLIDataMap["time"] = data; data.clear(); data.push_back("default"); data.push_back("1"); CLIDataMap["Iterations"] = data; data.clear(); data.push_back("default"); data.push_back("0"); CLIDataMap["iter-interval"] = data; data.clear(); data.push_back("default"); data.push_back(presetFileName); CLIDataMap["Preset-File"] = data; data.clear(); data.push_back("default"); data.push_back(outputFileName); CLIDataMap["Data-Dir"] = data; data.clear(); data.push_back("default"); data.push_back(outputFileName + ".zip"); CLIDataMap["Output-File"] = data; data.clear(); data.push_back("default"); data.push_back(msgOutputLevel); CLIDataMap["Message-Level"] = data; data.clear(); data.push_back("default"); data.push_back(stutterStatitLevel); CLIDataMap["Stutter-Statit"] = data; data.clear(); data.push_back("default"); data.push_back(filerMode); CLIDataMap["Mode"] = data; data.clear(); data.push_back("default"); data.push_back(filerLoginUser); CLIDataMap["FilerLoginUser"] = data; data.clear(); data.push_back("default"); data.push_back(sktrace_points); CLIDataMap["SKTRACE_POINTS"] = data; data.clear(); data.push_back("default"); data.push_back(appName); CLIDataMap["HOST_APP_NAME"] = data; data.clear(); data.push_back("default"); data.push_back(appArgs); CLIDataMap["HOST_APP_ARGS"] = data; data.clear(); data.push_back("default"); data.push_back("false"); CLIDataMap["config-all"] = data; data.clear(); data.push_back("default"); data.push_back("false"); CLIDataMap["BACKUPLOG"] = data; data.clear(); data.push_back("default"); data.push_back(""); CLIDataMap["SSHKnownHosts-FilePath"] = data; sampleInterval = -1; maxRetries = 100; maxRunTime = -1; bsystemShellExclude = false; diagPasswdCMode = ""; bclientCredsProvided = false; bdiagPasswdProvided = false; bkeyPassPharse = false; // used by perfstat::requestClusterInfo to get node mgmt ips ipFamily = "*"; } void CLIHandler::setSSHKeyPaths() { vector data; SSHPrivateKeyPath = sshPrivateKeyFilename; SSHPublicKeyPath = sshPublicKeyFilename; data.clear(); data.push_back("default"); data.push_back(sshPrivateKeyFilename); CLIDataMap["sshprivatekey-path"] = data; data.clear(); data.push_back("default"); data.push_back(sshPublicKeyFilename); CLIDataMap["sshpublickey-path"] = data; } void CLIHandler::setSampleInterval(int time) { vector data; //hist interval is not set by user if(sampleInterval == -1) { if(time ==1) sampleInterval = 1; else if(time <=5) sampleInterval = 10; else if(time <=10) sampleInterval = 30; else sampleInterval = 60; data.push_back("default"); data.push_back(boost::lexical_cast(sampleInterval)); CLIDataMap["sample-interval"] = data; samples = ((time*60)/sampleInterval)-1; data.clear(); data.push_back("default"); data.push_back(boost::lexical_cast(samples)); CLIDataMap["samples"] = data; } else { samples = ((time*60)/sampleInterval)-1; data.clear(); data.push_back("set"); data.push_back(boost::lexical_cast(samples)); CLIDataMap["samples"] = data; } } string CLIHandler::generateDateString() { time_t rawtime; struct tm * timeinfo; char buffer [80]; string timeStr; time ( &rawtime ); startEpoch = rawtime; timeinfo = gmtime ( &rawtime ); strftime (buffer,80,"%a %b %d %H:%M:%S GMT %Y",timeinfo); vector data; data.push_back("default"); data.push_back(buffer); CLIDataMap["start-time"] = data; timeinfo = localtime ( &rawtime ); strftime (buffer,80,"%Y%m%d_%H%M%S",timeinfo); timeStr = buffer; return timeStr; } bool CLIHandler::isIPv6Addr(string ipAddr) { struct sockaddr_in6 sa; if (inet_pton(AF_INET6, ipAddr.c_str(), &(sa.sin6_addr)) == 1) { return true; } else { return false; } } bool CLIHandler::isIPv4Addr(string ipAddr) { struct sockaddr_in sa; if (inet_pton(AF_INET, ipAddr.c_str(), &(sa.sin_addr)) == 1) { return true; } else { return false; } } string CLIHandler::getIPFamily() { return ipFamily; } void CLIHandler::getIPAddressAndHostName(vector tmpData) { #ifdef WIN32 WSADATA wsadata; WSAStartup(MAKEWORD(2,0), &wsadata); #endif hostent * hostinfo; clusterIPs.clear(); for (int i = 0; i < tmpData.size(); i++) { int ipType = 0; if (isIPv4Addr(tmpData[i])) { // cout << "Cluster IPv4 addr: " << tmpData[i] << endl; ipType = AF_INET; ipFamily = "ipv4"; } else if (isIPv6Addr(tmpData[i])) { // cout << "Cluster IPv6 addr: " << tmpData[i] << endl; ipType = AF_INET6; ipFamily = "ipv6"; } else if(isalpha(tmpData[i].c_str()[0])) { // cout << "Cluster hostname: " << tmpData[i] << endl; clusterName.push_back(tmpData[i]); if((hostinfo = gethostbyname(tmpData[i].c_str())) != NULL) { clusterIPs.push_back(inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list)); } else { cout << "FATAL: unable to resolve IP addr for cluster: " << tmpData[i] << endl; exit(1); } } else { cout << "FATAL: Invalid IP address and/or cluster name: " << tmpData[i] << endl; exit(1); } if (ipType != 0) { // cout << "Attempting to discover cluster name from IP: " << tmpData[i] << endl; clusterIPs.push_back(tmpData[i]); hostinfo = gethostbyaddr(tmpData[i].c_str(), sizeof tmpData[i], ipType); if(hostinfo != NULL) { // cout << "Resolved to cluster name: " << hostinfo->h_name << endl; clusterName.push_back(hostinfo->h_name); } else { clusterName.push_back(""); cout << "WARNING : Not able to get cluster name from cluster IP: " << tmpData[i] << endl; } } } #ifdef WIN32 WSACleanup(); #endif } void CLIHandler::getLocalHostInfo() { #ifdef WIN32 WSADATA wsadata; WSAStartup(MAKEWORD(2,0), &wsadata); #endif char osVersion[255]; char name[255]; hostent * hostinfo; #ifdef WIN32 sprintf(osVersion,"%s",getenv("os")); #else //we shall execute the 'uname -s command to get the OS version FILE *pPipe; char *command = "uname -s"; if( (pPipe = popen( command, "r" )) == NULL ) sprintf(osVersion, "%s", " "); fgets(osVersion, 255, pPipe); int strl = strlen(osVersion); if(strl > 1) osVersion[strl - 1] = '\0'; //need to chop off the newline character from the result if (pclose(pPipe)) { commonOutputHandle->writeDataToLogFile("ERROR","Error while getting the OS Version"); } #endif //struct in_addr addr; //generate IP and host name for the box if( gethostname ( name, sizeof(name)) == 0) { vector data; data.push_back("set"); data.push_back(name); CLIDataMap["host-name"] = data; if((hostinfo = gethostbyname(name)) != NULL) { data.clear(); data.push_back("set"); data.push_back(inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list)); CLIDataMap["host-ip"] = data; } // Added for *IX flavor else { #ifndef WIN32 FILE *tmpPipe; char hostString[512]; string hostIP = ""; string hostName1 = boost::lexical_cast(name); string command = "host " + hostName1; if((tmpPipe = popen( const_cast(command.c_str()), "r" )) == NULL ) { sprintf(hostString, "%s", " "); } fgets(hostString, 512, tmpPipe); int strl = strlen(hostString); if(strl > 1) { hostString[strl - 1] = '\0'; //need to chop off the newline character from the result if(strstr(hostString, "not found")) { commonOutputHandle->writeDataToLogFile("WARNING","Failed to get IP address with DNS lookup"); } else { vector tmpVector = tokenizeString(hostString, " "); hostIP = tmpVector.back(); } } pclose(tmpPipe); if(!hostIP.empty()) { data.clear(); data.push_back("set"); data.push_back(hostIP); CLIDataMap["host-ip"] = data; } #endif } data.clear(); data.push_back("set"); data.push_back(osVersion); CLIDataMap["HOST-OS-VERSION"] = data; } #ifdef WIN32 WSACleanup(); #endif } vector CLIHandler::tokenizeString(string dataStr, string sep) { vector output; char * token; char *dataArr; dataArr = new char[dataStr.length() + 1]; strcpy(dataArr, dataStr.c_str()); token = strtok (dataArr, sep.c_str()); while (token != NULL) { output.push_back(token); token = strtok (NULL, sep.c_str()); } delete [] dataArr; return output; } string CLIHandler::getPresetFileName() { return presetFileName; } string CLIHandler::getOutputFileName() { return outputFileName; } string CLIHandler::getSystemShellPassword() { return freeBSDPasswd; } void CLIHandler::setSystemShellPassword(string passwd) { freeBSDPasswd = passwd; } int CLIHandler::getMaxRunTime() { return maxRunTime; } int CLIHandler::getSampleTime() { return sampleTime; } int CLIHandler::getRequestTimeoutSecs() { return requestTimeoutSecs; } int CLIHandler::getNumberOfIter() { return numOfIter; } int CLIHandler::getSampleTimeBtwIter() { return sampleTimeBtwIter; } int CLIHandler::getSampleInterval() { return sampleInterval; } int CLIHandler::getSamples() { return samples; } bool CLIHandler::getSSHKeyProvidedFlag() { return SSHKeyProvided; } vector CLIHandler::getClusterIP() { return clusterIPs; } void CLIHandler::push_ClusterIP(string ClusterIP) { clusterIPs.push_back(ClusterIP); } void CLIHandler::pop_ClusterIP() { clusterIPs.pop_back(); } void CLIHandler::erase_ClusterIP(int pos) { clusterIPs.erase(clusterIPs.begin() + pos); } vector CLIHandler::getClusterName() { return clusterName; } vector CLIHandler::getNodeIPs() { return nodeIPs; } void CLIHandler::setNodeIPs(vector names) { nodeIPs = names; string nameStr; for(int i=0; i<(int)nodeIPs.size(); i++) { nameStr.append(nodeIPs[i] + ", ");; } vector data; data.push_back("set"); data.push_back(nameStr); CLIDataMap["nodes"] = data; } void CLIHandler::setNodeIPs(vector names, int index) { nodeIPs = names; string nameStr; clusterToNodeMap[clusterIPs[index]] = std::vector(nodeIPs.begin() + nodeToClusterMap.size(), nodeIPs.end()); for(int i=0; i<(int)nodeIPs.size(); i++) { if (nodeToClusterMap.size() < nodeIPs.size()) { /* We don't clear nodeIPs vector. It will having list of all the nodes of * previous clusters. We insert new node after last node of previous cluster */ nodeToClusterMap[nodeIPs[nodeToClusterMap.size()]] = clusterIPs[index]; } nameStr.append(nodeIPs[i] + ", ");; } vector data; data.push_back("set"); data.push_back(nameStr); CLIDataMap["nodes"] = data; } void CLIHandler::setNodeToClusterMap(string nodeIP, string clusterMgmtIP) { nodeToClusterMap[nodeIP] = clusterMgmtIP; } vector CLIHandler::getNodeNames() { return nodeNames; } void CLIHandler::setNodeNames(vector names) { nodeNames = names; } vector CLIHandler::getHostNames() { return hostNames; } map > CLIHandler::getIncludeCommands() { return includeCommands; } map > CLIHandler::getExcludeCommands() { return excludeCommands; } map > CLIHandler::getCLIDataMap() { return CLIDataMap; } string CLIHandler::findNodeCluster(string nodeIP) { return nodeToClusterMap[nodeIP]; } vector CLIHandler::getEnableFlagCommands() { return enableFlagCommands; } string CLIHandler::getStutterStatitLevel() { return stutterStatitLevel; } string CLIHandler::getSSHPrivateKeyPath() { return SSHPrivateKeyPath; } string CLIHandler::getSSHKnownHostsFilePath() { return SSHKnownHostsFilePath; } string CLIHandler::getSSHPublicKeyPath() { return SSHPublicKeyPath; } string CLIHandler::getSSHKeyPath() { return sshKeyPath; } time_t CLIHandler::getStartEpoch() { return startEpoch; } string CLIHandler::getVersion() { return version; } string CLIHandler::getClusterID() { return clusterID; } string CLIHandler::getFilerLoginUser() { return filerLoginUser; } string CLIHandler::getFilerMode() { return filerMode; } bool CLIHandler::getHostOrFilerFlag() { return onlyFilerFlag; } bool CLIHandler::getSSHFlag() { return sshFlag; } bool CLIHandler::getModuleInstFlag() { return moduleInstFlag; } vector CLIHandler::getTargetProfileNames() { return targetProfiles; } bool CLIHandler::getProfileFlag() { return profileFlag; } vector CLIHandler::getLoginCredOfFiler() { return loginCredOfFiler; } void CLIHandler::setClusterID(string data) { clusterID = data; } void CLIHandler::setSSHPrivateKeyPath(string path) { SSHPrivateKeyPath = path; vector data; data.push_back("default"); data.push_back(SSHPrivateKeyPath); CLIDataMap["sshPrivatekey-path"] = data; } void CLIHandler::setSSHPublicKeyPath(string path) { SSHPublicKeyPath = path; vector data; data.push_back("default"); data.push_back(SSHPublicKeyPath); CLIDataMap["sshPublickey-path"] = data; } bool CLIHandler::getConfigAllFlag() { return configAllFlag; } //burt 662532 bool CLIHandler::getWaflBufstatsFlag() { return WaflBufstats; } //663869 perfstat8 crashed: double free or corruption !prev: 0xd95504e8 bool CLIHandler::getstatformatflag() { return statformatflag; } //Burt720131 bool CLIHandler::getIterativeWaflCPstatsFlag() { return iterWaflCPstats; } bool CLIHandler::getSystemShellLoginFlag() { return systemShellLoginFlag; } void CLIHandler::setSystemShellLoginFlag(bool bsysshellFlag) { systemShellLoginFlag = bsysshellFlag; } void CLIHandler::processOptions(string key, string value) { // This is to check whether the value is option or a string if(!value.empty()) { string str = value; string subStr = str.substr(0,1); if(subStr.compare("-") == 0) { string errorMsg = "Error while parsing " + key; errorMsg = errorMsg + " options.Exiting..."; commonOutputHandle->writeDataToLogFile("ERROR", errorMsg); commonOutputHandle->writeDataToLogFile("ERROR", "Please run \"perfstat8.exe -h\" for details on options.\n"); exit(0); } } if (key.compare("help") == 0) { readManPageFile(0); exit(0); } else if (key.compare("version") == 0) { readManPageFile(1); exit(0); } else if (key.compare("mode") == 0) { // BURT:627040 replace 10-mode option CLI by alias cluster-mode, cluster, c. std::transform(value.begin(), value.end(), value.begin(), (int(*)(int))std::tolower); if(value.compare("10-mode") == 0 || value.compare("cluster") == 0 || value.compare("cluster-mode") == 0 || value.compare("c") == 0) { value.assign("10-mode"); } //mode should be in {7-mode, cluster-mode, c-mode, c, 10-mode} if( !(value.compare("10-mode") == 0) && !(value.compare("7-mode") == 0)){ cout << "ERROR, Error mode option does not support."< data; data.push_back("set"); data.push_back(value); CLIDataMap["Mode"] = data; } else if (key.compare("print-preset") ==0) { perfstatPreset* preset = new perfstatPreset(this); vector vecPreset = (*preset).getPerfstatPreset(); for(int i=0; i<(int)vecPreset.size(); i++) { cout << vecPreset[i] << "\n"; } delete preset; exit(0); } else if (key.compare("unzip") ==0) { outputHandler ohandle; ohandle.generateUnArchiveFile(value); cout << "unzipping file : " << value; exit(0); } else if (key.compare("verbose")==0) { msgOutputLevel = "verbose"; vector data; data.push_back("set"); data.push_back(msgOutputLevel); CLIDataMap["Message-Level"] = data; } else if (key.compare("debug")==0) { msgOutputLevel = "debug"; vector data; data.push_back("set"); data.push_back(msgOutputLevel); CLIDataMap["Message-Level"] = data; } else if (key.compare("quiet")==0) { msgOutputLevel = "quiet"; vector data; data.push_back("set"); data.push_back(msgOutputLevel); CLIDataMap["Message-Level"] = data; } else if (key.compare("ip-version") == 0) { if (!value.compare("4") || !value.compare("ipv4")) { ipFamily = "ipv4"; } else if (!value.compare("6") || !value.compare("ipv6")){ ipFamily = "ipv6"; } else { cout << "FATAL: illegal value to --ip-version: " << value << endl << "Acceptable values are 4,ipv4,6 and ipv6." << endl; exit(1); } vector data; data.push_back("set"); data.push_back(ipFamily); CLIDataMap["IP Version"] = data; } else if (key.compare("full-stutter-statit")==0) { stutterStatitLevel = "full"; vector data; data.push_back("set"); data.push_back(stutterStatitLevel); CLIDataMap["Stutter-Statit"] = data; } else if (key.compare("sshprivatekey-file")==0) { // BURT 541639 struct stat tmpFileInfo; int returnVal; returnVal = stat(value.c_str(),&tmpFileInfo); if( returnVal == 0) { //Stat managed to get the file attributes that means the file exists, check if its a directory if(tmpFileInfo.st_mode & S_IFDIR ) { cout << "ERROR\tThe sshprivatekey-file option value is not a regular file" << endl; #ifndef WIN32 cout << "Please run \"perfstat8.exe -h\" for details on options." << endl; exit(0); #endif } } SSHPrivateKeyPath = value; SSHKeyProvided = true; vector data; data.push_back("set"); data.push_back(SSHPrivateKeyPath); CLIDataMap["sshprivatekey-path"] = data; } else if (key.compare("SSHKnownHosts-FilePath")==0) { struct stat tmpFileInfo; int returnVal; returnVal = stat(value.c_str(),&tmpFileInfo); if( returnVal == 0) { //Stat managed to get the file attributes that means the file exists, check if its a directory if(tmpFileInfo.st_mode & S_IFDIR ) { cout << "ERROR\tThe SSHKnownHosts-FilePath option value is not a regular file" << endl; #ifndef WIN32 cout << "Please run \"perfstat8.exe -h\" for details on options." << endl; exit(0); #endif } } SSHKnownHostsFilePath = value; vector data; data.push_back("set"); data.push_back(SSHKnownHostsFilePath); CLIDataMap["SSHKnownHosts-FilePath"] = data; } else if (key.compare("no-stutter-statit")==0) { stutterStatitLevel = "no"; vector data; data.push_back("set"); data.push_back(stutterStatitLevel); CLIDataMap["Stutter-Statit"] = data; } //burt 662532 "wafl_bufstats" need to be removed else if (key.compare("wafl-bufstats")==0) { WaflBufstats = true; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["wafl-bufstats"] = data; } //663869 perfstat8 crashed: double free or corruption !prev: 0xd95504e8 else if (key.compare("stats-format")==0) { statformatflag = true; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["stats-format"] = data; } //Burt720131 else if (key.compare("iter-wafl-cpstats") == 0) { iterWaflCPstats = true; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["iter-wafl-cpstats"] = data; } //Burt744483 /* else if (key.compare("no-systemshell-login") == 0) { systemShellLoginFlag = false; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["no-systemshell-login"] = data; } */ else if (key.compare("config-all")==0) { configAllFlag = true; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["config-all"] = data; } else if (key.compare("preset-file")==0) { presetFileName = value; vector data; data.push_back("set"); data.push_back(value); CLIDataMap["Preset-File"] = data; } else if (key.compare("clusterinfo")==0) { clusterIPs = tokenizeString(value, ","); getIPAddressAndHostName(clusterIPs); string IPaddrs; string Clusternames; for(int i = 0; i<(int)clusterIPs.size(); i++) { if((i+1) == (int)clusterIPs.size()) { IPaddrs.append(clusterIPs[i]); Clusternames.append(clusterName[i]); } else { IPaddrs.append(clusterIPs[i] + ", "); Clusternames.append(clusterName[i]); } } vector data; data.push_back("set"); data.push_back(IPaddrs); CLIDataMap["Cluster-IP"] = data; data.clear(); data.push_back("set"); data.push_back(Clusternames); CLIDataMap["Cluster-Name"] = data; } else if (key.compare("output-file")==0) { outputFileName = value; vector data; data.push_back("set"); data.push_back(outputFileName); CLIDataMap["Output-File"] = data; } else if (key.compare("max-run-time")==0) { maxRunTime = boost::lexical_cast(value); vector data; data.push_back("set"); data.push_back(value); CLIDataMap["max-run-time"] = data; } else if (key.compare("time")==0) { sampleTime = boost::lexical_cast(value); vector data; data.push_back("set"); data.push_back(value); CLIDataMap["Time"] = data; } else if (key.compare("sample-interval")==0) { sampleInterval = boost::lexical_cast(value); vector data; data.push_back("set"); data.push_back(value); CLIDataMap["sample-interval"] = data; } else if (key.compare("iteration")==0) { vector indata = tokenizeString(value, ","); if(indata.size() > 1) { numOfIter = boost::lexical_cast(indata[0].c_str()); sampleTimeBtwIter = boost::lexical_cast(indata[1].c_str()); vector data; data.push_back("set"); data.push_back(indata[0]); CLIDataMap["Iterations"] = data; data.clear(); data.push_back("set"); data.push_back(indata[1]); CLIDataMap["iter-interval"] = data; } else { numOfIter = boost::lexical_cast(indata[0].c_str()); vector data; data.push_back("set"); data.push_back(indata[0]); CLIDataMap["Iterations"] = data; } } else if (key.compare("nodes") == 0) { nodeIPs = tokenizeString(value, ","); string names; for(int i=0; i<(int)nodeIPs.size(); i++) { if (!isIPv4Addr(nodeIPs[i]) && !isIPv6Addr(nodeIPs[i])) { cout << "FATAL: Invalid IP address: " << nodeIPs[i] << endl; exit(1); } if((i+1) == (int)nodeIPs.size()) { names.append(nodeIPs[i]); } else { names.append(nodeIPs[i] + ", "); } } vector data; data.push_back("set"); data.push_back(names); CLIDataMap["Nodes"] = data; } else if (key.compare("hosts")==0) { /* The format for Remote host at CLI is ,, */ bIsHostFlag = true; vector allHostDetails = tokenizeString(value, ","); string names = ""; for(size_t nIndex = 0; nIndex < allHostDetails.size(); ++nIndex) { vector hostDetails = tokenizeString(allHostDetails[nIndex], ":"); if(hostDetails.size() == 3) { hostNames.push_back(hostDetails[0]); SetRemoteHostCreds(hostDetails[0], hostDetails[1], hostDetails[2]); string tmp = hostDetails[0]; if((nIndex+1) == (int)allHostDetails.size()) { tmp = tmp + ":" + hostDetails[1]; names.append(tmp); } else { tmp = tmp + ":" + hostDetails[1] + ", "; names.append(tmp); } } else { commonOutputHandle->writeDataToLogFile("ERROR", "Error while parsing Remote host options Exiting"); commonOutputHandle->writeDataToLogFile("ERROR", "Please run \"perfstat8.exe -h\" for details on options.\n"); exit(0); } } vector data; data.push_back("set"); data.push_back(names); CLIDataMap["Hosts"] = data; } else if (key.compare("include")==0) { vector data; data.push_back("set"); data.push_back(value); CLIDataMap["include"] = data; vector inCommands = tokenizeString(value, ";"); string command; for(int i=0; i<(int)inCommands.size(); i++) { vector tmpVec = tokenizeString(inCommands[i], "="); vector valueVec = tokenizeString(tmpVec[1], ","); includeCommands[tmpVec[0]].insert(includeCommands[tmpVec[0]].end(),valueVec.begin(),valueVec.end()); } } else if (key.compare("exclude")==0) { vector data; data.push_back("set"); data.push_back(value); CLIDataMap["exclude"] = data; vector exCommands = tokenizeString(value, ";"); string command; for(int i=0; i<(int)exCommands.size(); i++) { vector tmpVec = tokenizeString(exCommands[i], "="); vector valueVec = tokenizeString(tmpVec[1], ","); excludeCommands[tmpVec[0]].insert(excludeCommands[tmpVec[0]].end(), valueVec.begin(), valueVec.end()); } // Check for --exclude="SHELL=SYSTEMSHELL" for(map >::iterator iter = excludeCommands.begin();iter != excludeCommands.end(); iter++ ) { string key = (*iter).first; vector value = ((*iter).second); std::transform(key.begin(), key.end(), key.begin(), (int(*)(int))std::toupper); if(key.compare("SHELL") == 0) { for(size_t vecIndex = 0; vecIndex < value.size(); ++vecIndex) { if(value[vecIndex].compare("SYSTEMSHELL") == 0) { bsystemShellExclude = true; break; } } break; } } } else if (key.compare("enable-flag")==0) { vector data; data.push_back("set"); data.push_back(value); CLIDataMap["enable-flag"] = data; enableFlagCommands = tokenizeString(value, ","); } else if (key.compare("login")==0) { filerLoginUser = value; vector data; data.push_back("set"); data.push_back(value); CLIDataMap["FilerLoginUser"] = data; } else if (key.compare("SKTRACE_POINTS")==0) { vector tmpSktracePoints = tokenizeString(value, ","); string names; for(int i=0; i<(int)tmpSktracePoints.size(); i++) { if((i+1) == (int)tmpSktracePoints.size()) names.append(tmpSktracePoints[i]); else names.append(tmpSktracePoints[i] + ", "); //Now fill the sktrace point MAP. vector tmpSKpoint = tokenizeString(tmpSktracePoints[i], ":"); if( (int)tmpSKpoint.size() != 2 ) { //syntax will be ":" cout<<"Error Invalid sktrace point syntax: "<:\" "< data; data.push_back("set"); data.push_back(names); CLIDataMap["SKTRACE_POINTS"] = data; //set the doSktraceFlag true doSktraceFlag = true; } else if (key.compare("FILER_ONLY")==0) { onlyFilerFlag = true; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["ONLYFILERFLAG"] = data; } else if (key.compare("SSH")==0) { sshFlag = true; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["SSHFLAG"] = data; } else if (key.compare("MODULE_INST")==0) { rasModuleInsts = tokenizeString(value, ","); string names; for(int i=0; i<(int)rasModuleInsts.size(); i++) { if((i+1) == (int)rasModuleInsts.size()) names.append(rasModuleInsts[i]); else names.append(rasModuleInsts[i] + ", "); } vector data; data.push_back("set"); data.push_back(names); CLIDataMap["MODULE_INST"] = data; moduleInstFlag = true; } else if (key.compare("PROFILES")==0) { profileFlag = true; targetProfiles = tokenizeString(value, ","); string names; for(int i=0; i<(int)targetProfiles.size(); i++) { if((i+1) == (int)targetProfiles.size()) names.append(targetProfiles[i]); else names.append(targetProfiles[i] + ", "); } vector data; data.push_back("set"); data.push_back(names); CLIDataMap["PROFILES"] = data; } else if (key.compare("app_name")==0) { appName = value; appFlag = true; vector data; data.push_back("set"); data.push_back(value); CLIDataMap["HOST_APP_NAME"] = data; } else if (key.compare("app_args")==0) { appArgs = value; //Find the oracle_login and replace the passwd with string size_t start = 0; size_t end = value.find("/",start); if(end!= string::npos) { int j=end+1; while(!isspace(value[j]) && isalnum(value[j])) { value[j]='*'; j++; } } vector data; data.push_back("set"); data.push_back(value); CLIDataMap["HOST_APP_ARGS"] = data; } else if (key.compare("switch")==0) { isSwitchFlag = true; vector tmpSwitchInfo; tmpSwitchInfo =tokenizeString(value, ","); string names; for(int i=0; i<(int)tmpSwitchInfo.size(); i++) { vector tmpSwitchCreds; tmpSwitchCreds = tokenizeString(tmpSwitchInfo[i], ":"); /** The syntax for switch details at commandline is ":::". If this option doesnt have all the 4 fields, we exit with error. So check the size of this tmp vector, if the size is less then 4 that the syntax is not followed properly at commandline for this switch */ if(tmpSwitchCreds.size() == 4) { vector switchCreds; targetSwitches.push_back(tmpSwitchCreds[0]); //Switch IP switchCreds.push_back(tmpSwitchCreds[1]); //Switch type switchCreds.push_back(tmpSwitchCreds[2]); //Switch login user switchCreds.push_back(tmpSwitchCreds[3]); //Switch login password switchDetails[targetSwitches[i]] = switchCreds; if((i+1) == (int)tmpSwitchInfo.size()) names.append(targetSwitches[i]+ ":" + tmpSwitchCreds[1]); //Header will print switch target switch details as switchIP:switchtype else names.append(targetSwitches[i]+ ":" + tmpSwitchCreds[1] + ", "); } else { commonOutputHandle->writeDataToLogFile("ERROR", "Error while parsing Switch options Exiting"); commonOutputHandle->writeDataToLogFile("ERROR", "Please run \"perfstat8.exe -h\" for details on options.\n"); exit(0); } } vector data; data.push_back("set"); data.push_back(names); CLIDataMap["SWITCH"] = data; } else if (key.compare("log") == 0) { bbackupLog = true; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["BACKUPLOG"] = data; } else if (key.compare("LEGACY_MODE") == 0) { bLegacyMode = true; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["LEGACY_MODE"] = data; } //else if (key.compare("OPENSSH") == 0) else if (key.compare("OPENSSH") == 0) { bOpenSSHFlag = true; vector data; data.push_back("set"); data.push_back("true"); CLIDataMap["OPENSSH"] = data; } else if(key.compare("diag-passwd") == 0) { bdiagPasswdProvided = true; diagPasswdCMode = value; } else if(key.compare("mcc") == 0) { bmccFlag = true; } else if(key.compare("SSHKey-passPhrase") == 0) { bkeyPassPharse = true; keyPassPhrase = value; } else if (key.compare("maxRetries")==0) { maxRetries = boost::lexical_cast(value); vector data; data.push_back("set"); data.push_back(value); CLIDataMap["maxRetries"] = data; } else if(key.compare("Clean-Up") == 0) { bcleanUpFlag = true; } else if(key.compare("vol_db") == 0) { bVol_dbFlag = true; } else { // FUTURE USE } } void CLIHandler::setSSHKey(CkSshKey* sshKey) { SSHKey = sshKey; } CkSshKey* CLIHandler::getSSHKey() { return SSHKey; } void CLIHandler::processCLIOptions(boostOptions::variables_map varMap) { setDefaults(); if (varMap.count("help")) { processOptions("help", ""); } if (varMap.count("version")) { processOptions("version", ""); } if (varMap.count("mode")) { string filerModeStr = varMap["mode"].as >().back(); processOptions("mode", filerModeStr); } if (varMap.count("print-preset")) { processOptions("print-preset", ""); } if (varMap.count("unzip")) { string filename = varMap["unzip"].as(); processOptions("unzip", filename); } if (varMap.count("verbose")) { processOptions("verbose", ""); } if (varMap.count("debug")) { processOptions("debug", ""); } if (varMap.count("quiet")) { processOptions("quiet", ""); } if (varMap.count("full-stutter-statit")) { processOptions("full-stutter-statit", ""); } if (varMap.count("sshprivatekey-file")) { SSHPrivateKeyPath = varMap["sshprivatekey-file"].as >().back(); processOptions("sshprivatekey-file", SSHPrivateKeyPath); } if (varMap.count("no-stutter-statit")) { processOptions("no-stutter-statit", ""); } //burt 662532 "wafl_bufstats" need to be removed if (varMap.count("wafl-bufstats")) { processOptions("wafl-bufstats", ""); } //663869 perfstat8 crashed: double free or corruption !prev: 0xd95504e8 if (varMap.count("stats-format")) { processOptions("stats-format", ""); } //Burt720131 if (varMap.count("iter-wafl-cpstats")) { processOptions("iter-wafl-cpstats", ""); } /* //Burt744483 if (varMap.count("no-systemshell-login")) { processOptions("no-systemshell-login", ""); } */ if (varMap.count("config-all")) { processOptions("config-all", ""); } if (varMap.count("preset-file")) { string fileName = varMap["preset-file"].as >().back(); processOptions("preset-file", fileName); } if (varMap.count("clusterinfo")) { // Remove duplicate from the vector vectortemp = vector(varMap["clusterinfo"].as >().begin(), varMap["clusterinfo"].as >().end()); std::sort(temp.begin(), temp.end()); temp.erase(std::unique(temp.begin(), temp.end()), temp.end()); string tmpData = temp[0]; for(int i = 1; i < temp.size(); i++) tmpData += "," + temp[i]; processOptions("clusterinfo", tmpData); } if (varMap.count("output-file")) { outputFileName = varMap["output-file"].as >().back(); processOptions("output-file", outputFileName); } if (varMap.count("max-run-time")) { maxRunTime = varMap["max-run-time"].as >().back(); processOptions("max-run-time", boost::lexical_cast(maxRunTime)); } if (varMap.count("time")) { sampleTime = varMap["time"].as >().back(); processOptions("time", boost::lexical_cast(sampleTime)); } if (varMap.count("sample-interval")) { sampleInterval = varMap["sample-interval"].as >().back(); processOptions("sample-interval", boost::lexical_cast(sampleInterval)); } if (varMap.count("iteration")) { string iterStr = varMap["iteration"].as >().back(); processOptions("iteration", iterStr); } if (varMap.count("nodes")) { // Remove duplicate from the vector std::vector temp = vector(varMap["nodes"].as >().begin(), varMap["nodes"].as >().end()); std::sort(temp.begin(), temp.end()); temp.erase(std::unique(temp.begin(), temp.end()),temp.end()); string iterStr = temp[0]; for(int i = 1; i < temp.size(); i++) iterStr += "," + temp[i]; processOptions("nodes", iterStr); } if (varMap.count("hosts")) { // Remove duplicate from the vector std::vector temp = vector(varMap["hosts"].as >().begin(), varMap["hosts"].as >().end()); std::sort(temp.begin(), temp.end()); temp.erase(std::unique(temp.begin(), temp.end()),temp.end()); string iterStr = temp[0]; for(int i = 1; i < temp.size(); i++) iterStr += "," + temp[i]; processOptions("hosts", iterStr); } if (varMap.count("include")) { std::vector temp = vector(varMap["include"].as >().begin(), varMap["include"].as >().end()); string iterStr = temp[0]; for(int i = 1; i < temp.size(); i++) iterStr += ";" + temp[i]; processOptions("include", iterStr); } if (varMap.count("exclude")) { std::vector temp = vector(varMap["exclude"].as >().begin(), varMap["exclude"].as >().end()); string iterStr = temp[0]; for(int i = 1; i < temp.size(); i++) iterStr += ";" + temp[i]; processOptions("exclude", iterStr); } if (varMap.count("enable-flag")) { string iterStr = varMap["enable-flag"].as(); processOptions("enable-flag", iterStr); } if (varMap.count("login")) { string filerLoginUserStr = varMap["login"].as(); processOptions("login", filerLoginUserStr); } if (varMap.count("SKTRACE_POINTS")) { string skTracePointStr = varMap["SKTRACE_POINTS"].as(); processOptions("SKTRACE_POINTS", skTracePointStr); } if (varMap.count("PROFILES")) { // Remove duplicate from the vector std::vector temp = vector(varMap["PROFILES"].as >().begin(), varMap["PROFILES"].as >().end()); std::sort(temp.begin(), temp.end()); temp.erase(std::unique(temp.begin(), temp.end()),temp.end()); string profileTargetStr = temp[0]; for(int i = 1; i < temp.size(); i++) profileTargetStr += "," + temp[i]; processOptions("PROFILES", profileTargetStr); } if (varMap.count("FILER_ONLY")) { processOptions("FILER_ONLY", ""); } if (varMap.count("SSH")) { processOptions("SSH", ""); } if (varMap.count("MODULE_INST")) { // Remove duplicate from the vector std::vector temp = vector(varMap["MODULE_INST"].as >().begin(), varMap["MODULE_INST"].as >().end()); std::sort(temp.begin(), temp.end()); temp.erase(std::unique(temp.begin(), temp.end()),temp.end()); string modInstTargetStr = temp[0]; for(int i = 1; i < temp.size(); i++) modInstTargetStr += "," + temp[i]; processOptions("MODULE_INST", modInstTargetStr); } if (varMap.count("app_name")) { string appNameStr = varMap["app_name"].as(); processOptions("app_name", appNameStr); } if (varMap.count("app_args")) { string appArgsStr = varMap["app_args"].as(); processOptions("app_args", appArgsStr); } if (varMap.count("switch")) { string targetSwStr = varMap["switch"].as(); processOptions("switch", targetSwStr); } if (varMap.count("log")) { processOptions("log", ""); } if (varMap.count("LEGACY_MODE")) { processOptions("LEGACY_MODE", ""); } if (varMap.count("openssh")) { processOptions("OPENSSH", ""); } if (varMap.count("diag-passwd")) { string diagData = varMap["diag-passwd"].as(); processOptions("diag-passwd", diagData); } if (varMap.count("mcc")) { processOptions("mcc",""); } if (varMap.count("SSHKey-passPhrase")) { string passPhrse = varMap["SSHKey-passPhrase"].as(); processOptions("SSHKey-passPhrase",passPhrse); } if (varMap.count("SSHKnownHosts-FilePath")) { SSHKnownHostsFilePath = varMap["SSHKnownHosts-FilePath"].as >().back(); processOptions("SSHKnownHosts-FilePath", SSHKnownHostsFilePath); } if (varMap.count("maxRetries")) { maxRetries = varMap["maxRetries"].as >().back(); processOptions("maxRetries", boost::lexical_cast(maxRetries)); } if (varMap.count("Clean-Up")) { processOptions("Clean-Up",""); } if (varMap.count("vol_db")) { processOptions("vol_db",""); } if (varMap.count("ip-version")) { processOptions("ip-version", varMap["ip-version"].as()); } getLocalHostInfo(); if(bdiagPasswdProvided == true) { if(filerMode.compare("10-mode") == 0) { if(diagPasswdCMode.find(",") != string::npos) { cout << "ERROR, Error while parsing diag-passwd options Exiting" << endl; cout << "ERROR, Please run \"perfstat8.exe -h\" for details on options." << endl; exit(0); } } else{ vector sysShellDetails = tokenizeString(diagPasswdCMode, ","); for(int diagIndex = 0; diagIndex < sysShellDetails.size(); ++diagIndex) { vector diagDets = tokenizeString(sysShellDetails[diagIndex],":"); if(diagDets.size() == 2) { systemShellPasswds[diagDets[0]] = diagDets[1]; } else { cout << "ERROR, Error while parsing diag-passwd options Exiting" << endl; cout << "ERROR, Please run \"perfstat8.exe -h\" for details on options." << endl; exit(0); } } } } } //#ifdef WIN32 void CLIHandler::collectCLIOptions(int argCount, char* argList[], outputHandler* oHandle) { vector data; data.push_back("set"); string tmpCmd; for(int t=1; t:: pos =0; charCount = 0; bFlag = false; bool bhostFound = false; string strHostRep[4] = {"--hosts ", "--hosts=", "-H=", "-H "}; for(size_t index = 0; index < 4; ++index) { int nPos = tmpCmd.find(strHostRep[index], 0); if(nPos != string::npos) { pos = nPos; bhostFound = true; break; } } if(bhostFound == true) { while ( (pos = tmpCmd.find(":", pos)) != string::npos ) { charCount++; if(charCount == 2) { //password start from second occurernce of ':' int tmp = pos + 1; while((!ispunct(tmpCmd[tmp]))) { tmpCmd[tmp]='*'; tmp++; if(isspace(tmpCmd[tmp])) { bFlag = true; break; } } charCount = 0; // reset counter for the next Remote Host } if(bFlag == true) { break; } pos++; } } data.push_back(tmpCmd); CLIDataMap["command_line"] = data; commonOutputHandle = oHandle; try { boostOptions::options_description commonOpt("Options (common)"); // We took last value if an option specified by multiple times. //typedef std::vector MultiOccurred; //MultiOccurred multivalue; commonOpt.add_options() ("help,h", "Produce help message.") ("version,v", "Prints perfstat version, and supported ONTAP versions.") ("quiet,q", "Suppress all non-error messages.") ("verbose", "Increase verbosity (beware: prints all command executions.") ("debug", "Beware verbose output. Both 'verbose' and 'debug' will add client-side timestamps to output..") ("dryrun", "Do not actually execute, just pretend.") ; boostOptions::options_description runModeOpt("Options ('run' mode)"); runModeOpt.add_options() ("clusterinfo", boostOptions::value >(), "cluster IP.") ("sample-interval", boostOptions::value >(), "Specifies statit/sysstat frequency") //("config-all", "captures config information in every iteration.") ("preset-file", boostOptions::value >(), "Use a custom preset file.") ("print-preset", "Prints the internal (default) preset file when running perfstat binary.") ("output-file,o", boostOptions::value >(), "Use a different output file name. (default: 'perfstat_data_yyyymmdd_hhmmss.zip')") ("keep-tmpdir", "Keep the temporary directory around.") ("config-all", "captures config information in every iteration. (default: CONFIG info is captured only during the first iteration)") ("run-timeout", boostOptions::value >(), "number of seconds to wait before killing a command. (default: 3600 seconds, or 1 hour)") ("force-dbladecli", "runs dbladecli -cF , which forcibly takes over the dbladecli.") ("time,t", boostOptions::value >(), "sample time in seconds, per iteration. (default: 120 seconds).") ("iteration,i", boostOptions::value >(), "repeat N times with M seconds between samples. (default: N=1, M=0)") ("nodes,n", boostOptions::value >(), "node names to collect from. (defaults to all nodes)") ("hosts,H", boostOptions::value >(), "host names to collect from. (defaults to localhost)") //(",F", "do not capture information from local host.") (",p", "capture performance data only (PERF, STATS, PARALLEL); same as --exclude='TYPE=CONFIG'.") (",c", "capture config info only; same as --exclude='TYPE=PERF,LOGS'") ("include", boostOptions::value >(), "Includes *only* commands matching PATTERN, and excludes everything else.") ("exclude", boostOptions::value >(), "Excludes *only* commands matching PATTERN, and excludes everything else.") ("enable-flag", boostOptions::value(), "unzips file") ("unzip", boostOptions::value(), "unzips file") ("full-stutter-statit", "") ("no-stutter-statit", "") //burt 662532 "wafl_bufstats" need to be removed ("wafl-bufstats", "Execute the wafl bufstats command.") //663869 perfstat8 crashed: double free or corruption !prev: 0xd95504e8 ("stats-format", "Parse stats stop command output") //Burt720131 ("iter-wafl-cpstats", "Enable collection of multiple samples of wafl cpstats command output over the sampling period") ("max-run-time", boostOptions::value >(), "") ("sshprivatekey-file", boostOptions::value >(), "") ("switch,S", boostOptions::value(), "Collect the data from target switches.The format should :::" ) ("mode,m", boostOptions::value >(), "Mode of the target controller <7-mode/10-mode> . (default: '10-mode')") ("FILER_ONLY,z", "Capture information from controller(s) only. (default: Along with controller(s),local host data also get collected)") ("SSH,s", "How the command should be execute, using SSH or RSH. (default: RSH)") ("MODULE_INST,r", boostOptions::value >(), "Capture RAS trace for the instances of pre-configured modules(default: instance-id 1)") ("PROFILES,p", boostOptions::value >(), "Capture MP Domain profiles from controllers") ("login,l", boostOptions::value(), "Login user of the controller to be sampled") ("SKTRACE_POINTS,k", boostOptions::value(), "Toggle sktrace data collection for the specified (trace point,trace level) value pairs. Valid trace points to enable are SK, WAFL, SCSITARGET, DISK, and READAHEAD. (default:SK,7,WAFL,4)") //("SKTRACE_BUF_SIZE,B", boostOptions::value(), "Specifies size of sktrace buffer. (default: 64m )") ("app_name,a", boostOptions::value(), "Application name for which data to be collected on the host. (default: none)") ("app_args,w", boostOptions::value(), "Arguments required to collect the application data. (default: none)") ("log,L", "Collects back up log information. (default: none)") ("LEGACY_MODE", "Collects data in Legacy Mode. (default: none)") ("openssh,g", "Collects data using OPENSSH. (default: none)") ("diag-passwd", boostOptions::value(), "diag (systemshell) password.") ("mcc","Collect data for metro cluster") ("SSHKey-passPhrase",boostOptions::value(), "PassPharse (SSH Key file Password) password.") ("SSHKnownHosts-FilePath",boostOptions::value >(), "OpenSSH know-host File Path") ("maxRetries,R",boostOptions::value >(), "Max Read Retry attempts") ("Clean-Up,C","Delete output folder from local host and delte perfstat user from controller.") ("vol_db","Collect vol_db lookup info volumes under each node") ("ip-version", boostOptions::value(), "Set IP version of node mgmt IPs to use in case of conflicts.") //("no-systemshell-login", "Force perfstat not to login into freebsd shell to execute systemshell commands") ; boostOptions::positional_options_description posOption; posOption.add("clusterinfo", -1); boostOptions::options_description allOptDesc("Allowed options :"); allOptDesc.add(commonOpt).add(runModeOpt);//.add(parseModeOpt); boostOptions::variables_map varMap; boostOptions::store(boostOptions::command_line_parser(argCount, argList). options(allOptDesc).positional(posOption).run(), varMap); //boostOptions::store(boostOptions::parse_command_line(argCount, argList, allOptDesc), varMap); boostOptions::notify(varMap); processCLIOptions(varMap); setSampleInterval(sampleTime); commonOutputHandle->setOutputLevel(msgOutputLevel); commonOutputHandle->createLogDataHandler(outputFileName); checkSSHOptions(); commonOutputHandle->writeDataToLogFile("INFO", "*------------- "+ version +" -------------*"); commonOutputHandle->writeDataToLogFile("INFO", "Parsing CLI options."); } catch(std::exception &e) { cout << "FATAL: caught exception during CLI parse" << e.what() << endl; commonOutputHandle->writeDataToLogFile("\nERROR", e.what()); commonOutputHandle->writeDataToLogFile("ERROR", "Error while parsing CLI options Exiting\n"); commonOutputHandle->writeDataToLogFile("ERROR", "Please run \"perfstat8.exe -h\" for details on options.\n"); exit(1); } catch(...) { cout << "FATAL: caught unknown exception during CLI parse" << endl; commonOutputHandle->writeDataToLogFile("ERROR", "unknown type of exception\n"); commonOutputHandle->writeDataToLogFile("ERROR", "Error while parsing CLI options Exiting\n"); commonOutputHandle->writeDataToLogFile("ERROR", "Please run \"perfstat8.exe -h\" for details on options.\n"); exit(1); } } void CLIHandler::setNodeDirectory(string nodeName, string dirPath) { nodeDirectory[nodeName]=dirPath; } string CLIHandler::getNodeDirectory(string nodeName) { return nodeDirectory[nodeName]; } void CLIHandler::setFilerCreds(string hostName, string userName, string passwd) { vector tmp; tmp.push_back(userName); tmp.push_back(passwd); filerLoginCreds[hostName] = tmp; } vector CLIHandler::getFilerCreds( string hostName) { return filerLoginCreds[hostName]; } vector CLIHandler::getModuleInstances() { return rasModuleInsts; } bool CLIHandler::getAppFlag() { return appFlag; } string CLIHandler::getAppName() { return appName; } string CLIHandler::getAppArgs() { return appArgs; } vector CLIHandler::getSwitchDetails(string hostname) { return switchDetails[hostname]; } bool CLIHandler::getSwitchFlag() { return isSwitchFlag; } bool CLIHandler::getMccFlag() { return bmccFlag; } bool CLIHandler::getCleanUpFlag() { return bcleanUpFlag; } string CLIHandler::getSSHKeyPassPhrase() { return keyPassPhrase; } bool CLIHandler::getSSHPassPhraseFlag() { return bkeyPassPharse; } int CLIHandler::getMaxRetries() { return maxRetries; } vector CLIHandler::getTargetSwitches() { return targetSwitches; } vector CLIHandler::GetRemoteHostCreds( string hostName) { return remoteHostCreds[hostName]; } bool CLIHandler :: GetRemoteHostFlag() { return bIsHostFlag; } vector CLIHandler :: GetRemoteHosts() { return hostNames; } void CLIHandler::SetRemoteHostCreds(string hostName, string userName, string passwd) { vector tmp; tmp.push_back(userName); tmp.push_back(passwd); remoteHostCreds[hostName] = tmp; } map CLIHandler::getAllSktracePoints() { return sktracePoints; } bool CLIHandler::getSKTraceFlag() { return doSktraceFlag; } bool CLIHandler::getVol_dbFlag() { return bVol_dbFlag; } bool CLIHandler :: getBackUpLogFlag() { return bbackupLog; } void CLIHandler :: setModuleInstFlag(bool moduleFlag) { moduleInstFlag = moduleFlag; } bool CLIHandler :: getSystemShellExcludedFlag() const { return bsystemShellExclude; } void CLIHandler :: setSystemShellExcludedFlag(bool systemShellflag) { bsystemShellExclude = systemShellflag; } string CLIHandler :: getSystemShellPasswd(string nodeIP, const int index) { if(index == 1) { return diagPasswdCMode; } else { return systemShellPasswds[nodeIP]; } } const bool CLIHandler :: isDiagPasswdProvided() const { return bdiagPasswdProvided; } const bool CLIHandler :: isclientCredsProvided() const { return bclientCredsProvided; } vector CLIHandler ::getClientCreds() { return clientCreds; } bool CLIHandler :: getLegacyMode() const { return bLegacyMode; } void CLIHandler ::setLegacyMode(bool legacyMode) { bLegacyMode = legacyMode; } bool CLIHandler :: getOPenSSHFlag() const { return bOpenSSHFlag; } void CLIHandler :: setOPenSSHFlag(bool openSSHFlag) { bOpenSSHFlag = openSSHFlag; } void CLIHandler :: checkSSHOptions() { bnativeRshPresent = checkRSH(); bool bisPlinkPresent = false; /* plink support Deprecated #ifdef WIN32 bisPlinkPresent = commonOutputHandle->fileExists("plink.exe"); if(bisPlinkPresent == false) { bisPlinkPresent = commonOutputHandle->fileExists("plink"); } #endif */ if(filerMode.compare("10-mode") == 0) { if(bLegacyMode == true) { // REVIEW_COMMENTS commonOutputHandle->writeDataToLogFile("STATUS", "--LEGACY_MODE option is supported only for 7-mode systems."); commonOutputHandle->writeDataToLogFile("STATUS", "Detected C-Mode. Ignoring the --LEGACY_MODE option and continuing in Normal mode."); bLegacyMode = false; } #ifdef WIN32 if(bOpenSSHFlag == true) { commonOutputHandle->writeDataToLogFile("STATUS", "-g option is supported only for 7-mode systems."); commonOutputHandle->writeDataToLogFile("STATUS", "Detected C-Mode. Ignoring the -g option and continuing in Normal mode"); bOpenSSHFlag = false; } #endif if(SSHKeyProvided == true && bOpenSSHFlag == false && sshFlag == false) { sshFlag = true; } } else { // If ssh private key is given we are making the --SSH also true, irrespective of whether it is true or not if(SSHKeyProvided == true && bOpenSSHFlag == false && sshFlag == false) { sshFlag = true; } #ifndef WIN32 // Check to see whether SSH option should be used or RSH should be used. if(sshFlag == true && SSHKeyProvided == false) { // REVIEW_COMMENTS commonOutputHandle->writeDataToLogFile("STATUS", "--SSH option must be used in conjunction with --sshprivatekey-file."); //commonOutputHandle->writeDataToLogFile("STATUS", "Would you like to run the perfstat using \"rsh\""); //commonOutputHandle->writeDataToLogFile("STATUS", "If yes please type \"y\" else type \"n\" to exit (y/n) : "); //string strOption = ""; //cin >> strOption; //cin.ignore(); //std::transform(strOption.begin(), strOption.end(), strOption.begin(), (int(*)(int))std::toupper); //if(strOption.compare("Y") == 0 || strOption.compare("YES") == 0) { commonOutputHandle->writeDataToLogFile("STATUS", "The current perfstat execution will be done through \"rsh\"" ); sshFlag = false; //} //else { //commonOutputHandle->writeDataToLogFile("STATUS", "Exiting now. Please re-run perfstat using --SSH option along with --sshprivatekey-file option"); //commonOutputHandle->writeDataToLogFile("STATUS", "Example: ./perfstat8 --nodes= --SSH --sshprivatekey-file=\"\" [OPTIONS]\n"); //exit(0); //} } #else // REVIEW_COMMENTS if(bOpenSSHFlag == true) { if(SSHKeyProvided == false) { commonOutputHandle->writeDataToLogFile("WARNING", "Option -g is supported only with --LEGACY_MODE in conjunction with --sshprivatekey-file option." ); commonOutputHandle->writeDataToLogFile("STATUS", "Please setup \"openssh\" by following \"openssh_procedure.txt\" and re-run the command with -g option." ); commonOutputHandle->writeDataToLogFile("STATUS", "Example: perfstat8.exe --verbose --nodes= --mode=\"7-mode\" -g --sshprivatekey-file=\"\"\n" ); exit(0); } if(bLegacyMode == false) { commonOutputHandle->writeDataToLogFile("STATUS", "-g option will work only for Legacy Mode."); //commonOutputHandle->writeDataToLogFile("STATUS", "Perfstat run in Legacy Mode (Excludes systemshell and SKTrace data)."); //commonOutputHandle->writeDataToLogFile("STATUS", "If yes please type \"y\" else type \"n\" to exit (y/n) : "); //string strOption = ""; //cin >> strOption; //cin.ignore(); //std::transform(strOption.begin(), strOption.end(), strOption.begin(), (int(*)(int))std::toupper); //if(strOption.compare("Y") == 0 || strOption.compare("YES") == 0) { commonOutputHandle->writeDataToLogFile("STATUS", "The current perfstat run will be done in Legacy Mode." ); commonOutputHandle->writeDataToLogFile("STATUS", "Please note that, In Legacy mode systemshell and SKTRACE data would not be collected" ); bLegacyMode = true; setLegacyMode(true); //} //else { //commonOutputHandle->writeDataToLogFile("STATUS", "-g option in the command line doesn't support Non-Legacy Mode. Exiting now."); //commonOutputHandle->writeDataToLogFile("STATUS", "Example: perfstat8.exe --verbose --nodes= --mode=\"7-mode\" -g --sshprivatekey-file= --LEGACY_MODE [OPTIONS]\n"); //exit(0); //} } } // Check for OpenSSH if(bLegacyMode == true && bOpenSSHFlag == false) { commonOutputHandle->writeDataToLogFile("STATUS", "Please setup \"openssh\" by following \"openssh_procedure.txt\" and re-run the command with -g option."); exit(0); } /* Deprecated from Perfstat v8.3 // Check for the existence of the plink.exe. if(bLegacyMode == true && sshFlag == true) { // If not an WIN7/WIN2K8 machine and plink.exe is not present //if(bisPlinkPresent == false) { if(bisPlinkPresent == false && bnativeRshPresent == true) { // REVIEW_COMMENTS commonOutputHandle->writeDataToLogFile("STATUS", "Please copy the plink.exe in the same directory where perfstat8 binary is present and re-run the perfstat test.\n"); exit(0); } } */ #endif // Check for rsh binary if(sshFlag == false && bOpenSSHFlag == false) { string strRSHSuccess = " successful"; if(bnativeRshPresent == false) { strRSHSuccess = " not successful"; } commonOutputHandle->writeDataToLogFile("STATUS", "Checking for the presence of Native \"rsh\"..." + strRSHSuccess); } if(bLegacyMode == true) { if(bnativeRshPresent == false && bOpenSSHFlag == false) { if(sshFlag == false) { commonOutputHandle->writeDataToLogFile("STATUS", "Native rsh binary (rsh.exe) does not exist on this host."); #ifndef WIN32 commonOutputHandle->writeDataToLogFile("STATUS", "Please verify if rsh is working by running the following command \"rsh -l \"date\"\"\n"); exit(0); #else commonOutputHandle->writeDataToLogFile("STATUS", "Typically, WIN7/WIN2K8 do not carry rsh.exe."); #endif } #ifdef WIN32 commonOutputHandle->writeDataToLogFile("STATUS", "Please setup \"openssh\" by following \"openssh_procedure.txt\" and re-run the command with -g option."); commonOutputHandle->writeDataToLogFile("STATUS", "Example: \"perfstat8.exe --verbose --nodes= --mode=\"7-mode\" -g --sshprivatekey-file=\"privatekey\" --LEGACY_MODE\" [OPTIONS]\n"); exit(0); #endif } } /* else { #ifdef WIN32 if(sshFlag == false && bOpenSSHFlag == false && bnativeRshPresent == false) { commonOutputHandle->writeDataToLogFile("STATUS", "Parallel Commands will not be executed,as rsh.exe is not available on this host"); //commonOutputHandle->writeDataToLogFile("STATUS", "Do you want to run the parallel commands using SSH"); //commonOutputHandle->writeDataToLogFile("STATUS", "press \"y\" for YES else press \"n\" (y/n) : "); //string choice = ""; //cin >> choice; //cin.ignore(); //std::transform(choice.begin(), choice.end(), choice.begin(), (int(*)(int))std::toupper); //if(choice.compare("YES") == 0 || choice.compare("Y") == 0) { sshFlag = true; //} } */ #ifdef WIN32 if(bnativeRshPresent == false && bOpenSSHFlag == false) { //if(bisPlinkPresent == false) { commonOutputHandle->writeDataToLogFile("STATUS", "Parallel Commands cannot be executed as openSSH/RSH is not present."); commonOutputHandle->writeDataToLogFile("STATUS", "Please setup \"openssh\" by following \"openssh_procedure.txt\" and re-run the command with -g option."); } #endif //} } } void CLIHandler :: setMapData(const string& key, string value) { if(key.compare("LEGACY_MODE") == 0) { vector data = CLIDataMap["LEGACY_MODE"]; string nodeIPs = ""; if(data.size() == 2) { nodeIPs = data[1]; nodeIPs = nodeIPs + ","; nodeIPs = nodeIPs + value; } else { nodeIPs = value; } vector info; info.push_back("set"); info.push_back(nodeIPs); CLIDataMap["LEGACY_MODE"] = info; } } void CLIHandler :: setSSHProvidedKeyFlag(bool bSSHKeyFlag) { SSHKeyProvided = bSSHKeyFlag; } bool CLIHandler :: checkRSH() { bool bRes = true; string user = filerLoginUser; string testCmd = ""; #ifdef WIN32 testCmd = "rsh.exe >output_test_RSH 2>output_test_RSH_error"; _flushall(); #else testCmd = "rsh >output_test_RSH 2>output_test_RSH_error"; #endif int res = std::system(testCmd.c_str()); string out = commonOutputHandle->readFromFile("output_test_RSH_error"); if(!out.empty()) { if(out.find("is not recognized as an internal or external command") != string::npos) { bRes = false; } else { bRes = true; } } else { bRes = false; } remove("output_test_RSH"); remove("output_test_RSH_error"); return bRes; } bool CLIHandler :: getNativeRshPresent() const { return bnativeRshPresent; }