Commit | Line | Data |
---|---|---|
254bbf53 BS |
1 | /** @file |
2 | * @brief Logger class implementation. This class implements the Logging facility. | |
3 | * | |
4 | * | |
5 | * | |
6 | * @copyright Intra2net AG | |
7 | * @license GPLv2 | |
8 | */ | |
9 | ||
10 | ||
4de6a9b8 | 11 | #include "logger.hpp" |
77e65070 | 12 | #include "version_info.h" |
254bbf53 | 13 | |
ca5d6889 | 14 | #include <iostream> |
88a594e8 BS |
15 | #include <syslog.h> |
16 | #include <sstream> | |
17 | ||
3c0cd271 BS |
18 | #include <boost/foreach.hpp> |
19 | ||
8bca3c5d BS |
20 | namespace po = boost::program_options; |
21 | ||
92beaba3 BS |
22 | typedef boost::shared_ptr<boost::program_options::options_description> Options_descriptionPtr; |
23 | ||
8bca3c5d | 24 | using namespace std; |
254bbf53 BS |
25 | |
26 | /** | |
27 | * Default Constructor | |
28 | */ | |
29 | Logger::Logger() | |
8bca3c5d | 30 | : Loglevel(0) |
2e956a36 | 31 | , Syslog(false) |
cbbdeb6c | 32 | , ExternalWarningLevel(0) |
e8787e2e | 33 | , ExternalLogOnlyOnce(false) |
254bbf53 | 34 | { |
e8787e2e | 35 | set_log_facility(Loglevel,Syslog,ExternalWarningLog,ExternalWarningLevel,ExternalLogOnlyOnce); |
254bbf53 BS |
36 | } |
37 | ||
38 | ||
39 | /** | |
40 | * Default Destructor | |
41 | */ | |
42 | Logger::~Logger() | |
43 | { | |
254bbf53 BS |
44 | } |
45 | ||
46 | ||
47 | /** | |
e8787e2e BS |
48 | * Decides if a external log message can be send. |
49 | * @param msg The message to log. | |
50 | */ | |
51 | bool Logger::is_allowed_to_send( const string& msg ) const | |
52 | { | |
53 | if ( (ExternalLogOnlyOnce) && (ExternalSendMessages.find(msg) != ExternalSendMessages.end()) ) | |
54 | return false; | |
55 | return true; | |
56 | } | |
57 | ||
58 | ||
59 | /** | |
60 | * Clears the external send messages set. | |
61 | */ | |
62 | void Logger::clear_external_send_messages() | |
63 | { | |
64 | ExternalSendMessages.clear(); | |
65 | } | |
66 | ||
67 | ||
68 | /** | |
59c8d63c BS |
69 | * Decides if Logging through syslog if enabled or through std. |
70 | * @param msg The message to log. | |
71 | */ | |
ce70569b | 72 | void Logger::log_notice(const string& msg) const |
59c8d63c BS |
73 | { |
74 | if ( Syslog ) | |
75 | syslog(LOG_NOTICE,msg.c_str()); | |
76 | else | |
27baf279 | 77 | cout << msg << endl;; |
59c8d63c BS |
78 | } |
79 | ||
80 | ||
81 | /** | |
47e0ee60 BS |
82 | * Escape shell arguments. |
83 | * @param input The input to escape. | |
84 | * @return The escaped string ready to use for the shell. | |
85 | */ | |
86 | string Logger::escape_shellarg(const string &input) | |
87 | { | |
88 | string output = "'"; | |
89 | string::const_iterator it, it_end = input.end(); | |
90 | for (it = input.begin(); it != it_end; it++) | |
91 | { | |
92 | if ( (*it) == '\'') | |
93 | output += "'\\'"; | |
94 | ||
95 | output += *it; | |
96 | } | |
97 | ||
98 | output += "'"; | |
99 | return output; | |
100 | } | |
101 | ||
102 | ||
103 | /** | |
59c8d63c BS |
104 | * Decides if Logging through syslog if enabled or through std. |
105 | * @param msg The message to log. | |
106 | */ | |
e8787e2e | 107 | void Logger::log_warning(const string& msg, int level) |
59c8d63c BS |
108 | { |
109 | if ( Syslog ) | |
110 | syslog(LOG_WARNING,msg.c_str()); | |
111 | else | |
27baf279 | 112 | cout << msg << endl; |
cbbdeb6c | 113 | |
e8787e2e | 114 | if ( (level <= ExternalWarningLevel) && (!ExternalWarningLog.empty()) && (is_allowed_to_send(msg)) ) |
cbbdeb6c | 115 | { |
e8787e2e BS |
116 | string message = msg; |
117 | // Remove endline from msg. | |
118 | if (!message.empty() && message[message.length()-1] == '\n') | |
43f4565e | 119 | message.erase(message.length()-1); /*lint !e534 */ |
e8787e2e | 120 | |
47e0ee60 BS |
121 | message = escape_shellarg(message); |
122 | ||
cbbdeb6c BS |
123 | string external = ExternalWarningLog; |
124 | external.append(" "); | |
e8787e2e | 125 | external.append(message); |
d77313ea | 126 | if ( system(external.c_str()) != 0 ) |
d77313ea | 127 | print_error_external_logging(external); |
e8787e2e | 128 | else |
43f4565e | 129 | ExternalSendMessages.insert(msg); /*lint !e534 */ |
cbbdeb6c | 130 | } |
59c8d63c BS |
131 | } |
132 | ||
133 | ||
134 | /** | |
135 | * Decides if Logging through syslog if enabled or through std. | |
136 | * @param msg The message to log. | |
137 | */ | |
ce70569b | 138 | void Logger::log_error(const string& msg) const |
59c8d63c BS |
139 | { |
140 | if ( Syslog ) | |
141 | syslog(LOG_ERR,msg.c_str()); | |
142 | else | |
27baf279 | 143 | cerr << msg << endl; |
59c8d63c BS |
144 | } |
145 | ||
146 | ||
147 | /** | |
8bca3c5d BS |
148 | * Setter for member Loglevel. |
149 | * @param _loglevel Value to set Loglevel to. | |
150 | */ | |
e8787e2e BS |
151 | void Logger::set_external_log_only_once( const bool _external_log_only_once ) |
152 | { | |
153 | ExternalLogOnlyOnce = _external_log_only_once; | |
154 | } | |
155 | ||
156 | ||
157 | /** | |
158 | * Setter for member Loglevel. | |
159 | * @param _loglevel Value to set Loglevel to. | |
160 | */ | |
8bca3c5d BS |
161 | void Logger::set_loglevel(const int _loglevel) |
162 | { | |
163 | Loglevel = _loglevel; | |
164 | } | |
165 | ||
166 | ||
167 | /** | |
168 | * Getter for member Loglevel. | |
169 | * @return Loglevel. | |
170 | */ | |
b38684ce | 171 | int Logger::get_loglevel() const |
8bca3c5d BS |
172 | { |
173 | return Loglevel; | |
174 | } | |
175 | ||
176 | ||
177 | /** | |
178 | * Setter for member Syslog. | |
179 | * @param _syslog Wether to log through syslog or not. | |
180 | */ | |
181 | void Logger::set_syslog(const bool _syslog) | |
182 | { | |
183 | Syslog = _syslog; | |
184 | } | |
185 | ||
186 | ||
187 | /** | |
188 | * Getter for member Syslog. | |
189 | * @return True if logging through syslog is enabled, false otherwise. | |
190 | */ | |
b38684ce | 191 | bool Logger::get_syslog() const |
8bca3c5d BS |
192 | { |
193 | return Syslog; | |
194 | } | |
195 | ||
196 | ||
197 | /** | |
198 | * Initialize the logging facility. | |
199 | */ | |
e8787e2e | 200 | void Logger::set_log_facility(const int _loglevel, const bool _syslog, const string& _external_error_log, const int _external_error_level, const bool _external_log_only_once ) |
8bca3c5d BS |
201 | { |
202 | Loglevel = _loglevel; | |
203 | Syslog = _syslog; | |
cbbdeb6c BS |
204 | ExternalWarningLog = _external_error_log; |
205 | ExternalWarningLevel = _external_error_level; | |
e8787e2e | 206 | ExternalLogOnlyOnce = _external_log_only_once; |
8bca3c5d BS |
207 | |
208 | if ( Syslog ) | |
209 | openlog("bpdyndnsd",LOG_PID,LOG_DAEMON); | |
210 | } | |
211 | ||
212 | ||
213 | /** | |
254bbf53 BS |
214 | * Prints out the usage to the command line. |
215 | */ | |
b38684ce | 216 | void Logger::print_usage(const Options_descriptionPtr opt_desc) const |
254bbf53 | 217 | { |
cbbdeb6c | 218 | int level = 0; |
d77313ea | 219 | if ( level <= Loglevel ) |
59c8d63c BS |
220 | { |
221 | ostringstream msg; | |
222 | msg << "Usage: bpdyndnsd [Command line options]" << "\n" << endl; | |
223 | msg << *opt_desc << endl; | |
ce70569b | 224 | log_notice(msg.str()); |
59c8d63c | 225 | } |
254bbf53 BS |
226 | } |
227 | ||
228 | ||
229 | /** | |
230 | * Prints out the programm name and the given version string on stdout. | |
231 | * @param version Version string. | |
232 | */ | |
b38684ce | 233 | void Logger::print_version() const |
254bbf53 | 234 | { |
cbbdeb6c | 235 | int level = 0; |
d77313ea | 236 | if ( level <= Loglevel ) |
59c8d63c BS |
237 | { |
238 | ostringstream msg; | |
77e65070 | 239 | msg << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << MAJOR_VERSION << "." << MINOR_VERSION << endl; |
ce70569b | 240 | log_notice(msg.str()); |
59c8d63c | 241 | } |
254bbf53 BS |
242 | } |
243 | ||
244 | ||
245 | /** | |
246 | * Prints out the successful parsing of the command line options. | |
247 | */ | |
b38684ce | 248 | void Logger::print_cmd_parsed() const |
254bbf53 | 249 | { |
cbbdeb6c | 250 | int level = 1; |
d77313ea | 251 | if ( level <= Loglevel ) |
59c8d63c | 252 | { |
ce70569b | 253 | log_notice("Command line options successfully parsed."); |
59c8d63c | 254 | } |
254bbf53 BS |
255 | } |
256 | ||
257 | ||
b38684ce | 258 | void Logger::print_conf_files_parsed() const |
667c672c | 259 | { |
cbbdeb6c | 260 | int level = 1; |
d77313ea | 261 | if ( level <= Loglevel ) |
667c672c | 262 | { |
ce70569b | 263 | log_notice("Config files successfully parsed."); |
667c672c BS |
264 | } |
265 | } | |
266 | ||
267 | ||
254bbf53 BS |
268 | /** |
269 | * Prints out the successful parsing of the config files. | |
daf2ea82 | 270 | * @param config_path The specified config path. |
254bbf53 | 271 | */ |
b38684ce | 272 | void Logger::print_conf_loaded(const string& config_path) const |
254bbf53 | 273 | { |
cbbdeb6c | 274 | int level = 1; |
d77313ea | 275 | if ( level <= Loglevel ) |
59c8d63c BS |
276 | { |
277 | ostringstream msg; | |
278 | msg << "Config files successfully loaded in: " << config_path << endl; | |
ce70569b | 279 | log_notice(msg.str()); |
59c8d63c | 280 | } |
254bbf53 BS |
281 | } |
282 | ||
283 | ||
284 | /** | |
daf2ea82 BS |
285 | * Prints out the unsuccessful parsing of the config files. |
286 | * @param config_path The specified config path. | |
254bbf53 | 287 | */ |
b38684ce | 288 | void Logger::print_conf_not_loaded(const string& config_path) const |
254bbf53 | 289 | { |
cbbdeb6c | 290 | int level = 0; |
d77313ea | 291 | if ( level <= Loglevel ) |
59c8d63c BS |
292 | { |
293 | ostringstream msg; | |
294 | msg << "Config files couldn't be loaded in: " << config_path << endl; | |
ce70569b | 295 | log_error(msg.str()); |
59c8d63c | 296 | } |
254bbf53 BS |
297 | } |
298 | ||
299 | ||
300 | /** | |
5b3f3f54 TJ |
301 | * Prints out the unsuccessful parsing of the config files. |
302 | */ | |
303 | void Logger::print_conf_reload_failed_exit() const | |
304 | { | |
305 | int level = 0; | |
306 | if ( level <= Loglevel ) | |
307 | log_error("Config files couldn't be reloaded. Exiting."); | |
308 | } | |
309 | ||
310 | ||
311 | /** | |
daf2ea82 BS |
312 | * A file could not be opened for reading. |
313 | * @param filename The filename. | |
254bbf53 | 314 | */ |
b38684ce | 315 | void Logger::print_error_opening_r(const string& filename) const |
254bbf53 | 316 | { |
cbbdeb6c | 317 | int level = 0; |
d77313ea | 318 | if ( level <= Loglevel ) |
59c8d63c BS |
319 | { |
320 | ostringstream msg; | |
321 | msg << "Error opening file for reading: " << filename << endl; | |
ce70569b | 322 | log_error(msg.str()); |
59c8d63c | 323 | } |
254bbf53 BS |
324 | } |
325 | ||
326 | ||
327 | /** | |
667c672c BS |
328 | * A file could not be opened for writing. |
329 | * @param filename The filename. | |
330 | */ | |
b38684ce | 331 | void Logger::print_error_opening_rw(const string& filename) const |
667c672c | 332 | { |
cbbdeb6c | 333 | int level = 0; |
d77313ea | 334 | if ( level <= Loglevel ) |
667c672c BS |
335 | { |
336 | ostringstream msg; | |
337 | msg << "Error opening file for writing: " << filename << endl; | |
ce70569b | 338 | log_error(msg.str()); |
667c672c BS |
339 | } |
340 | } | |
341 | ||
342 | ||
343 | /** | |
254bbf53 BS |
344 | * Desctructor of specified class was called. |
345 | * @param _class Name of the class. | |
346 | */ | |
b38684ce | 347 | void Logger::print_destructor_call(const string& _class) const |
254bbf53 | 348 | { |
cbbdeb6c | 349 | int level = 1; |
d77313ea | 350 | if ( level <= Loglevel ) |
59c8d63c BS |
351 | { |
352 | ostringstream msg; | |
353 | msg << "Destructor call: " << _class << endl; | |
ce70569b | 354 | log_notice(msg.str()); |
59c8d63c | 355 | } |
254bbf53 BS |
356 | } |
357 | ||
358 | ||
359 | /** | |
360 | * Constructor of specified class was called. | |
361 | * @param _class Name of the class. | |
362 | */ | |
b38684ce | 363 | void Logger::print_constructor_call(const string& _class) const |
254bbf53 | 364 | { |
cbbdeb6c | 365 | int level = 1; |
d77313ea | 366 | if ( level <= Loglevel ) |
59c8d63c BS |
367 | { |
368 | ostringstream msg; | |
369 | msg << "Constructor call: " << _class << endl; | |
ce70569b | 370 | log_notice(msg.str()); |
59c8d63c | 371 | } |
254bbf53 BS |
372 | } |
373 | ||
374 | ||
375 | /** | |
376 | * Update method for specified service was called. | |
0f0908e1 | 377 | * @param service The service for which the update is running. |
254bbf53 | 378 | */ |
b38684ce | 379 | void Logger::print_update_service(const string& service) const |
254bbf53 | 380 | { |
cbbdeb6c | 381 | int level = 0; |
d77313ea | 382 | if ( level <= Loglevel ) |
59c8d63c BS |
383 | { |
384 | ostringstream msg; | |
385 | msg << "Running update for service: " << service << endl; | |
ce70569b | 386 | log_notice(msg.str()); |
59c8d63c | 387 | } |
254bbf53 BS |
388 | } |
389 | ||
0f0908e1 TJ |
390 | /** |
391 | * Service is blocked for update because of too many errors | |
392 | * @param service The service for which the update is running. | |
393 | * @param remaining_seconds Remaining seconds this service is blocked | |
394 | */ | |
395 | void Logger::print_update_service_is_blocked(const std::string& service, int remaining_seconds) const | |
396 | { | |
397 | int level = 1; | |
398 | if ( level <= Loglevel ) | |
399 | { | |
400 | ostringstream msg; | |
401 | msg << "Service " << service << " is blocked for " << remaining_seconds << " seconds because of too many errors" << endl; | |
402 | log_notice(msg.str()); | |
403 | } | |
404 | } | |
405 | ||
406 | ||
407 | /** | |
408 | * Service will be blocked because of update errors | |
409 | * @param service The service for which the update is running. | |
410 | * @param block_seconds Number of seconds this service is blocked | |
411 | */ | |
412 | void Logger::print_block_service(const std::string& service, int block_seconds) const | |
413 | { | |
414 | int level = 0; | |
415 | if ( level <= Loglevel ) | |
416 | { | |
417 | ostringstream msg; | |
418 | msg << "Service " << service << " will be blocked for " << block_seconds << " seconds because of too many errors" << endl; | |
419 | log_notice(msg.str()); | |
420 | } | |
421 | } | |
422 | ||
254bbf53 | 423 | |
daf2ea82 BS |
424 | /** |
425 | * An unknown option on the command line was detected. | |
426 | * @param unknown_option The unknown option. | |
427 | */ | |
b38684ce | 428 | void Logger::print_unknown_cmd_option(const string& unknown_option) const |
254bbf53 | 429 | { |
cbbdeb6c | 430 | int level = 0; |
d77313ea | 431 | if ( level <= Loglevel ) |
59c8d63c BS |
432 | { |
433 | ostringstream msg; | |
434 | msg << "Unknown option on command line detected: " << unknown_option << endl; | |
ce70569b | 435 | log_error(msg.str()); |
59c8d63c | 436 | } |
254bbf53 BS |
437 | } |
438 | ||
439 | ||
daf2ea82 BS |
440 | /** |
441 | * An unknown protocol was specified. | |
442 | * @param protocol The unknown protocol. | |
443 | */ | |
b38684ce | 444 | void Logger::print_unknown_protocol(const string& protocol) const |
254bbf53 | 445 | { |
cbbdeb6c | 446 | int level = 0; |
d77313ea | 447 | if ( level <= Loglevel ) |
59c8d63c BS |
448 | { |
449 | ostringstream msg; | |
450 | msg << "Unknown protocol defined: " << protocol << endl; | |
ce70569b | 451 | log_error(msg.str()); |
59c8d63c | 452 | } |
254bbf53 BS |
453 | } |
454 | ||
455 | ||
daf2ea82 BS |
456 | /** |
457 | * Loading a service config file. | |
458 | * @param filename The service config file. | |
459 | */ | |
b38684ce | 460 | void Logger::print_load_service_conf(const string& filename) const |
254bbf53 | 461 | { |
cbbdeb6c | 462 | int level = 1; |
d77313ea | 463 | if ( level <= Loglevel ) |
59c8d63c BS |
464 | { |
465 | ostringstream msg; | |
466 | msg << "Loading service config file: " << filename << endl; | |
ce70569b | 467 | log_notice(msg.str()); |
59c8d63c | 468 | } |
254bbf53 BS |
469 | } |
470 | ||
471 | ||
daf2ea82 BS |
472 | /** |
473 | * Loading the main config file. | |
474 | * @param filename The main config file. | |
475 | */ | |
b38684ce | 476 | void Logger::print_load_main_conf(const string& filename) const |
254bbf53 | 477 | { |
cbbdeb6c | 478 | int level = 1; |
d77313ea | 479 | if ( level <= Loglevel ) |
59c8d63c BS |
480 | { |
481 | ostringstream msg; | |
482 | msg << "Loading main config file: " << filename << endl; | |
ce70569b | 483 | log_notice(msg.str()); |
59c8d63c | 484 | } |
254bbf53 BS |
485 | } |
486 | ||
487 | ||
daf2ea82 BS |
488 | /** |
489 | * There is an unknown option in a service config file. | |
490 | * @param unknown_option The unknown option. | |
491 | */ | |
8a00a649 | 492 | void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const |
254bbf53 | 493 | { |
cbbdeb6c | 494 | int level = 0; |
d77313ea | 495 | if ( level <= Loglevel ) |
59c8d63c BS |
496 | { |
497 | ostringstream msg; | |
8a00a649 | 498 | msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl; |
ce70569b | 499 | log_error(msg.str()); |
59c8d63c | 500 | } |
254bbf53 BS |
501 | } |
502 | ||
503 | ||
daf2ea82 BS |
504 | /** |
505 | * There is an unknown option in the main config file. | |
506 | * @param unknown_option The unknown option. | |
507 | */ | |
b38684ce | 508 | void Logger::print_unknown_main_conf_option(const string& unknown_option) const |
254bbf53 | 509 | { |
cbbdeb6c | 510 | int level = 0; |
d77313ea | 511 | if ( level <= Loglevel ) |
59c8d63c BS |
512 | { |
513 | ostringstream msg; | |
514 | msg << "Unknown option in main config file detected: " << unknown_option << endl; | |
ce70569b | 515 | log_error(msg.str()); |
59c8d63c | 516 | } |
254bbf53 BS |
517 | } |
518 | ||
519 | ||
daf2ea82 BS |
520 | /** |
521 | * The defined config path doesn't exist or is not a directory. | |
522 | * @param config_path The defined config path. | |
523 | */ | |
b38684ce | 524 | void Logger::print_error_config_path(const string& config_path) const |
254bbf53 | 525 | { |
cbbdeb6c | 526 | int level = 0; |
d77313ea | 527 | if ( level <= Loglevel ) |
59c8d63c BS |
528 | { |
529 | ostringstream msg; | |
530 | msg << "Config path doesn't exists or is not a diretory: " << config_path << endl; | |
ce70569b | 531 | log_error(msg.str()); |
59c8d63c | 532 | } |
254bbf53 BS |
533 | } |
534 | ||
535 | ||
daf2ea82 BS |
536 | /** |
537 | * There is a missing command line option to initialize a service object. | |
538 | */ | |
b38684ce | 539 | void Logger::print_missing_cmd_service_option() const |
254bbf53 | 540 | { |
cbbdeb6c | 541 | int level = 0; |
d77313ea | 542 | if ( level <= Loglevel ) |
59c8d63c | 543 | { |
ce70569b | 544 | log_error("Missing option to initialize service. Protocol, host, login and password must be specified."); |
59c8d63c | 545 | } |
254bbf53 | 546 | } |
388f4ab0 BS |
547 | |
548 | ||
c5675c01 | 549 | /** |
8a00a649 BS |
550 | * Missing option in service config file. |
551 | * @param service_conf_file Service config file | |
552 | */ | |
553 | void Logger::print_missing_service_conf_option(const string& service_conf_file) const | |
554 | { | |
cbbdeb6c | 555 | int level = 0; |
d77313ea | 556 | if ( level <= Loglevel ) |
8a00a649 BS |
557 | { |
558 | ostringstream msg; | |
559 | msg << "Missing option in service config file " << service_conf_file << " to initialize service. Protocol, host, login and password must be specified." << endl; | |
ce70569b | 560 | log_error(msg.str()); |
8a00a649 BS |
561 | } |
562 | } | |
563 | ||
564 | ||
565 | /** | |
c5675c01 BS |
566 | * Process running as daemon. |
567 | * @param pid The pid of the daemon. | |
568 | */ | |
b38684ce | 569 | void Logger::print_runnig_as_daemon(const int pid) const |
388f4ab0 | 570 | { |
cbbdeb6c | 571 | int level = 1; |
d77313ea | 572 | if ( level <= Loglevel ) |
59c8d63c BS |
573 | { |
574 | ostringstream msg; | |
f3141675 | 575 | msg << "Running as daemon: " << pid << endl; |
ce70569b | 576 | log_notice(msg.str()); |
59c8d63c | 577 | } |
388f4ab0 BS |
578 | } |
579 | ||
c5675c01 BS |
580 | |
581 | /** | |
582 | * Prints out the daemon mode. | |
583 | * @param daemon_mode The daemon mode. | |
584 | */ | |
b38684ce | 585 | void Logger::print_daemon_mode(const bool daemon_mode) const |
388f4ab0 | 586 | { |
cbbdeb6c | 587 | int level = 1; |
d77313ea | 588 | if ( level <= Loglevel ) |
59c8d63c BS |
589 | { |
590 | string mode = "disabled"; | |
591 | if (daemon_mode == true) | |
592 | mode = "enabled"; | |
593 | ostringstream msg; | |
594 | msg << "Daemon mode is " << mode << "." << endl; | |
ce70569b | 595 | log_notice(msg.str()); |
59c8d63c | 596 | } |
388f4ab0 BS |
597 | } |
598 | ||
599 | ||
c5675c01 BS |
600 | /** |
601 | * There was an error while trying to fork. | |
602 | */ | |
b38684ce | 603 | void Logger::print_error_fork() const |
388f4ab0 | 604 | { |
cbbdeb6c | 605 | int level = 0; |
d77313ea | 606 | if ( level <= Loglevel ) |
59c8d63c | 607 | { |
ce70569b | 608 | log_error("Error while trying to fork."); |
59c8d63c | 609 | } |
388f4ab0 BS |
610 | } |
611 | ||
612 | ||
c5675c01 BS |
613 | /** |
614 | * A pid in the pidfile was found. | |
615 | * @param pid The pid found in the pidfile. | |
616 | */ | |
b38684ce | 617 | void Logger::print_pid_found(const int pid) const |
388f4ab0 | 618 | { |
cbbdeb6c | 619 | int level = 1; |
d77313ea | 620 | if ( level <= Loglevel ) |
59c8d63c BS |
621 | { |
622 | ostringstream msg; | |
623 | msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl; | |
ce70569b | 624 | log_notice(msg.str()); |
59c8d63c | 625 | } |
388f4ab0 BS |
626 | } |
627 | ||
628 | ||
c5675c01 BS |
629 | /** |
630 | * Another process is already running. | |
631 | * @param pid The pid of the other process. | |
632 | */ | |
b38684ce | 633 | void Logger::print_process_already_running(const int pid) const |
388f4ab0 | 634 | { |
cbbdeb6c | 635 | int level = 0; |
d77313ea | 636 | if ( level <= Loglevel ) |
59c8d63c BS |
637 | { |
638 | ostringstream msg; | |
639 | msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl; | |
ce70569b | 640 | log_error(msg.str()); |
59c8d63c | 641 | } |
388f4ab0 | 642 | } |
c5675c01 BS |
643 | |
644 | ||
645 | /** | |
646 | * SIGTERM caught. | |
647 | */ | |
b38684ce | 648 | void Logger::print_caught_sigterm() const |
c5675c01 | 649 | { |
cbbdeb6c | 650 | int level = 0; |
d77313ea | 651 | if ( level <= Loglevel ) |
59c8d63c | 652 | { |
ce70569b | 653 | log_notice("Caught SIGTERM. Exiting..."); |
59c8d63c | 654 | } |
c5675c01 BS |
655 | } |
656 | ||
657 | ||
658 | /** | |
659 | * SIGUSR1 caught. | |
660 | */ | |
b38684ce | 661 | void Logger::print_caught_siguser1() const |
c5675c01 | 662 | { |
cbbdeb6c | 663 | int level = 0; |
d77313ea | 664 | if ( level <= Loglevel ) |
59c8d63c | 665 | { |
ce70569b | 666 | log_notice("Caught SIGUSR1. Switching to offline mode..."); |
59c8d63c | 667 | } |
c5675c01 BS |
668 | } |
669 | ||
670 | ||
671 | /** | |
672 | * SIGHUP caught. | |
673 | */ | |
b38684ce | 674 | void Logger::print_caught_sighup() const |
c5675c01 | 675 | { |
60657d55 | 676 | int level = 0; |
d77313ea | 677 | if ( level <= Loglevel ) |
59c8d63c | 678 | { |
64ff14c3 BS |
679 | log_notice("Caught SIGHUP. Reloading config..."); |
680 | } | |
681 | } | |
682 | ||
683 | ||
684 | /** | |
685 | * SIGUSR2 caught. | |
686 | */ | |
687 | void Logger::print_caught_siguser2() const | |
688 | { | |
60657d55 | 689 | int level = 0; |
64ff14c3 BS |
690 | if ( level <= Loglevel ) |
691 | { | |
692 | log_notice("Caught SIGUSR2. Switching to online mode..."); | |
693 | } | |
694 | } | |
695 | ||
696 | ||
697 | /** | |
698 | * SIGRTMIN caught. | |
699 | */ | |
700 | void Logger::print_caught_sigrtmin() const | |
701 | { | |
60657d55 | 702 | int level = 0; |
64ff14c3 BS |
703 | if ( level <= Loglevel ) |
704 | { | |
705 | log_notice("Caught SIGRTMIN. Switching to online mode with webcheck enabled..."); | |
59c8d63c | 706 | } |
c5675c01 | 707 | } |
8bca3c5d BS |
708 | |
709 | ||
710 | /** | |
3f39b968 TJ |
711 | * SIGRTMAX caught. |
712 | */ | |
713 | void Logger::print_caught_sigrtmax(int new_loglevel) const | |
714 | { | |
715 | int level = 0; | |
716 | if ( level <= Loglevel ) | |
717 | { | |
718 | ostringstream msg; | |
719 | msg << "Caught SIGRTMAX. Increasing log level to " << new_loglevel << endl; | |
720 | log_error(msg.str()); | |
721 | } | |
722 | } | |
723 | ||
724 | ||
725 | /** | |
8bca3c5d BS |
726 | * Error while setting signal handler. |
727 | */ | |
b38684ce | 728 | void Logger::print_error_setting_signal(const string& signal) const |
8bca3c5d | 729 | { |
cbbdeb6c | 730 | int level = 0; |
d77313ea | 731 | if ( level <= Loglevel ) |
59c8d63c BS |
732 | { |
733 | ostringstream msg; | |
667c672c | 734 | msg << "Error while setting signal handler for: " << signal << endl; |
ce70569b | 735 | log_error(msg.str()); |
59c8d63c | 736 | } |
8bca3c5d BS |
737 | } |
738 | ||
739 | ||
740 | /** | |
741 | * Error while setting signal handler. | |
742 | */ | |
b38684ce | 743 | void Logger::print_init_log_facility() const |
8bca3c5d | 744 | { |
cbbdeb6c | 745 | int level = 1; |
d77313ea | 746 | if ( level <= Loglevel ) |
59c8d63c BS |
747 | { |
748 | ostringstream msg; | |
4475e30a | 749 | msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << " ExternalLogOnlyOnce: " << ExternalLogOnlyOnce << endl; |
ce70569b | 750 | log_notice(msg.str()); |
59c8d63c | 751 | } |
8bca3c5d BS |
752 | } |
753 | ||
27baf279 | 754 | |
8bca3c5d BS |
755 | /** |
756 | * Be verbose. Currently we are in offline mode. | |
757 | */ | |
b38684ce | 758 | void Logger::print_offline_mode() const |
8bca3c5d | 759 | { |
60657d55 | 760 | int level = 1; |
d77313ea | 761 | if ( level <= Loglevel ) |
59c8d63c | 762 | { |
ce70569b | 763 | log_notice("Offline mode..."); |
59c8d63c | 764 | } |
8bca3c5d | 765 | } |
27baf279 BS |
766 | |
767 | ||
768 | /** | |
c7a2055a TJ |
769 | * Dialup mode: Print how long we plan to delay the next network traffic |
770 | * @param sleep_until Timestamp until we plan to keep quiet | |
771 | */ | |
772 | void Logger::print_sleep_dialup_mode(time_t sleep_until) const | |
773 | { | |
774 | int level = 1; | |
775 | if ( level <= Loglevel ) | |
776 | { | |
777 | ostringstream msg; | |
778 | msg << "Skipped update in dialup mode (" << sleep_until-time(NULL) << " more seconds)" << endl; | |
779 | log_error(msg.str()); | |
780 | } | |
781 | } | |
782 | ||
783 | /** | |
27baf279 BS |
784 | * Objects successfully serialized. |
785 | */ | |
b38684ce | 786 | void Logger::print_serialized_objects_success() const |
27baf279 | 787 | { |
cbbdeb6c | 788 | int level = 1; |
d77313ea | 789 | if ( level <= Loglevel ) |
27baf279 | 790 | { |
ce70569b | 791 | log_notice("Serialized objects successfully."); |
27baf279 BS |
792 | } |
793 | } | |
794 | ||
795 | ||
796 | /** | |
797 | * Objects successfully de-serialized. | |
798 | */ | |
b38684ce | 799 | void Logger::print_deserialized_objects_success() const |
27baf279 | 800 | { |
cbbdeb6c | 801 | int level = 1; |
d77313ea | 802 | if ( level <= Loglevel ) |
27baf279 | 803 | { |
ce70569b | 804 | log_notice("De-serialized objects successfully."); |
27baf279 BS |
805 | } |
806 | } | |
807 | ||
808 | ||
5d38cfe6 BS |
809 | /** |
810 | * Prints out the content of a service object. | |
811 | * @param message Message to be added on output first. | |
812 | * @param protocol Service's protocol. | |
813 | * @param hostname Service's hostname. | |
814 | * @param login Service's login. | |
815 | * @param password Service's password. | |
816 | * @param actual_ip Service's actual_ip. | |
817 | * @param lastupdated Service's lastupdated. | |
818 | */ | |
4553e833 | 819 | void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int max_equal_updates_in_succession, const int dns_cache_ttl , const string& actual_ip, std::map<time_t,std::string> lastupdated) const |
27baf279 | 820 | { |
cbbdeb6c | 821 | int level = 1; |
d77313ea | 822 | if ( level <= Loglevel ) |
27baf279 BS |
823 | { |
824 | ostringstream msg; | |
825 | msg << message << endl; | |
3c0cd271 BS |
826 | msg << "\t" << "Protocol: " << protocol << endl; |
827 | msg << "\t" << "Hostname: " << hostname << endl; | |
828 | msg << "\t" << "Login: " << login << endl; | |
829 | msg << "\t" << "Password: " << password << endl; | |
830 | msg << "\t" << "Update Interval: " << update_interval << endl; | |
831 | msg << "\t" << "Max Updates: " << max_updates_within_interval << endl; | |
4553e833 | 832 | msg << "\t" << "Max equal Updates:" << max_equal_updates_in_succession << endl; |
d5a516ba | 833 | msg << "\t" << "DNS Cache TTL: " << dns_cache_ttl << endl; |
3c0cd271 | 834 | msg << "\t" << "Actual_IP: " << actual_ip << endl; |
4553e833 | 835 | for ( std::map<time_t,std::string>::reverse_iterator r_iter = lastupdated.rbegin(); r_iter != lastupdated.rend(); r_iter++ ) |
3c0cd271 | 836 | { |
4553e833 | 837 | msg << "\t" << "Lastupdated: " << r_iter->first << " -> " << r_iter->second << endl; |
3c0cd271 | 838 | } |
ce70569b | 839 | log_notice(msg.str()); |
27baf279 BS |
840 | } |
841 | } | |
5d38cfe6 BS |
842 | |
843 | ||
844 | /** | |
845 | * Caught exception while serialize. | |
846 | * @param exception Exception message. | |
847 | */ | |
ce70569b | 848 | void Logger::print_exception_serialize(const string& errMsg) const |
5d38cfe6 | 849 | { |
cbbdeb6c | 850 | int level = 0; |
d77313ea | 851 | if ( level <= Loglevel ) |
667c672c BS |
852 | { |
853 | ostringstream msg; | |
ce70569b BS |
854 | msg << "Error while trying to serialize Serviceholder object: " << errMsg << endl; |
855 | log_error(msg.str()); | |
667c672c BS |
856 | } |
857 | } | |
858 | ||
859 | ||
860 | /** | |
861 | * Caught exception while de-serialize. | |
862 | * @param exception Exception message. | |
863 | */ | |
ce70569b | 864 | void Logger::print_exception_deserialize(const string& errMsg) const |
667c672c | 865 | { |
cbbdeb6c | 866 | int level = 0; |
d77313ea | 867 | if ( level <= Loglevel ) |
667c672c BS |
868 | { |
869 | ostringstream msg; | |
ce70569b BS |
870 | msg << "Error while trying to de-serialize Serviceholder object: " << errMsg << endl; |
871 | log_error(msg.str()); | |
667c672c BS |
872 | } |
873 | } | |
874 | ||
875 | ||
876 | /** | |
877 | * Child couldn't be killed by parent. | |
878 | * @param pid Pid of the child. | |
879 | */ | |
b38684ce | 880 | void Logger::print_error_kill_child(const int pid) const |
667c672c | 881 | { |
cbbdeb6c | 882 | int level = 0; |
d77313ea | 883 | if ( level <= Loglevel ) |
667c672c BS |
884 | { |
885 | ostringstream msg; | |
886 | msg << "Could not kill child process with PID: " << pid << endl; | |
ce70569b | 887 | log_error(msg.str()); |
667c672c BS |
888 | } |
889 | } | |
890 | ||
891 | ||
0665b239 BS |
892 | /** |
893 | * Child was killed by parent because of error. | |
894 | * @param pid The pid (child) killed. | |
895 | */ | |
b38684ce | 896 | void Logger::print_child_killed(const int pid) const |
584b9407 | 897 | { |
cbbdeb6c | 898 | int level = 1; |
d77313ea | 899 | if ( level <= Loglevel ) |
584b9407 BS |
900 | { |
901 | ostringstream msg; | |
902 | msg << "Killed child process with PID: " << pid << endl; | |
ce70569b | 903 | log_notice(msg.str()); |
584b9407 BS |
904 | } |
905 | } | |
906 | ||
907 | ||
667c672c BS |
908 | /** |
909 | * There is no object file. | |
910 | * @param object_file The object file. | |
911 | */ | |
e8787e2e | 912 | void Logger::print_no_object_file(const string& object_file) |
667c672c | 913 | { |
cbbdeb6c BS |
914 | int level = 1; |
915 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
667c672c BS |
916 | { |
917 | ostringstream msg; | |
918 | msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl; | |
cbbdeb6c | 919 | log_warning(msg.str(),level); |
667c672c | 920 | } |
5d38cfe6 | 921 | } |
0665b239 BS |
922 | |
923 | ||
924 | /** | |
925 | * Prints out the given hostname | |
926 | * @param hostname Hostname as string. | |
927 | */ | |
e8d4a6f8 | 928 | void Logger::print_hostname(const string& hostname) const |
0665b239 | 929 | { |
cbbdeb6c | 930 | int level = 1; |
d77313ea | 931 | if ( level <= Loglevel ) |
0665b239 BS |
932 | { |
933 | ostringstream msg; | |
934 | msg << "Detected following hostname of localhost: " << hostname << endl; | |
ce70569b | 935 | log_notice(msg.str()); |
0665b239 BS |
936 | } |
937 | } | |
938 | ||
939 | ||
940 | /** | |
019dc0d9 | 941 | * Prints out the detected own ipv4 address |
0665b239 BS |
942 | * @param ip_addr String representation of the detected ip. |
943 | */ | |
c3dea5dc | 944 | void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const |
0665b239 | 945 | { |
cbbdeb6c | 946 | int level = 1; |
d77313ea | 947 | if ( level <= Loglevel ) |
0665b239 BS |
948 | { |
949 | ostringstream msg; | |
c3dea5dc | 950 | msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl; |
ce70569b | 951 | log_notice(msg.str()); |
019dc0d9 BS |
952 | } |
953 | } | |
954 | ||
955 | ||
956 | /** | |
957 | * Prints out the detected own ipv5 address | |
958 | * @param ip_addr String representation of the detected ip. | |
959 | */ | |
c3dea5dc | 960 | void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const |
019dc0d9 | 961 | { |
cbbdeb6c | 962 | int level = 1; |
d77313ea | 963 | if ( level <= Loglevel ) |
019dc0d9 BS |
964 | { |
965 | ostringstream msg; | |
c3dea5dc | 966 | msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl; |
ce70569b | 967 | log_notice(msg.str()); |
0665b239 BS |
968 | } |
969 | } | |
970 | ||
971 | ||
972 | /** | |
973 | * Exception while trying to resolve hostname to ip. | |
974 | * @param exception The exception caught. | |
975 | * @param hostname The hostname. | |
976 | */ | |
ce70569b | 977 | void Logger::print_error_hostname_to_ip(const string& errMsg, const string& hostname) const |
0665b239 | 978 | { |
a03fb896 | 979 | int level = 0; |
d77313ea | 980 | if ( level <= Loglevel ) |
0665b239 BS |
981 | { |
982 | ostringstream msg; | |
ce70569b | 983 | msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << errMsg << endl; |
e8787e2e | 984 | log_error(msg.str()); |
0665b239 BS |
985 | } |
986 | } | |
68c6b4af BS |
987 | |
988 | ||
1c0908b5 BS |
989 | /** |
990 | * The update of the given service was successful. | |
991 | * @param service The service. | |
992 | */ | |
993 | void Logger::print_update_service_successful(const string& service) const | |
68c6b4af | 994 | { |
cbbdeb6c | 995 | int level = 0; |
d77313ea | 996 | if ( level <= Loglevel ) |
68c6b4af BS |
997 | { |
998 | ostringstream msg; | |
999 | msg << "Updated service successful: " << service << endl; | |
ce70569b | 1000 | log_notice(msg.str()); |
1c0908b5 BS |
1001 | } |
1002 | } | |
1003 | ||
1004 | ||
1005 | /** | |
1006 | * No ip could be determined through webcheck | |
1007 | */ | |
e8787e2e | 1008 | void Logger::print_webcheck_no_ip() |
1c0908b5 | 1009 | { |
cbbdeb6c BS |
1010 | int level = 0; |
1011 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1c0908b5 | 1012 | { |
20cc3887 | 1013 | log_warning("IP-Address of this host could not be determined through any configured webcheck url.",level); |
1c0908b5 BS |
1014 | } |
1015 | } | |
1016 | ||
1017 | ||
1018 | /** | |
1019 | * Connection problem while trying to get ip through webcheck url | |
1020 | * @param curl_err_buff Curl error message | |
1021 | * @param url the url | |
1022 | */ | |
e8787e2e | 1023 | void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url) |
1c0908b5 | 1024 | { |
cbbdeb6c BS |
1025 | int level = 1; |
1026 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1c0908b5 BS |
1027 | { |
1028 | ostringstream msg; | |
1029 | msg << "There was a problem while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl; | |
cbbdeb6c | 1030 | log_warning(msg.str(),level); |
1c0908b5 BS |
1031 | } |
1032 | } | |
1033 | ||
1034 | ||
1035 | /** | |
1036 | * Prints out curl error. | |
1037 | * @param curl_err_buff Curl error message. | |
1038 | * @param url URL | |
1039 | */ | |
1040 | void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const | |
1041 | { | |
cbbdeb6c | 1042 | int level = 0; |
d77313ea | 1043 | if ( level <= Loglevel ) |
1c0908b5 BS |
1044 | { |
1045 | ostringstream msg; | |
1046 | msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl; | |
ce70569b | 1047 | log_error(msg.str()); |
68c6b4af BS |
1048 | } |
1049 | } | |
1c0908b5 BS |
1050 | |
1051 | ||
1052 | /** | |
1053 | * Prints out the received data through curl. | |
1054 | * @param curl_data Data string | |
1055 | */ | |
1056 | void Logger::print_received_curl_data(const string& curl_data) const | |
1057 | { | |
cbbdeb6c | 1058 | int level = 1; |
d77313ea | 1059 | if ( level <= Loglevel ) |
1c0908b5 BS |
1060 | { |
1061 | ostringstream msg; | |
1062 | msg << "Received CURL data: " << curl_data << endl; | |
ce70569b | 1063 | log_notice(msg.str()); |
1c0908b5 BS |
1064 | } |
1065 | } | |
1066 | ||
1067 | ||
1068 | /** | |
1069 | * IP was foudn through regex | |
1070 | * @param ip The IP found. | |
1071 | */ | |
1072 | void Logger::print_regex_found_ip(const string& ip) const | |
1073 | { | |
cbbdeb6c | 1074 | int level = 1; |
d77313ea | 1075 | if ( level <= Loglevel ) |
1c0908b5 BS |
1076 | { |
1077 | ostringstream msg; | |
1078 | msg << "Found IP-Address via regex: " << ip << endl; | |
ce70569b | 1079 | log_notice(msg.str()); |
1c0908b5 BS |
1080 | } |
1081 | } | |
1082 | ||
1083 | ||
1084 | /** | |
1085 | * No IP was found through regex. | |
1086 | * @param data The data string which should contain a valid IP.s | |
1087 | */ | |
e8787e2e | 1088 | void Logger::print_regex_ip_not_found(const string& data) |
1c0908b5 | 1089 | { |
efbde536 | 1090 | int level = 1; |
cbbdeb6c | 1091 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) |
1c0908b5 BS |
1092 | { |
1093 | ostringstream msg; | |
1094 | msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl; | |
cbbdeb6c | 1095 | log_warning(msg.str(),level); |
1c0908b5 BS |
1096 | } |
1097 | } | |
3c0cd271 BS |
1098 | |
1099 | ||
1100 | /** | |
1101 | * Detected multiple occurrences of the same option. | |
1102 | * @param message Error message. | |
1103 | */ | |
1104 | void Logger::print_multiple_cmd_option(const string& message) const | |
1105 | { | |
cbbdeb6c | 1106 | int level = 0; |
d77313ea | 1107 | if ( level <= Loglevel ) |
3c0cd271 BS |
1108 | { |
1109 | ostringstream msg; | |
1110 | msg << "The same option is only allowed once: " << message << endl; | |
ce70569b | 1111 | log_error(msg.str()); |
3c0cd271 BS |
1112 | } |
1113 | } | |
1114 | ||
1115 | ||
1116 | /** | |
1117 | * An update would exceed the update interval. Prints out a warning message. | |
0ebcd4ef | 1118 | * @param override_log_level Override log level with zero if true |
3c0cd271 BS |
1119 | * @param current_time Current time. |
1120 | * @param old_time Time of update #MaxUpdatesWithinInterval ago. | |
1121 | * @param MaxUpdatesWithinInterval Number of allowed updates in one update interval. | |
1122 | * @param service The service which exceeds update interval. | |
1123 | */ | |
0ebcd4ef | 1124 | void Logger::print_update_not_allowed(bool override_log_level, const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const string& service) |
3c0cd271 | 1125 | { |
efbde536 | 1126 | int level = 1; |
0ebcd4ef TJ |
1127 | |
1128 | if (override_log_level) | |
1129 | level = 0; | |
1130 | ||
cbbdeb6c | 1131 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) |
3c0cd271 BS |
1132 | { |
1133 | ostringstream msg; | |
1134 | msg << "Update not allowed for service: " << service << ". Too many updates within max update interval. Current time: " << current_time << ". Update time before " << MaxUpdatesWithinInterval << " updates: " << old_time << endl; | |
cbbdeb6c | 1135 | log_warning(msg.str(),level); |
3c0cd271 BS |
1136 | } |
1137 | } | |
1138 | ||
1139 | ||
1140 | /** | |
1141 | * Failure while running update for service. | |
1142 | * @param service Services' name. | |
1143 | */ | |
e8787e2e | 1144 | void Logger::print_update_service_failure(const string& service) |
3c0cd271 | 1145 | { |
cbbdeb6c BS |
1146 | int level = 0; |
1147 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
3c0cd271 BS |
1148 | { |
1149 | ostringstream msg; | |
1150 | msg << "Could not update service: " << service << endl; | |
cbbdeb6c | 1151 | log_warning(msg.str(),level); |
3c0cd271 BS |
1152 | } |
1153 | } | |
e304c27b | 1154 | |
e38d7604 TJ |
1155 | /** |
1156 | * Start message | |
1157 | */ | |
1158 | void Logger::print_started() const | |
1159 | { | |
1160 | int level = 0; | |
1161 | if ( level <= Loglevel ) | |
1162 | { | |
1163 | log_notice("Started"); | |
1164 | } | |
1165 | } | |
1166 | ||
e304c27b BS |
1167 | |
1168 | /** | |
1169 | * Starting shutdown | |
1170 | */ | |
1171 | void Logger::print_starting_shutdown() const | |
1172 | { | |
cbbdeb6c | 1173 | int level = 0; |
d77313ea | 1174 | if ( level <= Loglevel ) |
e304c27b | 1175 | { |
ce70569b | 1176 | log_notice("Shutting down ..."); |
e304c27b BS |
1177 | } |
1178 | } | |
1179 | ||
1180 | ||
1181 | /** | |
1182 | * Shutdown complete | |
1183 | */ | |
1184 | void Logger::print_shutdown_succeeded() const | |
1185 | { | |
cbbdeb6c | 1186 | int level = 0; |
d77313ea | 1187 | if ( level <= Loglevel ) |
e304c27b | 1188 | { |
ce70569b | 1189 | log_notice("Shutting down complete ..."); |
e304c27b BS |
1190 | } |
1191 | } | |
1192 | ||
1193 | ||
1194 | /** | |
1195 | * Shutdown parent succeeded | |
1196 | */ | |
1197 | void Logger::print_shutdown_parent_succeeded() const | |
1198 | { | |
cbbdeb6c | 1199 | int level = 0; |
d77313ea | 1200 | if ( level <= Loglevel ) |
e304c27b | 1201 | { |
ce70569b | 1202 | log_notice("Shutting down parent process completed ..."); |
e304c27b BS |
1203 | } |
1204 | } | |
1205 | ||
1206 | ||
1207 | /** | |
1208 | * Starting shutdown parent | |
1209 | */ | |
1210 | void Logger::print_starting_shutdown_parent() const | |
1211 | { | |
cbbdeb6c | 1212 | int level = 0; |
d77313ea | 1213 | if ( level <= Loglevel ) |
e304c27b | 1214 | { |
ce70569b | 1215 | log_notice("Shutting down parent process ..."); |
e304c27b BS |
1216 | } |
1217 | } | |
0541cd71 BS |
1218 | |
1219 | ||
1220 | /** | |
1221 | * DNS cache record timeout | |
1222 | * @param hostname Hostname | |
1223 | * @param lastupdated Lastupdated | |
1224 | * @param dns_cache_ttl DNS cache TTL | |
1225 | * @param current_time Current time | |
1226 | */ | |
8a00a649 | 1227 | void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const |
0541cd71 | 1228 | { |
cbbdeb6c | 1229 | int level = 1; |
d77313ea | 1230 | if ( level <= Loglevel ) |
0541cd71 BS |
1231 | { |
1232 | ostringstream msg; | |
d5a516ba | 1233 | msg << "DNS cache record for host <" << hostname << "> expired or host will be updated for the first time: Lastupdated: " << lastupdated << " DNS cache ttl: " << dns_cache_ttl << " Current time: " << current_time << " Checking current DNS cache status." << endl; |
ce70569b | 1234 | log_notice(msg.str()); |
0541cd71 BS |
1235 | } |
1236 | } | |
1237 | ||
1238 | ||
1239 | /** | |
8a00a649 BS |
1240 | * Missing proxy option on command line. |
1241 | */ | |
1242 | void Logger::print_missing_cmd_proxy_option() const | |
1243 | { | |
cbbdeb6c | 1244 | int level = 0; |
d77313ea | 1245 | if ( level <= Loglevel ) |
8a00a649 | 1246 | { |
ce70569b | 1247 | log_error("Missing option to initialize proxy. http_proxy and http_proxy_port must be specified."); |
8a00a649 BS |
1248 | } |
1249 | } | |
1250 | ||
1251 | ||
1252 | /** | |
1253 | * Multiple option in service config file. | |
1254 | * @param service_conf_file Service config file | |
1255 | * @param message Multiple option text | |
1256 | */ | |
1257 | void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const | |
1258 | { | |
cbbdeb6c | 1259 | int level = 0; |
d77313ea | 1260 | if ( level <= Loglevel ) |
8a00a649 BS |
1261 | { |
1262 | ostringstream msg; | |
1263 | msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl; | |
ce70569b | 1264 | log_error(msg.str()); |
8a00a649 BS |
1265 | } |
1266 | } | |
1267 | ||
1268 | ||
1269 | /** | |
1270 | * Multiple option in main config file. | |
1271 | * @param service_conf_file Service config file | |
1272 | * @param message Multiple option text | |
1273 | */ | |
1274 | void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const | |
1275 | { | |
cbbdeb6c | 1276 | int level = 0; |
d77313ea | 1277 | if ( level <= Loglevel ) |
8a00a649 BS |
1278 | { |
1279 | ostringstream msg; | |
1280 | msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl; | |
ce70569b | 1281 | log_error(msg.str()); |
8a00a649 BS |
1282 | } |
1283 | } | |
1284 | ||
1285 | ||
1286 | /** | |
1287 | * Missing proxy option in main config file. | |
2dd2db3e | 1288 | * @param main_conf_filename The concerning config file. |
8a00a649 BS |
1289 | */ |
1290 | void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const | |
1291 | { | |
cbbdeb6c | 1292 | int level = 0; |
d77313ea | 1293 | if ( level <= Loglevel ) |
8a00a649 BS |
1294 | { |
1295 | ostringstream msg; | |
1296 | msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl; | |
ce70569b | 1297 | log_error(msg.str()); |
8a00a649 BS |
1298 | } |
1299 | } | |
2dd2db3e BS |
1300 | |
1301 | ||
1302 | /** | |
1303 | * There is no domain part in the given hostname | |
1304 | * @param hostname The hostname with no domain part in it. | |
1305 | */ | |
d5a516ba | 1306 | void Logger::print_no_domain_part(const string& hostname) const |
2dd2db3e BS |
1307 | { |
1308 | int level = 0; | |
d77313ea | 1309 | if ( level <= Loglevel ) |
2dd2db3e BS |
1310 | { |
1311 | ostringstream msg; | |
1312 | msg << "There is no domain part in the given hostname: " << hostname << endl; | |
ce70569b | 1313 | log_notice(msg.str()); |
2dd2db3e BS |
1314 | } |
1315 | } | |
d5a516ba BS |
1316 | |
1317 | ||
1318 | /** | |
31af6a2e BS |
1319 | * Service is not initialized properly. |
1320 | * @param service The service. | |
1321 | */ | |
e8787e2e | 1322 | void Logger::print_httphelper_not_initialized() const |
31af6a2e BS |
1323 | { |
1324 | int level = 0; | |
1325 | if ( level <= Loglevel ) | |
1326 | { | |
e8787e2e | 1327 | log_error("HTTP-Helper is not initialized properly."); |
31af6a2e BS |
1328 | } |
1329 | } | |
1330 | ||
1331 | ||
1332 | /** | |
cfdfbf4c | 1333 | * A curl error occured. |
31af6a2e BS |
1334 | * @param msg The error message |
1335 | * @param curl_err_code The resulting curl error code | |
1336 | */ | |
c730deea | 1337 | void Logger::print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const |
31af6a2e BS |
1338 | { |
1339 | string curl_err = ""; | |
1340 | ||
1341 | if ( curl_err_code == CURLE_FAILED_INIT ) | |
1342 | curl_err = "CURLE_FAILED_INIT"; | |
1343 | else | |
1344 | curl_err = "UNKNOWN"; | |
1345 | ||
1346 | int level = 0; | |
e8787e2e | 1347 | if ( (level <= Loglevel) ) |
31af6a2e BS |
1348 | { |
1349 | ostringstream msg; | |
557b6f56 | 1350 | msg << "Curl error: " << err_msg << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */ |
ce70569b | 1351 | log_error(msg.str()); |
31af6a2e BS |
1352 | } |
1353 | } | |
1354 | ||
1355 | ||
1356 | /** | |
cfdfbf4c | 1357 | * A curl error occured. |
d5a516ba BS |
1358 | * @param url The url requested by the curl operation |
1359 | * @param curl_err_code The resulting curl error code | |
1360 | */ | |
31af6a2e | 1361 | void Logger::print_curl_error(const string& url, const CURLcode curl_err_code) const |
d5a516ba BS |
1362 | { |
1363 | string curl_err = ""; | |
1364 | ||
31af6a2e | 1365 | if ( curl_err_code == CURLE_URL_MALFORMAT ) |
d5a516ba | 1366 | curl_err = "CURLE_URL_MALFORMAT"; |
31af6a2e | 1367 | else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST ) |
d5a516ba | 1368 | curl_err = "CURLE_COULDNT_RESOLVE_HOST"; |
31af6a2e | 1369 | else if ( curl_err_code == CURLE_COULDNT_CONNECT ) |
d5a516ba BS |
1370 | curl_err = "CURLE_COULDNT_CONNECT"; |
1371 | else | |
1372 | curl_err = "UNKNOWN"; | |
1373 | ||
1374 | int level = 0; | |
e8787e2e | 1375 | if ( (level <= Loglevel) ) |
d5a516ba BS |
1376 | { |
1377 | ostringstream msg; | |
557b6f56 | 1378 | msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */ |
e8787e2e | 1379 | log_error(msg.str()); |
d5a516ba BS |
1380 | } |
1381 | } | |
1382 | ||
1383 | ||
1384 | /** | |
cfdfbf4c | 1385 | * A curl error occured. |
d5a516ba BS |
1386 | * @param url The url requested by the curl operation |
1387 | * @param curl_err_code The resulting curl error code | |
1388 | * @param curl_err_buff The curl error buffer | |
1389 | */ | |
c730deea | 1390 | void Logger::print_curl_error(const string& url, const CURLcode curl_err_code, const char * curl_err_buff) const |
d5a516ba BS |
1391 | { |
1392 | string curl_err = ""; | |
1393 | ||
c730deea | 1394 | if ( curl_err_code == CURLE_URL_MALFORMAT ) |
d5a516ba | 1395 | curl_err = "CURLE_URL_MALFORMAT"; |
c730deea | 1396 | else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST ) |
d5a516ba | 1397 | curl_err = "CURLE_COULDNT_RESOLVE_HOST"; |
c730deea | 1398 | else if ( curl_err_code == CURLE_COULDNT_CONNECT ) |
d5a516ba BS |
1399 | curl_err = "CURLE_COULDNT_CONNECT"; |
1400 | else | |
1401 | curl_err = "UNKNOWN"; | |
1402 | ||
1403 | int level = 0; | |
e8787e2e | 1404 | if ( (level <= Loglevel) ) |
d5a516ba BS |
1405 | { |
1406 | ostringstream msg; | |
557b6f56 | 1407 | msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << " " << curl_err_buff << endl; /*lint !e641 */ |
e8787e2e | 1408 | log_error(msg.str()); |
d5a516ba BS |
1409 | } |
1410 | } | |
1411 | ||
1412 | ||
1413 | /** | |
1414 | * Prints out the data received by curl operation | |
43f4565e | 1415 | * @param CurlWritedataBuff |
d5a516ba BS |
1416 | */ |
1417 | void Logger::print_curl_data(const string& curl_writedata_buff) const | |
1418 | { | |
1419 | int level = 1; | |
d77313ea | 1420 | if ( level <= Loglevel ) |
d5a516ba BS |
1421 | { |
1422 | ostringstream msg; | |
b6228761 | 1423 | msg << "Data received by curl: " << curl_writedata_buff << endl; |
ce70569b | 1424 | log_notice(msg.str()); |
d5a516ba BS |
1425 | } |
1426 | } | |
1427 | ||
1428 | ||
1429 | /** | |
a03fb896 BS |
1430 | * Not authorized to perform requested update operation |
1431 | * @param service The requested service. | |
d5a516ba BS |
1432 | * @param username Username |
1433 | * @param password Password | |
1434 | */ | |
a03fb896 | 1435 | void Logger::print_service_not_authorized(const string& service, const string& username, const string& password) const |
d5a516ba BS |
1436 | { |
1437 | int level = 0; | |
e8787e2e | 1438 | if ( level <= Loglevel ) |
d5a516ba BS |
1439 | { |
1440 | ostringstream msg; | |
a03fb896 | 1441 | msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":" << password << endl; |
e8787e2e | 1442 | log_notice(msg.str()); |
d5a516ba BS |
1443 | } |
1444 | } | |
1445 | ||
1446 | ||
1447 | /** | |
1448 | * Prints out the http status code | |
1449 | * @param url Url | |
1450 | * @param output HTTP status code | |
1451 | */ | |
1af7c124 | 1452 | void Logger::print_http_status_code(const string& url, const long http_code) const |
d5a516ba BS |
1453 | { |
1454 | int level = 1; | |
d77313ea | 1455 | if ( level <= Loglevel ) |
d5a516ba BS |
1456 | { |
1457 | ostringstream msg; | |
1458 | msg << "Requested URL: " << url << " Received HTTP status code: " << http_code << endl; | |
ce70569b | 1459 | log_notice(msg.str()); |
d5a516ba BS |
1460 | } |
1461 | } | |
b6228761 BS |
1462 | |
1463 | ||
1464 | /** | |
1465 | * Generic failure while trying to update service | |
1466 | * @param url The requested URL | |
1467 | * @param curl_data The received curl_data from the server | |
1468 | */ | |
1469 | void Logger::print_update_failure(const string& url, const string& curl_data) const | |
1470 | { | |
1471 | int level = 0; | |
e8787e2e | 1472 | if ( (level <= Loglevel) ) |
b6228761 BS |
1473 | { |
1474 | ostringstream msg; | |
1475 | msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << curl_data << endl; | |
e8787e2e | 1476 | log_error(msg.str()); |
b6228761 BS |
1477 | } |
1478 | } | |
1a00eac6 BS |
1479 | |
1480 | ||
1481 | /** | |
b17fd691 BS |
1482 | * Generic failure while trying to update service |
1483 | * @param url The requested URL | |
1484 | * @param http_status_code The received http status code | |
1485 | */ | |
1486 | void Logger::print_update_failure(const string& url, const long http_status_code) const | |
1487 | { | |
1488 | int level = 0; | |
e8787e2e | 1489 | if ( level <= Loglevel ) |
b17fd691 BS |
1490 | { |
1491 | ostringstream msg; | |
1492 | msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << http_status_code << endl; | |
e8787e2e | 1493 | log_error(msg.str()); |
b17fd691 BS |
1494 | } |
1495 | } | |
1496 | ||
1497 | /** | |
1a00eac6 | 1498 | * Hostname is invalid, contains no or only one domain part. |
43f4565e | 1499 | * @param hostname The full qualified host name. |
1a00eac6 | 1500 | */ |
e8787e2e | 1501 | void Logger::print_invalid_hostname(const string& hostname) |
1a00eac6 BS |
1502 | { |
1503 | int level = 0; | |
1504 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1505 | { | |
1506 | ostringstream msg; | |
1507 | msg << "The configured hostname: " << hostname << " is invalid. Please add the corresponding domain part." << endl; | |
1508 | log_warning(msg.str(),level); | |
1509 | } | |
1510 | } | |
4ef36a12 BS |
1511 | |
1512 | ||
1513 | /** | |
1514 | * An IP in a private range was detected | |
1515 | * @param ip The private IP | |
1516 | */ | |
e8787e2e | 1517 | void Logger::print_ip_is_local(const string& ip) |
4ef36a12 | 1518 | { |
60657d55 | 1519 | int level = 1; |
4ef36a12 BS |
1520 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) |
1521 | { | |
1522 | ostringstream msg; | |
1523 | msg << "The detected IP is within a private IP range: " << ip << endl; | |
1524 | log_warning(msg.str(),level); | |
1525 | } | |
1526 | } | |
1527 | ||
1528 | ||
1529 | /** | |
1530 | * Regex is matching in string | |
1531 | * @param regex The regex pattern | |
1532 | * @param matching_string The string | |
1533 | */ | |
a78b44b5 | 1534 | void Logger::print_regex_match(const string& regex, const string& matching_string) const |
4ef36a12 BS |
1535 | { |
1536 | int level = 1; | |
d77313ea | 1537 | if ( level <= Loglevel ) |
4ef36a12 BS |
1538 | { |
1539 | ostringstream msg; | |
1540 | msg << "Regex: " << regex << " is matching in: " << matching_string << endl; | |
ce70569b | 1541 | log_notice(msg.str()); |
4ef36a12 BS |
1542 | } |
1543 | } | |
a78b44b5 BS |
1544 | |
1545 | ||
1546 | /** | |
1547 | * Regex is not matching | |
1548 | * @param regex Regex | |
1549 | * @param not_matching_string String | |
1550 | */ | |
e8787e2e | 1551 | void Logger::print_no_regex_match(const string& regex, const string& not_matching_string) |
a78b44b5 BS |
1552 | { |
1553 | int level = 1; | |
1554 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1555 | { | |
1556 | ostringstream msg; | |
1557 | msg << "Regex: " << regex << " is not matching in: " << not_matching_string << endl; | |
1558 | log_warning(msg.str(),level); | |
1559 | } | |
1560 | } | |
1561 | ||
1562 | ||
1563 | /** | |
1564 | * Could not parse gnudip initial reply. | |
1565 | * @param curl_data The data received from gnudip server which should contain salt, time and sign. | |
1566 | */ | |
1567 | void Logger::print_could_not_parse_received_data(const string& curl_data) const | |
1568 | { | |
1569 | int level = 0; | |
e8787e2e | 1570 | if ( (level <= Loglevel) ) |
a78b44b5 BS |
1571 | { |
1572 | ostringstream msg; | |
1573 | msg << "Could not parse salt, time and sign from initial gnudip server reply: " << curl_data << endl; | |
e8787e2e | 1574 | log_error(msg.str()); |
a78b44b5 BS |
1575 | } |
1576 | } | |
1577 | ||
1578 | ||
1579 | /** | |
1580 | * Gnudip salt, time and sign could not be got from map | |
1581 | */ | |
1582 | void Logger::print_could_not_get_initial_gnudip_data() const | |
1583 | { | |
1584 | int level = 0; | |
e8787e2e | 1585 | if ( (level <= Loglevel) ) |
a78b44b5 | 1586 | { |
e8787e2e | 1587 | log_error("Could not get salt, time and sign from map."); |
a78b44b5 BS |
1588 | } |
1589 | } | |
1590 | ||
1591 | ||
a2f5be94 BS |
1592 | |
1593 | /** | |
1594 | * Gnudip protocol requires explicit declaration of a servername. | |
1595 | */ | |
e8787e2e | 1596 | void Logger::print_gnudip_requires_servername() |
a78b44b5 BS |
1597 | { |
1598 | int level = 0; | |
1599 | if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) ) | |
1600 | { | |
20cc3887 | 1601 | log_warning("Gnudip requires explicit definition of servername via config!",level); |
a78b44b5 BS |
1602 | } |
1603 | } | |
a2f5be94 BS |
1604 | |
1605 | ||
1606 | /** | |
1607 | * An exception occured while computing the md5 sum. | |
1608 | * @param what The exception occured. | |
1609 | */ | |
c1b8cb79 | 1610 | void Logger::print_exception_md5_sum(const string& what) const |
a2f5be94 BS |
1611 | { |
1612 | int level = 0; | |
d77313ea | 1613 | if ( level <= Loglevel ) |
a2f5be94 BS |
1614 | { |
1615 | ostringstream msg; | |
1616 | msg << "An exception occured while computing a md5 sum: " << what << endl; | |
ce70569b | 1617 | log_error(msg.str()); |
a2f5be94 BS |
1618 | } |
1619 | } | |
a03fb896 BS |
1620 | |
1621 | ||
1622 | /** | |
cfdfbf4c | 1623 | * A network exception occured. |
a03fb896 BS |
1624 | * @param what The exception occured. |
1625 | */ | |
c1b8cb79 | 1626 | void Logger::print_network_error(const string& what) const |
a03fb896 BS |
1627 | { |
1628 | int level = 0; | |
d77313ea | 1629 | if ( level <= Loglevel ) |
a03fb896 BS |
1630 | { |
1631 | ostringstream msg; | |
cfdfbf4c | 1632 | msg << "A network exception occured: " << what << endl; |
ce70569b | 1633 | log_error(msg.str()); |
a03fb896 BS |
1634 | } |
1635 | } | |
1636 | ||
1637 | ||
1638 | /** | |
1639 | * An undefined protocol error occured. | |
1640 | * @param protocol The protocol | |
1641 | * @param error The error | |
1642 | */ | |
c1b8cb79 | 1643 | void Logger::print_undefined_protocol_error(const string& protocol, const string& error) const |
a03fb896 BS |
1644 | { |
1645 | int level = 0; | |
d77313ea | 1646 | if ( level <= Loglevel ) |
a03fb896 BS |
1647 | { |
1648 | ostringstream msg; | |
1649 | msg << "An undefined protocol error occured. Protocol: " << protocol << " Error: " << error << endl; | |
ce70569b | 1650 | log_error(msg.str()); |
a03fb896 BS |
1651 | } |
1652 | } | |
d77313ea BS |
1653 | |
1654 | /** | |
1655 | * Error while trying to log through external program. | |
1656 | * @param external_prog The external program called. | |
1657 | */ | |
c1b8cb79 | 1658 | void Logger::print_error_external_logging(const string& external_prog) const |
d77313ea BS |
1659 | { |
1660 | int level = 0; | |
1661 | if ( level <= Loglevel ) | |
1662 | { | |
1663 | ostringstream msg; | |
1664 | msg << "Error while trying to log through external program: " << external_prog << endl; | |
ce70569b | 1665 | log_notice(msg.str()); |
d77313ea BS |
1666 | } |
1667 | } | |
c1b8cb79 BS |
1668 | |
1669 | ||
1670 | /** | |
1671 | * Error while parsing config file. | |
1672 | * @param error Error occured. | |
1673 | * @param config_file Config file. | |
1674 | */ | |
1675 | void Logger::print_error_parsing_config_file(const string& filename, const string& error) const | |
1676 | { | |
1677 | int level = 0; | |
1678 | if ( level <= Loglevel ) | |
1679 | { | |
1680 | ostringstream msg; | |
1681 | msg << "Error while parsing config file: " << filename << " Error: " << error << endl; | |
ce70569b | 1682 | log_notice(msg.str()); |
c1b8cb79 BS |
1683 | } |
1684 | } | |
1685 | ||
1686 | ||
1687 | /** | |
1688 | * Error while parsing cmd option | |
1689 | * @param error Error | |
1690 | */ | |
1691 | void Logger::print_error_parsing_cmd(const string& error) const | |
1692 | { | |
1693 | int level = 0; | |
1694 | if ( level <= Loglevel ) | |
1695 | { | |
1696 | ostringstream msg; | |
1697 | msg << "Error while parsing cmd options: " << error << endl; | |
ce70569b | 1698 | log_error(msg.str()); |
c1b8cb79 BS |
1699 | } |
1700 | } | |
2b0f7c11 BS |
1701 | |
1702 | ||
1703 | /** | |
1704 | * The webcheck interval was exceeded, so webcheck not allowed. | |
1705 | * @param last_webcheck Time of last webcheck. | |
3c4705d9 | 1706 | * @param webcheck_interval Webcheck interval time in seconds. |
2b0f7c11 BS |
1707 | * @param current_time Current system time. |
1708 | */ | |
c730deea | 1709 | void Logger::print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const |
2b0f7c11 | 1710 | { |
60657d55 | 1711 | int level = 1; |
2b0f7c11 BS |
1712 | if ( level <= Loglevel ) |
1713 | { | |
1714 | ostringstream msg; | |
3c4705d9 TJ |
1715 | msg << "Skipped webcheck in idle period (" << (last_webcheck+webcheck_interval)-current_time << " more seconds"; |
1716 | msg << ", last_webcheck: " << last_webcheck << ", webcheck_interval(sec): " << webcheck_interval << ")" << endl; | |
ce70569b | 1717 | log_notice(msg.str()); |
2b0f7c11 BS |
1718 | } |
1719 | } | |
1af7c124 BS |
1720 | |
1721 | ||
1722 | /** | |
1723 | * Checking if hosts needs update. | |
1724 | * @param hostname Hostname | |
1725 | * @param current_time Current time | |
1726 | * @param lastupdated Last updated | |
1727 | */ | |
c730deea | 1728 | void Logger::print_check_service_update(const string& hostname, const time_t current_time, const time_t lastupdated) const |
1af7c124 BS |
1729 | { |
1730 | int level = 1; | |
1731 | if ( level <= Loglevel ) | |
1732 | { | |
1733 | ostringstream msg; | |
1734 | msg << "Checking if host: " << hostname << " needs update. Current time: " << current_time << " Last updated: " << lastupdated << endl; | |
ce70569b | 1735 | log_notice(msg.str()); |
1af7c124 BS |
1736 | } |
1737 | } | |
1738 | ||
1739 | ||
1740 | /** | |
1741 | * Cached DNS entry | |
1742 | * @param hostname Hostname | |
1743 | * @param ip_dns_recheck DNS recheck IP | |
1744 | * @param ip_last_update IP set in last update | |
1745 | * @param ip_host Hosts' IP | |
1746 | */ | |
1747 | void Logger::print_cached_dns_entry(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host) const | |
1748 | { | |
1749 | int level = 1; | |
1750 | if ( level <= Loglevel ) | |
1751 | { | |
1752 | ostringstream msg; | |
1753 | msg << "Cached DNS record for host <" << hostname << "> : " << ip_dns_recheck << " Last updated IP: " << ip_last_update << " Hosts IP: " << ip_host << endl; | |
ce70569b | 1754 | log_notice(msg.str()); |
1af7c124 BS |
1755 | } |
1756 | } | |
1757 | ||
1758 | ||
1759 | /** | |
1af7c124 BS |
1760 | * Updating service |
1761 | * @param hostname Hostname | |
1762 | * @param ip_dns_recheck Cached DNS entry | |
1763 | * @param ip_last_update IP set in last update | |
1764 | * @param ip_host Hosts IP | |
1765 | * @param lastupdated Lastupdated | |
1766 | */ | |
08a5a621 | 1767 | void Logger::print_update_service(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated) const{ |
1af7c124 BS |
1768 | int level = 1; |
1769 | if ( level <= Loglevel ) | |
1770 | { | |
1771 | ostringstream msg; | |
1772 | msg << "Updating service. Hostname: " << hostname << " DNS-Record: " << ip_dns_recheck << " IP set in last update: " << ip_last_update << " Lastupdated: " << lastupdated << " Hosts IP: " << ip_host << endl; | |
ce70569b | 1773 | log_notice(msg.str()); |
1af7c124 BS |
1774 | } |
1775 | } | |
1776 | ||
1777 | ||
1778 | /** | |
1779 | * TTL expired | |
1780 | * @param hostname Hostname | |
1781 | * @param ip_dns_recheck Cached DNS entry | |
1782 | * @param ip_last_update IP set in last update | |
1783 | * @param ip_host Hosts IP | |
1784 | * @param lastupdated Last updated | |
1785 | * @param dns_cache_ttl DNS cache ttl | |
1786 | * @param current_time Current time | |
1787 | */ | |
08a5a621 | 1788 | void Logger::print_update_service_ttl_expired(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const |
1af7c124 BS |
1789 | { |
1790 | int level = 1; | |
1791 | if ( level <= Loglevel ) | |
1792 | { | |
1793 | ostringstream msg; | |
1794 | msg << "TTL for service expired and still pointing to old IP. Hostname: " << hostname << " DNS-Record: " << ip_dns_recheck << " IP set in last update: " << ip_last_update << " Lastupdated: " << lastupdated << "DNS Cache TTL: " << dns_cache_ttl << " Current Time: " << current_time << " Hosts IP: " << ip_host << endl; | |
ce70569b | 1795 | log_notice(msg.str()); |
1af7c124 BS |
1796 | } |
1797 | } | |
1798 | ||
1799 | ||
1800 | /** | |
1801 | * TTL expired | |
d55e13a6 | 1802 | * @param override_log_level Override log level with zero if true |
1af7c124 BS |
1803 | * @param hostname Hostname |
1804 | * @param ip_dns_recheck Cached DNS entry | |
1805 | * @param ip_last_update IP set in last update | |
1806 | * @param ip_host Hosts IP | |
1807 | * @param lastupdated Last updated | |
1808 | * @param dns_cache_ttl DNS cache ttl | |
1809 | * @param current_time Current time | |
1810 | */ | |
d55e13a6 | 1811 | void Logger::print_update_service_ttl_not_expired(bool override_log_level, const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated, const int dns_cache_ttl, const time_t current_time) const |
1af7c124 BS |
1812 | { |
1813 | int level = 1; | |
d55e13a6 TJ |
1814 | |
1815 | if (override_log_level) | |
1816 | level = 0; | |
1817 | ||
1af7c124 BS |
1818 | if ( level <= Loglevel ) |
1819 | { | |
1820 | ostringstream msg; | |
1821 | msg << "Waiting for DNS cache TTL to expire. Hostname: " << hostname << " DNS-Record: " << ip_dns_recheck << " IP set in last update: " << ip_last_update << " Lastupdated: " << lastupdated << "DNS Cache TTL: " << dns_cache_ttl << " Current Time: " << current_time << " Hosts IP: " << ip_host << endl; | |
ce70569b | 1822 | log_notice(msg.str()); |
1af7c124 BS |
1823 | } |
1824 | } | |
1825 | ||
1826 | ||
1827 | /** | |
1828 | * No update needed | |
d55e13a6 | 1829 | * @param override_log_level Override log level with zero if true |
1af7c124 BS |
1830 | * @param hostname Hostname |
1831 | * @param ip_dns_recheck Cached DNS entry | |
1832 | * @param ip_last_update IP set in last update | |
1833 | * @param ip_host Hosts IP | |
1834 | * @param lastupdated Last updated | |
1835 | */ | |
d55e13a6 | 1836 | void Logger::print_no_update_needed(bool override_log_level, const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host, const time_t lastupdated) const |
1af7c124 BS |
1837 | { |
1838 | int level = 1; | |
d55e13a6 TJ |
1839 | |
1840 | if (override_log_level) | |
1841 | level = 0; | |
1842 | ||
1af7c124 BS |
1843 | if ( level <= Loglevel ) |
1844 | { | |
1845 | ostringstream msg; | |
1846 | msg << "No update needed for host: " << hostname << " Cached DNS record: " << ip_dns_recheck << " IP set in last update: " << ip_last_update << " Hosts IP: " << ip_host << " Last updated: " << lastupdated << endl; | |
ce70569b | 1847 | log_notice(msg.str()); |
1af7c124 BS |
1848 | } |
1849 | } | |
1d2e2f56 BS |
1850 | |
1851 | ||
1852 | /** | |
1853 | * Error while trying to get local wan interface IP address through getifaddrs. | |
1854 | * @param error The system call which raised the error. | |
1855 | * @param error The error set by getifaddrs. | |
1856 | */ | |
1857 | void Logger::print_error_getting_local_wan_ip(const std::string& system_call, const std::string& error) const | |
1858 | { | |
1859 | int level = 0; | |
1860 | if ( level <= Loglevel ) | |
1861 | { | |
1862 | ostringstream msg; | |
1863 | msg << "Error while trying to get local wan interface IP address through '" << system_call << "': " << error << endl; | |
ce70569b | 1864 | log_error(msg.str()); |
1d2e2f56 BS |
1865 | } |
1866 | } | |
1867 | ||
1868 | ||
1869 | /** | |
1870 | * Could not get IP address of local wan interface. | |
f3141675 TJ |
1871 | * @param override_log_level Override log level with zero if true |
1872 | */ | |
1873 | void Logger::print_no_wan_ip(bool override_log_level) const | |
1874 | { | |
1875 | int level = 1; | |
1876 | ||
1877 | if (override_log_level) | |
1878 | level = 0; | |
1879 | ||
1880 | if ( level <= Loglevel ) | |
1881 | { | |
1882 | ostringstream msg; | |
1883 | msg << "Could not get IP address of local wan interface. Will retry later." << endl; | |
1884 | log_error(msg.str()); | |
1885 | } | |
1886 | } | |
1887 | ||
62956d9a TJ |
1888 | /** |
1889 | * Print extenral WAN IP | |
1890 | * @param override_log_level Override log level with zero if true | |
1891 | * @param ip External WAN IP | |
1892 | */ | |
1893 | void Logger::print_external_wan_ip(bool override_log_level, const std::string &ip) const | |
1894 | { | |
1895 | int level = 1; | |
1896 | ||
1897 | if (override_log_level) | |
1898 | level = 0; | |
1899 | ||
1900 | if ( level <= Loglevel ) | |
1901 | { | |
1902 | ostringstream msg; | |
1903 | msg << "Determined WAN interface IP: " << ip << endl; | |
1904 | log_error(msg.str()); | |
1905 | } | |
1906 | } | |
f3141675 TJ |
1907 | |
1908 | /** | |
1909 | * Could not resolve current IP for DNS name | |
1910 | * @param override_log_level Override log level with zero if true | |
1d2e2f56 | 1911 | */ |
f3141675 | 1912 | void Logger::print_dns_lookup_failed(bool override_log_level, const std::string &hostname) const |
1d2e2f56 | 1913 | { |
60657d55 | 1914 | int level = 1; |
f3141675 TJ |
1915 | |
1916 | if (override_log_level) | |
1917 | level = 0; | |
1918 | ||
1d2e2f56 BS |
1919 | if ( level <= Loglevel ) |
1920 | { | |
1921 | ostringstream msg; | |
f3141675 | 1922 | msg << "Could not resolve IP address for host " << hostname << ". Will retry later." << endl; |
ce70569b | 1923 | log_error(msg.str()); |
1d2e2f56 BS |
1924 | } |
1925 | } | |
60657d55 BS |
1926 | |
1927 | ||
1928 | /** | |
1929 | * Invalid service config was detected. | |
1930 | */ | |
1931 | void Logger::print_invalid_service_config() const | |
1932 | { | |
1933 | int level = 0; | |
1934 | if ( level <= Loglevel ) | |
1935 | { | |
1936 | log_error("Ignoring invalid service. Please check.\n"); | |
1937 | } | |
1938 | } | |
4475e30a BS |
1939 | |
1940 | ||
1941 | /** | |
1942 | * Print simple message. | |
1943 | */ | |
1944 | void Logger::print_msg( const string& msg ) const | |
1945 | { | |
1946 | int level = 0; | |
1947 | if ( level <= Loglevel ) | |
1948 | { | |
1949 | log_error(msg); | |
1950 | } | |
1951 | } | |
4553e833 BS |
1952 | |
1953 | ||
1954 | /** | |
1955 | * Print the last updates. | |
1956 | * @param ip_host Actual host IP. | |
1957 | * @param max_equal_updates_in_succession Maximal number of updates for the same IP in succession. | |
1958 | * @param last_updates Map with the last updates in it. | |
1959 | * @param hostname The service hostname. | |
1960 | */ | |
1961 | void Logger::print_last_updates( const std::string& ip_host, const int max_equal_updates_in_succession, const std::map<time_t,std::string>& last_updates, const std::string& hostname ) const | |
1962 | { | |
1963 | int level = 1; | |
1964 | ||
1965 | if ( level <= Loglevel ) | |
1966 | { | |
1967 | ostringstream msg; | |
1968 | msg << "Last updates for " << hostname << " : "; | |
1969 | ||
1970 | int i = 0; | |
1971 | for ( std::map<time_t,std::string>::reverse_iterator r_iter; (r_iter != last_updates.rend()) && (i < max_equal_updates_in_succession); r_iter++ ) | |
1972 | { | |
1973 | msg << r_iter->first << "->" << r_iter->second; | |
1974 | i++; | |
1975 | } | |
1976 | msg << ". Actual internet IP: " << ip_host << endl; | |
1977 | ||
1978 | log_notice(msg.str()); | |
1979 | } | |
1980 | } | |
1981 | ||
1982 | ||
1983 | /** | |
1984 | * Print the burnt IP. | |
1985 | * @param ip_host Actual host IP which is burnt. | |
1986 | * @param hostname The service hostname. | |
1987 | */ | |
1988 | void Logger::print_ip_burnt( const std::string& ip_host, const std::string& hostname ) const | |
1989 | { | |
1990 | int level = 0; | |
1991 | if ( level <= Loglevel ) | |
1992 | { | |
1993 | ostringstream msg; | |
1994 | msg << "IP address " << ip_host << " was updated too often in succession, host " << hostname << " blocked until IP Address will be different." << endl; | |
1995 | log_error(msg.str()); | |
1996 | } | |
1997 | } |