BOOL TRAP_MONITOR(char *mstr, int altype, char *custpath, char *szReturn) { FILE *fp = NULL; int lines = 0, matchCount = 0; char *ca = NULL, *cb = NULL; char szBuffer[8192] = {0}; char std_log[256] = {0}; sprintf(std_log, "%s\\logs\\traps.log", FuncGetInstallRootPath()); if((fp = fopen(std_log, "r")) == NULL) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TRAP_1%>"));//<%IDS_TRAP_1%> return FALSE; } while(!feof(fp)) { memset(szBuffer, 0, sizeof(szBuffer)); fgets(szBuffer, sizeof(szBuffer), fp); if(!strncmp(szBuffer, "+++SNMP-TRAP-PDU: ", 18)) { lines ++; if(*mstr) { ca = szBuffer; while(cb = strstr(ca, "[Message]:=")) { char szMess[4096] = {0}; sscanf(cb + 11, "%[^$$$]$$$", szMess); if(strstr(szMess, mstr)) { matchCount ++; break; } ca = cb + 11; } } } } fclose(fp); sprintf(szReturn, "lines=%d$matchCount=%d$", lines, matchCount); return TRUE; }
void WriteLogFile(CString strMsg) { FILE *stream; char chTime[50] = {0}; //打开文件 stream=fopen(FuncGetInstallRootPath() + "\\AlertServer.log","a"); if(stream == NULL) return ; SYSTEMTIME time; //取系统当前时间 GetLocalTime(&time); sprintf(chTime ,"%02dY-%02dM-%02dD %02dH-%02dM-%02dS ", time.wYear - 2000, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond ); fputs(chTime , stream); fputs(strMsg.GetBuffer(strMsg.GetLength()),stream); fputs("\n",stream); fclose(stream); }
/* * 函数介绍:程序入口函数 * 输入参数:argv[1]为-install是安装服务,-remove时删除服务,argv[2]安装时为服务控制台显示服务名称 删除时为注册服务名称,此程序为AlertService * 输出参数:无 * 返回值: */ int _tmain(int argc, _TCHAR* argv[]) { int nRetCode = 0; if(WriteIniFileString("testsection","testkey","testvalue","alert.ini")) { DeleteIniFileSection("testsection","alert.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","TxtTemplate.ini")) { DeleteIniFileSection("testsection","TxtTemplate.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","smsconfig.ini")) { DeleteIniFileSection("testsection","smsconfig.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","general.ini")) { DeleteIniFileSection("testsection","general.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","itsmConfig.ini")) { DeleteIniFileSection("testsection","itsmConfig.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","watchsheetcfg.ini")) { DeleteIniFileSection("testsection","watchsheetcfg.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","email.ini")) { DeleteIniFileSection("testsection","email.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","emailAdress.ini")) { DeleteIniFileSection("testsection","emailAdress.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","smsphoneset.ini")) { DeleteIniFileSection("testsection","smsphoneset.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","interfacedll.ini")) { DeleteIniFileSection("testsection","interfacedll.ini"); } if(WriteIniFileString("testsection","testkey","testvalue","OfbizConfig.ini")) { DeleteIniFileSection("testsection","OfbizConfig.ini"); } #if 1 try { if(hasrun()) return 0; CAlertMain alertmain; alertmain.Init(); //MSG msg; //BOOL bRet=TRUE; //while((bRet=::GetMessage(&msg,NULL,0,0))!=0) //{ // if(bRet==-1) // { // continue; // } // TranslateMessage(&msg); // ::DispatchMessage(&msg); //} MSG msg; while(::GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); ::DispatchMessage(&msg); switch(msg.message) { case WM_QUIT: exit(1); break; default: break; } } } catch(...) { } #else // argc = 2; // argv[1] = "-remove"; // argv[2] = "AlertService"; //#if 1 // RunThread(NULL); //#else // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs cerr << _T("Fatal Error: MFC initialization failed") << endl; nRetCode = 1; } g_strRootPath= FuncGetInstallRootPath(); SERVICE_TABLE_ENTRY Table[] = { {"AlertService7",StartAlertService}, {NULL, NULL} }; CString outStr = "parameter required in the command line"; if(argc <= 1) { cout << (LPCTSTR)outStr << endl; } else { if(_stricmp(argv[1],"-install") == 0) { InstallService(argv[2]); } else if(_stricmp(argv[1],"-remove") == 0) { StopService(argv[2]); } else { cout << outStr << endl; } } if(!StartServiceCtrlDispatcher(Table)) { g_strMessage.Format("StartServiceCtrlDispatcher error = %d\r\n", GetLastError()); WriteLogFile(g_strMessage); } #endif //CAlertMain::pSender.Release(); return nRetCode; }
BOOL RLOGINCLUSTER_MONITOR(char *server, int port, char *uid, char *pwd, char *pserver, int pport, char *puid, char *ppwd, char *pprompt, char *prompts, char *ostype, char *clusterlog, char *cpath, char *szReturn) { int ret = 0; int hSocket = 0; BOOL bResult = TRUE; char iniFile[256] = {0}; char cmd[256] = {0}; /************************************* * For Reason Of Prompt */ int c = 0; char *ca = prompts, *cb = NULL; char arprompt[PR_NUM][256]; memset(arprompt, 0, sizeof(arprompt)); while(cb = strchr(ca, 0x20)) { if(ca == cb) { ca ++; continue; } strncpy(arprompt[c++], ca, cb - ca); ca = cb + 1; } strcpy(arprompt[c++], ca); /***********************************/ hSocket = rlogin_init(server, port, pserver, pport, puid, ppwd); if(hSocket <= 0) { if(hSocket == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_1%>")); // <%IDS_TelMonitor_1%> else if(hSocket == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_2%>")); // <%IDS_TelMonitor_2%> else if(hSocket == -3) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_3%>")); // <%IDS_TelMonitor_3%> else if(hSocket == -4) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_4%>")); // <%IDS_TelMonitor_4%> else if(hSocket == -5) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_5%>")); // <%IDS_TelMonitor_5%> else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_6%>")); // <%IDS_TelMonitor_6%> bResult = FALSE; goto err; } if((ret = rlogin_connect(hSocket, uid, pwd, pprompt, arprompt)) < 0) { if(ret == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_7%>")); // <%IDS_TelMonitor_7%> else if(ret == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_8%>")); // <%IDS_TelMonitor_8%> else if(ret == -3) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_9%>")); // <%IDS_TelMonitor_9%> else if(ret == -4) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_10%>")); // <%IDS_TelMonitor_10%> else if(ret == -5) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_11%>")); // <%IDS_TelMonitor_11%> else if(ret == -6) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_12%>")); // <%IDS_TelMonitor_12%> else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_13%>")); // <%IDS_TelMonitor_13%> bResult = FALSE; goto err; } #if _DEBUG sprintf(iniFile, "%s\\templates.os\\%s", FuncGetInstallRootPath(), ostype); #else sprintf(iniFile, "%s\\MonitorManager\\templates.os\\%s", FuncGetInstallRootPath(), ostype); #endif DFN_GetPrivateProfileString("cat", "command", "", cmd, sizeof(cmd), iniFile); if(!*cmd) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_14%>")); // <%IDS_TelMonitor_14%> bResult = FALSE; goto err; } if(ca = strstr(cmd, "<file>")) { strcpy(ca, clusterlog); *(ca + strlen(clusterlog)) = 0; } if((ret = rlogin_command(hSocket, cmd)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_15%>")); // <%IDS_TelMonitor_15%> bResult = FALSE; goto err; } { int index = 0; CString strBuffer(rlogin_databuffer); CString strLine = _T(""); // Cluster if((index = strBuffer.Find("CLUSTER", 0)) >= 0) { strBuffer.Delete(0, index); } else { sprintf(szReturn, "error=%s", "No Cluster"); // No Cluster bResult = FALSE; goto err; } strLine = GetStringFromLineNo(strBuffer, 2); sprintf(szReturn, "%sClusterName=%s$ClusterStatus=%s$", szReturn, GetColumnFromLine(strLine, 1), GetColumnFromLine(strLine, 2)); // Node if((index = strBuffer.Find("NODE", 0)) >= 0) { strBuffer.Delete(0, index); } else { sprintf(szReturn, "error=%s", "No Node"); // No Node bResult = FALSE; goto err; } strLine = GetStringFromLineNo(strBuffer, 2); sprintf(szReturn, "%sNodeName=%s$NodeStatus=%s$NodeState=%s$", szReturn, GetColumnFromLine(strLine, 1), GetColumnFromLine(strLine, 2), GetColumnFromLine(strLine, 3)); // Package if((index = strBuffer.Find("PACKAGE", 0)) >= 0) { strBuffer.Delete(0, index); } else { sprintf(szReturn, "error=%s", "No Package"); // No Package bResult = FALSE; goto err; } strLine = GetStringFromLineNo(strBuffer, 2); sprintf(szReturn, "%sPackageName=%s$PackageStatus=%s$PackageState=%s$PackageAutorun=%s$", szReturn, GetColumnFromLine(strLine, 1), GetColumnFromLine(strLine, 2), GetColumnFromLine(strLine, 3), GetColumnFromLine(strLine, 4)); } err: shutdown(hSocket, 0x02); closesocket(hSocket); return bResult; }
BOOL HTTPCLUSTER_MONITOR(char *url, char *uid, char *pwd, char *pserver, int pport, char *puid, char *ppwd, char *ostype, char *clusterlog, char *cpath, char *szReturn) { int ret = 0; BOOL bResult = TRUE; char *ca = NULL; char iniFile[256] = {0}; char cmd[256] = {0}; #if _DEBUG sprintf(iniFile, "%s\\templates.os\\%s", FuncGetInstallRootPath(), ostype); #else sprintf(iniFile, "%s\\MonitorManager\\templates.os\\%s", FuncGetInstallRootPath(), ostype); #endif DFN_GetPrivateProfileString("cat", "command", "", cmd, sizeof(cmd), iniFile); if(!*cmd) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_14%>")); // <%IDS_TelMonitor_14%> return FALSE; } if(ca = strstr(cmd, "<file>")) { strcpy(ca, clusterlog); *(ca + strlen(clusterlog)) = 0; } char msg[100 * 1024] = {0}; if(!http_command(url, cmd, READ_TIMEOUT, uid, pwd, pserver, pport, puid, ppwd, msg)) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_TelMonitor_15%>")); // <%IDS_TelMonitor_15%> return FALSE; } { int index = 0; CString strBuffer(msg); CString strLine = _T(""); // Cluster if((index = strBuffer.Find("CLUSTER", 0)) >= 0) { strBuffer.Delete(0, index); } else { sprintf(szReturn, "error=%s", "No Cluster"); // No Cluster return FALSE; } strLine = GetStringFromLineNo(strBuffer, 2); sprintf(szReturn, "%sClusterName=%s$ClusterStatus=%s$", szReturn, GetColumnFromLine(strLine, 1), GetColumnFromLine(strLine, 2)); // Node if((index = strBuffer.Find("NODE", 0)) >= 0) { strBuffer.Delete(0, index); } else { sprintf(szReturn, "error=%s", "No Node"); // No Node return FALSE; } strLine = GetStringFromLineNo(strBuffer, 2); sprintf(szReturn, "%sNodeName=%s$NodeStatus=%s$NodeState=%s$", szReturn, GetColumnFromLine(strLine, 1), GetColumnFromLine(strLine, 2), GetColumnFromLine(strLine, 3)); // Package if((index = strBuffer.Find("PACKAGE", 0)) >= 0) { strBuffer.Delete(0, index); } else { sprintf(szReturn, "error=%s", "No Package"); // No Package return FALSE; } strLine = GetStringFromLineNo(strBuffer, 2); sprintf(szReturn, "%sPackageName=%s$PackageStatus=%s$PackageState=%s$PackageAutorun=%s$", szReturn, GetColumnFromLine(strLine, 1), GetColumnFromLine(strLine, 2), GetColumnFromLine(strLine, 3), GetColumnFromLine(strLine, 4)); } return TRUE; }
BOOL SSHCLUSTER_MONITOR(char *server, int port, char *uid, char *pwd, char *ostype, char *clusterlog, char *cpath, char *szReturn) { CString strCmdLine = _T(""), strResult = _T(""); int nResult = 0; char *ca = NULL; char iniFile[256] = {0}; char cmd[256] = {0}; #if _DEBUG sprintf(iniFile, "%s\\templates.os\\%s", FuncGetInstallRootPath(), ostype); #else sprintf(iniFile, "%s\\MonitorManager\\templates.os\\%s", FuncGetInstallRootPath(), ostype); #endif DFN_GetPrivateProfileString("cat", "command", "", cmd, sizeof(cmd), iniFile); if(!*cmd) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_SSHMonitor_1%>")); // <%IDS_SSHMonitor_1%> return FALSE; } if(ca = strstr(cmd, "<file>")) { strcpy(ca, clusterlog); *(ca + strlen(clusterlog)) = 0; } strCmdLine.Format("%s \"-ssh\" \"-t\" \"%d\" \"-P\" \"%d\" \"-pw\" \"%s\" \"%s@%s\" \"%s\"", PLINK_PATH, CALL_TIMEOUT, port, pwd, uid, server, cmd); nResult = executeExeFile(strCmdLine, strResult); switch(nResult) { case DragonFlow_OK: { int index = 0; CString strBuffer = strResult; CString strLine = _T(""); // Cluster if((index = strBuffer.Find("CLUSTER", 0)) >= 0) { strBuffer.Delete(0, index); } else { sprintf(szReturn, "error=%s", "No Cluster"); // No Cluster return FALSE; } strLine = GetStringFromLineNo(strBuffer, 2); sprintf(szReturn, "%sClusterName=%s$ClusterStatus=%s$", szReturn, GetColumnFromLine(strLine, 1), GetColumnFromLine(strLine, 2)); // Node if((index = strBuffer.Find("NODE", 0)) >= 0) { strBuffer.Delete(0, index); } else { sprintf(szReturn, "error=%s", "No Node"); // No Node return FALSE; } strLine = GetStringFromLineNo(strBuffer, 2); sprintf(szReturn, "%sNodeName=%s$NodeStatus=%s$NodeState=%s$", szReturn, GetColumnFromLine(strLine, 1), GetColumnFromLine(strLine, 2), GetColumnFromLine(strLine, 3)); // Package if((index = strBuffer.Find("PACKAGE", 0)) >= 0) { strBuffer.Delete(0, index); } else { sprintf(szReturn, "error=%s", "No Package"); // No Package return FALSE; } strLine = GetStringFromLineNo(strBuffer, 2); sprintf(szReturn, "%sPackageName=%s$PackageStatus=%s$PackageState=%s$PackageAutorun=%s$", szReturn, GetColumnFromLine(strLine, 1), GetColumnFromLine(strLine, 2), GetColumnFromLine(strLine, 3), GetColumnFromLine(strLine, 4)); } return TRUE; case DragonFlow_Timeout: sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_SSHMonitor_3%>")); // <%IDS_SSHMonitor_3%> break; case DragonFlow_OpenConnection: sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_SSHMonitor_4%>")); // <%IDS_SSHMonitor_4%> break; case DragonFlow_CreateOutputThread: case DragonFlow_CreateErrorOutputThread: case DragonFlow_CreateInputThread: case DragonFlow_WriteToStandardOutput: case DragonFlow_OpenCommandFile: case DragonFlow_NotEnoughSpace: case DragonFlow_InitialiseWinSock: case DragonFlow_WinSockVersionIncompatible: sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_SSHMonitor_5%>")); // <%IDS_SSHMonitor_5%> break; case DragonFlow_FatalError: sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_SSHMonitor_6%>")); // <%IDS_SSHMonitor_6%> break; default: sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_SSHMonitor_7%>")); // <%IDS_SSHMonitor_7%> break; } return FALSE; }
BOOL WebLogic(const char * strParas, char * szReturn, int& nSize) //(CStringList ¶mList, char *szReturn) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); //参数解析: CString strServIp = _T(""), strServPort = _T(""), strUserName = _T(""), strUserPwd = _T(""), strTaskType = _T(""), strTaskParam = _T(""); CString strProxyServ = _T(""), strProxyUser = _T(""); int nServerPort = 21; int nTimeout = 60; BOOL bRet = FALSE; // Check Content Change CStringList paramList; MakeStringListByChar(paramList,strParas); POSITION pos = paramList.GetHeadPosition(); while(pos) { CString strTemp = paramList.GetNext(pos); if(strTemp.Find(__USERNAME__, 0) == 0) { strUserName = strTemp.Right(strTemp.GetLength() - strlen(__USERNAME__)); } else if(strTemp.Find(__PASSWORD__, 0) == 0) { strUserPwd = strTemp.Right(strTemp.GetLength() - strlen(__PASSWORD__)); } else if(strTemp.Find(__TIMEOUT__, 0) == 0) { nTimeout = atoi(strTemp.Right(strTemp.GetLength() - strlen(__TIMEOUT__))); } else if(strTemp.Find(__SERVERIP__, 0) == 0) { strServIp = strTemp.Right(strTemp.GetLength() - strlen(__SERVERIP__)); } else if(strTemp.Find(__SERVERPORT__, 0) == 0) { strServPort = strTemp.Right(strTemp.GetLength() - strlen(__SERVERPORT__)); } else if(strTemp.Find(__TASKTYPE__, 0) == 0) { strTaskType = strTemp.Right(strTemp.GetLength() - strlen(__TASKTYPE__)); } else if(strTemp.Find(__TASKPARAM__, 0) == 0) { strTaskParam = strTemp.Right(strTemp.GetLength() - strlen(__TASKPARAM__)); } else { } } if(strUserName.IsEmpty()) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("IDS_Poor_UserName"));//"缺少用户姓名!");//<%IDS_Monitor_40%>"缺少FTP服务器地址" return FALSE; } if(strUserPwd.IsEmpty()) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("IDS_Poor_Password"));//"缺少用户密码!");//<%IDS_Monitor_40%> return FALSE; } if(strServIp.IsEmpty()) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("IDS_Poor_ServerAddress"));//"缺少服务器地址!");//<%IDS_Monitor_40%>"缺少FTP服务器地址" return FALSE; } if(strServPort.IsEmpty()) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("IDS_Poor_ServerPort"));//"缺少服务器端口地址!");//<%IDS_Monitor_40%>"缺少FTP服务器地址" return FALSE; } if(strTaskType.IsEmpty()) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("IDS_Poor_TaskType"));//"缺少任务类型!");//<%IDS_Monitor_40%>"缺少FTP服务器地址" return FALSE; } if(strTaskParam.IsEmpty()) { strTaskParam = "null"; } if(nTimeout <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("IDS_TimeoutParamError"));//"超时参数有错误!");//<%IDS_Monitor_40%>"缺少FTP服务器地址" return FALSE; } //取数据的实现 CString strCustomerPath = _T(""); strCustomerPath.Format("%s\\fcgi-bin", FuncGetInstallRootPath()); //CString strCmdLine = "CMD /C " + strCustomerPath + "\\MonitorManager\\WeblogicMonitor.bat \""; CString strCmdLine = "CMD /C \"" + strCustomerPath + "\\WeblogicMonitor.bat\" "; strCmdLine += strUserName + " "; strCmdLine += strUserPwd + " "; strCmdLine += "t3://" + strServIp + ":" + strServPort; strCmdLine += " " + strTaskType; strCmdLine += " " + strTaskParam; SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; HANDLE hRead, hWrite; long retval = CreatePipe(&hRead, &hWrite, &sa, 12000) ; if(retval == 0) { return false; } else { STARTUPINFO si; memset(&si, 0, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; si.hStdOutput = hWrite; si.hStdError = hWrite; // si.wShowWindow =SW_HIDE; PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(PROCESS_INFORMATION)); puts(strCmdLine); if (CreateProcess(NULL, strCmdLine.GetBuffer(strCmdLine.GetLength()), &sa, &sa, TRUE, CREATE_NEW_CONSOLE/*CREATE_NO_WINDOW*/, NULL, NULL, &si, &pi)) { bRet = TRUE; DWORD dwResult = WaitForSingleObject(pi.hProcess, 6000*1000); if (dwResult == WAIT_OBJECT_0) { DWORD dwExitCode = 0; if (GetExitCodeProcess(pi.hProcess, &dwExitCode)) { //if (dwExitCode == 0) { // CFile* pFile = NULL; int nFileLength = 0; TRY { pFile = new CFile(hRead); nFileLength = pFile->GetLength(); } CATCH(CFileException, pEx) { // Do Nothing. } END_CATCH char * buffer = NULL; buffer = (char*)malloc(nFileLength+1); // pFile->Read(buffer, nFileLength); CString strSource = _T(""); strSource.Format("%s", buffer); //WeblogicMonitor(去掉call setWLSEnv.cmd所生成的输出) int nOrder = strSource.Find("FileSplitFlag"); nOrder += 13; strSource = strSource.Mid(nOrder); // nOrder = strSource.Find("EndSplitFlag"); //nOrder += 13; strSource = strSource.Left(nOrder); strSource.Replace("WaitingForConnectionCurrentCount","WaitConnetCurCount"); strSource.Replace( "Error=","error=" ); //生成正确格式的输出串 strcpy(szReturn, strSource); //sprintf(szReturn, "error=%s",buffer); // free(buffer); if (pFile != NULL) { pFile->Close(); delete pFile; } } //else { } }
bool AIXERRPT_TEL_VALUE(char *server, int port, char *uid, char *pwd, char *pserver, int pport, char *puid, char *ppwd, char *lprom, char *pprom, char *prom, char *inifile, int ngid, char* strmid, char *custpath, char *szReturn) { int ret = 0; int hSocket = 0; bool bResult = TRUE; char buffer[256] = {0}; char mbuffer[256] = {0}; char mdate[256] = {0}; char datebuff[64] = {0}; char curdate[64] = {0}; //char szIniFile[256] = {0}; char szTmpIniFile[256] = {0}; int isChinese = 0; //puts("ok"); /************************************* * For Reason Of Prompt */ int c = 0; char *ca = prom, *cb = NULL; char arprompt[PR_NUM][256]; memset(arprompt, 0, sizeof(arprompt)); LPGDATA pgd=new GDATA; memset(pgd,0,sizeof(GDATA)); while(cb = strchr(ca, 0x20)) { if(ca == cb) { ca ++; continue; } strncpy(arprompt[c++], ca, cb - ca); ca = cb + 1; } strcpy(arprompt[c++], ca); /***********************************/ hSocket = telnet_init(server, port, pserver, pport, puid, ppwd); if(hSocket <= 0) { if(hSocket == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_1%>"));//<%IDS_MQ_1%>"连接失败:域名解析" else if(hSocket == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_2%>"));//<%IDS_MQ_2%>"连接失败:通信初始化" else if(hSocket == -3) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_3%>"));//<%IDS_MQ_3%>"连接失败:连接超时" else if(hSocket == -4) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_4%>"));//<%IDS_MQ_4%>"代理服务器连接失败" else if(hSocket == -5) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_5%>"));//<%IDS_MQ_5%>"代理服务器错误" else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_6%>"));//<%IDS_MQ_6%>"连接失败:未知错误" bResult = FALSE; goto err; } Tel_Param param; if((ret = telnet_connect(hSocket, uid, pwd, lprom, pprom, arprompt,pgd,¶m)) < 0) { if(ret == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_7%>"));//<%IDS_MQ_7%>"登录失败:读数据超时" else if(ret == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_8%>"));//<%IDS_MQ_8%>"登录失败:读数据错误" else if(ret == -3) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_9%>"));//<%IDS_MQ_9%>"登录失败:查找提示符" else if(ret == -4) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_10%>"));//<%IDS_MQ_10%>"登录失败:查找登录提示符" else if(ret == -5) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_11%>"));//<%IDS_MQ_11%>"登录失败:查找密码提示符" else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_12%>"));//<%IDS_MQ_12%>"登录失败:未知错误" bResult = FALSE; goto err; } if(DFNParser_GetPrivateProfileString("errorlog", "command", "", buffer, sizeof(buffer), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); bResult = FALSE; goto err; } if(DFNParser_GetPrivateProfileString("errorlog", "matchline", "", mbuffer, sizeof(mbuffer), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); bResult = FALSE; goto err; } if(DFNParser_GetPrivateProfileString("date", "command", "", mdate, sizeof(mdate), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); bResult = FALSE; goto err; } isChinese = DFNParser_GetPrivateProfileInt("date", "isChinese", 0, inifile); if((ret = telnet_command(hSocket, mdate,pgd,¶m)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } if(isChinese) { char week[64] = {0}; int years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0; if(sscanf(pgd->databuffer, "公元%d年%d月%d日 %s %d时%d分%d秒", &years, &months, &days, week, &hours, &minutes, &seconds) != 7) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } sprintf(curdate, "%2.2d%2.2d%2.2d%2.2d%2.2d", months, days, hours, minutes, years % 100); } else { char week[16] = {0}; char month[16] = {0}; int day = 0; int hours = 0, mins = 0, secs = 0; char div[16] = {0}; int year = 0; if(sscanf(pgd->databuffer, "%s %s %d %d:%d:%d %s %d", week, month, &day, &hours, &mins, &secs, div, &year) != 8) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } if(convert_date(month, day, hours, mins, year, curdate)) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } } sprintf(szTmpIniFile, "logfile.ini"); DFN_GetPrivateProfileString(strmid, "lastdate", "", datebuff, sizeof(datebuff), szTmpIniFile); if(!*datebuff) strncpy(datebuff, curdate, 10); if(ca = strchr(buffer, '<')) { strncpy(ca, datebuff, 10); *(ca + 10) = 0; } memset(pgd->databuffer, 0, BUF_SIZE); pgd->datalen = 0; printf("Error Report Command is :%s\n", buffer); if((ret = telnet_command(hSocket, buffer,pgd)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } if(ret == 0 || !strstr(pgd->databuffer, mbuffer)) { char tmp [256] = {0}; //ofstream fout("aixerr.log",ios::app); //int i = GetConfirms(strmid); //fout << itoa(i, tmp, 10) <<"\r\n"; //fout << flush; //fout.close(); if(GetConfirms(strmid) > 0) DFN_WritePrivateProfileString(strmid, "needconfirm", _ltoa(FALSE, tmp, 10), szTmpIniFile); BOOL bChange = DFN_GetPrivateProfileInt(strmid, "needconfirm", FALSE, szTmpIniFile); if (!bChange) { sprintf(szReturn, "status=0$" ); //0: 未改变 1:改变 } else { sprintf(szReturn, "status=1$" ); } } else { sprintf(szReturn, "status=1$" ); FILE *fp = NULL; char szErrptLogFile[256] = {0}; sprintf(szErrptLogFile, "%s\\data\\TmpIniFile\\logfile_%s.log", FuncGetInstallRootPath(), strmid); if(fp = fopen(szErrptLogFile, "a+")) { fprintf(fp, "%s", pgd->databuffer); fclose(fp); } char tmp [256] = {0}; printf("Track record\n"); DFN_WritePrivateProfileString(strmid, "needconfirm", _ltoa(TRUE, tmp, 10), szTmpIniFile); } DFN_WritePrivateProfileString(strmid, "lastdate", curdate, szTmpIniFile); err: shutdown(hSocket, 0x02); closesocket(hSocket); delete pgd; return bResult; }
BOOL AIXERRPT_SSH_VALUE(char *server, int port, char *uid, char *pwd, char *inifile, int ngid, char* strmid, char *custpath, char *privatekeyfile, char *szReturn) { int ret = 0; char buffer[256] = {0}; char mbuffer[256] = {0}; char mdate[256] = {0}; char datebuff[64] = {0}; char curdate[64] = {0}; char szTmpIniFile[256] = {0}; int isChinese = 0; CString strResult = _T(""); if(DFNParser_GetPrivateProfileString("errorlog", "command", "", buffer, sizeof(buffer), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); return FALSE; } if(DFNParser_GetPrivateProfileString("errorlog", "matchline", "", mbuffer, sizeof(mbuffer), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); return FALSE; } if(DFNParser_GetPrivateProfileString("date", "command", "", mdate, sizeof(mdate), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); return FALSE; } isChinese = DFNParser_GetPrivateProfileInt("date", "isChinese", 0, inifile); if((ret = ssh_command(server,port, uid, pwd, mdate, privatekeyfile, strResult)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } if(isChinese) { char week[64] = {0}; int years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0; if(sscanf(strResult, "公元%d年%d月%d日 %s %d时%d分%d秒", &years, &months, &days, week, &hours, &minutes, &seconds) != 7) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } sprintf(curdate, "%2.2d%2.2d%2.2d%2.2d%2.2d", months, days, hours, minutes, years % 100); } else { char week[16] = {0}; char month[16] = {0}; int day = 0; int hours = 0, mins = 0, secs = 0; char div[16] = {0}; int year = 0; if(sscanf(strResult, "%s %s %d %d:%d:%d %s %d", week, month, &day, &hours, &mins, &secs, div, &year) != 8) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } if(convert_date(month, day, hours, mins, year, curdate)) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } } sprintf(szTmpIniFile, "logfile.ini"); DFN_GetPrivateProfileString(strmid, "lastdate", "", datebuff, sizeof(datebuff), szTmpIniFile); if(!*datebuff) strncpy(datebuff, curdate, 10); char *ca = NULL; if(ca = strchr(buffer, '<')) { strncpy(ca, datebuff, 10); *(ca + 10) = 0; } strResult = _T(""); if((ret = ssh_command(server, port, uid, pwd, buffer, privatekeyfile, strResult)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } if(ret == 0 || !strstr(strResult, mbuffer)) { char tmp [256] = {0}; if(GetConfirms(strmid) > 0) DFN_WritePrivateProfileString(strmid, "needconfirm", _ltoa(FALSE, tmp, 10), szTmpIniFile); BOOL bChange = DFN_GetPrivateProfileInt(strmid, "needconfirm", FALSE, szTmpIniFile); if (!bChange) { //sprintf(szReturn, "status=%s$", FuncGetStringFromIDS("<%IDS_AIXErrpt_01%>")); sprintf(szReturn, "status=0$" ); //0: 未改变 1:改变 } else { //sprintf(szReturn, "status=%s$", FuncGetStringFromIDS("<%IDS_AIXErrpt_02%>")); sprintf(szReturn, "status=1$" ); //0: 未改变 1:改变 } } else { //sprintf(szReturn, "status=%s$", FuncGetStringFromIDS("<%IDS_AIXErrpt_02%>")); sprintf(szReturn, "status=1$" ); //0: 未改变 1:改变 FILE *fp = NULL; char szErrptLogFile[256] = {0}; sprintf(szErrptLogFile, "%s\\data\\TmpIniFile\\logfile_%s.log", FuncGetInstallRootPath(), strmid); if(fp = fopen(szErrptLogFile, "a+")) { fprintf(fp, "%s", strResult); fclose(fp); } char tmp [256] = {0}; DFN_WritePrivateProfileString(strmid, "needconfirm", _ltoa(TRUE, tmp, 10), szTmpIniFile); } DFN_WritePrivateProfileString(strmid, "lastdate", curdate, szTmpIniFile); return TRUE; }
BOOL CISCOCONFIG_MONITOR62(char *server, int port, char *pwd, char *enpwd, char *pwdprompt, char *prompt, char *enpwdprompt, char *enprompt, char *encmd, char *monitorid, char *proxy_server, int proxy_port, char *proxy_uid, char *proxy_pwd, char *custpath, char *szReturn) { int ret = 0; int hSocket = 0; char runcmd[64] = {0}; printf("Server:%s\nPort:%d\n", server, port); hSocket = telnet_init(server, port, proxy_server, proxy_port, proxy_uid, proxy_pwd); if(hSocket <= 0) { if(hSocket == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_1%>"));//<%IDS_CiscoLog_1%> else if(hSocket == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_2%>"));//<%IDS_CiscoLog_2%> else if(hSocket == -3) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_3%>"));//<%IDS_CiscoLog_3%> else if(hSocket == -4) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_4%>"));//<%IDS_CiscoLog_4%> else if(hSocket == -5) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_5%>"));//<%IDS_CiscoLog_5%> else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_6%>"));//<%IDS_CiscoLog_6%> return FALSE; } LPGDATA pgd=new GDATA; memset(pgd,0,sizeof(GDATA)); printf("Connect Cisio network set\n"); if((ret = cisco_connect(hSocket, pwd, pwdprompt, prompt,pgd)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_7%>"));//<%IDS_CiscoLog_7%> delete pgd; return FALSE; } strncpy(runcmd, "enable\r\n", 8); send(hSocket, runcmd, strlen(runcmd), 0); printf("Login Cisio Config\n"); if((ret = cisco_connect(hSocket, enpwd, enpwdprompt, enprompt,pgd)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_8%>"));//<%IDS_CiscoLog_8%> delete pgd; return FALSE; } printf("Execute command\n"); if((ret = cisco_command(hSocket, encmd, enprompt,pgd)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_9%>"));//<%IDS_CiscoLog_9%> delete pgd; return FALSE; } int index = 0; char prebuffer[MAX_READ_SIZE] = {0}; CString strBuffer(pgd->databuffer); index = strBuffer.Find("show running-config\r\n", 0); if(index >= 0) strBuffer.Delete(0, index + 21); if(!strBuffer.Right(strlen(enprompt)).Compare(enprompt)) { index = strBuffer.ReverseFind('\r'); if(index >= 0) strBuffer = strBuffer.Left(index); } FILE *cisco_fp = NULL; char prefile[256] = {0}; sprintf(prefile, "%s\\cisco_config_%s", custpath, monitorid); if((_access(prefile, 0x04)) == -1) { if((cisco_fp = fopen(prefile, "w")) == NULL) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_10%>"));//<%IDS_CiscoLog_10%> delete pgd; return FALSE; } sprintf(szReturn,"status=%s$", FuncGetStringFromIDS("<%IDS_CiscoLog_11%>"));//<%IDS_CiscoLog_11%> int i = fwrite(strBuffer, sizeof(char), strBuffer.GetLength(), cisco_fp); fclose(cisco_fp); delete pgd; return TRUE; } if((cisco_fp = fopen(prefile, "r")) == NULL) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_12%>"));//<%IDS_CiscoLog_12%> delete pgd; return FALSE; } int j = fread(prebuffer, sizeof(char), sizeof(prebuffer), cisco_fp); fclose(cisco_fp); prebuffer[j] = 0; int m = strlen(prebuffer); int n = strBuffer.GetLength(); if(!strBuffer.Compare(prebuffer)) { char buffer [256] = {0}; char tmp [256] = {0}; #if _DEBUG sprintf(buffer, "%s\\temp\\Cisio_logfile_%s.ini", FuncGetInstallRootPath(), server); #else sprintf(buffer, "%s\\MonitorManager\\temp\\logfile.ini", FuncGetInstallRootPath()); #endif BOOL bChange = DFN_GetPrivateProfileInt(monitorid, "needconfirm", FALSE, buffer); if (!bChange) { sprintf(szReturn, "status=%s$", FuncGetStringFromIDS("<%IDS_CiscoLog_13%>"));//<%IDS_CiscoLog_13%> delete pgd; return TRUE; } else { sprintf(szReturn, "status=%s$", FuncGetStringFromIDS("<%IDS_CiscoLog_14%>"));//<%IDS_CiscoLog_14%> delete pgd; return TRUE; } } else { sprintf(szReturn, "status=%s$", FuncGetStringFromIDS("<%IDS_CiscoLog_14%>"));//<%IDS_CiscoLog_14%> if((cisco_fp = fopen(prefile, "w")) == NULL) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CiscoLog_15%>"));//<%IDS_CiscoLog_15%> delete pgd; return FALSE; } int k = fwrite(strBuffer, sizeof(char), strBuffer.GetLength(), cisco_fp); fclose(cisco_fp); char buffer [256] = {0}; char tmp [256] = {0}; #if _DEBUG sprintf(buffer, "%s\\temp\\Cisio_logfile_%s.ini", FuncGetInstallRootPath(), server); #else sprintf(buffer, "%s\\MonitorManager\\temp\\logfile.ini", FuncGetInstallRootPath()); #endif DFN_WritePrivateProfileString(monitorid, "needconfirm", _ltoa(TRUE, tmp, 10), buffer); delete pgd; return TRUE; } }