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