implement SMS sending via IPC queue loop

This commit is contained in:
2011-12-19 18:35:14 +04:00
parent 94e7bc7478
commit d8829305fc
4 changed files with 107 additions and 75 deletions

24
yasnd.c
View File

@ -2,7 +2,6 @@
#include <sys/io.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <confuse.h>
@ -20,8 +19,8 @@ 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=3; // count of failures while hosts checking, that triggers SMS sending
long failures_second=6; // count of failures while hosts checking, that triggers host's reset
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
pid_t mainloop_clone_pid; // pid of clone process, that containt main loop
@ -254,30 +253,29 @@ int loop_function()
}
for (int i=0;i<hosts_count;i++)
{
mymsgbuf qbuf;
if (hosts[i].fail_count>failures_second && hosts[i].alert_sent && !hosts[i].reaction_obtained)
{
if (lpt_enable)
{
char message[150];
sprintf(message,"Host %s does not answer and no reaction on this. Trying to reset it(LPT pin %d)",hosts[i].hostname,hosts[i].lpt_pin);
log_debug(message,DEBUG_BASE);
if (sms_send_enable)
gammu_send_sms(message);
qbuf.mtype=SMS_SEND_TYPE;
sprintf(qbuf.mtext,"Host %s does not answer and no reaction on this. Trying to reset it(LPT pin %d)",hosts[i].hostname,hosts[i].lpt_pin);
reset_pin(hosts[i].lpt_pin);
hosts[i].reaction_obtained=true;
// send message with SMS text to IPC queue
send_message(qid,&qbuf);
}
continue;
}
if (hosts[i].fail_count>failures_first && !hosts[i].alert_sent)
{
char message[100];
sprintf(message,"Host %s does not answer(LPT pin %d)",hosts[i].hostname,hosts[i].lpt_pin);
log_debug(message,DEBUG_BASE);
if (sms_send_enable)
gammu_send_sms(message);
qbuf.mtype=SMS_SEND_TYPE;
sprintf(qbuf.mtext,"Host %s does not answer(LPT pin %d)",hosts[i].hostname,hosts[i].lpt_pin);
// set alert flag to prevent sending more than 1 message
// for unreachable host
hosts[i].alert_sent=true;
// send message with SMS text to IPC queue
send_message(qid,&qbuf);
continue;
}
}