Exemplo n.º 1
0
BOOL Util::InsertSVMQ(CString strQueueName, CString strMessage, CString strLabel)
{
      MutexLock lock(g_InsertMQLock);
      if(strLabel.isEmpty())
         strLabel="SVMQ";

      void *pqueue=NULL;
      int err=0;
      CString strError="";
      if((err=OpenQueue(g_SVMQAddress.getText(), (char *)strQueueName, &pqueue))>0)
      {
           if((err=Push(pqueue, strLabel, strMessage))>0)
	   {
	       CloseQueue(pqueue);
	       return TRUE;
	   }else
	   {
	      CloseQueue(pqueue);
	      strError.Format("Send Message error errorid:%d",err);
	      throw MSException((char *)strError);
	      
	   }
	   
          
      }else
      {
          puts("Open queue failed");
          strError.Format("Open queue failed errorid:%d",err);
	  throw MSException(strError.getText());
      }
      
      return TRUE;

}
Exemplo n.º 2
0
int MonitorThread::MakeInBuf()
{
     CStringList&lstParam=m_Monitor->GetParameterList();

	 CStringList::iterator it;
	 int len=0;
	 for(it=lstParam.begin();it!=lstParam.end();it++)
	 {
		 len+=(*it).size()+1;
	 }

	 len++;
//	 printf("len:%d,lst size:%d\n",len,lstParam.size());

	 if(!m_InBuf.checksize(len))
	 {
		 throw MSException("Malloc memmory failed for inbuf");
		 return 0;
	 }

//	 printf("buf length:%d\n",m_InBuf.size());

	 char *pt=m_InBuf;
	 for(it=lstParam.begin();it!=lstParam.end();it++)
	 {
		 strcpy(pt,(*it).c_str());
		 pt+=(*it).size()+1;
	 }

//	 printf("data size:%d\n",pt-(char*)m_InBuf);

	 return len;
}
Exemplo n.º 3
0
void ThreadContrl::ExecuteMonitor(Monitor *pMonitor)
{
	if(pMonitor==NULL)
	  return ;
    
     MonitorThread *pThread=(MonitorThread*)GetIdleThread();
     if(pThread==NULL)
     {
        throw MSException("Get Idle thread error");
     }
     pMonitor->m_isRefresh=true;
     
     puts("*****Start monitor...*****");
     pThread->ExecuteMonitor(pMonitor);
     
     int i=0;
     while(pMonitor->GetRunning()&&i<120)
     {
         ThreadEx::sleep(1000);
	     i++;
     }
     
     if(pMonitor->GetRunning())
       puts("*****Timeout*****");
     else
       puts("*****Success*****");
     
   
}
Exemplo n.º 4
0
BOOL Util::Init()
{

//	CString strPath=_T("");

/*	strPath=GetRootPath();
	if(strPath.IsEmpty())
		throw MSException("RootPath is empty");

	strcpy(strRootPath,(LPCSTR)strPath);*/

/*	strPath.Format("%s\\MonitorManager\\ResLibrary.dll",g_strRootPath);

	m_hResLibrary=::LoadLibrary(strPath);
	if(m_hResLibrary==NULL)
		throw MSException("Load ResLibrary.dll failed");*/
	
	CString strPath="";

	strPath.Format("%s\\fcgi-bin\\MonitorScheduleWeb.dll",GetRootPath());

	HMODULE m_hWebDll=::LoadLibrary(strPath);
	if(m_hWebDll==NULL)
		throw MSException("Load MonitorScheduleWeb.dll failed");
	sendmsg = (SendMsg)::GetProcAddress(m_hWebDll, "SendMsg");
	if(sendmsg == NULL)
	{
		puts("  获取dll函数失败, Failed to GetProcAddress: MonitorScheduleWeb.dll 's SendMsg;  ");
	}

	return TRUE;

}
Exemplo n.º 5
0
BOOL ScheduleThread::Init()
{
	SetThreadName("Main dispatch thread");
	/*	if(m_hThread==NULL)
	throw MSException("Error : Create schedule thread failed");
	*/

	OBJECT robj=::LoadResource("default",g_ServerHost);
	if(robj!=INVALID_VALUE)
	{
		MAPNODE map=GetResourceNode(robj);
		if(map!=INVALID_VALUE)
		{
			string svalue="";
			if(FindNodeValue(map,"IDS_MonitorDisabled",svalue))
				s_str_disable=svalue;
			svalue="";
			if(FindNodeValue(map,"IDS_GroupDependMonitor",svalue))
				s_str_gddisable=svalue;
			svalue="";
			if(FindNodeValue(map,"IDS_DisableMonitorSchedule",svalue))
				s_str_taskplandisable=svalue;
			svalue="";
			if(FindNodeValue(map,"IDS_TempDisableMonitorTime",svalue))
				s_str_tempdisable=svalue;
		}

		::CloseResource(robj);

	}


	m_pThreadContrl=new ThreadContrl(m_pSchMain);
	if(!m_pThreadContrl->Init())
		throw MSException("Error : initialize threads contrl failed");
	if(!m_pThreadContrl->Start())
		throw MSException("Error : Start threads contrl failed");
	InitMonitorTime();



	return TRUE;
}
Exemplo n.º 6
0
BOOL ThreadContrl::Init()
{
	m_pTaskQueueManager=new QueuesManager(m_pSchMain);
	if(m_pTaskQueueManager==NULL)
		throw MSException("Error : Create QueueManager failed");
	m_pTaskQueueManager->Init();

	SetThreadName("Task check thread");
	m_pOption=m_pSchMain->m_pOption;

	return AddNewThreads(/*WORKCOUNT+Univ::pluscount*/70)>0;

}
Exemplo n.º 7
0
bool MonitorThread::Run_Dll(LPFUNC func,int buflen)
{
	bool bret=false;

	__try{

		bret=(*func)(m_InBuf,m_RetBuf,buflen);
	}
	__except(filter(GetExceptionCode(), GetExceptionInformation()))
	{
		throw MSException("__try find --RunMonitor-Execute monitor happen exception");

	}


	return bret;
}
Exemplo n.º 8
0
bool Util::SendMsgToWsServer(string szId, string szText)
{
	bool bRet = true;
	string errorMsg = "";
	if(sendmsg == NULL)
	{
		//Init();
		char buf[1024]={0};
		sprintf(buf,"%s/fcgi-bin/MonitorScheduleWeb.dll",GetRootPath().getText());
		//strPath = ".\\MonitorScheduleWeb.dll";
		//puts(strPath);
		HMODULE m_hWebDll=::LoadLibrary(buf);
		if(m_hWebDll==NULL)
			throw MSException("Load MonitorScheduleWeb.dll failed");
		sendmsg = (SendMsg)::GetProcAddress(m_hWebDll, "SendMsg");
		if(sendmsg == NULL)
		{
			puts("  获取dll函数失败, Failed to GetProcAddress: MonitorScheduleWeb.dll 's SendMsg;  ");
		}

		sprintf(buf,"%s/fcgi-bin/WebECC.ini",GetRootPath().getText());
		INIFile inf=LoadIni(buf);
		szServer=GetIniSetting(inf,"WebECC","WebService","");
		szPort=GetIniSetting(inf,"WebECC","WebPort","");
		//puts(szServer.c_str());
		//puts(szPort.c_str());
	}
	

	bRet = sendmsg(szId, szText, szServer, szPort, errorMsg);
	if(bRet)
	{
		puts("sendmsg sucess\n");
	}
	else
	{
		puts("sendmsg failed\n");
		puts(errorMsg.c_str());
	}
		
	return bRet;
}
Exemplo n.º 9
0
void MonitorThread::ParserMonitorState()
{
	if(m_MonitorState==Monitor::STATUS_BAD)
		return;

	if(CheckStateByType(Error))
	{
		m_MonitorState=Monitor::STATUS_ERROR;
		return;
	}else if(CheckStateByType(Warning))
	{
		m_MonitorState=Monitor::STATUS_WARNING;
		return;
	}else if(CheckStateByType(Normal))
	{
		m_MonitorState=Monitor::STATUS_OK;
		return;
	}else{
		m_MonitorState=Monitor::STATUS_BAD;
		puts("No state be match");
		throw MSException("Parser monitor state error");
	}

}
Exemplo n.º 10
0
BOOL MonitorThread::PaserResult()
{
	m_strDisplay.clear();
	CString strContent=m_RetBuf;
	CString strDisplay="";


	strContent.Replace("\r","");
	strContent.Replace("\n","");

	if(strContent.empty())
	{
		m_MonitorState=Monitor::STATUS_ERROR;
		throw MSException("Return value is empty");
	}

	if(strContent.Find("error=",0)>-1)
	{
		m_MonitorState=Monitor::STATUS_ERROR;
		GetProperty("error=", strContent, strDisplay);
		m_strDisplay=strDisplay;
		return TRUE;

	}

	CReturnDataList &LstRet=m_Monitor->GetReutrnList();
	m_RetValueCount=(int)LstRet.size();

	ReturnValue*prv=NULL;
	BOOL bv=m_RetValueCount>retcount;
	CString strSection="";

//	POSITION pos=LstRet.GetHeadPosition();
	int n=0;
	ReturnData*prd=NULL;
	CReturnDataList::iterator it;
	for(it=LstRet.begin();it!=LstRet.end();it++)
//	while(pos)
	{
//		prd=LstRet.GetNext(pos);
		prd=(*it);
		if(bv)
		   prv=new ReturnValue;
		else
			prv=m_RetValues+n;

		strSection=prd->m_Name;
		strSection+="=";

		prv->m_pReturnData=prd;

		if(stricmp(prd->m_Type,"Int")==0)
		{
			GetProperty(strSection,strContent,prv->m_value.nVal);
			strDisplay.Format("%s=%d, ",(char *)prd->m_Label,prv->m_value.nVal);
//			printf("label===%s\n",prd->m_Label);
		}else if(stricmp(prd->m_Type,"Float")==0)
		{
			GetProperty(strSection,strContent,prv->m_value.fVal);
			strDisplay.Format("%s=%0.2f, ",(char *)prd->m_Label,prv->m_value.fVal);
//			printf("label===%s\n",prd->m_Label);
		}else if(stricmp(prd->m_Type,"String")==0)
		{
			GetProperty(strSection,strContent,prv->m_value.szVal);
			strDisplay.Format("%s=%s, ",(char *)prd->m_Label,prv->m_value.szVal);
//			printf("label===%s\n",prd->m_Label);
		}else
		{
			if(bv)
				delete prv;
			throw MSException("ParserResult error unknown type name");
		}
		if(bv)
			m_RetValueList.push_front(prv);

		n++;

		m_strDisplay+=strDisplay;

	}

	return TRUE;

}
Exemplo n.º 11
0
BOOL MonitorThread::PaserResultV70(void)
{
	m_RVmap.clear();

	if(!BulidStringMap(m_RVmap,m_RetBuf))
	{
		throw MSException("Build return data failed");
		return false;
	}

	if(m_Monitor->m_isRefresh)
	{
		puts("\n------------------------Return value-----------------------");

		STRINGMAP::iterator itm;
		while(m_RVmap.findnext(itm))
			printf("%s=%s\n",(*itm).getkey().getword(),(*itm).getvalue().getword());

		puts("-------------------------End return value--------------------");
	}


	if(m_RVmap.size()==0)
	{
		m_MonitorState=Monitor::STATUS_BAD;
		throw MSException("Return value is empty");
	}

	svutil::word *pv=m_RVmap.find("error");
	if(pv!=NULL)
	{
		m_MonitorState=Monitor::STATUS_BAD;
		m_strDisplay=pv->getword();
		return true;

	}

	CReturnDataList &LstRet=m_Monitor->GetReutrnList();
	m_RetValueCount=(int)LstRet.size();

	ReturnValue*prv=NULL;
	BOOL bv=m_RetValueCount>retcount;
	CString strDisplay="";


	int n=0;
	ReturnData*prd=NULL;
	CReturnDataList::iterator it;
	svutil::word *pvalue=NULL;

	for(it=LstRet.begin();it!=LstRet.end();it++)
	{
		prd=(*it);
		if(bv)
		   prv=new ReturnValue;
		else
			prv=m_RetValues+n;

		prv->m_pReturnData=prd;

		pvalue=m_RVmap.find((LPCSTR)prd->m_Name);
		if(pvalue==NULL)
		{
			printf("name :%s\n",(LPCSTR)prd->m_Name);
			throw MSException("ParserResult error return value is bad");
		}

		if(stricmp(prd->m_Type,"Int")==0)
		{
			prv->m_value.nVal=atoi(pvalue->getword());

			strDisplay.Format("%s=%d, ",(char *)prd->m_Label,prv->m_value.nVal);
//			printf("label===%s\n",prd->m_Label);
		}else if(stricmp(prd->m_Type,"Float")==0)
		{
			prv->m_value.fVal=atof(pvalue->getword());
			strDisplay.Format("%s=%0.2f, ",(char *)prd->m_Label,prv->m_value.fVal);
//			printf("label===%s\n",prd->m_Label);
		}else if(stricmp(prd->m_Type,"String")==0)
		{
			if(strlen(pvalue->getword())>RETVALUEMAXCOUNT-1)
				throw MSException("Return string value too big");
			strcpy(prv->m_value.szVal,pvalue->getword());
			strDisplay.Format("%s=%s, ",(char *)prd->m_Label,prv->m_value.szVal);
//			printf("label===%s\n",prd->m_Label);
		}else
		{
			if(bv)
				delete prv;
			throw MSException("ParserResult error unknown type name");
		}
		if(bv)
			m_RetValueList.push_back(prv);

		n++;

		m_strDisplay+=strDisplay;

	}


	return TRUE;

}
Exemplo n.º 12
0
void MonitorThread::run()
{
	//DWORD dret;
	CString strError="";
	InitData();

#ifdef WIN32
	if(FAILED(::CoInitialize(NULL)))
	{
		strError.Format("CoInitialize failed when create thread:%s",m_ThreadName);
		putil->ErrorLog((LPCSTR)strError);
		return;
	}

#endif

	Monitor *pMonitor=NULL;

	printf("In Thread :%s\n",this->m_ThreadName);

	try{

		while(TRUE)
		{
			//		dret=::WaitForSingleObject(m_hEvent,INFINITE);
			//		if(dret==WAIT_FAILED)

			if(!m_Event.wait())
			{
				strError="MonitorThread wait failed";
				throw MSException((LPCSTR)strError);
			}
			if(m_Monitor==NULL)
			{
				//			 ::ResetEvent(m_hEvent);
				m_Event.reset();
				m_pThreadContrl->AddToIdleThread(this);
				continue;
			}

			if(!InitSocket())
				throw MSException("Init socket failed");


			/*		BOOL ist=FALSE;
			ist=(m_Monitor->GetMonitorClass().CompareNoCase("WMI")==0);

			if(ist)
			printf("��%s,Class is :%s\n",GetThreadName(),m_Monitor->GetMonitorClass());*/


			m_nRunCount=0;
			m_StartTime=CTime::GetCurrentTimeEx();

			try{
				RunMonitor();
			}catch(MSException &e)
			{
				char errlog[2048]={0};
				sprintf(errlog,"%s,%s,MonitorID:%s",this->m_ThreadName,e.GetDescription(),m_Monitor->GetMonitorID());
				//strError.Format("%s,%s,MonitorID:%s",this->m_ThreadName,e.GetDescription(),m_Monitor->GetMonitorID());
			//	putil->ErrorLog(strError);
				putil->ErrorLog(errlog);
			}catch(...)
			{
				char errlog[2048]={0};
				sprintf(errlog,"Executent monitor exception,MonitorID:%s",m_Monitor->GetMonitorID());
				//strError.Format("Executent monitor exception,MonitorID:%s",m_Monitor->GetMonitorID());
				//putil->ErrorLog(strError);
				putil->ErrorLog(errlog);
			}
			int oldstate=m_Monitor->GetLastState();
			if(oldstate!=m_MonitorState)
			{
				if((m_MonitorState==Monitor::STATUS_ERROR)||(m_MonitorState==Monitor::STATUS_BAD))
					m_Monitor->CalculateErrorFrequency(true);
				else if((oldstate==Monitor::STATUS_ERROR)||(oldstate==Monitor::STATUS_BAD))
					m_Monitor->CalculateErrorFrequency(false);

			}

			m_Monitor->SetLastState(m_MonitorState);


			m_pThreadContrl->AdjustRetByMonitor(m_Monitor,FALSE);

			m_Monitor->SetRunning(FALSE);

			pMonitor=m_Monitor;
			InitData();
			//		::ResetEvent(m_hEvent);
			m_Event.reset();
			m_pThreadContrl->AddToIdleThread(this);

			m_pThreadContrl->CheckTaskQueueByMonitor(pMonitor);


		}
	}catch(...)
	{
		char errlog[2048]={0};
		sprintf(errlog,"Thread  exit by exception, thread:%s",m_ThreadName);

	//	strError.Format("Thread  exit by exception, thread:%s",m_ThreadName);
	//	putil->ErrorLog((LPCSTR)strError);
		putil->ErrorLog(errlog);
		return;

	}

#ifdef WIN32

	::CoUninitialize();
#endif


}
Exemplo n.º 13
0
void ThreadContrl::run()
{

#ifdef WIN32

	MSG msg;
	Monitor*pMonitor=NULL;

	m_ThreadID=::GetCurrentThreadId();

//	::SetThreadPriority(this->m_hThread,THREAD_PRIORITY_HIGHEST);
	try{
		
		while(TRUE)
		{
			if(::PeekMessage(&msg,NULL,0,0,PM_REMOVE))
			{
				switch(msg.message)
				{
				case WM_CHECKTASKS:
					CheckAllTaskQueue();
					break;
				case WM_CHECKSINGLETASK:
					////putil->ErrorLog("Get check single task");
					pMonitor=(Monitor*)msg.lParam;
				//	ProcessSingleTask(pMonitor);
					ProcessSingleTaskEx(pMonitor);
					break;
				default:
					TranslateMessage(&msg);
					::DispatchMessage(&msg);
				}
				
				
			}else
				if(!::WaitMessage())
					throw MSException("Contrl thread exit");
		}
		
	}catch(MSException &e)
	{
		CString strError="";
		strError.Format("ThreadContrl dispatch thread exit by :%s",e.Description);
		//putil->ErrorLog((LPCSTR)strError);
		ExitProcess(3);
	}catch(...)
	{
		CString strError="";
		strError.Format("ThreadContrl dispatch thread exit by :%d",::GetLastError());
		//putil->ErrorLog((LPCSTR)strError);
		ExitProcess(4);

	}

#else

	TMSG tmsg;
	Monitor *pMonitor=NULL;

	try{

		while(m_MSGQueue.RecMsg(&tmsg)==0)
		{
			switch(tmsg.type)
			{
			case WM_CHECKTASKS:
				CheckAllTaskQueue();
				break;
			case WM_CHECKSINGLETASK:
				pMonitor=(Monitor*)tmsg.pdata;
				ProcessSingleTaskEx(pMonitor);
				break;
			}
		}

	}catch(MSException &e)
	{
		CString strError="";
		strError.Format("ThreadContrl dispatch thread exit by :%s",e.Description);
		//putil->ErrorLog((LPCSTR)strError);
		//ExitProcess(3);
		::exit(1);
	}


#endif


}
Exemplo n.º 14
0
bool MonitorThread::RunInProcess(int iLen,string dllname,string funname)
{
	if(m_Monitor==NULL)
		throw MSException("Monitor is empty in RunInProcess function");

#ifdef WIN32

	DWORD dw=::GetCurrentThreadId();
	char queuename[256]={0};
	sprintf(queuename,"SiteView_RunMonitor_%d",dw);
	::CreateQueue(queuename,2);
	::ClearQueueMessage(queuename);

	ProcessMonitorData pdata;
	pdata.m_data=m_InBuf.getbuffer();
	pdata.m_datalen=iLen;
	pdata.m_dllname=dllname;
	pdata.m_funname=funname;
    
	int len=pdata.GetRawDataSize();
	if(len<=RETBUFCOUNT)
	{
		if(!pdata.GetRawData(m_RetBuf,len))
			throw MSException("Get data failed in RunInProcess function");
		if(!::PushMessage(queuename,"InData",m_RetBuf,len))
			throw MSException("PushMessage failed in RunInProcess function");
	}else
	{
		svutil::buffer ibuf;
		if(!ibuf.checksize(len))
			throw MSException("Malloc memmory failed in RunInProcess function");

		if(!pdata.GetRawData(ibuf,len))
			throw MSException("Get data failed2 in RunInProcess function");
	}
	char strCommandLine[1024]={0};
	sprintf(strCommandLine,"%s\\fcgi-bin\\MonitorSchedule.exe -e %s",(char *)g_strRootPath,queuename);
//	sprintf(strCommandLine,"\"%s\\fcgi-bin\\MonitorSchedule.exe\"",(char *)g_strRootPath);
	PROCESS_INFORMATION pi;
	ZeroMemory( &pi, sizeof(PROCESS_INFORMATION) );
	STARTUPINFO si;
	ZeroMemory( &si, sizeof(STARTUPINFO) );
	si.cb=sizeof(STARTUPINFO);

	char strDir[256]={0};
	sprintf(strDir,"%s\\fcgi-bin\\",(char *)g_strRootPath);
	printf("CommandLine :%s\n",strCommandLine);
	printf("dir :%s\n",strDir);

	if(!::CreateProcess(NULL,
		strCommandLine,
		NULL,
		NULL,
		FALSE,
		/*CREATE_NO_WINDOW*/CREATE_NEW_CONSOLE,
		NULL,
		strDir,
		&si,&pi))
	{
		
		DWORD dw=GetLastError();
		printf("error:%d\n",dw);
		::DeleteQueue(queuename);

		throw MSException("Create process failed in RunInProcess function");
	}

   ::WaitForSingleObject(pi.hProcess,INFINITE);

   MQRECORD mrd=::PopMessage(queuename);
   if(mrd==INVALID_VALUE)
   {
		::DeleteQueue(queuename);
	   throw MSException("Receive messgae failed in RunInProcess function");
   }

   string label="";
   unsigned int blen=0;
   svutil::TTime rt;
   if(!GetMessageData(mrd,label,rt,NULL,blen))
   {
	   ::CloseMQRecord(mrd);
		::DeleteQueue(queuename);
	   throw MSException("GetMessageData failed in RunInProcess function");
   }

   if(label.compare("SiteView_Return")!=0)
   {
	   ::CloseMQRecord(mrd);
		::DeleteQueue(queuename);
	   throw MSException("Return data error in RunInProcess function");
   }

   if(blen>RETBUFCOUNT)
   {
	   ::CloseMQRecord(mrd);
		::DeleteQueue(queuename);
	   throw MSException("Return data too big in RunInProcess function");
   }

   if(!GetMessageData(mrd,label,rt,m_RetBuf,blen))
   {
	   ::CloseMQRecord(mrd);
		::DeleteQueue(queuename);
	   throw MSException("GetMessageData failed2 in RunInProcess function");
   }
   ::CloseMQRecord(mrd);
   ::DeleteQueue(queuename);


#endif

	return true;
}
Exemplo n.º 15
0
void MonitorThread::ProcessResultV70(void)
{

	ReturnValue* pRV=NULL;
	CReturnValueList::iterator itv;
	CString strTemp="";

	char buf[2048]={0};
	int buflen=2048;
	int dlen=0;
	MakeRecord mr(buf,buflen,m_MonitorState);
	
	if((m_MonitorState==Monitor::STATUS_BAD)||(m_MonitorState==Monitor::STATUS_NULL))
	{
	
		if(!mr.MakeError(m_MonitorState,(LPCSTR)m_strDisplay))
		{
			throw MSException("Make record failed");
		}
		dlen=mr.GetDataSize();
	}else{
//		printf("Return count :%d\n",m_RetValueCount);
		for(int n=0;n<m_RetValueCount;n++)
		{
			if(m_RetValueCount>retcount)
			{
				if(n==0)
					itv=m_RetValueList.begin();
				pRV=*itv++;

			}else
				pRV=m_RetValues+n;
			if(pRV==NULL)
			{
				throw MSException("Return value is NULL");
			}
		
		    if(!mr.MakeBuf(pRV))
			{
				throw MSException("Make result failed");
			}

		}
		dlen=mr.GetDataSize();
	}

	//CString strCostTime="";

	//CTime time=CTime::GetCurrentTimeEx();
	//CTimeSpan ts=time-m_StartTime;

	//strCostTime.Format("[Cost time :%ld seconds]",ts.GetTotalSeconds());
	//m_strDisplay+=strCostTime;


	char *pt=buf;
	pt+=dlen;
	if(buflen-dlen<strlen((char *)m_strDisplay)+1)
		throw MSException("Process result -- string too big");
	strcpy(pt,(char *)m_strDisplay);
	dlen+=strlen((char *)m_strDisplay)+1;

	printf("MonitorId:%s,MonitorType:%d,state:%d,dstr:%s\n",m_Monitor->GetMonitorID(),m_Monitor->GetMonitorType(),m_MonitorState,(char *)m_strDisplay);

//	puts((char *)m_strDisplay);
//	const char *ps=m_Monitor->GetMonitorID();
//	puts(ps);

	if(m_Monitor->isDelete)
		return ;


	if(m_Monitor->m_isRefresh)
		putil->InsertSvdb(m_Monitor->GetMonitorID(),buf,dlen,g_ServerHost);
	else
		putil->InsertSvdb(m_Monitor->GetMonitorID(),buf,dlen);

	if(m_Monitor->m_isRefresh)
	{
		char buf[100]={0};
		sprintf(buf,"%s",m_Monitor->GetMonitorID());
		string text="Refresh ,PushMessage f: \"";
		text+=g_RefreshQueueName + "\"";
		if(!::PushMessage(g_RefreshQueueName,"Refresh_OK",buf,strlen(buf)+1,"default",g_QueueAddr))
			putil->ErrorLog(text.c_str());
	}

	
}
Exemplo n.º 16
0
void MonitorThread::RunMonitor()
{
	m_nRunCount++;

	CString strError="";

	if(m_Monitor==NULL)
		throw MSException("Monitor is NULL");

	CString strDLLName="",
		strFuncName="";

	if(m_pThreadContrl->m_pOption->m_isDemo)
	{
		puts("=================Demo mode=========================");
		strDLLName.Format("%s/fcgi-bin/%s",(char *)g_strRootPath,m_pThreadContrl->m_pOption->m_DemoDLL.c_str());
		strFuncName=m_pThreadContrl->m_pOption->m_DemoFunction.c_str();

	}else
	{
		strDLLName.Format("%s/fcgi-bin/%s",(char *)g_strRootPath,(char *)m_Monitor->GetLibrary());
		strFuncName=m_Monitor->GetProcess();
	}

	if(strFuncName.empty())
	{
		throw MSException("RunMonitor-Function name is empty");
	}

	if(m_Monitor->m_isRefresh)
	{
		puts("-----------------Load library-------------------------");
		printf("Library name:%s\n",(char *)strDLLName);
		printf("Function name:%s\n",(char *)strFuncName);
		puts("-----------------End load library---------------------");
		puts("\n-----------------Input parameter----------------------");

		CStringList&lst=m_Monitor->GetParameterList();

		CStringList::iterator it;
		for(it=lst.begin();it!=lst.end();it++)
			printf("%s\n",(*it).c_str());

		puts("----------------End input parameter-------------------");
	}


#ifdef	WIN32

	HMODULE hm=::LoadLibrary(strDLLName);
	if(!hm)
	{
		strError.Format("RunMonitor-Load library failed,DLL name:%s",(char *)strDLLName);
		throw MSException((LPCSTR)strError);
	}

#ifndef SVVER70

	GatherData *pGetData=(GatherData*)::GetProcAddress(hm,(LPCSTR)strFuncName);
	if(!pGetData)
	{
		::FreeLibrary(hm);
		throw MSException("RunMonitor-GetProcAddress failed");
	}

/*	CStringList&lst=m_Monitor->GetParameterList();
	POSITION pos=lst.GetHeadPosition();
	while(pos)
		printf("%s\n",lst.GetNext(pos));

	puts(strDLLName);
	puts(strFuncName);*/

	try{
		CStringList&lstParam=m_Monitor->GetParameterList();
		(*pGetData)(lstParam,m_RetBuf);
	}catch(...)
	{
		::FreeLibrary(hm);
		throw MSException("RunMonitor-Execute monitor happen exception");
	}

#else

	LPFUNC pfunc = (LPFUNC)GetProcAddress(hm,(LPCSTR)strFuncName);
	if(!pfunc)
	{
		::FreeLibrary(hm);
		throw MSException("RunMonitor-GetProcAddress failed");

	}


	int iLen=MakeInBuf();
	int buflen=RETBUFCOUNT;

	if(!m_Monitor->m_isRunInProcess)
	{

		try{

			(*pfunc)(m_InBuf,m_RetBuf,buflen);
			//Run_Dll(pfunc,buflen);

		}catch(MSException &e)
		{
		//	putil->ErrorLog(strError);
			::FreeLibrary(hm);
			throw MSException(e.GetDescription());
		}catch(...)
		{
			::FreeLibrary(hm);
			throw MSException("RunMonitor-Execute monitor happen exception");
		}
	}else{
     	::FreeLibrary(hm);
		RunInProcess(iLen,strDLLName.getText(),strFuncName.getText());
	}

#endif

	::FreeLibrary(hm);
#else
   void *dp;
   char *error;

   dp = dlopen(strDLLName, RTLD_LAZY);
   
   if(dp == NULL)
   {
   		error=dlerror();
   		strError.Format("RunMonitor-Load library failed,DLL name:%s,Error:%s",(char *)strDLLName,error);
		throw MSException((LPCSTR)strError);
   }

   GatherData *pGetData = (GatherData*)dlsym(dp, strFuncName);

   error = dlerror();

   if (error)
   {
	    dlclose(dp);
	   throw MSException("RunMonitor-GetProcAddress failed");
   }

	try{
		CStringList&lstParam=m_Monitor->GetParameterList();
		
	        CStringList::const_iterator it;
		it=lstParam.begin();
		while(it!=lstParam.end())
		{
		   puts(*it++);
		}
		
	
		(*pGetData)(lstParam,m_RetBuf);

	}catch(...)
	{
	//	::FreeLibrary(hm);
	    //    dlclose(dp);
		throw MSException("RunMonitor-Execute monitor happen exception");
	}
	
	puts(m_RetBuf);

	 dlclose(dp);



#endif


/*	puts("\n#########################################################");
	printf("Result is:%s\n",m_RetBuf);
	puts("############################end##########################");
*/
#ifdef SVVER70
	 PaserResultV70();
#else
	PaserResult();
#endif
	
	try{

     	ParserMonitorState();

	}catch(...)
	{
		m_MonitorState=Monitor::STATUS_BAD;
		printf(".....%s.....\n",(char *)m_strDisplay);
		m_strDisplay="Error:Set state error";
#ifdef SVVER70
		ProcessResultV70();
#else
		ProcessResult();
#endif
		return ;

	}
	if(m_MonitorState==Monitor::STATUS_BAD)
	{
		if((m_Monitor->GetCheckError())&&(m_nRunCount<2))
		{
			ClearResult();
			RunMonitor();
			return;
		}
	}
	
	
	//if((m_MonitorState==Monitor::STATUS_ERROR)&&(m_nRunCount<2)&&(strcmp(m_Monitor->GetEntityType(),"NetworkEquipment")==0))
	//{
	//	ClearResult();
	//	RunMonitor();
	//	return;
	//}

#ifdef SVVER70
	ProcessResultV70();
#else
	ProcessResult();
#endif
	

}
Exemplo n.º 17
0
BOOL ThreadContrl::AddTask(Monitor *pMonitor)
{ 
//	if(m_hThread==NULL)
//		throw MSException("Error : NO ThreadContrl thread");

	CString strError="";
	if(pMonitor==NULL)
		throw MSException("Monitor is empty");

	//bool ist=false;

	//if(stricmp(pMonitor->GetMonitorClass().getText(),"telnet")==0)
	//{
	//	char buf[100]={0};
	//	sprintf(buf,"////////////////class:%s telnet monitor:%s//////////////\n",pMonitor->GetMonitorClass().getText(),
	//		pMonitor->GetMonitorID());

	//	ist=true;

	//	//putil->ErrorLog(buf);
	//}

	if(pMonitor->GetSkipCount()>=MAXSKIPCOUNT)
	{
		strError.Format("SkipCount > %d, MonitorID:%s, this monitor will be deleted. ",MAXSKIPCOUNT,pMonitor->GetMonitorID());
		m_pSchMain->DeleteMonitorV70(pMonitor->GetMonitorID());
		string strTemp = strError.getText();
		WriteLog( strTemp.c_str() );
		//putil->ErrorLog(strError);
		//throw MSException((LPCSTR)strError);
		return false;
	}

	if(pMonitor->GetRunning())
	{
		pMonitor->SetSkipCount(pMonitor->GetSkipCount()+1);
		strError.Format("Monitor skip count:%d,Monitor ID:%s",pMonitor->GetSkipCount(),pMonitor->GetMonitorID());
		string strTemp = strError.getText();
		WriteLog( strTemp.c_str() );
		//putil->ErrorLog(strError);

	}else{
		if(!CheckSubsequent(pMonitor))
		{
			//if(ist)
			//	//putil->ErrorLog("will Start Monitor");
			StartMonitor(pMonitor);
	//		StartMonitor(PopMonitorInQueue(pMonitor));
		}
		else
		{
			//if(ist)
			//	//putil->ErrorLog("Enter queue");
			AddQueue(pMonitor);
		}
	}


	return TRUE;

}