diff --git a/yasnd.c b/yasnd.c index e1f7378..ea07539 100644 --- a/yasnd.c +++ b/yasnd.c @@ -16,6 +16,7 @@ cfg_t *cfg; // pointer to configuration structure host_decl* hosts=NULL; // structure with hosts' definitions int hosts_count=0; // count of hosts int debug_flag=0; +bool sms_send_enable=false; // send or not send alerts via SMS char* recipient_number=NULL; // recipient of sms alerts void log_debug(const char *message,int verbosity) @@ -45,6 +46,7 @@ void init() cfg_opt_t opts[] = { CFG_STR_LIST("hosts", "{}", CFGF_NONE), CFG_SIMPLE_INT("debug", &debug_flag), + CFG_SIMPLE_BOOL("sms_send_enable", &sms_send_enable), CFG_SIMPLE_STR("sms_recipient", &recipient_number), CFG_END() }; @@ -55,6 +57,15 @@ void init() log_event("Error parsing config file"); exit(EXIT_FAILURE); } + // if SMS sending is enabled, recipient address must also be defined + if (sms_send_enable) + { + if (recipient_number==NULL) + { + log_event("Error: no recipient for sms alerts defined in config file"); + exit(EXIT_FAILURE); + } + } // hosts' array must not be empty hosts_count=cfg_size(cfg,"hosts"); if (hosts_count==0) @@ -130,7 +141,8 @@ void loop_function() sprintf(log_message,"Host %s does not answer, sending sms",hosts[i].hostname); log_debug(log_message,DEBUG_BASE); sprintf(sms_message,"Host %s does not answer",hosts[i].hostname); - gammu_send_sms(sms_message); + if (sms_send_enable) + gammu_send_sms(sms_message); } } }