59 |
|
// check against the array value |
60 |
|
if ( titles[i] == sinput.substr(0,found) ){ |
61 |
|
// is the one we are looking for. |
62 |
< |
if ( debug == 1 ){ |
62 |
> |
if ( debug == 2 ){ |
63 |
|
std::cout << "SysMon::collect::Found Value\n"; |
64 |
< |
gotTitle = 1; |
64 |
> |
|
65 |
|
} |
66 |
+ |
gotTitle = 1; |
67 |
|
// now modify the data in the arrays if they are numbers |
68 |
|
int * end; |
69 |
|
char *buffer; |
75 |
|
if ( *end == sinput.length()-1 ){ |
76 |
|
// was the end.. ok |
77 |
|
|
78 |
< |
} // if |
78 |
> |
} // if |
79 |
|
} else { |
80 |
|
// must have worked! |
81 |
|
double dbl2 = 0; //strtod(values[i], &end); |
82 |
|
dbl2 += dbl; |
83 |
|
char *buffer; |
84 |
< |
int precision = 5; |
84 |
> |
int precision = 5; |
85 |
|
int decimal, sign; |
86 |
|
buffer = ecvt (dbl2, precision, &decimal, &sign); |
87 |
|
} // if |
104 |
|
|
105 |
|
} // while |
106 |
|
|
107 |
+ |
// delete p; |
108 |
+ |
|
109 |
|
if ( debug == 1 ){ |
110 |
|
std::cout << "SysMon::collect::Parse from StatGrab finished\n"; |
111 |
|
} |
126 |
|
|
127 |
|
// create an xml object |
128 |
|
XMLFormatter xml = XMLFormatter(); |
129 |
+ |
|
130 |
+ |
int i=0; |
131 |
+ |
int count = 0; |
132 |
+ |
int finished = 0; |
133 |
+ |
string root = "packet."; |
134 |
+ |
string level = root; |
135 |
+ |
string attributes = ""; |
136 |
+ |
string attr = ""; |
137 |
+ |
// while ( i < titlepointer ){ |
138 |
+ |
// hard coding |
139 |
+ |
while ( i < 10 ){ |
140 |
+ |
finished = 0; |
141 |
+ |
count = 0; |
142 |
+ |
attr = ""; |
143 |
+ |
while ( finished != 1 ){ |
144 |
+ |
count++; |
145 |
+ |
if ( count > 10 ){ |
146 |
+ |
// don't do more than 10 times.. its probably not gonna work! |
147 |
+ |
finished = 1; |
148 |
+ |
} |
149 |
+ |
|
150 |
+ |
// do for each item |
151 |
+ |
int where = titles[i].find(level,0); |
152 |
+ |
|
153 |
+ |
// where now contains the position of 'level' |
154 |
+ |
if ( where != string::npos ){ |
155 |
+ |
// we found it, now check the size to see if this is the final level |
156 |
+ |
// grab the end bit a look for .'s |
157 |
+ |
string end = titles[i].substr(level.length(), titles[i].length()-level.length() ); |
158 |
+ |
|
159 |
+ |
// now end should contain "something.something" etc |
160 |
+ |
// look to find a . in there that means more to traverse |
161 |
+ |
// but check for 'attributes' tags... |
162 |
+ |
|
163 |
+ |
where = end.find("attributes.",0); |
164 |
+ |
if ( where != string::npos ){ |
165 |
+ |
// is an attribute |
166 |
+ |
// need to check that there are no more levels above this one |
167 |
+ |
|
168 |
+ |
|
169 |
+ |
|
170 |
+ |
/* |
171 |
+ |
|
172 |
+ |
// where points to the start of attributes |
173 |
+ |
int start = 0; |
174 |
+ |
if ( level.find(".",start) < where-1 ){ |
175 |
+ |
start = level.find(".", start); |
176 |
+ |
} // if |
177 |
+ |
|
178 |
+ |
// start points to the thing to apply the attributes to. |
179 |
+ |
// need to take the level upto before this point |
180 |
+ |
string needLevel = end.substr(0,start-2); |
181 |
+ |
std::cout << "needlevel " << needLevel << endl; |
182 |
+ |
|
183 |
+ |
// now we need to find the level we are at |
184 |
+ |
while (( needLevel.length() > 0 ) && (needLevel.find(".",0) != string::npos ) ){ |
185 |
+ |
int got = needLevel.find(".",0); |
186 |
+ |
if ( got != string::npos ){ |
187 |
+ |
// we need to grab up until the . |
188 |
+ |
xml.addNest(needLevel.substr(0,got)); |
189 |
+ |
level += needLevel.substr(0,got); |
190 |
+ |
level += "."; |
191 |
+ |
std::cout << "Adding Nest " << needLevel.substr(0,got) << endl; |
192 |
+ |
needLevel = needLevel.substr(got+1, needLevel.length()-(got+1)); |
193 |
+ |
} // if |
194 |
+ |
std::cout << "needlevel " << needLevel << endl; |
195 |
+ |
} // while |
196 |
+ |
|
197 |
+ |
// add the final nest |
198 |
+ |
xml.addNest(needLevel); |
199 |
+ |
level += needLevel; |
200 |
+ |
level += "."; |
201 |
+ |
std::cout << "Adding Nest " << needLevel << endl; |
202 |
+ |
|
203 |
+ |
*/ |
204 |
+ |
|
205 |
+ |
// now write out the variable |
206 |
+ |
xml.addElement(end, values[i]); |
207 |
+ |
finished = 1; |
208 |
+ |
|
209 |
+ |
} else { |
210 |
+ |
if ( where == 0 ){ |
211 |
+ |
// this is something we care about. |
212 |
+ |
// it has an attribute tab, and thus we want to add it |
213 |
+ |
// to the tag one lower than this (hopefully level!) |
214 |
+ |
|
215 |
+ |
// attributes = attributes + mount |
216 |
+ |
attributes += end.substr(where+11, end.length()-(where+11)); |
217 |
+ |
// attributes = attributes + mount=" |
218 |
+ |
attributes += "=\""; |
219 |
+ |
// attributes = attributes + mount="/dev |
220 |
+ |
attributes += values[i]; |
221 |
+ |
// attributes = attributes + mount="/dev" |
222 |
+ |
attributes += "\" "; |
223 |
+ |
} else { |
224 |
+ |
// need to check if we are the last element before |
225 |
+ |
// an attribute tag, so we want to get up to this tag first |
226 |
+ |
while ( end.find(".",0) != string::npos ){ |
227 |
+ |
|
228 |
+ |
where = end.find(".",0); |
229 |
+ |
string newNest = end.substr(0,where); |
230 |
+ |
xml.addNest(newNest); |
231 |
+ |
level += newNest; |
232 |
+ |
level += "."; |
233 |
+ |
// redefine end |
234 |
+ |
end = end.substr(where+1, end.length()-(where+1)); |
235 |
+ |
} // while |
236 |
+ |
|
237 |
+ |
|
238 |
+ |
xml.addElement(end, values[i]); |
239 |
+ |
finished = 1; |
240 |
+ |
} // if where == 0 |
241 |
+ |
} // if attribute tags |
242 |
|
|
243 |
< |
// 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 |
< |
|
243 |
> |
|
244 |
|
|
245 |
+ |
|
246 |
+ |
} else { // if doesn't contains level |
247 |
+ |
|
248 |
+ |
// we need to move one back and try again, until we are all the way |
249 |
+ |
// back to "packet." |
250 |
+ |
// go about it by closing nests |
251 |
+ |
|
252 |
+ |
while ( level.length() > root.length() ){ |
253 |
+ |
// need to close one nest and locate the next . from the end (hassle) |
254 |
+ |
int start = 0; |
255 |
+ |
if ( level.find(".",start) != string::npos ){ |
256 |
+ |
start = level.find(".", start); |
257 |
+ |
} // if |
258 |
+ |
// should now have the last . |
259 |
+ |
xml.closeNest(); |
260 |
+ |
level = level.substr(0, start+1); |
261 |
+ |
} |
262 |
+ |
|
263 |
+ |
} // if contains level |
264 |
+ |
|
265 |
+ |
} // while |
266 |
+ |
i++; |
267 |
+ |
} // while |
268 |
|
|
269 |
|
|
152 |
– |
// xml. |
153 |
– |
|
154 |
– |
|
155 |
– |
// } // for |
270 |
|
|
271 |
+ |
|
272 |
+ |
|
273 |
+ |
|
274 |
+ |
|
275 |
|
// return the string |
276 |
|
return xml.returnXML(); |
277 |
|
|