--- projects/cms/source/host/c++/SysMon.cpp 2001/02/26 15:00:42 1.1 +++ projects/cms/source/host/c++/SysMon.cpp 2001/03/05 12:38:35 1.2 @@ -59,10 +59,11 @@ int SysMon::collect(){ // check against the array value if ( titles[i] == sinput.substr(0,found) ){ // is the one we are looking for. - if ( debug == 1 ){ + if ( debug == 2 ){ std::cout << "SysMon::collect::Found Value\n"; - gotTitle = 1; + } + gotTitle = 1; // now modify the data in the arrays if they are numbers int * end; char *buffer; @@ -74,13 +75,13 @@ int SysMon::collect(){ if ( *end == sinput.length()-1 ){ // was the end.. ok - } // if + } // if } else { // must have worked! double dbl2 = 0; //strtod(values[i], &end); dbl2 += dbl; char *buffer; - int precision = 5; + int precision = 5; int decimal, sign; buffer = ecvt (dbl2, precision, &decimal, &sign); } // if @@ -103,6 +104,8 @@ int SysMon::collect(){ } // while + // delete p; + if ( debug == 1 ){ std::cout << "SysMon::collect::Parse from StatGrab finished\n"; } @@ -123,37 +126,152 @@ string SysMon::getData(){ // create an xml object XMLFormatter xml = XMLFormatter(); + + int i=0; + int count = 0; + int finished = 0; + string root = "packet."; + string level = root; + string attributes = ""; + string attr = ""; + // while ( i < titlepointer ){ + // hard coding + while ( i < 10 ){ + finished = 0; + count = 0; + attr = ""; + while ( finished != 1 ){ + count++; + if ( count > 10 ){ + // don't do more than 10 times.. its probably not gonna work! + finished = 1; + } + + // do for each item + int where = titles[i].find(level,0); + + // where now contains the position of 'level' + if ( where != string::npos ){ + // we found it, now check the size to see if this is the final level + // grab the end bit a look for .'s + string end = titles[i].substr(level.length(), titles[i].length()-level.length() ); + + // now end should contain "something.something" etc + // look to find a . in there that means more to traverse + // but check for 'attributes' tags... + + where = end.find("attributes.",0); + if ( where != string::npos ){ + // is an attribute + // need to check that there are no more levels above this one + + + + /* + + // where points to the start of attributes + int start = 0; + if ( level.find(".",start) < where-1 ){ + start = level.find(".", start); + } // if + + // start points to the thing to apply the attributes to. + // need to take the level upto before this point + string needLevel = end.substr(0,start-2); + std::cout << "needlevel " << needLevel << endl; + + // now we need to find the level we are at + while (( needLevel.length() > 0 ) && (needLevel.find(".",0) != string::npos ) ){ + int got = needLevel.find(".",0); + if ( got != string::npos ){ + // we need to grab up until the . + xml.addNest(needLevel.substr(0,got)); + level += needLevel.substr(0,got); + level += "."; + std::cout << "Adding Nest " << needLevel.substr(0,got) << endl; + needLevel = needLevel.substr(got+1, needLevel.length()-(got+1)); + } // if + std::cout << "needlevel " << needLevel << endl; + } // while + + // add the final nest + xml.addNest(needLevel); + level += needLevel; + level += "."; + std::cout << "Adding Nest " << needLevel << endl; + + */ + + // now write out the variable + xml.addElement(end, values[i]); + finished = 1; + + } else { + if ( where == 0 ){ + // this is something we care about. + // it has an attribute tab, and thus we want to add it + // to the tag one lower than this (hopefully level!) + + // attributes = attributes + mount + attributes += end.substr(where+11, end.length()-(where+11)); + // attributes = attributes + mount=" + attributes += "=\""; + // attributes = attributes + mount="/dev + attributes += values[i]; + // attributes = attributes + mount="/dev" + attributes += "\" "; + } else { + // need to check if we are the last element before + // an attribute tag, so we want to get up to this tag first + while ( end.find(".",0) != string::npos ){ + + where = end.find(".",0); + string newNest = end.substr(0,where); + xml.addNest(newNest); + level += newNest; + level += "."; + // redefine end + end = end.substr(where+1, end.length()-(where+1)); + } // while + + + xml.addElement(end, values[i]); + finished = 1; + } // if where == 0 + } // if attribute tags - // spammage - // xml.addElement(titles[0],values[0]); // version - xml.addNest("os"); - xml.addElement("name",values[1]); // packet.os.name - xml.addElement("release",values[2]); // packet.os.release - xml.addElement("platform",values[3]); // packet.os.platform - xml.addElement("sysname",values[4]); // packet.os.sysname - xml.addElement("version",values[5]); // packet.os.version - xml.addElement("uptime",values[9]); // packet.os.uptime - xml.closeNest(); - xml.addNest("load"); - xml.addElement("load1",values[6]); // packet.load.load1 - xml.addElement("load5",values[7]); // packet.load.load5 - xml.addElement("load15",values[8]); // packet.load.load15 - xml.closeNest(); - xml.addNest("users"); - xml.addElement("count",values[10]); // packet.users.count - // xml.addElement("list",values[11]); // packet.users.list - // xml.addElement("list",values[11]); // packet.users.list - xml.closeNest(); - - + + + } else { // if doesn't contains level + + // we need to move one back and try again, until we are all the way + // back to "packet." + // go about it by closing nests + + while ( level.length() > root.length() ){ + // need to close one nest and locate the next . from the end (hassle) + int start = 0; + if ( level.find(".",start) != string::npos ){ + start = level.find(".", start); + } // if + // should now have the last . + xml.closeNest(); + level = level.substr(0, start+1); + } + + } // if contains level + + } // while + i++; + } // while - // xml. - - - // } // for + + + + // return the string return xml.returnXML();