11 |
|
// setup some standard variables |
12 |
|
sequence = 0; // no packets sent yet |
13 |
|
|
14 |
– |
// get our values from config |
15 |
– |
|
16 |
– |
|
14 |
|
// setup our arrays |
15 |
|
titlepointer = 0; |
16 |
< |
for ( int i=0; i < maxTitles; i++ ){ |
16 |
> |
for ( int i=0; i < max_titles; i++ ){ |
17 |
|
titles[i] = ""; |
18 |
|
values[i] = ""; |
19 |
|
} |
25 |
|
int SysMon::collect(){ |
26 |
|
if ( debug == 1 ){ |
27 |
|
std::cout << "SysMon::collect()\n"; |
28 |
< |
} |
28 |
> |
} // if |
29 |
|
|
30 |
|
// say we have checked again |
31 |
|
checks++; |
32 |
|
|
33 |
|
// collect the system data and place it in an array of strings. |
34 |
|
// presume that the data is all formtted correctly. |
35 |
< |
// char input[2048]; |
35 |
> |
|
36 |
|
if ( debug == 1 ){ |
37 |
|
std::cout << "SysMon::collect::ipipestream\n"; |
38 |
|
} |
39 |
< |
// ipipestream p("statgrab.pl"); |
40 |
< |
p = new SubPipe("statgrab.pl"); |
39 |
> |
|
40 |
> |
p = new SubPipe("./statgrab.pl"); |
41 |
|
|
42 |
|
// get the output into input from statgrab |
43 |
|
string sinput; |
44 |
|
while ( p->getLine(&sinput) == 0 ){ |
45 |
|
|
46 |
+ |
if ( titlepointer == max_titles ){ |
47 |
+ |
std::cout << "WARNING: Max Titles reached, skipping remaining" << endl; |
48 |
+ |
std::cout << "Try recompiling with a value greater than the current (" << max_titles << ")" << endl; |
49 |
+ |
titlepointer--; |
50 |
+ |
break; |
51 |
+ |
} // if |
52 |
+ |
|
53 |
|
// locate the first white space |
54 |
|
int found = sinput.find(" ",0); |
55 |
|
if ( found == string::npos ){ |
56 |
|
// error |
57 |
|
if ( debug == 1 ){ |
58 |
|
std::cout << "SysMon::collect::Parse error from statgrab.pl\n"; |
59 |
< |
} |
59 |
> |
} // if |
60 |
|
} else { |
61 |
|
int gotTitle = 0; |
62 |
|
// now use the array of titles and values |
63 |
< |
for ( int i = 0; i < maxTitles; i++ ){ |
63 |
> |
for ( int i = 0; i < max_titles; i++ ){ |
64 |
|
// check against the array value |
65 |
|
if ( titles[i] == sinput.substr(0,found) ){ |
66 |
|
// is the one we are looking for. |
77 |
|
if ( gotTitle == 0 ){ |
78 |
|
// didnt |
79 |
|
if ( debug == 1 ){ |
80 |
< |
std::cout << "SysMon::collect::Adding New Value\n"; |
81 |
< |
std::cout << "'" << sinput.substr(0,found) << "' : "; |
82 |
< |
std::cout << "'" << sinput.substr(found+1, sinput.length()) << "'\n"; |
83 |
< |
} |
80 |
> |
std::cout << "SysMon::collect::Adding New Value\n"; |
81 |
> |
std::cout << "'" << sinput.substr(0,found) << "' : "; |
82 |
> |
std::cout << "'" << sinput.substr(found+1, sinput.length()) << "'\n"; |
83 |
> |
} // if |
84 |
|
titles[titlepointer] = sinput.substr(0,found); |
85 |
|
values[titlepointer] = sinput.substr(found+1, sinput.length()); |
86 |
|
titlepointer++; |
90 |
|
|
91 |
|
} // while |
92 |
|
|
93 |
+ |
// delete the pointer to free up memory |
94 |
|
delete p; |
95 |
|
|
96 |
|
if ( debug == 1 ){ |
97 |
|
std::cout << "SysMon::collect::Parse from StatGrab finished\n"; |
98 |
< |
} |
98 |
> |
} // if |
99 |
|
|
100 |
|
// return sucessful |
101 |
|
return 0; |
105 |
|
void SysMon::clearData(){ |
106 |
|
|
107 |
|
titlepointer = 0; |
108 |
< |
for ( int i=0; i < maxTitles; i++ ){ |
108 |
> |
for ( int i=0; i < max_titles; i++ ){ |
109 |
|
titles[i] = ""; |
110 |
|
values[i] = ""; |
111 |
< |
} |
111 |
> |
} // for |
112 |
|
|
113 |
|
return; |
114 |
|
|
119 |
|
|
120 |
|
if ( debug == 1 ){ |
121 |
|
std::cout << "SysMon::getData()\n"; |
122 |
< |
} |
122 |
> |
} // if |
123 |
|
|
124 |
|
// create an xml object |
125 |
|
XMLFormatter xml = XMLFormatter(); |
126 |
|
|
127 |
|
if ( debug == 1 ){ |
128 |
|
std::cout << "SysMon::getData::Sorting " << titlepointer << " elements\n"; |
129 |
< |
} |
129 |
> |
} // if |
130 |
|
|
131 |
|
// firstly sort the data. |
132 |
|
// simple bubble sort |
150 |
|
} // for |
151 |
|
} // while |
152 |
|
|
153 |
< |
/* |
153 |
> |
/* used to check the array has sorted correctly |
154 |
|
for ( int i=0; i < titlepointer; i++ ){ |
155 |
|
std::cout << titles[i] << endl; |
151 |
– |
|
156 |
|
} |
157 |
< |
*/ |
157 |
> |
*/ |
158 |
|
|
155 |
– |
|
159 |
|
// work through each one of the titles in turn and |
160 |
|
// work out their levels. |
161 |
|
|
175 |
|
|
176 |
|
if ( debug == 1 ){ |
177 |
|
std::cout << "SysMon::getData::Starting while\n"; |
178 |
< |
} |
178 |
> |
} // if |
179 |
|
|
180 |
|
while ( count <= titlepointer ){ |
181 |
< |
|
179 |
< |
|
180 |
< |
|
181 |
> |
|
182 |
|
if ( debug == 1 ){ |
183 |
|
std::cout << "Processing: " << titles[count] << endl; |
184 |
< |
} |
184 |
> |
} // if |
185 |
|
|
186 |
|
retryCount++; |
187 |
|
|
225 |
|
// first one mind! |
226 |
|
if ( levels[0] == "packet" ){ |
227 |
|
level--; |
228 |
< |
} |
228 |
> |
} // if |
229 |
> |
|
230 |
|
} // while dotPosition |
231 |
|
|
232 |
|
// now grab the value title |
248 |
|
xml.addElement(attributeLevel,attributes,""); |
249 |
|
if ( debug == 1 ){ |
250 |
|
std::cout << "Adding Element + attributes" << endl; |
251 |
< |
} |
252 |
< |
// count++; |
251 |
> |
} // if |
252 |
> |
|
253 |
|
} // if |
254 |
|
isAttrib = 0; |
255 |
|
attributeLevel = ""; |
259 |
|
newLevelString += levels[i]; |
260 |
|
if ( i != level-1 ){ |
261 |
|
newLevelString += "."; |
262 |
< |
} |
262 |
> |
} // if |
263 |
|
} // for |
264 |
|
} // if levels[level] |
265 |
|
|
272 |
|
newLevelString += levels[i]; |
273 |
|
if ( i != level-1 ){ |
274 |
|
newLevelString += "."; |
275 |
< |
} |
275 |
> |
} // if |
276 |
|
} // for |
277 |
|
|
278 |
|
isAttrib = 1; |
286 |
|
xml.addElement(attributeLevel,attributes,""); |
287 |
|
if ( debug == 1 ){ |
288 |
|
std::cout << "Adding Element + attributes1" << endl; |
289 |
< |
} |
289 |
> |
} // if |
290 |
|
attributeLevel = ""; |
291 |
|
attributes = ""; |
292 |
|
count++; |
295 |
|
xml.addElement(attributeLevel,attributes,""); |
296 |
|
if ( debug == 1 ){ |
297 |
|
std::cout << "Adding Element + attributes2" << endl; |
298 |
< |
} |
298 |
> |
} // if |
299 |
|
attributeLevel = ""; |
300 |
|
attributes = ""; |
301 |
|
count++; |
311 |
|
xml.addElement(attributeLevel,attributes,""); |
312 |
|
if ( debug == 1 ){ |
313 |
|
std::cout << "Adding Element + attributes3" << endl; |
314 |
< |
} |
314 |
> |
} // if |
315 |
|
attributeLevel = ""; |
316 |
|
attributes = ""; |
317 |
|
count++; |
323 |
|
newLevelString += levels[i]; |
324 |
|
if ( i != level-1 ){ |
325 |
|
newLevelString += "."; |
326 |
< |
} |
326 |
> |
} // if |
327 |
|
} // for |
328 |
|
} // if level == 1 |
329 |
|
|
335 |
|
attributes += "=\""; |
336 |
|
attributes += values[count]; |
337 |
|
attributes += "\" "; |
338 |
< |
// now check if this is the last element |
337 |
< |
|
338 |
< |
|
338 |
> |
|
339 |
|
} else { |
340 |
|
xml.addElement(levels[level], values[count]); |
341 |
|
count++; |
342 |
|
if ( debug == 1 ){ |
343 |
|
std::cout << "Adding Element" << endl; |
344 |
< |
} |
345 |
< |
} |
344 |
> |
} // if |
345 |
> |
} // if |
346 |
|
|
347 |
|
} else { |
348 |
|
// gotta change it |
351 |
|
|
352 |
|
if ( currentLevelint <= 0 ){ |
353 |
|
break; |
354 |
< |
} |
354 |
> |
} // if |
355 |
|
|
356 |
|
// back up atleast one level... |
357 |
|
xml.closeNest(); |
358 |
|
if ( debug == 1 ){ |
359 |
|
std::cout << "Closing Nest" << endl; |
360 |
< |
} |
360 |
> |
} // if |
361 |
|
// remove the last item |
362 |
|
currentLevelint--; |
363 |
|
|
381 |
|
xml.addNest(levels[currentLevelint]); |
382 |
|
if ( debug == 1 ){ |
383 |
|
std::cout << "Adding nest " << levels[currentLevelint] << endl; |
384 |
< |
} |
384 |
> |
} // if |
385 |
|
|
386 |
|
// set this to be the top level of the new level |
387 |
|
currentLevelint++; |
415 |
|
|
416 |
|
if ( debug == 1 ){ |
417 |
|
std::cout << "\n"; |
418 |
< |
} |
418 |
> |
} // if |
419 |
|
|
420 |
|
// return the string |
421 |
|
return xml.returnXML(); |