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