change host structure definition in config file
This commit is contained in:
parent
d4f632689a
commit
240aa35786
22
yasnd.c
22
yasnd.c
@ -20,7 +20,7 @@ char* recipient_number=NULL; // recipient of sms alerts
|
||||
bool lpt_enable=false; // control usage of LPT port to reset target devices
|
||||
int lpt_port=0x378; // LPT port in hex(0x378 is usually LPT1)
|
||||
bool loop_locked=false; // flag for locking main loop while config re-reading
|
||||
int failures_first=3; // count of failures while hosts checking, that triggers first SMS sending
|
||||
long failures_first=3; // count of failures while hosts checking, that triggers first SMS sending
|
||||
pid_t mainloop_clone_pid; // pid of clone process, that containt main loop
|
||||
|
||||
void log_debug(const char *message,int verbosity)
|
||||
@ -81,11 +81,22 @@ void lpt_lock()
|
||||
outb (1, lpt_port);
|
||||
}
|
||||
|
||||
// Function, that checks that defined host entry is valid
|
||||
int cb_validate_host(cfg_t *cfg, cfg_opt_t *opt)
|
||||
{
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
static cfg_opt_t host_opts[] = {
|
||||
CFG_STR("hostname", 0, CFGF_NONE),
|
||||
CFG_INT("lpt_pin", 0, CFGF_NONE),
|
||||
CFG_END()
|
||||
};
|
||||
// Initialize config parsing library
|
||||
cfg_opt_t opts[] = {
|
||||
CFG_STR_LIST("hosts", "{}", CFGF_NONE),
|
||||
CFG_SEC("host", host_opts, CFGF_MULTI | CFGF_TITLE),
|
||||
CFG_SIMPLE_INT("debug", &debug_flag),
|
||||
CFG_SIMPLE_BOOL("lpt_enable", &lpt_enable),
|
||||
CFG_SIMPLE_INT("lpt_port", &lpt_port),
|
||||
@ -97,6 +108,8 @@ void init()
|
||||
CFG_END()
|
||||
};
|
||||
cfg = cfg_init(opts, CFGF_NONE);
|
||||
// set a validating callback function for host sections
|
||||
cfg_set_validate_func(cfg, "host", &cb_validate_host);
|
||||
// check if config file is valid and parse it
|
||||
if (cfg_parse(cfg, "/etc/yasnd.conf") == CFG_PARSE_ERROR)
|
||||
{
|
||||
@ -128,7 +141,7 @@ void init()
|
||||
}
|
||||
}
|
||||
// hosts' array must not be empty
|
||||
hosts_count=cfg_size(cfg,"hosts");
|
||||
hosts_count=cfg_size(cfg,"host");
|
||||
if (hosts_count==0)
|
||||
{
|
||||
log_event("Error: no hosts to check defined in config file");
|
||||
@ -139,7 +152,8 @@ void init()
|
||||
// ...and fill it with config file content
|
||||
for (int i=0;i<hosts_count;i++)
|
||||
{
|
||||
hosts[i].hostname=cfg_getnstr(cfg,"hosts",i);
|
||||
cfg_t* host = cfg_getnsec(cfg, "host", i);
|
||||
hosts[i].hostname=cfg_getstr(host,"hostname");
|
||||
hosts[i].fail_count=0;
|
||||
hosts[i].alert_sent=false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user