diff --git a/yasnd.c b/yasnd.c index f6771f0..e891326 100644 --- a/yasnd.c +++ b/yasnd.c @@ -102,6 +102,7 @@ void init() { hosts[i].hostname=cfg_getnstr(cfg,"hosts",i); hosts[i].fail_count=0; + hosts[i].alert_sent=false; } // initialize gammu structures gammu_init(); @@ -148,7 +149,10 @@ void loop_function() // if host is alive - reset failure counter // otherwise - increment it if (WEXITSTATUS(pid_status) == 0) + { hosts[i].fail_count=0; + hosts[i].alert_sent=false; + } else hosts[i].fail_count++; } @@ -156,13 +160,16 @@ void loop_function() } for (int i=0;i0) + if (hosts[i].fail_count>0 && !hosts[i].alert_sent) { char message[100]; sprintf(message,"Host %s does not answer",hosts[i].hostname); log_debug(message,DEBUG_BASE); if (sms_send_enable) gammu_send_sms(message); + // set alert flag to prevent sending more than 1 message + // for unreachable host + hosts[i].alert_sent=true; } } } diff --git a/yasnd.h b/yasnd.h index 1bf3fac..14bced8 100644 --- a/yasnd.h +++ b/yasnd.h @@ -19,6 +19,7 @@ typedef struct { char* hostname; // address of host pid_t helper_pid; // pid of helper('pinger') child process int fail_count; // how many times in a row host was unreachable + bool alert_sent; // variable, that changed when host goes online/offline } host_decl; // External variables