| 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 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
localTime = time(NULL); |
| 137 |
– |
// std::cout << "."; |
| 156 |
|
// keep going while no non-fatal errors have occurred |
| 157 |
|
int waitTime = 0; |
| 158 |
|
|
| 159 |
|
if ( nextTCPTime <= nextAveragerTime ){ |
| 142 |
– |
// std::cout << "-"; |
| 160 |
|
if ( nextTCPTime >= nextUDPTime ){ |
| 144 |
– |
// std::cout << "}"; |
| 161 |
|
nextAction = 3; |
| 162 |
|
waitTime = nextUDPTime - localTime; |
| 163 |
|
} else { |
| 164 |
|
// set the heartbeat to be the next item |
| 149 |
– |
// std::cout << "{"; |
| 165 |
|
nextAction = 1; |
| 166 |
|
waitTime = nextTCPTime - localTime; |
| 167 |
|
} // if |
| 168 |
|
} else { |
| 154 |
– |
// std::cout << "+"; |
| 169 |
|
if ( nextAveragerTime >= nextUDPTime ){ |
| 156 |
– |
// std::cout << "["; |
| 170 |
|
nextAction = 3; |
| 171 |
|
waitTime = nextUDPTime - localTime; |
| 172 |
|
} else { |
| 173 |
|
// set grabstats to be in the next action |
| 161 |
– |
// 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 |
< |
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 |
|
string seq = ""; |
| 231 |
|
// char * buffer; |
| 235 |
|
string date = ""; |
| 236 |
|
sprintf(buffer,"%u", localTime); |
| 237 |
|
date = buffer; |
| 238 |
< |
string attributes = "type=\"data\" machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+seq+"\""; |
| 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 |
+ |
// now clear the averaged data |
| 245 |
+ |
sysMon.clearData(); |
| 246 |
|
sequence++; |
| 247 |
|
break; |
| 248 |
|
} // switch |