Exemple #1
0
void		bbwincmd(int argc, char *argv[]) {
	string 	bbdisparg;
	
	BBWinNet	bbobj;
	if (strcmp(argv[1], "$") == 0) {
		cout << "will use environment variable BBDISPLAY" << endl;
		bbdisparg = getBBDisplaySetting();
	} else {
		bbdisparg = argv[1];
	}
	bbobj.SetBBDisplay(bbdisparg);
	cout << "bbdisplay defined to : " << bbobj.GetBBDisplay() << "\n";
	cout << "port defined to : " << bbobj.GetPort() << "\n";
	bbobj.SetDebug(true);
	string message = argv[2];
	bool	unkownMessage = false;
	for (int inc = 0; messTable[inc].callBack != NULL; ++inc) {
		int res = message.find(messTable[inc].argument);
		if (res >= 0 && (unsigned int)res <= message.size()) {
			unkownMessage = true;
			if (argc >= messTable[inc].minArg) {
				messTable[inc].callBack(argc, argv, bbobj);
			} else {
				cout << "\n";
				cout << "Error : not enough arguments for : \"" << message << "\"" << "\n\n";
			}
			break ;
		}
	}
	if (unkownMessage == false) {
		cout << "\n";
		cout << "Error : unknown Xymon message type : \"" << message << "\"" << "\n\n";
	}
}
Exemple #2
0
void		BBWinAgentManager::Query(LPCTSTR testName, LPTSTR dest, DWORD size) {
	bbdisplay_t::iterator			itr;
	BBWinNet	hobNet;
	string		result;

	assert(testName != NULL);
	assert(dest != NULL);
	itr = m_bbdisplay.begin();
	hobNet.SetBBDisplay((*itr));
	PrepareBBWinNetObj(hobNet);
	try {
		hobNet.Query(testName, result);
	} catch (BBWinNetException ex) {
		if (m_logReportFailure) {
			string mes;

			mes = "Sending config message to " + (*itr) + " failed.";
			LPCTSTR		arg[] = {m_agentName.c_str(), mes.c_str(), NULL};
			m_log->reportWarnEvent(BBWIN_AGENT, EVENT_MESSAGE_AGENT, 2, arg);
		}
	}
	try
	{
		if (dest != NULL && size != 0)
			strncpy(dest, result.c_str(), size);
	}
	catch (...)
	{
		// Failed to write
	}
}
Exemple #3
0
void 			BBWinAgentManager::Status(LPCTSTR testName, LPCTSTR color, LPCTSTR text, LPCTSTR lifeTime) {
	bbdisplay_t::iterator			itr;
	BBWinNet	hobNet;
	
	assert(testName != NULL);
	assert(color != NULL);
	assert(text != NULL);
	assert(lifeTime != NULL);
	Pager(testName, color, text, lifeTime);
	PrepareBBWinNetObj(hobNet);
	for ( itr = m_bbdisplay.begin(); itr != m_bbdisplay.end(); ++itr) {
		hobNet.SetBBDisplay((*itr));
		try {
			hobNet.Status(testName, color, text, lifeTime);
		} catch (BBWinNetException ex) {
			if (m_logReportFailure) {
				string mes;
						
				mes = "Sending report to " + (*itr) + " failed.";
				LPCTSTR		arg[] = {m_agentName.c_str(), mes.c_str(), NULL};
				m_log->reportWarnEvent(BBWIN_AGENT, EVENT_MESSAGE_AGENT, 2, arg);
			}
			continue ; 
		}
	}
}
Exemple #4
0
void		BBWinAgentManager::Config(LPCTSTR fileName, LPCTSTR dest) {
	bbdisplay_t::iterator			itr;
	BBWinNet	hobNet;

	assert(fileName != NULL);
	assert(dest != NULL);
	itr = m_bbdisplay.begin(); 
	hobNet.SetBBDisplay((*itr));
	PrepareBBWinNetObj(hobNet);
	try {
		hobNet.Config(fileName, dest);
	} catch (BBWinNetException ex) {
		if (m_logReportFailure) {
			string mes;

			mes = "Sending config message to " + (*itr) + " failed.";
			LPCTSTR		arg[] = {m_agentName.c_str(), mes.c_str(), NULL};
			m_log->reportWarnEvent(BBWIN_AGENT, EVENT_MESSAGE_AGENT, 2, arg);
		}
	}
}
Exemple #5
0
void		BBWinAgentManager::Drop()  {
	bbdisplay_t::iterator			itr;
	BBWinNet						hobNet;
		
	PrepareBBWinNetObj(hobNet);
	for ( itr = m_bbdisplay.begin(); itr != m_bbdisplay.end(); ++itr) {
		hobNet.SetBBDisplay((*itr));
		try {
			hobNet.Drop();
		} catch (BBWinNetException ex) {
			if (m_logReportFailure) {
				string mes;
			
				mes = "Sending report to " + (*itr) + " failed.";
				LPCTSTR		arg[] = {m_agentName.c_str(), mes.c_str(), NULL};
				m_log->reportWarnEvent(BBWIN_AGENT, EVENT_MESSAGE_AGENT, 2, arg);
			}
			continue ; 
		}
	}
}
Exemple #6
0
void BBWinCentralHandler::run() {
	DWORD 		dwWait;
	std::list<BBWinHandler *>::iterator		itr;
	
	clientLocalCfgPath = m_data.setting["tmppath"] + (string)"\\clientlocal.cfg";
	for (;;) {
		std::ofstream	report(reportPath.c_str(), std::ios_base::trunc | ios_base::binary);
		bool		created = false;

		if (report) {
			report << "client " << m_data.setting["hostname"] << ".bbwin " << m_data.setting["configclass"] << "\n";
			report.close();
			created = true;
			GetClock();
			string		osversion;
			uname(osversion);
			bbwinClientData_callback("osversion", osversion);
		} else {
			string mess, err;

			mess = (string)"failed to create the report file " + reportPath;
			GetLastErrorString(err);
			LPCTSTR		args[] = {mess.c_str(), err.c_str(), NULL};
			m_log->reportErrorEvent(BBWIN_SERVICE, EVENT_HOBBIT_FAILED_CLIENTDATA, 2, args);
		}

		for (itr = m_agents.begin(); itr != m_agents.end(); ++itr) {
			(*itr)->Run();
			dwWait = WaitForMultipleObjects(m_hCount, m_hEvents , FALSE, 0);
			if (( dwWait >= WAIT_OBJECT_0 && dwWait <= (WAIT_OBJECT_0 + m_hCount - 1) ) || (dwWait >= WAIT_ABANDONED_0 && dwWait <= (WAIT_ABANDONED_0 + m_hCount - 1) )) {
				DeleteFile(reportPath.c_str());
				return ;
			}
		}
		if (created) {
			bbdisplay_t::iterator			itr;
			
			string		result;

			for (itr = m_bbdisplay.begin(); itr != m_bbdisplay.end(); ++itr) {
				BBWinNet	hobNet;
				hobNet.SetBBDisplay((*itr));
				try {
					hobNet.ClientData(reportPath, clientLocalCfgPath);
				} catch (BBWinNetException ex) {
					string mess, err;

					GetLastErrorString(err);
					mess = ex.getMessage();
					LPCTSTR		args[] = {mess.c_str(), err.c_str(), NULL};
					m_log->reportErrorEvent(BBWIN_SERVICE, EVENT_HOBBIT_FAILED_CLIENTDATA, 2, args);
				}
			}
			DeleteFile(reportSavePath.c_str());
			MoveFile(reportPath.c_str(), reportSavePath.c_str());
			DeleteFile(reportPath.c_str());
		}
		dwWait = WaitForMultipleObjects(m_hCount, m_hEvents , FALSE, m_timer * 1000 );
		if ( dwWait >= WAIT_OBJECT_0 && dwWait <= (WAIT_OBJECT_0 + m_hCount - 1) ) {    
			break ;
		} else if (dwWait >= WAIT_ABANDONED_0 && dwWait <= (WAIT_ABANDONED_0 + m_hCount - 1) ) {
			break ;
		}
	}
}
Exemple #7
0
void		BBWinAgentManager::Message(LPCTSTR message, LPTSTR dest, DWORD size) {
	bbdisplay_t::iterator			itr;
	BBWinNet	hobNet;
	string		result;

	assert(message != NULL);
	assert(dest != NULL);
	if (m_usepager == true && m_bbpager.size() > 0) { // extract the information needed to send pager notification
		string		tmp, type, testName, color, text, lifeTime;
		size_t		pos = 0;

		tmp = message;
		istringstream iss(tmp);
		std::getline( iss, tmp);
		size_t res = tmp.find_first_of(" ");
		if (res > 0 && res < tmp.length()) {
			
			type = tmp.substr(0, res);
			res = type.find_first_of("status");
			if (res >= 0 && res < tmp.length()) {
				size_t	end;
				
				tmp = tmp.substr(type.length() + 1);
				pos += type.length() + 1;
				res = type.find_first_of("+");
				if (res > 0 && res < type.length()) {
					lifeTime = type.substr(res + 1);
				}
				res = tmp.find_first_of(".");
				end = tmp.find_first_of(" ");
				testName = tmp.substr(res + 1, end - (res + 1));
				tmp = tmp.substr(end + 1);
				pos += end + 1;
				end = tmp.find_first_of(" ");
				color = tmp.substr(0, end);
				if (tmp.length() > (end + 2)) {
					pos += end + 2;
					text = message;
					text = text.substr(pos);
					Pager(testName.c_str(), color.c_str(), text.c_str(), lifeTime.c_str());
				}
			}
		}
	}
	for ( itr = m_bbdisplay.begin(); itr != m_bbdisplay.end(); ++itr) {
		hobNet.SetBBDisplay((*itr));
		PrepareBBWinNetObj(hobNet);
		try {
			hobNet.Message(message, result);
		} catch (BBWinNetException ex) {
			if (m_logReportFailure) {
				string mes;
			
				mes = "Sending report to " + (*itr) + " failed.";
				LPCTSTR		arg[] = {m_agentName.c_str(), mes.c_str(), NULL};
				m_log->reportWarnEvent(BBWIN_AGENT, EVENT_MESSAGE_AGENT, 2, arg);
			}
			continue ; 
		}
	}
	try
	{
		if (dest != NULL && size != 0)
			strncpy(dest, result.c_str(), size);
	}
	catch (...)
	{
		// Failed to write
	}
}