--- projects/cms/source/host/c++/Host.cpp 2001/03/05 12:40:32 1.2 +++ projects/cms/source/host/c++/Host.cpp 2002/05/21 16:47:11 1.7 @@ -1,3 +1,23 @@ +/* + * i-scream central monitoring system + * http://www.i-scream.org.uk + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + #include #include // linux header for the sleep function #include // itoa() @@ -64,11 +84,11 @@ int main(){ if ( debug == 1 ){ std::cout << "Using Default Tolerance\n"; } // if - MaxFilterRetrys = 5; + MaxFilterRetrys = 1; } // if - std::cout << "Configuring Alerter\n"; + // std::cout << "Configuring Alerter\n"; // Set the values at which the Alerter should kick in. and how many packets it should // send @@ -76,12 +96,12 @@ int main(){ std::cout << "Starting Data Collection\n"; // work out which is closer, the next heartbeat or the next data collection - long localTime = time(NULL); + int localTime = time(NULL); // std::cout << "#"; int nextUDPTime = localTime + UDPUpdateTime; int nextAveragerTime = localTime + AveragerUpdateTime; int nextTCPTime = localTime + TCPUpdateTime; - long sequence = 0; + int sequence = 0; int nextAction = 0; while ( noErrors == 1){ @@ -127,36 +147,31 @@ int main(){ } // if MaxFilterRetrys = 5; } // if - + // reloadConfig is done now + reloadConfig = 0; } // if reloadconfig + localTime = time(NULL); - // std::cout << "."; // keep going while no non-fatal errors have occurred int waitTime = 0; if ( nextTCPTime <= nextAveragerTime ){ - // std::cout << "-"; if ( nextTCPTime >= nextUDPTime ){ - // std::cout << "}"; nextAction = 3; waitTime = nextUDPTime - localTime; } else { // set the heartbeat to be the next item - // std::cout << "{"; nextAction = 1; waitTime = nextTCPTime - localTime; } // if } else { - // std::cout << "+"; if ( nextAveragerTime >= nextUDPTime ){ - // std::cout << "["; nextAction = 3; waitTime = nextUDPTime - localTime; } else { // set grabstats to be in the next action - // std::cout << "]"; nextAction = 2; waitTime = nextAveragerTime - localTime; } // if @@ -164,9 +179,7 @@ int main(){ // 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!!!! ????? - // will core dump if debug = 0 - sleep(waitTime); /// crashes here + sleep(waitTime); } @@ -202,31 +215,36 @@ int main(){ break; 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 << "Scheduled UDP Connection" << endl; + sysMon.collect(); nextUDPTime = localTime + UDPUpdateTime; // package up the system data - string host = (config.getSmallNet())->getHostName(); - string ip = (config.getSmallNet())->getHostIP(); + string host = config.getFQDN(); + // 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+"\""; + string seq = ""; + // char * buffer; + char buffer[32]; + sprintf(buffer,"%u", sequence); + seq = buffer; + string date = ""; + sprintf(buffer,"%u", localTime); + date = buffer; + string attributes = "type=\"data\" machine_name=\""+host+"\" ip=\"0.0.0.0\" date=\""+date+"\" seq_no=\""+seq+"\""; XMLFormatter xml("packet",attributes); // put in the data xml.addString(sysMon.getData()); (config.getSmallNet())->sendUPDPacket(config.getUDPFilterName(), config.getUDPFilterPort(), xml.returnXML()); - + // now clear the averaged data + sysMon.clearData(); + sequence++; break; } // switch @@ -240,4 +258,4 @@ int main(){ return 0; -} // main \ No newline at end of file +} // main