76 |
|
|
77 |
|
std::cout << "Starting Data Collection\n"; |
78 |
|
// work out which is closer, the next heartbeat or the next data collection |
79 |
< |
long localTime = time(NULL); |
79 |
> |
int localTime = time(NULL); |
80 |
|
// std::cout << "#"; |
81 |
|
int nextUDPTime = localTime + UDPUpdateTime; |
82 |
|
int nextAveragerTime = localTime + AveragerUpdateTime; |
83 |
|
int nextTCPTime = localTime + TCPUpdateTime; |
84 |
< |
long sequence = 0; |
84 |
> |
int sequence = 0; |
85 |
|
|
86 |
|
int nextAction = 0; |
87 |
|
while ( noErrors == 1){ |
127 |
|
} // if |
128 |
|
MaxFilterRetrys = 5; |
129 |
|
} // if |
130 |
< |
|
130 |
> |
// reloadConfig is done now |
131 |
> |
reloadConfig = 0; |
132 |
|
} // if reloadconfig |
133 |
|
|
134 |
|
|
135 |
+ |
|
136 |
|
localTime = time(NULL); |
135 |
– |
// std::cout << "."; |
137 |
|
// keep going while no non-fatal errors have occurred |
138 |
|
int waitTime = 0; |
139 |
|
|
140 |
|
if ( nextTCPTime <= nextAveragerTime ){ |
140 |
– |
// std::cout << "-"; |
141 |
|
if ( nextTCPTime >= nextUDPTime ){ |
142 |
– |
// std::cout << "}"; |
142 |
|
nextAction = 3; |
143 |
|
waitTime = nextUDPTime - localTime; |
144 |
|
} else { |
145 |
|
// set the heartbeat to be the next item |
147 |
– |
// std::cout << "{"; |
146 |
|
nextAction = 1; |
147 |
|
waitTime = nextTCPTime - localTime; |
148 |
|
} // if |
149 |
|
} else { |
152 |
– |
// std::cout << "+"; |
150 |
|
if ( nextAveragerTime >= nextUDPTime ){ |
154 |
– |
// std::cout << "["; |
151 |
|
nextAction = 3; |
152 |
|
waitTime = nextUDPTime - localTime; |
153 |
|
} else { |
154 |
|
// set grabstats to be in the next action |
159 |
– |
// std::cout << "]"; |
155 |
|
nextAction = 2; |
156 |
|
waitTime = nextAveragerTime - localTime; |
157 |
|
} // if |
159 |
|
|
160 |
|
// sleep until this time only if it is greater than 1! |
161 |
|
if ( waitTime >= 1 ){ |
162 |
< |
// need to output \n to std::cout or the wait is infinate!!!! ????? |
168 |
< |
// will core dump if debug = 0 |
169 |
< |
sleep(waitTime); /// crashes here |
162 |
> |
sleep(waitTime); |
163 |
|
|
164 |
|
} |
165 |
|
|
195 |
|
|
196 |
|
break; |
197 |
|
case 2: nextAveragerTime = localTime + AveragerUpdateTime; |
198 |
+ |
/* |
199 |
|
if ( sysMon.collect() > 0 ){ |
200 |
|
// suggests that there should be an alert |
201 |
|
std::cout << "Alert Status" << endl; |
202 |
< |
} |
202 |
> |
}*/ |
203 |
|
break; |
204 |
|
default: std::cout << "Scheduled UDP Connection" << endl; |
205 |
+ |
sysMon.collect(); |
206 |
|
nextUDPTime = localTime + UDPUpdateTime; |
207 |
|
// package up the system data |
208 |
< |
string host = (config.getSmallNet())->getHostName(); |
208 |
> |
string host = config.getFQDN(); |
209 |
|
string ip = (config.getSmallNet())->getHostIP(); |
210 |
|
|
211 |
< |
char * buffer; |
212 |
< |
buffer = l64a( sequence ); |
213 |
< |
char * seq = buffer; |
214 |
< |
buffer = l64a( localTime ); |
215 |
< |
char * date = buffer; |
216 |
< |
|
217 |
< |
|
218 |
< |
string attributes = "type=\"data\" machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+seq+"\""; |
211 |
> |
string seq = ""; |
212 |
> |
// char * buffer; |
213 |
> |
char buffer[32]; |
214 |
> |
sprintf(buffer,"%u", sequence); |
215 |
> |
seq = buffer; |
216 |
> |
string date = ""; |
217 |
> |
sprintf(buffer,"%u", localTime); |
218 |
> |
date = buffer; |
219 |
> |
string attributes = "type=\"data\" machine_name=\""+host+"\" date=\""+date+"\" seq_no=\""+seq+"\""; |
220 |
|
|
221 |
|
XMLFormatter xml("packet",attributes); |
222 |
|
// put in the data |
223 |
|
xml.addString(sysMon.getData()); |
224 |
|
(config.getSmallNet())->sendUPDPacket(config.getUDPFilterName(), config.getUDPFilterPort(), xml.returnXML()); |
225 |
< |
|
225 |
> |
// now clear the averaged data |
226 |
> |
sysMon.clearData(); |
227 |
> |
sequence++; |
228 |
|
break; |
229 |
|
} // switch |
230 |
|
|
238 |
|
|
239 |
|
return 0; |
240 |
|
|
241 |
< |
} // main |
241 |
> |
} // main |