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