- std::lock_guard<std::mutex> l(d_mutex);
- auto iter = d_statuses.find(cd);
- if(iter == d_statuses.end()) {
- // g_log<<Logger::Warning<<"Launching HTTP(s) status checker for "<<remote.toStringWithPort()<<" and URL "<<url<<endl;
- d_statuses[cd]=Checker{std::thread(&IsUpOracle::checkURLThread, this, remote, url, opts), false};
- return false;
- }
-
- return iter->second.status;
-}
-
-void IsUpOracle::checkTCPThread(ComboAddress rem, const opts_t& opts)
-{
- CheckDesc cd{rem, "", opts};
- setDown(cd);
- for(bool first=true;;first=false) {
- try {
- Socket s(rem.sin4.sin_family, SOCK_STREAM);
- ComboAddress src;
- s.setNonBlocking();
- if(opts.count("source")) {
- src=ComboAddress(opts.at("source"));
- s.bind(src);
- }
- s.connect(rem, 1);
- if(!isUp(cd)) {
- g_log<<Logger::Warning<<"Lua record monitoring declaring TCP/IP "<<rem.toStringWithPort()<<" ";
- if(opts.count("source"))
- g_log<<"(source "<<src.toString()<<") ";
- g_log<<"UP!"<<endl;
- }
- setUp(cd);
- }
- catch(NetworkError& ne) {
- if(isUp(rem, opts) || first)
- g_log<<Logger::Warning<<"Lua record monitoring declaring TCP/IP "<<rem.toStringWithPort()<<" DOWN: "<<ne.what()<<endl;
- setDown(cd);
- }
- sleep(1);
- }
-}
-
-
-void IsUpOracle::checkURLThread(ComboAddress rem, std::string url, const opts_t& opts)
-{
- setDown(rem, url, opts);
- for(bool first=true;;first=false) {
- try {
- string useragent = productName();
- if (opts.count("useragent")) {
- useragent = opts.at("useragent");
- }
- MiniCurl mc(useragent);
-
- string content;
- if(opts.count("source")) {
- ComboAddress src(opts.at("source"));
- content=mc.getURL(url, &rem, &src);
- }
- else {
- content=mc.getURL(url, &rem);
- }
- if(opts.count("stringmatch") && content.find(opts.at("stringmatch")) == string::npos) {
- throw std::runtime_error(boost::str(boost::format("unable to match content with `%s`") % opts.at("stringmatch")));
- }
- if(!upStatus(rem,url,opts))
- g_log<<Logger::Warning<<"LUA record monitoring declaring "<<rem.toString()<<" UP for URL "<<url<<"!"<<endl;
- setUp(rem, url,opts);
- }
- catch(std::exception& ne) {
- if(upStatus(rem,url,opts) || first)
- g_log<<Logger::Warning<<"LUA record monitoring declaring "<<rem.toString()<<" DOWN for URL "<<url<<", error: "<<ne.what()<<endl;
- setDown(rem,url,opts);
- }
- sleep(5);
- }