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