158158#include <string.h>
159159#endif
160160
161+ #include <stdarg.h>
162+
161163// specify event broker API version (required)
162164NEB_API_VERSION (CURRENT_NEB_API_VERSION );
163165
@@ -195,12 +197,23 @@ int statusengine_handle_data(int, void *);
195197void dump_object_data ();
196198
197199
198- void logswitch (int level , char * message ){
200+ void logswitch (int level , char * message , ...){
201+ char buffer [65536 ];
202+ va_list ap ;
203+
204+ // always prepend
205+ snprintf (buffer , 15 , "statusengine: " );
206+
207+ // easier logging with sprintf
208+ va_start (ap , message );
209+ vsnprintf ( buffer + strlen ( buffer ), sizeof ( buffer ) - strlen ( buffer ), message , ap );
210+ va_end ( ap );
211+
199212#ifdef NAGIOS
200- write_to_all_logs (message , level );
213+ write_to_all_logs (buffer , level );
201214#endif
202215#if defined NAEMON || defined NAEMON105 || defined NAEMONMASTER
203- nm_log (level , "%s" , message );
216+ nm_log (level , "%s" , buffer );
204217#endif
205218}
206219
@@ -260,7 +273,7 @@ int statusengine_process_module_args(char *args);
260273int statusengine_create_client () {
261274 // Create gearman client
262275 if (gearman_client_create (& gman_client ) == NULL ){
263- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Memory allocation failure on client creation\n" );
276+ logswitch (NSLOG_INFO_MESSAGE , "statusengine_create_client() Memory allocation failure on client creation\n" );
264277 }
265278
266279 gearman_return_t ret = gearman_client_add_server (& gman_client , gearman_server_addr , gearman_server_port );
@@ -301,20 +314,19 @@ int nebmodule_init(int flags, char *args, nebmodule *handle){
301314 neb_set_module_info (statusengine_module_handle , NEBMODULE_MODINFO_DESC , "A powerful and flexible event broker" );
302315
303316 //Welcome messages
304- logswitch (NSLOG_INFO_MESSAGE , "Statusengine - the missing event broker" );
305- logswitch (NSLOG_INFO_MESSAGE , "Statusengine - the missing event broker" );
306- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Copyright (c) 2014 - present Daniel Ziegler <daniel@statusengine.org>" );
307- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Please visit https://www.statusengine.org for more information" );
308- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Contribute to Statusenigne at: https://github.com/nook24/statusengine" );
309- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Thanks for using Statusengine :-)" );
317+ logswitch (NSLOG_INFO_MESSAGE , "the missing event broker" );
318+ logswitch (NSLOG_INFO_MESSAGE , "Copyright (c) 2014 - present Daniel Ziegler <daniel@statusengine.org>" );
319+ logswitch (NSLOG_INFO_MESSAGE , "Please visit https://www.statusengine.org for more information" );
320+ logswitch (NSLOG_INFO_MESSAGE , "Contribute to Statusenigne at: https://github.com/nook24/statusengine" );
321+ logswitch (NSLOG_INFO_MESSAGE , "Thanks for using Statusengine :-)" );
310322
311323 if (statusengine_process_module_args (args ) == ERROR ) {
312- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] An error occurred while attempting to process module arguments." );
324+ logswitch (NSLOG_INFO_MESSAGE , "An error occurred while attempting to process module arguments." );
313325 return ERROR ;
314326 }
315327
316328 //Register callbacks
317- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Register callbacks" );
329+ logswitch (NSLOG_INFO_MESSAGE , "Register callbacks" );
318330 neb_register_callback (NEBCALLBACK_HOST_STATUS_DATA , statusengine_module_handle , 0 , statusengine_handle_data );
319331 neb_register_callback (NEBCALLBACK_SERVICE_STATUS_DATA , statusengine_module_handle , 0 , statusengine_handle_data );
320332 neb_register_callback (NEBCALLBACK_PROCESS_DATA , statusengine_module_handle , 0 , statusengine_handle_data );
@@ -346,7 +358,7 @@ int nebmodule_init(int flags, char *args, nebmodule *handle){
346358int nebmodule_deinit (int flags , int reason ){
347359
348360 // Deregister all callbacks
349- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Deregister callbacks" );
361+ logswitch (NSLOG_INFO_MESSAGE , "Deregister callbacks" );
350362 neb_deregister_callback (NEBCALLBACK_HOST_STATUS_DATA , statusengine_handle_data );
351363 neb_deregister_callback (NEBCALLBACK_SERVICE_STATUS_DATA , statusengine_handle_data );
352364 neb_deregister_callback (NEBCALLBACK_PROCESS_DATA , statusengine_handle_data );
@@ -367,8 +379,8 @@ int nebmodule_deinit(int flags, int reason){
367379 neb_deregister_callback (NEBCALLBACK_CONTACT_NOTIFICATION_METHOD_DATA , statusengine_handle_data );
368380 neb_deregister_callback (NEBCALLBACK_EVENT_HANDLER_DATA , statusengine_handle_data );
369381
370- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] We are done here" );
371- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Bye" );
382+ logswitch (NSLOG_INFO_MESSAGE , "We are done here" );
383+ logswitch (NSLOG_INFO_MESSAGE , "Bye" );
372384
373385 //Delete gearman client
374386 gearman_client_free (& gman_client );
@@ -409,82 +421,82 @@ int statusengine_process_config_var(char *arg) {
409421 /* process the variable... */
410422 if (!strcmp (var , "use_host_status_data" )) {
411423 use_host_status_data = atoi (val );
412- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled host_status_data" );
424+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled host_status_data" );
413425 } else if (!strcmp (var , "use_service_status_data" )) {
414426 use_service_status_data = atoi (val );
415- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled service_status_data" );
427+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled service_status_data" );
416428 } else if (!strcmp (var , "use_process_data" )) {
417429 use_process_data = atoi (val );
418- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled process_data" );
430+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled process_data" );
419431 } else if (!strcmp (var , "use_service_check_data" )) {
420432 use_service_check_data = atoi (val );
421- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled service_check_data" );
433+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled service_check_data" );
422434 } else if (!strcmp (var , "use_host_check_data" )) {
423435 use_host_check_data = atoi (val );
424- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled host_check_data" );
436+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled host_check_data" );
425437 } else if (!strcmp (var , "use_state_change_data" )) {
426438 use_state_change_data = atoi (val );
427- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled state_change_data" );
439+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled state_change_data" );
428440 } else if (!strcmp (var , "use_log_data" )) {
429441 use_log_data = atoi (val );
430- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled log_data" );
442+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled log_data" );
431443 } else if (!strcmp (var , "use_system_command_data" )) {
432444 use_system_command_data = atoi (val );
433- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled system_command_data" );
445+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled system_command_data" );
434446 } else if (!strcmp (var , "use_comment_data" )) {
435447 use_comment_data = atoi (val );
436- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled comment_data" );
448+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled comment_data" );
437449 } else if (!strcmp (var , "use_external_command_data" )) {
438450 use_external_command_data = atoi (val );
439- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled external_command_data" );
451+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled external_command_data" );
440452 } else if (!strcmp (var , "use_acknowledgement_data" )) {
441453 use_acknowledgement_data = atoi (val );
442- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled acknowledgement_data" );
454+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled acknowledgement_data" );
443455 } else if (!strcmp (var , "use_flapping_data" )) {
444456 use_flapping_data = atoi (val );
445- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled flapping_data" );
457+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled flapping_data" );
446458 } else if (!strcmp (var , "use_downtime_data" )) {
447459 use_downtime_data = atoi (val );
448- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled downtime_data" );
460+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled downtime_data" );
449461 } else if (!strcmp (var , "use_notification_data" )) {
450462 use_notification_data = atoi (val );
451- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled notification_data" );
463+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled notification_data" );
452464 } else if (!strcmp (var , "use_program_status_data" )) {
453465 use_program_status_data = atoi (val );
454- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled program_status_data" );
466+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled program_status_data" );
455467 } else if (!strcmp (var , "use_contact_status_data" )) {
456468 use_contact_status_data = atoi (val );
457- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled contact_status_data" );
469+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled contact_status_data" );
458470 } else if (!strcmp (var , "use_contact_notification_data" )) {
459471 use_contact_notification_data = atoi (val );
460- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled contact_notification_data" );
472+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled contact_notification_data" );
461473 } else if (!strcmp (var , "use_contact_notification_method_data" )) {
462474 use_contact_notification_method_data = atoi (val );
463- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled contact_notification_method_data" );
475+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled contact_notification_method_data" );
464476 } else if (!strcmp (var , "use_event_handler_data" )) {
465477 use_event_handler_data = atoi (val );
466- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with disabled event_handler_data" );
478+ logswitch (NSLOG_INFO_MESSAGE , "start with disabled event_handler_data" );
467479 } else if (!strcmp (var , "enable_ochp" )) {
468480 enable_ochp = atoi (val );
469- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with enabled enable_ochp" );
481+ logswitch (NSLOG_INFO_MESSAGE , "start with enabled enable_ochp" );
470482 } else if (!strcmp (var , "enable_ocsp" )) {
471483 enable_ocsp = atoi (val );
472- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with enabled enable_ocsp" );
484+ logswitch (NSLOG_INFO_MESSAGE , "start with enabled enable_ocsp" );
473485 } else if (!strcmp (var , "use_object_data" )) {
474486 use_object_data = atoi (val );
475- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with enabled use_object_data" );
487+ logswitch (NSLOG_INFO_MESSAGE , "start with enabled use_object_data" );
476488 } else if (!strcmp (var , "gearman_server_addr" )) {
477489 gearman_server_addr = strdup (val );
478- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Gearman server address changed" );
490+ logswitch (NSLOG_INFO_MESSAGE , "Gearman server address changed: %s" , val );
479491 } else if (!strcmp (var , "gearman_server_port" )) {
480492 gearman_server_port = atoi (val );
481- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Gearman server port changed" );
493+ logswitch (NSLOG_INFO_MESSAGE , "Gearman server port changed: %i" , val );
482494 } else if (!strcmp (var , "use_restart_data" )) {
483495 use_restart_data = atoi (val );
484- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with enabled use_restart_data" );
496+ logswitch (NSLOG_INFO_MESSAGE , "start with enabled use_restart_data" );
485497 } else if (!strcmp (var , "use_service_perfdata" )) {
486498 use_service_perfdata = atoi (val );
487- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] start with enabled use_service_perfdata" );
499+ logswitch (NSLOG_INFO_MESSAGE , "start with enabled use_service_perfdata" );
488500 } else {
489501 return ERROR ;
490502 }
@@ -1547,7 +1559,7 @@ void dump_object_data(){
15471559
15481560 json_object_put (my_object );
15491561
1550- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping command configuration" );
1562+ logswitch (NSLOG_INFO_MESSAGE , "Dumping command configuration" );
15511563 for (temp_command = command_list ; temp_command != NULL ; temp_command = temp_command -> next ){
15521564 my_object = json_object_new_object ();
15531565 json_object_object_add (my_object , "object_type" , json_object_new_int (12 ));
@@ -1563,7 +1575,7 @@ void dump_object_data(){
15631575
15641576 //Fetch timeperiods
15651577 //Logging that we dump commands right now
1566- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping timeperiod configuration" );
1578+ logswitch (NSLOG_INFO_MESSAGE , "Dumping timeperiod configuration" );
15671579 for (temp_timeperiod = timeperiod_list ; temp_timeperiod != NULL ; temp_timeperiod = temp_timeperiod -> next ){
15681580 my_object = json_object_new_object ();
15691581 json_object_object_add (my_object , "object_type" , json_object_new_int (9 ));
@@ -1596,7 +1608,7 @@ void dump_object_data(){
15961608 }
15971609
15981610 //Fetch contact configuration
1599- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping contact configuration" );
1611+ logswitch (NSLOG_INFO_MESSAGE , "Dumping contact configuration" );
16001612 for (temp_contact = contact_list ; temp_contact != NULL ; temp_contact = temp_contact -> next ){
16011613 my_object = json_object_new_object ();
16021614 json_object_object_add (my_object , "object_type" , json_object_new_int (10 ));
@@ -1672,7 +1684,7 @@ void dump_object_data(){
16721684 }
16731685
16741686 //Fetch contact group configuration
1675- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping contact group configuration" );
1687+ logswitch (NSLOG_INFO_MESSAGE , "Dumping contact group configuration" );
16761688 for (temp_contactgroup = contactgroup_list ; temp_contactgroup != NULL ; temp_contactgroup = temp_contactgroup -> next ){
16771689 my_object = json_object_new_object ();
16781690 json_object_object_add (my_object , "object_type" , json_object_new_int (11 ));
@@ -1695,7 +1707,7 @@ void dump_object_data(){
16951707 }
16961708
16971709 //Fetch host configuration
1698- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping host configuration" );
1710+ logswitch (NSLOG_INFO_MESSAGE , "Dumping host configuration" );
16991711 for (temp_host = host_list ; temp_host != NULL ; temp_host = temp_host -> next ){
17001712 my_object = json_object_new_object ();
17011713 json_object_object_add (my_object , "object_type" , json_object_new_int (1 ));
@@ -1805,7 +1817,7 @@ void dump_object_data(){
18051817 }
18061818
18071819 //Fetch hostgroup configuration
1808- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping host group configuration" );
1820+ logswitch (NSLOG_INFO_MESSAGE , "Dumping host group configuration" );
18091821 for (temp_hostgroup = hostgroup_list ; temp_hostgroup != NULL ; temp_hostgroup = temp_hostgroup -> next ){
18101822 my_object = json_object_new_object ();
18111823 json_object_object_add (my_object , "object_type" , json_object_new_int (3 ));
@@ -1834,7 +1846,7 @@ void dump_object_data(){
18341846
18351847
18361848 //Fetch service configuration
1837- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping service configuration" );
1849+ logswitch (NSLOG_INFO_MESSAGE , "Dumping service configuration" );
18381850 for (temp_service = service_list ; temp_service != NULL ; temp_service = temp_service -> next ){
18391851 my_object = json_object_new_object ();
18401852 json_object_object_add (my_object , "object_type" , json_object_new_int (2 ));
@@ -1932,7 +1944,7 @@ void dump_object_data(){
19321944 }
19331945
19341946 //Fetch service groups
1935- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping service group configuration" );
1947+ logswitch (NSLOG_INFO_MESSAGE , "Dumping service group configuration" );
19361948 for (temp_servicegroup = servicegroup_list ; temp_servicegroup != NULL ; temp_servicegroup = temp_servicegroup -> next ){
19371949 my_object = json_object_new_object ();
19381950 json_object_object_add (my_object , "object_type" , json_object_new_int (4 ));
@@ -1959,7 +1971,7 @@ void dump_object_data(){
19591971
19601972 #if defined NAEMON || defined NAGIOS
19611973 //Fetch host escalations
1962- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping host escalation configuration" );
1974+ logswitch (NSLOG_INFO_MESSAGE , "Dumping host escalation configuration" );
19631975 for (x = 0 ; x < num_objects .hostescalations ; x ++ ){
19641976 temp_hostescalation = hostescalation_ary [x ];
19651977 my_object = json_object_new_object ();
@@ -1998,7 +2010,7 @@ void dump_object_data(){
19982010 }
19992011
20002012 //Fetch service escalations
2001- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping servcie escalation configuration" );
2013+ logswitch (NSLOG_INFO_MESSAGE , "Dumping servcie escalation configuration" );
20022014 for (x = 0 ; x < num_objects .serviceescalations ; x ++ ) {
20032015 temp_serviceescalation = serviceescalation_ary [x ];
20042016 my_object = json_object_new_object ();
@@ -2038,7 +2050,7 @@ void dump_object_data(){
20382050 json_object_put (my_object );
20392051 }
20402052
2041- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping host dependency configuration" );
2053+ logswitch (NSLOG_INFO_MESSAGE , "Dumping host dependency configuration" );
20422054 for (x = 0 ; x < num_objects .hostdependencies ; x ++ ){
20432055 temp_hostdependency = hostdependency_ary [x ];
20442056 my_object = json_object_new_object ();
@@ -2060,7 +2072,7 @@ void dump_object_data(){
20602072 json_object_put (my_object );
20612073 }
20622074
2063- logswitch (NSLOG_INFO_MESSAGE , "[Statusengine] Dumping service dependency configuration" );
2075+ logswitch (NSLOG_INFO_MESSAGE , "Dumping service dependency configuration" );
20642076 for (x = 0 ; x < num_objects .servicedependencies ; x ++ ){
20652077 temp_servicedependency = servicedependency_ary [x ];
20662078 my_object = json_object_new_object ();
0 commit comments