Example #1
0
static string GetTicket(const Str2StrMap& cookies, const Str2StrMap& parameter) {
  Str2StrMap::const_iterator it = cookies.find("t");
  if (it != cookies.end()) {
    return it->second;
  }
  it = parameter.find("t");
  if (it != parameter.end()) {
    return it->second;
  }
  return string();
}
Example #2
0
void FrequencyAnalyzer::analyze(const Str2StrMap& logmap) {
	time_t now = time(0);
	/*Str2StrMap::const_iterator logvalueiterator = logmap.find("value");
	 if (logvalueiterator == logmap.end())
	 {
	 return;
	 }
	 long now = lexical_cast<long>(logvalueiterator->second);*/

	Str2StrMap::const_iterator lognameiterator = logmap.find("name");
	if (lognameiterator == logmap.end()) {
		return;
	}
	string name = lognameiterator->second;

	IceUtil::Mutex::Lock lock(_mutex);

	_map[name].times.push(now);
	if (_map[name].times.size() == 1) {
		_map[name].lastalert = 0;
		return;
	}

	long last = _map[name].times.front();

	MCE_DEBUG("name: " << name << " size=" << _size << " mapsize="
			<< _map[name].times.size() << " last=" << last << " now=" << now << " lastalerm=" << _map[name].lastalert);

	if (now - last <= _time && (int) (_map[name].times.size()) >= _size) {
		string message = "";
		Str2StrMap::const_iterator logmessageiterator = logmap.find("message");
		if (logmessageiterator == logmap.end()) {
			Str2StrMap::const_iterator configmessageiterator = _configMap.find(
					"FrequencyAnalyzer.Message");
			if (configmessageiterator == _configMap.end()) {
				return;
			}
			message = configmessageiterator->second;
		} else {
			message = logmessageiterator->second;
		}
		stringstream ss;
		ss << name << ": " << message;
		if (now - _map[name].lastalert >= 900) {
			_map[name].lastalert = now;
			string key;
			stringstream stream(message);
			stream >> key;
			//向主题key发送信息ss.str()
			std::vector<string> subjects;
			subjects.push_back(key);
      MonitorAlerterAdapter::instance().alert(key, ss.str(), ALERTERALL, 900);
		}
Example #3
0
void UserConfigManagerI::createUserConfig(const Str2StrMap& properties, const Ice::Current& current) {
	InvokeClient ic = InvokeClient::create(current, "", InvokeClient::INVOKE_LEVEL_INFO);

	try {
		int userId;
		MyUtil::Str2StrMap::const_iterator itr = properties.find(CUCUSERID);
		if (itr == properties.end()) {
			MCE_WARN("UserConfigManagerI::createUserConfig, Exception[NoId]");
			return;
		} else {
			userId = boost::lexical_cast<int>(itr->second);
		}
		Lock lock(_tempMutexManager, userId);
		QueryRunner("user_config", CDbWServer).execute(Statement::buildInsert(TABLE_USER_CONFIG, properties));
		UserConfigDataIPtr rs = new UserConfigDataI;
		BatchConfigResHandlerI handler(rs);
		Str2StrMap filter;
		filter[CUCUSERID] = const_cast<Str2StrMap&> (properties)[CUCUSERID];
		QueryRunner("user_config", CDbWServer).query(Statement::buildSelect(TABLE_USER_CONFIG, filter), handler);
		ServiceI::instance().addObject(rs, USER_CONFIG, rs->userId);
		UserConfigReaderAdapter::instance().setData(userId, rs);
	} catch (Ice::Exception& e) {
		MCE_WARN("[UserConfigManagerI::createUserConfig] Ice::Exception : " << e.what());
	} catch (std::exception& e) {
		MCE_WARN("[UserConfigManagerI::createUserConfig] std::exception : " << e.what());
	} catch (...) {
		MCE_WARN("[UserConfigManagerI::createUserConfig] UNKNOWN exception");
	}
}
Example #4
0
void RestTask::_handle(){
	_timeStamp = time(NULL);
	--_retryCount;
	//handle();
  Str2StrMap paras;
	paras["call_id"] = boost::lexical_cast<string>(time(NULL));
	paras["v"] = "1.0";
	paras["format"] = "xml";
  Str2StrMap tmp = parameters();
  paras.insert(tmp.begin(), tmp.end());
	if(paras.find("api_key") == paras.end()){
    paras["api_key"] = "ffa4add0b30141aa9eb9a8f1af34a8c3";
  }
	paras["sig"] = makeSig(paras);
	if(paras.empty()){
		return;
	}
	string path = "http://api.renren.com/server/restserver.do";

	int userid = boost::lexical_cast<int>(paras["session_key"]);
	try{
		RestMediatorAdapter::instance().restRequest(id(), userid, path, paras);
	}catch(Ice::Exception& e){
		MCE_WARN("RestTask::handle-->RestMediatorAdapter::restRequest-->" << e);
	}
}
Example #5
0
static int GetTargetUserId(const Str2StrMap& parameter){
	int targetuser = -1;
	Str2StrMap::const_iterator it = parameter.find("targetuser");
	if(it != parameter.end()){
  	try {
      targetuser = boost::lexical_cast<int>(it->second);
    } catch (std::exception& e) {
      MCE_WARN("OnlineBuddyListCollector::fillData GetTargetUserId cast targetuser = "******"--> ERROR  err:"<<e.what());
			return -1;
    }
	}
	return targetuser;
}
Example #6
0
static int GetUserId(const Str2StrMap& cookies, const Str2StrMap& parameter) {
  int uid = 0;
  Str2StrMap::const_iterator it = cookies.find("id");
  if (it != cookies.end() && (!it->second.empty())) {
    try {
      uid = boost::lexical_cast<int>(it->second);
      return uid;
    } catch (...) {
      MCE_WARN("OnlineBuddyListCollector::fillData --> cast err, " << it->second);
    }
  }

  it = parameter.find("uid");
  if (it != parameter.end()) {
    try {
      uid = boost::lexical_cast<int>(it->second);
    } catch (std::exception& e) {
      MCE_WARN("OnlineBuddyListCollector::fillData --> cast wap uid err:"<<e.what());
    }
  }
  return uid;
}
Example #7
0
//-----------------------------------------------------------------
void DefaultResponseStat::response(const RequestPtr& request,
		const SessionPtr& session) {
	//	MCE_DEBUG("DefaultResponseStat::response --> config.size:"<<_config.size()
	//			<<" path:"<< request->path());
	map<string,ActionConfig>::iterator it = _config.find(request->path());
	if (it == _config.end()) {
		deliver(session, 404, 0, false, false, "", "");
		changeStat(session, &ConnectingStat::instance());
		return;
	}

	if (it->second.has_index) {
		int id = 0;
		string strHostId = request->cookie("id");
		if (!strHostId.empty()) {
			try{
				id = boost::lexical_cast<int>(strHostId);
			}catch(...){
				MCE_WARN("DefaultResponseStat::response --> cast err, " << strHostId);
			}
		} else {
			string uid = request->getProperty("uid");
			if(uid != "") {
				try {
					id = boost::lexical_cast<int>(uid);
				} catch(...) {
					MCE_WARN("DefaultResponseStat::respons -->cast uid err");
				}
			}
		}

		if(id>0) {
			ContentPtr body;
			int realid = id;
			if("/getroominfo.do" == request->path() || "/getgrouphistory.do" == request->path()){
				int gid = -1;
				Str2StrMap props = request->getProperties();
				Str2StrMap::iterator it = props.find("gid");
				if(it != props.end()){
					try {
						gid = boost::lexical_cast<int>(it->second);
					} catch (std::exception& e) {
						MCE_WARN("DefaultResponseStat::respons cast gid = " << it->second << "--> ERROR  err:"<<e.what());
					}
				}
				realid = gid;
			}
			if(realid > 0){
				body = PageCacheAdapter::instance().GetContent(realid, request->path(), request->cookies(), request->getProperties());
				if(!body->isBin) {
					try{
						body->data = gzip_compress(body->data);
					}catch(std::exception& e){
						MCE_WARN("Page::bodyGzip --> gzip err:"<<e.what());
						body->data = "";
						body->statusCode = 404;
					}catch(...){
						MCE_WARN("Page::bodyGzip --> gzip err");
						body->data = "";
						body->statusCode = 404;
					}
				}
			}else{
			}
			if(body) {
				deliver(session, body->statusCode, body->timeout, (bool)request->encoding(), false, "", body->data, body->isBin ,body->contentType);
				changeStat(session,&ConnectingStat::instance());
				return;
			}
		}
	} else {
		UserPagePtr up = ServiceI::instance().locateObject<UserPagePtr>(UPC, 0);
		ContentPtr body = up->body(request, 0);
		if(body) {
			deliver(session, body->statusCode, body->timeout, (bool)request->encoding(), false, "", body->data,body->isBin ,body->contentType);

			changeStat(session,&ConnectingStat::instance());
			return;
		}
	}
	MCE_WARN("DefaultResponseStat::respons --> retrun 404 " << request->path());
	deliver(session, 404, 0, false, false, "", "");
	changeStat(session,&ConnectingStat::instance());
	return;
}
Example #8
0
void RangeAnalyzer::analyze(const Str2StrMap& logmap) {
	MCE_INFO("RangeAnalyzer::analyze logmap.size = " << logmap.size());
	time_t now = time(0);
	Str2StrMap::const_iterator lognameiterator = logmap.find("name");
	if (lognameiterator == logmap.end()) {
		return;
	}
	string name = lognameiterator->second;

	Str2StrMap::const_iterator logvalueiterator = logmap.find("value");
        if (logvalueiterator == logmap.end()) {
                return;
        }
        int value = lexical_cast<int>(logvalueiterator->second);

	IceUtil::Mutex::Lock lock(_mutex);

	if (_map.find(name) == _map.end()) {
		_map[name] = new RangeNode(name, now, 0, 0);
		/*IceUtil::ThreadPtr mt = new RangeThread(_map[name], _interval, _waitcount, _alertmap);
		_threads.push_back(mt);
		mt->start(65535).detach();*/
		return;
	}
	_map[name]->lastpush = now;

	MCE_DEBUG("name: " << name << " value: " << value << _unit);

	stringstream maxstring;
	maxstring << "RangeAnalyzer."<<name<<".Max";
	stringstream minstring;
	minstring << "RangeAnalyzer."<<name<<".Min";
	stringstream moremaxstring;
	moremaxstring << "RangeAnalyzer."<<name<<".MoreMax";
	stringstream moreminstring;
	moreminstring << "RangeAnalyzer."<<name<<".MoreMin";

	ServiceI& service = ServiceI::instance();

	float __max=service.getCommunicator()->getProperties()->getPropertyAsIntWithDefault(maxstring.str(), (int)_max);
	float __min=service.getCommunicator()->getProperties()->getPropertyAsIntWithDefault(minstring.str(), (int)_min);
	float __moremin=service.getCommunicator()->getProperties()->getPropertyAsIntWithDefault(moreminstring.str(), (int)_moremin);
	float __moremax=service.getCommunicator()->getProperties()->getPropertyAsIntWithDefault(moremaxstring.str(), (int)_moremax);

	if (value > __max || value < __min) {
		MCE_DEBUG("alert: name: " << name << "value: " << value <<_unit);
		string message = "";
		Str2StrMap::const_iterator logmessageiterator = logmap.find("message");
		if (logmessageiterator == logmap.end()) {
			Str2StrMap::const_iterator configmessageiterator = _configMap.find(
					"RangeAnalyzer.Message");
			if (configmessageiterator == _configMap.end()) {
				return;
			}
			message = configmessageiterator->second;
		} else {
			message = logmessageiterator->second;
		}
		stringstream ss;
		ss << name << ": " << message << " "<<value<< _unit;
		if (now - _map[name]->lastalert >= 1800) {
			_map[name]->lastalert = now;
			if (_map[name]->alermtimes<1 || value < __moremin || value > __moremax) {
				_map[name]->alermtimes++;
				//向主题name发送信息ss.str()
				std::vector<string> subjects;
				subjects.push_back(name);
        MonitorAlerterAdapter::instance().alert(name, ss.str(), ALERTERALL, 900);
			}
		}
	}else{
		if(value>=__min+_deviation && value<=__max-_deviation){
			_map[name]->alermtimes=0;
		}
	}
}