From 1610c1394f3c35758b8e4cff7fb99b83316cca9d Mon Sep 17 00:00:00 2001 From: Sergey Popov Date: Tue, 3 Jan 2012 03:05:53 +0400 Subject: [PATCH] make failures thresholds configurable --- contrib/yasnd.conf.example | 10 +++++++++- yasnd.c | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/contrib/yasnd.conf.example b/contrib/yasnd.conf.example index 29161cf..a6121f6 100644 --- a/contrib/yasnd.conf.example +++ b/contrib/yasnd.conf.example @@ -1,4 +1,4 @@ -# hosts' list +# *** Hosts' parameters *** host 10.0.0.1 { hostname = "10.0.0.1" lpt_pin = 2 @@ -13,6 +13,14 @@ host 10.0.0.254 { } # log verbosity: 0 - normal mode, 1 - verbose, 2 - most verbose 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? # Note: first LPT pin is for management and it should not be used lpt_enable = true diff --git a/yasnd.c b/yasnd.c index 2702fe5..65035d0 100644 --- a/yasnd.c +++ b/yasnd.c @@ -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 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 -long 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 -long failures_third=9; // count of failures while hosts checking, that clean failure statistics +int failures_first=0; // count of failures while hosts checking, that triggers SMS sending +int failures_second=0; // count of failures while hosts checking, that triggers host's reset +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 void log_debug(const char *message,int verbosity) @@ -105,6 +105,9 @@ void init() cfg_opt_t opts[] = { CFG_SEC("host", host_opts, CFGF_MULTI | CFGF_TITLE), 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_INT("lpt_port", &lpt_port), CFG_SIMPLE_BOOL("sms_enable", &sms_enable), @@ -123,6 +126,12 @@ void init() log_event("Error parsing config file"); 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_enable) {