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