option to enable/disable SMS sending
This commit is contained in:
parent
849e8dc502
commit
cbd115f22c
12
yasnd.c
12
yasnd.c
@ -16,6 +16,7 @@ cfg_t *cfg; // pointer to configuration structure
|
|||||||
host_decl* hosts=NULL; // structure with hosts' definitions
|
host_decl* hosts=NULL; // structure with hosts' definitions
|
||||||
int hosts_count=0; // count of hosts
|
int hosts_count=0; // count of hosts
|
||||||
int debug_flag=0;
|
int debug_flag=0;
|
||||||
|
bool sms_send_enable=false; // send or not send alerts via SMS
|
||||||
char* recipient_number=NULL; // recipient of sms alerts
|
char* recipient_number=NULL; // recipient of sms alerts
|
||||||
|
|
||||||
void log_debug(const char *message,int verbosity)
|
void log_debug(const char *message,int verbosity)
|
||||||
@ -45,6 +46,7 @@ void init()
|
|||||||
cfg_opt_t opts[] = {
|
cfg_opt_t opts[] = {
|
||||||
CFG_STR_LIST("hosts", "{}", CFGF_NONE),
|
CFG_STR_LIST("hosts", "{}", CFGF_NONE),
|
||||||
CFG_SIMPLE_INT("debug", &debug_flag),
|
CFG_SIMPLE_INT("debug", &debug_flag),
|
||||||
|
CFG_SIMPLE_BOOL("sms_send_enable", &sms_send_enable),
|
||||||
CFG_SIMPLE_STR("sms_recipient", &recipient_number),
|
CFG_SIMPLE_STR("sms_recipient", &recipient_number),
|
||||||
CFG_END()
|
CFG_END()
|
||||||
};
|
};
|
||||||
@ -55,6 +57,15 @@ void init()
|
|||||||
log_event("Error parsing config file");
|
log_event("Error parsing config file");
|
||||||
exit(EXIT_FAILURE);
|
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' array must not be empty
|
||||||
hosts_count=cfg_size(cfg,"hosts");
|
hosts_count=cfg_size(cfg,"hosts");
|
||||||
if (hosts_count==0)
|
if (hosts_count==0)
|
||||||
@ -130,6 +141,7 @@ void loop_function()
|
|||||||
sprintf(log_message,"Host %s does not answer, sending sms",hosts[i].hostname);
|
sprintf(log_message,"Host %s does not answer, sending sms",hosts[i].hostname);
|
||||||
log_debug(log_message,DEBUG_BASE);
|
log_debug(log_message,DEBUG_BASE);
|
||||||
sprintf(sms_message,"Host %s does not answer",hosts[i].hostname);
|
sprintf(sms_message,"Host %s does not answer",hosts[i].hostname);
|
||||||
|
if (sms_send_enable)
|
||||||
gammu_send_sms(sms_message);
|
gammu_send_sms(sms_message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user