make failures thresholds configurable

This commit is contained in:
Sergey Popov 2012-01-03 03:05:53 +04:00
parent 0c2ff3313e
commit 1610c1394f
2 changed files with 21 additions and 4 deletions

View File

@ -1,4 +1,4 @@
# hosts' list # *** Hosts' parameters ***
host 10.0.0.1 { host 10.0.0.1 {
hostname = "10.0.0.1" hostname = "10.0.0.1"
lpt_pin = 2 lpt_pin = 2
@ -13,6 +13,14 @@ host 10.0.0.254 {
} }
# log verbosity: 0 - normal mode, 1 - verbose, 2 - most verbose # log verbosity: 0 - normal mode, 1 - verbose, 2 - most verbose
debug = 2 debug = 2
# *** Threshold parameters ***
# Number of failures while hosts checking, that triggers SMS sending
failures_first = 1
# Number of failures while hosts checking, that triggers host's reset, if no reaction was received
failures_second = 3
# Number of failures while hosts checking, that clean host's failure statistics
failures_third = 9
# *** Notification parametes ***
# Use LPT for reset target devices? # Use LPT for reset target devices?
# Note: first LPT pin is for management and it should not be used # Note: first LPT pin is for management and it should not be used
lpt_enable = true lpt_enable = true

15
yasnd.c
View File

@ -19,9 +19,9 @@ char* recipient_number=NULL; // recipient of sms alerts
bool lpt_enable=false; // control usage of LPT port to reset target devices 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) 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 bool loop_locked=false; // flag for locking main loop while config re-reading
long failures_first=0; // count of failures while hosts checking, that triggers SMS sending int failures_first=0; // count of failures while hosts checking, that triggers SMS sending
long failures_second=1; // count of failures while hosts checking, that triggers host's reset int failures_second=0; // count of failures while hosts checking, that triggers host's reset
long failures_third=9; // count of failures while hosts checking, that clean failure statistics int failures_third=0; // count of failures while hosts checking, that clean failure statistics
pid_t mainloop_clone_pid; // pid of clone process, that containt main loop pid_t mainloop_clone_pid; // pid of clone process, that containt main loop
void log_debug(const char *message,int verbosity) void log_debug(const char *message,int verbosity)
@ -105,6 +105,9 @@ void init()
cfg_opt_t opts[] = { cfg_opt_t opts[] = {
CFG_SEC("host", host_opts, CFGF_MULTI | CFGF_TITLE), CFG_SEC("host", host_opts, CFGF_MULTI | CFGF_TITLE),
CFG_SIMPLE_INT("debug", &debug_flag), CFG_SIMPLE_INT("debug", &debug_flag),
CFG_SIMPLE_INT("failures_first", &failures_first),
CFG_SIMPLE_INT("failures_second", &failures_second),
CFG_SIMPLE_INT("failures_third", &failures_third),
CFG_SIMPLE_BOOL("lpt_enable", &lpt_enable), CFG_SIMPLE_BOOL("lpt_enable", &lpt_enable),
CFG_SIMPLE_INT("lpt_port", &lpt_port), CFG_SIMPLE_INT("lpt_port", &lpt_port),
CFG_SIMPLE_BOOL("sms_enable", &sms_enable), CFG_SIMPLE_BOOL("sms_enable", &sms_enable),
@ -123,6 +126,12 @@ void init()
log_event("Error parsing config file"); log_event("Error parsing config file");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// failures thresholds must be explicitly defined in config
if (failures_first==0 || failures_second==0 || failures_third==0)
{
log_event("Error: all failures threshold parameters must be defined in config file");
exit(EXIT_FAILURE);
}
// if SMS is enabled, all of phone parameters must be explicitly defined // if SMS is enabled, all of phone parameters must be explicitly defined
if (sms_enable) if (sms_enable)
{ {