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