prevent duplicate alerts on same problem with host

This commit is contained in:
Sergey Popov 2011-12-12 14:31:18 +04:00
parent 1036bd84f2
commit eeb0166fa7
2 changed files with 9 additions and 1 deletions

View File

@ -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;
}
}
}

View File

@ -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