prevent duplicate alerts on same problem with host
This commit is contained in:
9
yasnd.c
9
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;i<hosts_count;i++)
|
||||
{
|
||||
if (hosts[i].fail_count>0)
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user