prevent duplicate alerts on same problem with host
This commit is contained in:
parent
1036bd84f2
commit
eeb0166fa7
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
yasnd.h
1
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
|
||||
|
Loading…
Reference in New Issue
Block a user