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