Increase log level on SIGRTMAX. Reset it on SIGHUP
[bpdyndnsd] / src / logger.cpp
CommitLineData
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
23namespace po = boost::program_options;
24
92beaba3
BS
25typedef boost::shared_ptr<boost::program_options::options_description> Options_descriptionPtr;
26
8bca3c5d 27using namespace std;
254bbf53
BS
28
29/**
30 * Default Constructor
31 */
32Logger::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 */
45Logger::~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 */
54bool 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 */
65void 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 75void 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*/
89string 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 110void 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 141void 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
154void 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
164void Logger::set_loglevel(const int _loglevel)
165{
166 Loglevel = _loglevel;
167}
168
169
170/**
171 * Getter for member Loglevel.
172 * @return Loglevel.
173 */
b38684ce 174int 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 */
184void 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 194bool Logger::get_syslog() const
8bca3c5d
BS
195{
196 return Syslog;
197}
198
199
200/**
201 * Initialize the logging facility.
202 */
e8787e2e 203void 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 219void 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 236void 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 251void 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 261void 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 275void 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 291void 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 */
306void 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 318void 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 334void 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 350void 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 366void 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 382void 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 398void 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 414void 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 430void 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 446void 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 462void 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 478void 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 494void 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 509void 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 */
523void 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 539void 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 555void 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 573void 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 587void 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 603void 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 618void 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 631void 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 644void 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 */
657void 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 */
670void 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/**
3f39b968
TJ
681 * SIGRTMAX caught.
682 */
683void Logger::print_caught_sigrtmax(int new_loglevel) const
684{
685 int level = 0;
686 if ( level <= Loglevel )
687 {
688 ostringstream msg;
689 msg << "Caught SIGRTMAX. Increasing log level to " << new_loglevel << endl;
690 log_error(msg.str());
691 }
692}
693
694
695/**
8bca3c5d
BS
696 * Error while setting signal handler.
697 */
b38684ce 698void Logger::print_error_setting_signal(const string& signal) const
8bca3c5d 699{
cbbdeb6c 700 int level = 0;
d77313ea 701 if ( level <= Loglevel )
59c8d63c
BS
702 {
703 ostringstream msg;
667c672c 704 msg << "Error while setting signal handler for: " << signal << endl;
ce70569b 705 log_error(msg.str());
59c8d63c 706 }
8bca3c5d
BS
707}
708
709
710/**
711 * Error while setting signal handler.
712 */
b38684ce 713void Logger::print_init_log_facility() const
8bca3c5d 714{
cbbdeb6c 715 int level = 1;
d77313ea 716 if ( level <= Loglevel )
59c8d63c
BS
717 {
718 ostringstream msg;
4475e30a 719 msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << " ExternalLogOnlyOnce: " << ExternalLogOnlyOnce << endl;
ce70569b 720 log_notice(msg.str());
59c8d63c 721 }
8bca3c5d
BS
722}
723
27baf279 724
8bca3c5d
BS
725/**
726 * Be verbose. Currently we are in offline mode.
727 */
b38684ce 728void Logger::print_offline_mode() const
8bca3c5d 729{
60657d55 730 int level = 1;
d77313ea 731 if ( level <= Loglevel )
59c8d63c 732 {
ce70569b 733 log_notice("Offline mode...");
59c8d63c 734 }
8bca3c5d 735}
27baf279
BS
736
737
738/**
739 * Objects successfully serialized.
740 */
b38684ce 741void Logger::print_serialized_objects_success() const
27baf279 742{
cbbdeb6c 743 int level = 1;
d77313ea 744 if ( level <= Loglevel )
27baf279 745 {
ce70569b 746 log_notice("Serialized objects successfully.");
27baf279
BS
747 }
748}
749
750
751/**
752 * Objects successfully de-serialized.
753 */
b38684ce 754void Logger::print_deserialized_objects_success() const
27baf279 755{
cbbdeb6c 756 int level = 1;
d77313ea 757 if ( level <= Loglevel )
27baf279 758 {
ce70569b 759 log_notice("De-serialized objects successfully.");
27baf279
BS
760 }
761}
762
763
5d38cfe6
BS
764/**
765 * Prints out the content of a service object.
766 * @param message Message to be added on output first.
767 * @param protocol Service's protocol.
768 * @param hostname Service's hostname.
769 * @param login Service's login.
770 * @param password Service's password.
771 * @param actual_ip Service's actual_ip.
772 * @param lastupdated Service's lastupdated.
773 */
62df5f33 774void 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 775{
cbbdeb6c 776 int level = 1;
d77313ea 777 if ( level <= Loglevel )
27baf279
BS
778 {
779 ostringstream msg;
780 msg << message << endl;
3c0cd271
BS
781 msg << "\t" << "Protocol: " << protocol << endl;
782 msg << "\t" << "Hostname: " << hostname << endl;
783 msg << "\t" << "Login: " << login << endl;
784 msg << "\t" << "Password: " << password << endl;
785 msg << "\t" << "Update Interval: " << update_interval << endl;
786 msg << "\t" << "Max Updates: " << max_updates_within_interval << endl;
d5a516ba 787 msg << "\t" << "DNS Cache TTL: " << dns_cache_ttl << endl;
3c0cd271 788 msg << "\t" << "Actual_IP: " << actual_ip << endl;
62df5f33 789 BOOST_FOREACH( time_t update_time, lastupdated)
3c0cd271
BS
790 {
791 msg << "\t" << "Lastupdated: " << update_time << endl;
792 }
ce70569b 793 log_notice(msg.str());
27baf279
BS
794 }
795}
5d38cfe6
BS
796
797
798/**
799 * Caught exception while serialize.
800 * @param exception Exception message.
801 */
ce70569b 802void Logger::print_exception_serialize(const string& errMsg) const
5d38cfe6 803{
cbbdeb6c 804 int level = 0;
d77313ea 805 if ( level <= Loglevel )
667c672c
BS
806 {
807 ostringstream msg;
ce70569b
BS
808 msg << "Error while trying to serialize Serviceholder object: " << errMsg << endl;
809 log_error(msg.str());
667c672c
BS
810 }
811}
812
813
814/**
815 * Caught exception while de-serialize.
816 * @param exception Exception message.
817 */
ce70569b 818void Logger::print_exception_deserialize(const string& errMsg) const
667c672c 819{
cbbdeb6c 820 int level = 0;
d77313ea 821 if ( level <= Loglevel )
667c672c
BS
822 {
823 ostringstream msg;
ce70569b
BS
824 msg << "Error while trying to de-serialize Serviceholder object: " << errMsg << endl;
825 log_error(msg.str());
667c672c
BS
826 }
827}
828
829
830/**
831 * Child couldn't be killed by parent.
832 * @param pid Pid of the child.
833 */
b38684ce 834void Logger::print_error_kill_child(const int pid) const
667c672c 835{
cbbdeb6c 836 int level = 0;
d77313ea 837 if ( level <= Loglevel )
667c672c
BS
838 {
839 ostringstream msg;
840 msg << "Could not kill child process with PID: " << pid << endl;
ce70569b 841 log_error(msg.str());
667c672c
BS
842 }
843}
844
845
0665b239
BS
846/**
847 * Child was killed by parent because of error.
848 * @param pid The pid (child) killed.
849 */
b38684ce 850void Logger::print_child_killed(const int pid) const
584b9407 851{
cbbdeb6c 852 int level = 1;
d77313ea 853 if ( level <= Loglevel )
584b9407
BS
854 {
855 ostringstream msg;
856 msg << "Killed child process with PID: " << pid << endl;
ce70569b 857 log_notice(msg.str());
584b9407
BS
858 }
859}
860
861
667c672c
BS
862/**
863 * There is no object file.
864 * @param object_file The object file.
865 */
e8787e2e 866void Logger::print_no_object_file(const string& object_file)
667c672c 867{
cbbdeb6c
BS
868 int level = 1;
869 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
667c672c
BS
870 {
871 ostringstream msg;
872 msg << "There is no object file: " << object_file << ". Continue without recovering state from old services!" << endl;
cbbdeb6c 873 log_warning(msg.str(),level);
667c672c 874 }
5d38cfe6 875}
0665b239
BS
876
877
878/**
879 * Prints out the given hostname
880 * @param hostname Hostname as string.
881 */
e8d4a6f8 882void Logger::print_hostname(const string& hostname) const
0665b239 883{
cbbdeb6c 884 int level = 1;
d77313ea 885 if ( level <= Loglevel )
0665b239
BS
886 {
887 ostringstream msg;
888 msg << "Detected following hostname of localhost: " << hostname << endl;
ce70569b 889 log_notice(msg.str());
0665b239
BS
890 }
891}
892
893
894/**
019dc0d9 895 * Prints out the detected own ipv4 address
0665b239
BS
896 * @param ip_addr String representation of the detected ip.
897 */
c3dea5dc 898void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const
0665b239 899{
cbbdeb6c 900 int level = 1;
d77313ea 901 if ( level <= Loglevel )
0665b239
BS
902 {
903 ostringstream msg;
c3dea5dc 904 msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl;
ce70569b 905 log_notice(msg.str());
019dc0d9
BS
906 }
907}
908
909
910/**
911 * Prints out the detected own ipv5 address
912 * @param ip_addr String representation of the detected ip.
913 */
c3dea5dc 914void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const
019dc0d9 915{
cbbdeb6c 916 int level = 1;
d77313ea 917 if ( level <= Loglevel )
019dc0d9
BS
918 {
919 ostringstream msg;
c3dea5dc 920 msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl;
ce70569b 921 log_notice(msg.str());
0665b239
BS
922 }
923}
924
925
926/**
927 * Exception while trying to resolve hostname to ip.
928 * @param exception The exception caught.
929 * @param hostname The hostname.
930 */
ce70569b 931void Logger::print_error_hostname_to_ip(const string& errMsg, const string& hostname) const
0665b239 932{
a03fb896 933 int level = 0;
d77313ea 934 if ( level <= Loglevel )
0665b239
BS
935 {
936 ostringstream msg;
ce70569b 937 msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << errMsg << endl;
e8787e2e 938 log_error(msg.str());
0665b239
BS
939 }
940}
68c6b4af
BS
941
942
1c0908b5
BS
943/**
944 * The update of the given service was successful.
945 * @param service The service.
946 */
947void Logger::print_update_service_successful(const string& service) const
68c6b4af 948{
cbbdeb6c 949 int level = 0;
d77313ea 950 if ( level <= Loglevel )
68c6b4af
BS
951 {
952 ostringstream msg;
953 msg << "Updated service successful: " << service << endl;
ce70569b 954 log_notice(msg.str());
1c0908b5
BS
955 }
956}
957
958
959/**
960 * No ip could be determined through webcheck
961 */
e8787e2e 962void Logger::print_webcheck_no_ip()
1c0908b5 963{
cbbdeb6c
BS
964 int level = 0;
965 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1c0908b5 966 {
20cc3887 967 log_warning("IP-Address of this host could not be determined through any configured webcheck url.",level);
1c0908b5
BS
968 }
969}
970
971
972/**
973 * Connection problem while trying to get ip through webcheck url
974 * @param curl_err_buff Curl error message
975 * @param url the url
976 */
e8787e2e 977void Logger::print_webcheck_url_connection_problem(const char * curl_err_buff, const string& url)
1c0908b5 978{
cbbdeb6c
BS
979 int level = 1;
980 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1c0908b5
BS
981 {
982 ostringstream msg;
983 msg << "There was a problem while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
cbbdeb6c 984 log_warning(msg.str(),level);
1c0908b5
BS
985 }
986}
987
988
989/**
990 * Prints out curl error.
991 * @param curl_err_buff Curl error message.
992 * @param url URL
993 */
994void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const
995{
cbbdeb6c 996 int level = 0;
d77313ea 997 if ( level <= Loglevel )
1c0908b5
BS
998 {
999 ostringstream msg;
1000 msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
ce70569b 1001 log_error(msg.str());
68c6b4af
BS
1002 }
1003}
1c0908b5
BS
1004
1005
1006/**
1007 * Prints out the received data through curl.
1008 * @param curl_data Data string
1009 */
1010void Logger::print_received_curl_data(const string& curl_data) const
1011{
cbbdeb6c 1012 int level = 1;
d77313ea 1013 if ( level <= Loglevel )
1c0908b5
BS
1014 {
1015 ostringstream msg;
1016 msg << "Received CURL data: " << curl_data << endl;
ce70569b 1017 log_notice(msg.str());
1c0908b5
BS
1018 }
1019}
1020
1021
1022/**
1023 * IP was foudn through regex
1024 * @param ip The IP found.
1025 */
1026void Logger::print_regex_found_ip(const string& ip) const
1027{
cbbdeb6c 1028 int level = 1;
d77313ea 1029 if ( level <= Loglevel )
1c0908b5
BS
1030 {
1031 ostringstream msg;
1032 msg << "Found IP-Address via regex: " << ip << endl;
ce70569b 1033 log_notice(msg.str());
1c0908b5
BS
1034 }
1035}
1036
1037
1038/**
1039 * No IP was found through regex.
1040 * @param data The data string which should contain a valid IP.s
1041 */
e8787e2e 1042void Logger::print_regex_ip_not_found(const string& data)
1c0908b5 1043{
efbde536 1044 int level = 1;
cbbdeb6c 1045 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1c0908b5
BS
1046 {
1047 ostringstream msg;
1048 msg << "Could not extract an IP-Address via regex from following data:\n" << data << endl;
cbbdeb6c 1049 log_warning(msg.str(),level);
1c0908b5
BS
1050 }
1051}
3c0cd271
BS
1052
1053
1054/**
1055 * Detected multiple occurrences of the same option.
1056 * @param message Error message.
1057 */
1058void Logger::print_multiple_cmd_option(const string& message) const
1059{
cbbdeb6c 1060 int level = 0;
d77313ea 1061 if ( level <= Loglevel )
3c0cd271
BS
1062 {
1063 ostringstream msg;
1064 msg << "The same option is only allowed once: " << message << endl;
ce70569b 1065 log_error(msg.str());
3c0cd271
BS
1066 }
1067}
1068
1069
1070/**
1071 * An update would exceed the update interval. Prints out a warning message.
1072 * @param current_time Current time.
1073 * @param old_time Time of update #MaxUpdatesWithinInterval ago.
1074 * @param MaxUpdatesWithinInterval Number of allowed updates in one update interval.
1075 * @param service The service which exceeds update interval.
1076 */
e8787e2e 1077void Logger::print_update_not_allowed(const time_t current_time, const time_t old_time, const int MaxUpdatesWithinInterval, const string& service)
3c0cd271 1078{
efbde536 1079 int level = 1;
cbbdeb6c 1080 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
3c0cd271
BS
1081 {
1082 ostringstream msg;
1083 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 1084 log_warning(msg.str(),level);
3c0cd271
BS
1085 }
1086}
1087
1088
1089/**
1090 * Failure while running update for service.
1091 * @param service Services' name.
1092 */
e8787e2e 1093void Logger::print_update_service_failure(const string& service)
3c0cd271 1094{
cbbdeb6c
BS
1095 int level = 0;
1096 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
3c0cd271
BS
1097 {
1098 ostringstream msg;
1099 msg << "Could not update service: " << service << endl;
cbbdeb6c 1100 log_warning(msg.str(),level);
3c0cd271
BS
1101 }
1102}
e304c27b 1103
e38d7604
TJ
1104/**
1105 * Start message
1106 */
1107void Logger::print_started() const
1108{
1109 int level = 0;
1110 if ( level <= Loglevel )
1111 {
1112 log_notice("Started");
1113 }
1114}
1115
e304c27b
BS
1116
1117/**
1118 * Starting shutdown
1119 */
1120void Logger::print_starting_shutdown() const
1121{
cbbdeb6c 1122 int level = 0;
d77313ea 1123 if ( level <= Loglevel )
e304c27b 1124 {
ce70569b 1125 log_notice("Shutting down ...");
e304c27b
BS
1126 }
1127}
1128
1129
1130/**
1131 * Shutdown complete
1132 */
1133void Logger::print_shutdown_succeeded() const
1134{
cbbdeb6c 1135 int level = 0;
d77313ea 1136 if ( level <= Loglevel )
e304c27b 1137 {
ce70569b 1138 log_notice("Shutting down complete ...");
e304c27b
BS
1139 }
1140}
1141
1142
1143/**
1144 * Shutdown parent succeeded
1145 */
1146void Logger::print_shutdown_parent_succeeded() const
1147{
cbbdeb6c 1148 int level = 0;
d77313ea 1149 if ( level <= Loglevel )
e304c27b 1150 {
ce70569b 1151 log_notice("Shutting down parent process completed ...");
e304c27b
BS
1152 }
1153}
1154
1155
1156/**
1157 * Starting shutdown parent
1158 */
1159void Logger::print_starting_shutdown_parent() const
1160{
cbbdeb6c 1161 int level = 0;
d77313ea 1162 if ( level <= Loglevel )
e304c27b 1163 {
ce70569b 1164 log_notice("Shutting down parent process ...");
e304c27b
BS
1165 }
1166}
0541cd71
BS
1167
1168
1169/**
1170 * DNS cache record timeout
1171 * @param hostname Hostname
1172 * @param lastupdated Lastupdated
1173 * @param dns_cache_ttl DNS cache TTL
1174 * @param current_time Current time
1175 */
8a00a649 1176void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
0541cd71 1177{
cbbdeb6c 1178 int level = 1;
d77313ea 1179 if ( level <= Loglevel )
0541cd71
BS
1180 {
1181 ostringstream msg;
d5a516ba 1182 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 1183 log_notice(msg.str());
0541cd71
BS
1184 }
1185}
1186
1187
1188/**
8a00a649
BS
1189 * Missing proxy option on command line.
1190 */
1191void Logger::print_missing_cmd_proxy_option() const
1192{
cbbdeb6c 1193 int level = 0;
d77313ea 1194 if ( level <= Loglevel )
8a00a649 1195 {
ce70569b 1196 log_error("Missing option to initialize proxy. http_proxy and http_proxy_port must be specified.");
8a00a649
BS
1197 }
1198}
1199
1200
1201/**
1202 * Multiple option in service config file.
1203 * @param service_conf_file Service config file
1204 * @param message Multiple option text
1205 */
1206void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const
1207{
cbbdeb6c 1208 int level = 0;
d77313ea 1209 if ( level <= Loglevel )
8a00a649
BS
1210 {
1211 ostringstream msg;
1212 msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl;
ce70569b 1213 log_error(msg.str());
8a00a649
BS
1214 }
1215}
1216
1217
1218/**
1219 * Multiple option in main config file.
1220 * @param service_conf_file Service config file
1221 * @param message Multiple option text
1222 */
1223void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const
1224{
cbbdeb6c 1225 int level = 0;
d77313ea 1226 if ( level <= Loglevel )
8a00a649
BS
1227 {
1228 ostringstream msg;
1229 msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl;
ce70569b 1230 log_error(msg.str());
8a00a649
BS
1231 }
1232}
1233
1234
1235/**
1236 * Missing proxy option in main config file.
2dd2db3e 1237 * @param main_conf_filename The concerning config file.
8a00a649
BS
1238 */
1239void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const
1240{
cbbdeb6c 1241 int level = 0;
d77313ea 1242 if ( level <= Loglevel )
8a00a649
BS
1243 {
1244 ostringstream msg;
1245 msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl;
ce70569b 1246 log_error(msg.str());
8a00a649
BS
1247 }
1248}
2dd2db3e
BS
1249
1250
1251/**
1252 * There is no domain part in the given hostname
1253 * @param hostname The hostname with no domain part in it.
1254 */
d5a516ba 1255void Logger::print_no_domain_part(const string& hostname) const
2dd2db3e
BS
1256{
1257 int level = 0;
d77313ea 1258 if ( level <= Loglevel )
2dd2db3e
BS
1259 {
1260 ostringstream msg;
1261 msg << "There is no domain part in the given hostname: " << hostname << endl;
ce70569b 1262 log_notice(msg.str());
2dd2db3e
BS
1263 }
1264}
d5a516ba
BS
1265
1266
1267/**
31af6a2e
BS
1268 * Service is not initialized properly.
1269 * @param service The service.
1270 */
e8787e2e 1271void Logger::print_httphelper_not_initialized() const
31af6a2e
BS
1272{
1273 int level = 0;
1274 if ( level <= Loglevel )
1275 {
e8787e2e 1276 log_error("HTTP-Helper is not initialized properly.");
31af6a2e
BS
1277 }
1278}
1279
1280
1281/**
1282 * An curl error occured.
1283 * @param msg The error message
1284 * @param curl_err_code The resulting curl error code
1285 */
c730deea 1286void Logger::print_curl_error_init(const std::string& err_msg, const CURLcode curl_err_code) const
31af6a2e
BS
1287{
1288 string curl_err = "";
1289
1290 if ( curl_err_code == CURLE_FAILED_INIT )
1291 curl_err = "CURLE_FAILED_INIT";
1292 else
1293 curl_err = "UNKNOWN";
1294
1295 int level = 0;
e8787e2e 1296 if ( (level <= Loglevel) )
31af6a2e
BS
1297 {
1298 ostringstream msg;
557b6f56 1299 msg << "Curl error: " << err_msg << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
ce70569b 1300 log_error(msg.str());
31af6a2e
BS
1301 }
1302}
1303
1304
1305/**
d5a516ba
BS
1306 * An curl error occured.
1307 * @param url The url requested by the curl operation
1308 * @param curl_err_code The resulting curl error code
1309 */
31af6a2e 1310void Logger::print_curl_error(const string& url, const CURLcode curl_err_code) const
d5a516ba
BS
1311{
1312 string curl_err = "";
1313
31af6a2e 1314 if ( curl_err_code == CURLE_URL_MALFORMAT )
d5a516ba 1315 curl_err = "CURLE_URL_MALFORMAT";
31af6a2e 1316 else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST )
d5a516ba 1317 curl_err = "CURLE_COULDNT_RESOLVE_HOST";
31af6a2e 1318 else if ( curl_err_code == CURLE_COULDNT_CONNECT )
d5a516ba
BS
1319 curl_err = "CURLE_COULDNT_CONNECT";
1320 else
1321 curl_err = "UNKNOWN";
1322
1323 int level = 0;
e8787e2e 1324 if ( (level <= Loglevel) )
d5a516ba
BS
1325 {
1326 ostringstream msg;
557b6f56 1327 msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << endl; /*lint !e641 */
e8787e2e 1328 log_error(msg.str());
d5a516ba
BS
1329 }
1330}
1331
1332
1333/**
1334 * An curl error occured.
1335 * @param url The url requested by the curl operation
1336 * @param curl_err_code The resulting curl error code
1337 * @param curl_err_buff The curl error buffer
1338 */
c730deea 1339void Logger::print_curl_error(const string& url, const CURLcode curl_err_code, const char * curl_err_buff) const
d5a516ba
BS
1340{
1341 string curl_err = "";
1342
c730deea 1343 if ( curl_err_code == CURLE_URL_MALFORMAT )
d5a516ba 1344 curl_err = "CURLE_URL_MALFORMAT";
c730deea 1345 else if ( curl_err_code == CURLE_COULDNT_RESOLVE_HOST )
d5a516ba 1346 curl_err = "CURLE_COULDNT_RESOLVE_HOST";
c730deea 1347 else if ( curl_err_code == CURLE_COULDNT_CONNECT )
d5a516ba
BS
1348 curl_err = "CURLE_COULDNT_CONNECT";
1349 else
1350 curl_err = "UNKNOWN";
1351
1352 int level = 0;
e8787e2e 1353 if ( (level <= Loglevel) )
d5a516ba
BS
1354 {
1355 ostringstream msg;
557b6f56 1356 msg << "Curl error while requesting following url: " << url << " Curl error code: " << curl_err_code << " " << curl_err << " " << curl_err_buff << endl; /*lint !e641 */
e8787e2e 1357 log_error(msg.str());
d5a516ba
BS
1358 }
1359}
1360
1361
1362/**
1363 * Prints out the data received by curl operation
43f4565e 1364 * @param CurlWritedataBuff
d5a516ba
BS
1365 */
1366void Logger::print_curl_data(const string& curl_writedata_buff) const
1367{
1368 int level = 1;
d77313ea 1369 if ( level <= Loglevel )
d5a516ba
BS
1370 {
1371 ostringstream msg;
b6228761 1372 msg << "Data received by curl: " << curl_writedata_buff << endl;
ce70569b 1373 log_notice(msg.str());
d5a516ba
BS
1374 }
1375}
1376
1377
1378/**
a03fb896
BS
1379 * Not authorized to perform requested update operation
1380 * @param service The requested service.
d5a516ba
BS
1381 * @param username Username
1382 * @param password Password
1383 */
a03fb896 1384void Logger::print_service_not_authorized(const string& service, const string& username, const string& password) const
d5a516ba
BS
1385{
1386 int level = 0;
e8787e2e 1387 if ( level <= Loglevel )
d5a516ba
BS
1388 {
1389 ostringstream msg;
a03fb896 1390 msg << "Not authorized to perform update operation on service: " << service << " Please check username and password: " << username << ":" << password << endl;
e8787e2e 1391 log_notice(msg.str());
d5a516ba
BS
1392 }
1393}
1394
1395
1396/**
1397 * Prints out the http status code
1398 * @param url Url
1399 * @param output HTTP status code
1400 */
1af7c124 1401void Logger::print_http_status_code(const string& url, const long http_code) const
d5a516ba
BS
1402{
1403 int level = 1;
d77313ea 1404 if ( level <= Loglevel )
d5a516ba
BS
1405 {
1406 ostringstream msg;
1407 msg << "Requested URL: " << url << " Received HTTP status code: " << http_code << endl;
ce70569b 1408 log_notice(msg.str());
d5a516ba
BS
1409 }
1410}
b6228761
BS
1411
1412
1413/**
1414 * Generic failure while trying to update service
1415 * @param url The requested URL
1416 * @param curl_data The received curl_data from the server
1417 */
1418void Logger::print_update_failure(const string& url, const string& curl_data) const
1419{
1420 int level = 0;
e8787e2e 1421 if ( (level <= Loglevel) )
b6228761
BS
1422 {
1423 ostringstream msg;
1424 msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << curl_data << endl;
e8787e2e 1425 log_error(msg.str());
b6228761
BS
1426 }
1427}
1a00eac6
BS
1428
1429
1430/**
b17fd691
BS
1431 * Generic failure while trying to update service
1432 * @param url The requested URL
1433 * @param http_status_code The received http status code
1434 */
1435void Logger::print_update_failure(const string& url, const long http_status_code) const
1436{
1437 int level = 0;
e8787e2e 1438 if ( level <= Loglevel )
b17fd691
BS
1439 {
1440 ostringstream msg;
1441 msg << "Problem while trying to updating service. Requested URL: " << url << " Error Code from Server: " << http_status_code << endl;
e8787e2e 1442 log_error(msg.str());
b17fd691
BS
1443 }
1444}
1445
1446/**
1a00eac6 1447 * Hostname is invalid, contains no or only one domain part.
43f4565e 1448 * @param hostname The full qualified host name.
1a00eac6 1449 */
e8787e2e 1450void Logger::print_invalid_hostname(const string& hostname)
1a00eac6
BS
1451{
1452 int level = 0;
1453 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1454 {
1455 ostringstream msg;
1456 msg << "The configured hostname: " << hostname << " is invalid. Please add the corresponding domain part." << endl;
1457 log_warning(msg.str(),level);
1458 }
1459}
4ef36a12
BS
1460
1461
1462/**
1463 * An IP in a private range was detected
1464 * @param ip The private IP
1465 */
e8787e2e 1466void Logger::print_ip_is_local(const string& ip)
4ef36a12 1467{
60657d55 1468 int level = 1;
4ef36a12
BS
1469 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1470 {
1471 ostringstream msg;
1472 msg << "The detected IP is within a private IP range: " << ip << endl;
1473 log_warning(msg.str(),level);
1474 }
1475}
1476
1477
1478/**
1479 * Regex is matching in string
1480 * @param regex The regex pattern
1481 * @param matching_string The string
1482 */
a78b44b5 1483void Logger::print_regex_match(const string& regex, const string& matching_string) const
4ef36a12
BS
1484{
1485 int level = 1;
d77313ea 1486 if ( level <= Loglevel )
4ef36a12
BS
1487 {
1488 ostringstream msg;
1489 msg << "Regex: " << regex << " is matching in: " << matching_string << endl;
ce70569b 1490 log_notice(msg.str());
4ef36a12
BS
1491 }
1492}
a78b44b5
BS
1493
1494
1495/**
1496 * Regex is not matching
1497 * @param regex Regex
1498 * @param not_matching_string String
1499 */
e8787e2e 1500void Logger::print_no_regex_match(const string& regex, const string& not_matching_string)
a78b44b5
BS
1501{
1502 int level = 1;
1503 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1504 {
1505 ostringstream msg;
1506 msg << "Regex: " << regex << " is not matching in: " << not_matching_string << endl;
1507 log_warning(msg.str(),level);
1508 }
1509}
1510
1511
1512/**
1513 * Could not parse gnudip initial reply.
1514 * @param curl_data The data received from gnudip server which should contain salt, time and sign.
1515 */
1516void Logger::print_could_not_parse_received_data(const string& curl_data) const
1517{
1518 int level = 0;
e8787e2e 1519 if ( (level <= Loglevel) )
a78b44b5
BS
1520 {
1521 ostringstream msg;
1522 msg << "Could not parse salt, time and sign from initial gnudip server reply: " << curl_data << endl;
e8787e2e 1523 log_error(msg.str());
a78b44b5
BS
1524 }
1525}
1526
1527
1528/**
1529 * Gnudip salt, time and sign could not be got from map
1530 */
1531void Logger::print_could_not_get_initial_gnudip_data() const
1532{
1533 int level = 0;
e8787e2e 1534 if ( (level <= Loglevel) )
a78b44b5 1535 {
e8787e2e 1536 log_error("Could not get salt, time and sign from map.");
a78b44b5
BS
1537 }
1538}
1539
1540
a2f5be94
BS
1541
1542/**
1543 * Gnudip protocol requires explicit declaration of a servername.
1544 */
e8787e2e 1545void Logger::print_gnudip_requires_servername()
a78b44b5
BS
1546{
1547 int level = 0;
1548 if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
1549 {
20cc3887 1550 log_warning("Gnudip requires explicit definition of servername via config!",level);
a78b44b5
BS
1551 }
1552}
a2f5be94
BS
1553
1554
1555/**
1556 * An exception occured while computing the md5 sum.
1557 * @param what The exception occured.
1558 */
c1b8cb79 1559void Logger::print_exception_md5_sum(const string& what) const
a2f5be94
BS
1560{
1561 int level = 0;
d77313ea 1562 if ( level <= Loglevel )
a2f5be94
BS
1563 {
1564 ostringstream msg;
1565 msg << "An exception occured while computing a md5 sum: " << what << endl;
ce70569b 1566 log_error(msg.str());
a2f5be94
BS
1567 }
1568}
a03fb896
BS
1569
1570
1571/**
1572 * An network exception occured.
1573 * @param what The exception occured.
1574 */
c1b8cb79 1575void Logger::print_network_error(const string& what) const
a03fb896
BS
1576{
1577 int level = 0;
d77313ea 1578 if ( level <= Loglevel )
a03fb896
BS
1579 {
1580 ostringstream msg;
1581 msg << "An netowrk exception occured: " << what << endl;
ce70569b 1582 log_error(msg.str());
a03fb896
BS
1583 }
1584}
1585
1586
1587/**
1588 * An undefined protocol error occured.
1589 * @param protocol The protocol
1590 * @param error The error
1591 */
c1b8cb79 1592void Logger::print_undefined_protocol_error(const string& protocol, const string& error) const
a03fb896
BS
1593{
1594 int level = 0;
d77313ea 1595 if ( level <= Loglevel )
a03fb896
BS
1596 {
1597 ostringstream msg;
1598 msg << "An undefined protocol error occured. Protocol: " << protocol << " Error: " << error << endl;
ce70569b 1599 log_error(msg.str());
a03fb896
BS
1600 }
1601}
d77313ea
BS
1602
1603/**
1604 * Error while trying to log through external program.
1605 * @param external_prog The external program called.
1606 */
c1b8cb79 1607void Logger::print_error_external_logging(const string& external_prog) const
d77313ea
BS
1608{
1609 int level = 0;
1610 if ( level <= Loglevel )
1611 {
1612 ostringstream msg;
1613 msg << "Error while trying to log through external program: " << external_prog << endl;
ce70569b 1614 log_notice(msg.str());
d77313ea
BS
1615 }
1616}
c1b8cb79
BS
1617
1618
1619/**
1620 * Error while parsing config file.
1621 * @param error Error occured.
1622 * @param config_file Config file.
1623 */
1624void Logger::print_error_parsing_config_file(const string& filename, const string& error) const
1625{
1626 int level = 0;
1627 if ( level <= Loglevel )
1628 {
1629 ostringstream msg;
1630 msg << "Error while parsing config file: " << filename << " Error: " << error << endl;
ce70569b 1631 log_notice(msg.str());
c1b8cb79
BS
1632 }
1633}
1634
1635
1636/**
1637 * Error while parsing cmd option
1638 * @param error Error
1639 */
1640void Logger::print_error_parsing_cmd(const string& error) const
1641{
1642 int level = 0;
1643 if ( level <= Loglevel )
1644 {
1645 ostringstream msg;
1646 msg << "Error while parsing cmd options: " << error << endl;
ce70569b 1647 log_error(msg.str());
c1b8cb79
BS
1648 }
1649}
2b0f7c11
BS
1650
1651
1652/**
1653 * The webcheck interval was exceeded, so webcheck not allowed.
1654 * @param last_webcheck Time of last webcheck.
1655 * @param webcheck_interval Webcheck interval time.
1656 * @param current_time Current system time.
1657 */
c730deea 1658void Logger::print_webcheck_exceed_interval( const time_t last_webcheck, const int webcheck_interval, const time_t current_time ) const
2b0f7c11 1659{
60657d55 1660 int level = 1;
2b0f7c11
BS
1661 if ( level <= Loglevel )
1662 {
1663 ostringstream msg;
1664 msg << "Exceeding webcheck interval: LastWebcheck " << last_webcheck << " + WebcheckInterval(sec) " << webcheck_interval << " >= CurrentTime " << current_time << endl;
ce70569b 1665 log_notice(msg.str());
2b0f7c11
BS
1666 }
1667}
1af7c124
BS
1668
1669
1670/**
1671 * Checking if hosts needs update.
1672 * @param hostname Hostname
1673 * @param current_time Current time
1674 * @param lastupdated Last updated
1675 */
c730deea 1676void Logger::print_check_service_update(const string& hostname, const time_t current_time, const time_t lastupdated) const
1af7c124
BS
1677{
1678 int level = 1;
1679 if ( level <= Loglevel )
1680 {
1681 ostringstream msg;
1682 msg << "Checking if host: " << hostname << " needs update. Current time: " << current_time << " Last updated: " << lastupdated << endl;
ce70569b 1683 log_notice(msg.str());
1af7c124
BS
1684 }
1685}
1686
1687
1688/**
1689 * Cached DNS entry
1690 * @param hostname Hostname
1691 * @param ip_dns_recheck DNS recheck IP
1692 * @param ip_last_update IP set in last update
1693 * @param ip_host Hosts' IP
1694 */
1695void Logger::print_cached_dns_entry(const string& hostname, const string& ip_dns_recheck, const string& ip_last_update, const string& ip_host) const
1696{
1697 int level = 1;
1698 if ( level <= Loglevel )
1699 {
1700 ostringstream msg;
1701 msg << "Cached DNS record for host <" << hostname << "> : " << ip_dns_recheck << " Last updated IP: " << ip_last_update << " Hosts IP: " << ip_host << endl;
ce70569b 1702 log_notice(msg.str());
1af7c124
BS
1703 }
1704}
1705
1706
1707/**
1af7c124
BS
1708 * Updating service
1709 * @param hostname Hostname
1710 * @param ip_dns_recheck Cached DNS entry
1711 * @param ip_last_update IP set in last update
1712 * @param ip_host Hosts IP
1713 * @param lastupdated Lastupdated
1714 */
08a5a621 1715void 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
1716 int level = 1;
1717 if ( level <= Loglevel )
1718 {
1719 ostringstream msg;
1720 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 1721 log_notice(msg.str());
1af7c124
BS
1722 }
1723}
1724
1725
1726/**
1727 * TTL expired
1728 * @param hostname Hostname
1729 * @param ip_dns_recheck Cached DNS entry
1730 * @param ip_last_update IP set in last update
1731 * @param ip_host Hosts IP
1732 * @param lastupdated Last updated
1733 * @param dns_cache_ttl DNS cache ttl
1734 * @param current_time Current time
1735 */
08a5a621 1736void 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
1737{
1738 int level = 1;
1739 if ( level <= Loglevel )
1740 {
1741 ostringstream msg;
1742 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 1743 log_notice(msg.str());
1af7c124
BS
1744 }
1745}
1746
1747
1748/**
1749 * TTL expired
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 * @param dns_cache_ttl DNS cache ttl
1757 * @param current_time Current time
1758 */
d55e13a6 1759void 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
1760{
1761 int level = 1;
d55e13a6
TJ
1762
1763 if (override_log_level)
1764 level = 0;
1765
1af7c124
BS
1766 if ( level <= Loglevel )
1767 {
1768 ostringstream msg;
1769 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 1770 log_notice(msg.str());
1af7c124
BS
1771 }
1772}
1773
1774
1775/**
1776 * No update needed
d55e13a6 1777 * @param override_log_level Override log level with zero if true
1af7c124
BS
1778 * @param hostname Hostname
1779 * @param ip_dns_recheck Cached DNS entry
1780 * @param ip_last_update IP set in last update
1781 * @param ip_host Hosts IP
1782 * @param lastupdated Last updated
1783 */
d55e13a6 1784void 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
1785{
1786 int level = 1;
d55e13a6
TJ
1787
1788 if (override_log_level)
1789 level = 0;
1790
1af7c124
BS
1791 if ( level <= Loglevel )
1792 {
1793 ostringstream msg;
1794 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 1795 log_notice(msg.str());
1af7c124
BS
1796 }
1797}
1d2e2f56
BS
1798
1799
1800/**
1801 * Error while trying to get local wan interface IP address through getifaddrs.
1802 * @param error The system call which raised the error.
1803 * @param error The error set by getifaddrs.
1804 */
1805void Logger::print_error_getting_local_wan_ip(const std::string& system_call, const std::string& error) const
1806{
1807 int level = 0;
1808 if ( level <= Loglevel )
1809 {
1810 ostringstream msg;
1811 msg << "Error while trying to get local wan interface IP address through '" << system_call << "': " << error << endl;
ce70569b 1812 log_error(msg.str());
1d2e2f56
BS
1813 }
1814}
1815
1816
1817/**
1818 * Could not get IP address of local wan interface.
f3141675
TJ
1819 * @param override_log_level Override log level with zero if true
1820 */
1821void Logger::print_no_wan_ip(bool override_log_level) const
1822{
1823 int level = 1;
1824
1825 if (override_log_level)
1826 level = 0;
1827
1828 if ( level <= Loglevel )
1829 {
1830 ostringstream msg;
1831 msg << "Could not get IP address of local wan interface. Will retry later." << endl;
1832 log_error(msg.str());
1833 }
1834}
1835
62956d9a
TJ
1836/**
1837 * Print extenral WAN IP
1838 * @param override_log_level Override log level with zero if true
1839 * @param ip External WAN IP
1840 */
1841void Logger::print_external_wan_ip(bool override_log_level, const std::string &ip) const
1842{
1843 int level = 1;
1844
1845 if (override_log_level)
1846 level = 0;
1847
1848 if ( level <= Loglevel )
1849 {
1850 ostringstream msg;
1851 msg << "Determined WAN interface IP: " << ip << endl;
1852 log_error(msg.str());
1853 }
1854}
f3141675
TJ
1855
1856/**
1857 * Could not resolve current IP for DNS name
1858 * @param override_log_level Override log level with zero if true
1d2e2f56 1859 */
f3141675 1860void Logger::print_dns_lookup_failed(bool override_log_level, const std::string &hostname) const
1d2e2f56 1861{
60657d55 1862 int level = 1;
f3141675
TJ
1863
1864 if (override_log_level)
1865 level = 0;
1866
1d2e2f56
BS
1867 if ( level <= Loglevel )
1868 {
1869 ostringstream msg;
f3141675 1870 msg << "Could not resolve IP address for host " << hostname << ". Will retry later." << endl;
ce70569b 1871 log_error(msg.str());
1d2e2f56
BS
1872 }
1873}
60657d55
BS
1874
1875
1876/**
1877 * Invalid service config was detected.
1878 */
1879void Logger::print_invalid_service_config() const
1880{
1881 int level = 0;
1882 if ( level <= Loglevel )
1883 {
1884 log_error("Ignoring invalid service. Please check.\n");
1885 }
1886}
4475e30a
BS
1887
1888
1889/**
1890 * Print simple message.
1891 */
1892void Logger::print_msg( const string& msg ) const
1893{
1894 int level = 0;
1895 if ( level <= Loglevel )
1896 {
1897 log_error(msg);
1898 }
1899}