--- projects/cms/source/host/c++/Host.cpp 2001/02/26 14:59:04 1.1 +++ projects/cms/source/host/c++/Host.cpp 2001/03/05 12:40:32 1.2 @@ -1,5 +1,6 @@ #include #include // linux header for the sleep function +#include // itoa() #include #include "SysMon.h" // #include "Config.h" - redefinition error - turns out i don't need it @@ -14,6 +15,7 @@ int main(){ // list of local variables int noErrors = 1; + int reloadConfig = 0; // print some extra info.. int debug = 0; @@ -23,7 +25,7 @@ int main(){ std::cout << "C Host starting..\n"; std::cout << "Attemping to load config\n"; - Config config("killigrew.ukc.ac.uk",4567,debug); // host, port, debug (0/1) + Config config("raptor.ukc.ac.uk",4567,debug); // host, port, debug (0/1) std::cout << "Creating data collector\n"; SysMon sysMon(config, debug); @@ -37,6 +39,7 @@ int main(){ } // if } // if + std::cout << "Configuring TCPUpdateTime\n"; int TCPUpdateTime = config.getIntProperty("TCPUpdateTime"); if ( TCPUpdateTime == -1){ @@ -55,86 +58,169 @@ int main(){ AveragerUpdateTime = 2; } // if + std::cout << "Configuring Filter Retry Tolerances\n"; + int MaxFilterRetrys = config.getIntProperty("MAXTCPFilterRetries"); + if ( MaxFilterRetrys == -1){ + if ( debug == 1 ){ + std::cout << "Using Default Tolerance\n"; + } // if + MaxFilterRetrys = 5; + } // if + + std::cout << "Configuring Alerter\n"; // Set the values at which the Alerter should kick in. and how many packets it should // send // now do the data collection + std::cout << "Starting Data Collection\n"; // work out which is closer, the next heartbeat or the next data collection - int localTime = time(NULL); - std::cout << "#"; + long localTime = time(NULL); + // std::cout << "#"; int nextUDPTime = localTime + UDPUpdateTime; int nextAveragerTime = localTime + AveragerUpdateTime; int nextTCPTime = localTime + TCPUpdateTime; - int sequence = 0; - + long sequence = 0; + int nextAction = 0; while ( noErrors == 1){ - std::cout << "."; + // firstly check we haven't got to reload our config + if ( reloadConfig == 1 ){ + // reload the config by starting a new + std::cout << "Forcing reload of Configuration\n"; + config = Config("raptor.ukc.ac.uk",4567,debug); + + std::cout << "Configuring UDPUpdateTime\n"; + int UDPUpdateTime = config.getIntProperty("UDPUpdateTime"); + if ( UDPUpdateTime == -1 ){ + if ( debug == 1 ){ + std::cout << "Using Default time!\n"; + UDPUpdateTime = 5; + } // if + } // if + + + std::cout << "Configuring TCPUpdateTime\n"; + int TCPUpdateTime = config.getIntProperty("TCPUpdateTime"); + if ( TCPUpdateTime == -1){ + if ( debug == 1 ){ + std::cout << "Using Default time!\n"; + TCPUpdateTime = 10; + } // if + } // if + + std::cout << "Configuring AveragerUpdateTime\n"; + int AveragerUpdateTime = config.getIntProperty("AVERAGERUpdateTime"); + if ( AveragerUpdateTime == -1){ + if ( debug == 1 ){ + std::cout << "Using Default time!\n"; + } // if + AveragerUpdateTime = 2; + } // if + + std::cout << "Configuring Filter Retry Tolerances\n"; + int MaxFilterRetrys = config.getIntProperty("MAXTCPFilterRetries"); + if ( MaxFilterRetrys == -1){ + if ( debug == 1 ){ + std::cout << "Using Default Tolerance\n"; + } // if + MaxFilterRetrys = 5; + } // if + + } // if reloadconfig + + + localTime = time(NULL); + // std::cout << "."; // keep going while no non-fatal errors have occurred int waitTime = 0; if ( nextTCPTime <= nextAveragerTime ){ - std::cout << "-"; + // std::cout << "-"; if ( nextTCPTime >= nextUDPTime ){ - std::cout << "}"; + // std::cout << "}"; nextAction = 3; - waitTime = nextUDPTime - time(NULL); + waitTime = nextUDPTime - localTime; } else { // set the heartbeat to be the next item - std::cout << "{"; + // std::cout << "{"; nextAction = 1; - waitTime = nextTCPTime - time(NULL); + waitTime = nextTCPTime - localTime; } // if } else { - std::cout << "+"; + // std::cout << "+"; if ( nextAveragerTime >= nextUDPTime ){ - std::cout << "["; + // std::cout << "["; nextAction = 3; - waitTime = nextUDPTime - time(NULL); + waitTime = nextUDPTime - localTime; } else { // set grabstats to be in the next action - std::cout << "]"; + // std::cout << "]"; nextAction = 2; - waitTime = nextAveragerTime - time(NULL); + waitTime = nextAveragerTime - localTime; } // if } // if // sleep until this time only if it is greater than 1! if ( waitTime >= 1 ){ // need to output \n to std::cout or the wait is infinate!!!! ????? - std::cout << "_\n"; + // will core dump if debug = 0 sleep(waitTime); /// crashes here - std::cout << "_"; + } - std::cout << "~"; + localTime = time(NULL); + int con = -1; + int conCount = 0; + // do the action switch (nextAction){ - case 1: std::cout << "T"; + case 1: std::cout << "Scheduled TCP Heartbeat Connection" << endl; nextTCPTime = localTime + TCPUpdateTime; - // SmallNet * net = config.getSmallNet(); - // net->connectHeartBeat(config.getFilterName(),config.getFilterPort()); + // connect to the filter - should do all the talking within config. + con = (config.getSmallNet())->connectHeartBeat(config.getUDPFilterName(), config.getFilterPort()); + conCount = 0; + while (( con != 0 ) && ( conCount < MaxFilterRetrys )){ + int con = (config.getSmallNet())->connectHeartBeat(config.getUDPFilterName(), config.getFilterPort()); + conCount++; + } + // if con != 0, then we must reconnect to the main filter manager and + // reload our config! + if ( con == 0 ){ + // run the chat script + int result = config.chatHeartBeat(); + if ( result != 0 ){ + // gotta reload our config + reloadConfig = 1; + } // if + } else { + // set the config to be reloaded next time + reloadConfig = 1; + } // if con =!= 0 + break; - case 2: std::cout << "A"; - nextAveragerTime = localTime + AveragerUpdateTime; + case 2: nextAveragerTime = localTime + AveragerUpdateTime; if ( sysMon.collect() > 0 ){ // suggests that there should be an alert - + std::cout << "Alert Status" << endl; } break; - default: std::cout << "U"; + default: std::cout << "Scheduled UDP Connection" << endl; nextUDPTime = localTime + UDPUpdateTime; // package up the system data - /// lovely HARD CODING!!!! - string h1 = "raptor.ukc.ac.uk"; - string ip1 = "129.12.4.232"; - string date1 = "00000001"; - string seq = "-64773929"; - - string attributes = "type=\"data\" machine_name=\""+h1+"\" ip=\""+ip1+"\" date=\""+date1+"\" seq_no=\""+seq+"\""; + string host = (config.getSmallNet())->getHostName(); + string ip = (config.getSmallNet())->getHostIP(); + + char * buffer; + buffer = l64a( sequence ); + char * seq = buffer; + buffer = l64a( localTime ); + char * date = buffer; + + + string attributes = "type=\"data\" machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+seq+"\""; XMLFormatter xml("packet",attributes); // put in the data @@ -148,7 +234,8 @@ int main(){ std::cout << "A fatal error occurred which caused this program to quit\n"; std::cout << "It is suggested that all belly button lint should be removed\n"; - std::cout << "prior to use of this program"; + std::cout << "prior to use of this program\n"; + std::cout << "Oh and BTW, All you BASE are belong to us!\n"; std::cout << "Error Code: " << noErrors << "\n"; return 0;