1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
#include <iostream.h> |
21 |
|
#include <unistd.h> // linux header for the sleep function |
22 |
|
#include <stdlib.h> // itoa() |
83 |
|
if ( debug == 1 ){ |
84 |
|
std::cout << "Using Default Tolerance\n"; |
85 |
|
} // if |
86 |
< |
MaxFilterRetrys = 5; |
86 |
> |
MaxFilterRetrys = 1; |
87 |
|
} // if |
88 |
|
|
89 |
|
|
90 |
< |
std::cout << "Configuring Alerter\n"; |
90 |
> |
// std::cout << "Configuring Alerter\n"; |
91 |
|
// Set the values at which the Alerter should kick in. and how many packets it should |
92 |
|
// send |
93 |
|
|
95 |
|
|
96 |
|
std::cout << "Starting Data Collection\n"; |
97 |
|
// work out which is closer, the next heartbeat or the next data collection |
98 |
< |
long localTime = time(NULL); |
98 |
> |
int localTime = time(NULL); |
99 |
|
// std::cout << "#"; |
100 |
|
int nextUDPTime = localTime + UDPUpdateTime; |
101 |
|
int nextAveragerTime = localTime + AveragerUpdateTime; |
102 |
|
int nextTCPTime = localTime + TCPUpdateTime; |
103 |
< |
long sequence = 0; |
103 |
> |
int sequence = 0; |
104 |
|
|
105 |
|
int nextAction = 0; |
106 |
|
while ( noErrors == 1){ |
146 |
|
} // if |
147 |
|
MaxFilterRetrys = 5; |
148 |
|
} // if |
149 |
< |
|
149 |
> |
// reloadConfig is done now |
150 |
> |
reloadConfig = 0; |
151 |
|
} // if reloadconfig |
152 |
|
|
153 |
|
|
154 |
+ |
|
155 |
|
localTime = time(NULL); |
135 |
– |
// std::cout << "."; |
156 |
|
// keep going while no non-fatal errors have occurred |
157 |
|
int waitTime = 0; |
158 |
|
|
159 |
|
if ( nextTCPTime <= nextAveragerTime ){ |
140 |
– |
// std::cout << "-"; |
160 |
|
if ( nextTCPTime >= nextUDPTime ){ |
142 |
– |
// std::cout << "}"; |
161 |
|
nextAction = 3; |
162 |
|
waitTime = nextUDPTime - localTime; |
163 |
|
} else { |
164 |
|
// set the heartbeat to be the next item |
147 |
– |
// std::cout << "{"; |
165 |
|
nextAction = 1; |
166 |
|
waitTime = nextTCPTime - localTime; |
167 |
|
} // if |
168 |
|
} else { |
152 |
– |
// std::cout << "+"; |
169 |
|
if ( nextAveragerTime >= nextUDPTime ){ |
154 |
– |
// std::cout << "["; |
170 |
|
nextAction = 3; |
171 |
|
waitTime = nextUDPTime - localTime; |
172 |
|
} else { |
173 |
|
// set grabstats to be in the next action |
159 |
– |
// std::cout << "]"; |
174 |
|
nextAction = 2; |
175 |
|
waitTime = nextAveragerTime - localTime; |
176 |
|
} // if |
178 |
|
|
179 |
|
// sleep until this time only if it is greater than 1! |
180 |
|
if ( waitTime >= 1 ){ |
181 |
< |
// need to output \n to std::cout or the wait is infinate!!!! ????? |
168 |
< |
// will core dump if debug = 0 |
169 |
< |
sleep(waitTime); /// crashes here |
181 |
> |
sleep(waitTime); |
182 |
|
|
183 |
|
} |
184 |
|
|
214 |
|
|
215 |
|
break; |
216 |
|
case 2: nextAveragerTime = localTime + AveragerUpdateTime; |
217 |
+ |
/* |
218 |
|
if ( sysMon.collect() > 0 ){ |
219 |
|
// suggests that there should be an alert |
220 |
|
std::cout << "Alert Status" << endl; |
221 |
< |
} |
221 |
> |
}*/ |
222 |
|
break; |
223 |
|
default: std::cout << "Scheduled UDP Connection" << endl; |
224 |
+ |
sysMon.collect(); |
225 |
|
nextUDPTime = localTime + UDPUpdateTime; |
226 |
|
// package up the system data |
227 |
< |
string host = (config.getSmallNet())->getHostName(); |
228 |
< |
string ip = (config.getSmallNet())->getHostIP(); |
227 |
> |
string host = config.getFQDN(); |
228 |
> |
// string ip = (config.getSmallNet())->getHostIP(); |
229 |
|
|
230 |
< |
char * buffer; |
231 |
< |
buffer = l64a( sequence ); |
232 |
< |
char * seq = buffer; |
233 |
< |
buffer = l64a( localTime ); |
234 |
< |
char * date = buffer; |
235 |
< |
|
236 |
< |
|
237 |
< |
string attributes = "type=\"data\" machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+seq+"\""; |
230 |
> |
string seq = ""; |
231 |
> |
// char * buffer; |
232 |
> |
char buffer[32]; |
233 |
> |
sprintf(buffer,"%u", sequence); |
234 |
> |
seq = buffer; |
235 |
> |
string date = ""; |
236 |
> |
sprintf(buffer,"%u", localTime); |
237 |
> |
date = buffer; |
238 |
> |
string attributes = "type=\"data\" machine_name=\""+host+"\" ip=\"0.0.0.0\" date=\""+date+"\" seq_no=\""+seq+"\""; |
239 |
|
|
240 |
|
XMLFormatter xml("packet",attributes); |
241 |
|
// put in the data |
242 |
|
xml.addString(sysMon.getData()); |
243 |
|
(config.getSmallNet())->sendUPDPacket(config.getUDPFilterName(), config.getUDPFilterPort(), xml.returnXML()); |
244 |
< |
|
244 |
> |
// now clear the averaged data |
245 |
> |
sysMon.clearData(); |
246 |
> |
sequence++; |
247 |
|
break; |
248 |
|
} // switch |
249 |
|
|
257 |
|
|
258 |
|
return 0; |
259 |
|
|
260 |
< |
} // main |
260 |
> |
} // main |