| 39 |
|
if ( debug == 1 ){ |
| 40 |
|
std::cout << "SysMon::collect::ipipestream\n"; |
| 41 |
|
} |
| 42 |
< |
ipipestream p("statgrab.pl"); |
| 42 |
> |
// ipipestream p("statgrab.pl"); |
| 43 |
> |
p = new SubPipe("statgrab.pl"); |
| 44 |
|
|
| 45 |
|
// get the output into input from statgrab |
| 46 |
< |
while ( p.getline (input, 2048) ){ |
| 46 |
> |
string sinput; |
| 47 |
> |
while ( p->getLine(&sinput) ){ |
| 48 |
|
// find the first non-whitespace char in input |
| 49 |
< |
string sinput = input; |
| 49 |
> |
|
| 50 |
|
// locate the first white space |
| 51 |
|
int found = sinput.find(" ",0); |
| 52 |
|
if ( found == string::npos ){ |
| 61 |
|
// check against the array value |
| 62 |
|
if ( titles[i] == sinput.substr(0,found) ){ |
| 63 |
|
// is the one we are looking for. |
| 64 |
< |
if ( debug == 1 ){ |
| 64 |
> |
if ( debug == 2 ){ |
| 65 |
|
std::cout << "SysMon::collect::Found Value\n"; |
| 66 |
< |
gotTitle = 1; |
| 66 |
> |
|
| 67 |
|
} |
| 68 |
+ |
gotTitle = 1; |
| 69 |
|
// now modify the data in the arrays if they are numbers |
| 70 |
< |
int * end; |
| 70 |
> |
char * end; |
| 71 |
|
char *buffer; |
| 72 |
|
// buffer = sinput.substr(found+1, sinput.length()); |
| 73 |
< |
double dbl = 0; // strtod((char *) sinput.substr(found+1, sinput.length()), &end); |
| 73 |
> |
double dbl = strtod( ((string) sinput.substr(found+1, sinput.length())).c_str(), &end); |
| 74 |
|
if ( dbl == 0 ){ |
| 75 |
|
// error? we aren't so sure. check the position |
| 76 |
|
// of end. |
| 77 |
|
if ( *end == sinput.length()-1 ){ |
| 78 |
|
// was the end.. ok |
| 79 |
< |
|
| 80 |
< |
} // if |
| 79 |
> |
// must have worked! |
| 80 |
> |
double dbl2 = 0; //strtod(values[i], &end); |
| 81 |
> |
dbl2 += dbl; |
| 82 |
> |
char * buffer; |
| 83 |
> |
int precision = 5; |
| 84 |
> |
int decimal, sign; |
| 85 |
> |
buffer = ecvt (dbl2, precision, &decimal, &sign); |
| 86 |
> |
} // if *end |
| 87 |
|
} else { |
| 88 |
|
// must have worked! |
| 89 |
|
double dbl2 = 0; //strtod(values[i], &end); |
| 90 |
|
dbl2 += dbl; |
| 91 |
< |
char *buffer; |
| 92 |
< |
int precision = 5; |
| 91 |
> |
char * buffer; |
| 92 |
> |
int precision = 5; |
| 93 |
|
int decimal, sign; |
| 94 |
|
buffer = ecvt (dbl2, precision, &decimal, &sign); |
| 95 |
|
} // if |
| 112 |
|
|
| 113 |
|
} // while |
| 114 |
|
|
| 115 |
+ |
delete p; |
| 116 |
+ |
|
| 117 |
|
if ( debug == 1 ){ |
| 118 |
|
std::cout << "SysMon::collect::Parse from StatGrab finished\n"; |
| 119 |
|
} |
| 134 |
|
|
| 135 |
|
// create an xml object |
| 136 |
|
XMLFormatter xml = XMLFormatter(); |
| 137 |
+ |
|
| 138 |
+ |
int i=0; |
| 139 |
+ |
int count = 0; |
| 140 |
+ |
int finished = 0; |
| 141 |
+ |
string root = "packet."; |
| 142 |
+ |
string level = root; |
| 143 |
+ |
string attributes = ""; |
| 144 |
+ |
string attr = ""; |
| 145 |
+ |
while ( i < titlepointer ){ |
| 146 |
+ |
finished = 0; |
| 147 |
+ |
count = 0; |
| 148 |
+ |
attr = ""; |
| 149 |
+ |
while ( finished != 1 ){ |
| 150 |
+ |
count++; |
| 151 |
+ |
if ( count > 10 ){ |
| 152 |
+ |
// don't do more than 10 times.. its probably not gonna work! |
| 153 |
+ |
finished = 1; |
| 154 |
+ |
} |
| 155 |
+ |
|
| 156 |
+ |
// do for each item |
| 157 |
+ |
int where = titles[i].find(level,0); |
| 158 |
+ |
|
| 159 |
+ |
// where now contains the position of 'level' |
| 160 |
+ |
if ( where != string::npos ){ |
| 161 |
+ |
// we found it, now check the size to see if this is the final level |
| 162 |
+ |
// grab the end bit a look for .'s |
| 163 |
+ |
string end = titles[i].substr(level.length(), titles[i].length()-level.length() ); |
| 164 |
+ |
|
| 165 |
+ |
// now end should contain "something.something" etc |
| 166 |
+ |
// look to find a . in there that means more to traverse |
| 167 |
+ |
// but check for 'attributes' tags... |
| 168 |
+ |
|
| 169 |
+ |
where = end.find("attributes.",0); |
| 170 |
+ |
if ( where != string::npos ){ |
| 171 |
+ |
// is an attribute |
| 172 |
+ |
// need to check that there are no more levels above this one |
| 173 |
+ |
|
| 174 |
+ |
|
| 175 |
+ |
|
| 176 |
+ |
/* |
| 177 |
+ |
|
| 178 |
+ |
// where points to the start of attributes |
| 179 |
+ |
int start = 0; |
| 180 |
+ |
if ( level.find(".",start) < where-1 ){ |
| 181 |
+ |
start = level.find(".", start); |
| 182 |
+ |
} // if |
| 183 |
+ |
|
| 184 |
+ |
// start points to the thing to apply the attributes to. |
| 185 |
+ |
// need to take the level upto before this point |
| 186 |
+ |
string needLevel = end.substr(0,start-2); |
| 187 |
+ |
std::cout << "needlevel " << needLevel << endl; |
| 188 |
+ |
|
| 189 |
+ |
// now we need to find the level we are at |
| 190 |
+ |
while (( needLevel.length() > 0 ) && (needLevel.find(".",0) != string::npos ) ){ |
| 191 |
+ |
int got = needLevel.find(".",0); |
| 192 |
+ |
if ( got != string::npos ){ |
| 193 |
+ |
// we need to grab up until the . |
| 194 |
+ |
xml.addNest(needLevel.substr(0,got)); |
| 195 |
+ |
level += needLevel.substr(0,got); |
| 196 |
+ |
level += "."; |
| 197 |
+ |
std::cout << "Adding Nest " << needLevel.substr(0,got) << endl; |
| 198 |
+ |
needLevel = needLevel.substr(got+1, needLevel.length()-(got+1)); |
| 199 |
+ |
} // if |
| 200 |
+ |
std::cout << "needlevel " << needLevel << endl; |
| 201 |
+ |
} // while |
| 202 |
+ |
|
| 203 |
+ |
// add the final nest |
| 204 |
+ |
xml.addNest(needLevel); |
| 205 |
+ |
level += needLevel; |
| 206 |
+ |
level += "."; |
| 207 |
+ |
std::cout << "Adding Nest " << needLevel << endl; |
| 208 |
+ |
|
| 209 |
+ |
*/ |
| 210 |
+ |
|
| 211 |
+ |
// now write out the variable |
| 212 |
+ |
xml.addElement(end, values[i]); |
| 213 |
+ |
finished = 1; |
| 214 |
+ |
|
| 215 |
+ |
} else { |
| 216 |
+ |
if ( where == 0 ){ |
| 217 |
+ |
// this is something we care about. |
| 218 |
+ |
// it has an attribute tab, and thus we want to add it |
| 219 |
+ |
// to the tag one lower than this (hopefully level!) |
| 220 |
+ |
|
| 221 |
+ |
// attributes = attributes + mount |
| 222 |
+ |
attributes += end.substr(where+11, end.length()-(where+11)); |
| 223 |
+ |
// attributes = attributes + mount=" |
| 224 |
+ |
attributes += "=\""; |
| 225 |
+ |
// attributes = attributes + mount="/dev |
| 226 |
+ |
attributes += values[i]; |
| 227 |
+ |
// attributes = attributes + mount="/dev" |
| 228 |
+ |
attributes += "\" "; |
| 229 |
+ |
} else { |
| 230 |
+ |
// need to check if we are the last element before |
| 231 |
+ |
// an attribute tag, so we want to get up to this tag first |
| 232 |
+ |
while ( end.find(".",0) != string::npos ){ |
| 233 |
+ |
|
| 234 |
+ |
where = end.find(".",0); |
| 235 |
+ |
string newNest = end.substr(0,where); |
| 236 |
+ |
xml.addNest(newNest); |
| 237 |
+ |
level += newNest; |
| 238 |
+ |
level += "."; |
| 239 |
+ |
// redefine end |
| 240 |
+ |
end = end.substr(where+1, end.length()-(where+1)); |
| 241 |
+ |
} // while |
| 242 |
+ |
|
| 243 |
+ |
|
| 244 |
+ |
xml.addElement(end, values[i]); |
| 245 |
+ |
finished = 1; |
| 246 |
+ |
} // if where == 0 |
| 247 |
+ |
} // if attribute tags |
| 248 |
|
|
| 249 |
< |
// spammage |
| 128 |
< |
// xml.addElement(titles[0],values[0]); // version |
| 129 |
< |
xml.addNest("os"); |
| 130 |
< |
xml.addElement("name",values[1]); // packet.os.name |
| 131 |
< |
xml.addElement("release",values[2]); // packet.os.release |
| 132 |
< |
xml.addElement("platform",values[3]); // packet.os.platform |
| 133 |
< |
xml.addElement("sysname",values[4]); // packet.os.sysname |
| 134 |
< |
xml.addElement("version",values[5]); // packet.os.version |
| 135 |
< |
xml.addElement("uptime",values[9]); // packet.os.uptime |
| 136 |
< |
xml.closeNest(); |
| 137 |
< |
xml.addNest("load"); |
| 138 |
< |
xml.addElement("load1",values[6]); // packet.load.load1 |
| 139 |
< |
xml.addElement("load5",values[7]); // packet.load.load5 |
| 140 |
< |
xml.addElement("load15",values[8]); // packet.load.load15 |
| 141 |
< |
xml.closeNest(); |
| 142 |
< |
xml.addNest("users"); |
| 143 |
< |
xml.addElement("count",values[10]); // packet.users.count |
| 144 |
< |
// xml.addElement("list",values[11]); // packet.users.list |
| 145 |
< |
// xml.addElement("list",values[11]); // packet.users.list |
| 146 |
< |
xml.closeNest(); |
| 147 |
< |
|
| 148 |
< |
|
| 249 |
> |
|
| 250 |
|
|
| 251 |
+ |
|
| 252 |
+ |
} else { // if doesn't contains level |
| 253 |
+ |
|
| 254 |
+ |
// we need to move one back and try again, until we are all the way |
| 255 |
+ |
// back to "packet." |
| 256 |
+ |
// go about it by closing nests |
| 257 |
+ |
|
| 258 |
+ |
while ( level.length() > root.length() ){ |
| 259 |
+ |
// need to close one nest and locate the next . from the end (hassle) |
| 260 |
+ |
int start = 0; |
| 261 |
+ |
if ( level.find(".",start) != string::npos ){ |
| 262 |
+ |
start = level.find(".", start); |
| 263 |
+ |
} // if |
| 264 |
+ |
// should now have the last . |
| 265 |
+ |
xml.closeNest(); |
| 266 |
+ |
level = level.substr(0, start+1); |
| 267 |
+ |
} |
| 268 |
+ |
|
| 269 |
+ |
} // if contains level |
| 270 |
+ |
|
| 271 |
+ |
} // while |
| 272 |
+ |
i++; |
| 273 |
+ |
} // while |
| 274 |
|
|
| 275 |
|
|
| 152 |
– |
// xml. |
| 153 |
– |
|
| 154 |
– |
|
| 155 |
– |
// } // for |
| 276 |
|
|
| 277 |
+ |
|
| 278 |
+ |
|
| 279 |
+ |
|
| 280 |
+ |
|
| 281 |
|
// return the string |
| 282 |
|
return xml.returnXML(); |
| 283 |
|
|