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