initial implementation of sms sending
This commit is contained in:
31
yasnd.c
31
yasnd.c
@ -8,7 +8,6 @@
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <confuse.h>
|
||||
|
||||
#include "yasnd.h"
|
||||
@ -17,7 +16,6 @@ cfg_t *cfg; // pointer to configuration structure
|
||||
host_decl* hosts=NULL; // structure with hosts' definitions
|
||||
int hosts_count=0; // count of hosts
|
||||
int debug_flag=0;
|
||||
GSM_StateMachine *state_machine=NULL; // structure to interact with mobile phones
|
||||
|
||||
void log_debug(const char *message,int verbosity)
|
||||
{
|
||||
@ -71,18 +69,8 @@ void init()
|
||||
hosts[i].fail_count=0;
|
||||
}
|
||||
// initialize gammu structures
|
||||
GSM_InitLocales(NULL);
|
||||
state_machine = GSM_AllocStateMachine();
|
||||
/* Set gammu configuration */
|
||||
GSM_Config *gammu_cfg = GSM_GetConfig(state_machine, 0);
|
||||
// first, free old values and set new one
|
||||
free(gammu_cfg->Device);
|
||||
gammu_cfg->Device = strdup("/dev/ttyACM0");
|
||||
free(gammu_cfg->Connection);
|
||||
gammu_cfg->Connection = strdup("at");
|
||||
strcpy(gammu_cfg->Model, "at");
|
||||
/* We care only about first configuration */
|
||||
GSM_SetConfigNum(state_machine, 1);
|
||||
gammu_init();
|
||||
|
||||
}
|
||||
|
||||
void check_host(int num,host_decl* host)
|
||||
@ -97,7 +85,7 @@ void check_host(int num,host_decl* host)
|
||||
char tmp[50];
|
||||
sprintf(tmp, "Pinging host %s", host->hostname);
|
||||
log_debug(tmp,DEBUG_BASE);
|
||||
execl("/bin/ping","/bin/ping","-c 4","-n",host->hostname,(char*) 0);
|
||||
execl("/bin/ping","/bin/ping","-c 1","-n",host->hostname,(char*) 0);
|
||||
// STUB: check result of exec call
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@ -131,6 +119,18 @@ void loop_function()
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i=0;i<hosts_count;i++)
|
||||
{
|
||||
if (hosts[i].fail_count>0)
|
||||
{
|
||||
char log_message[100];
|
||||
char sms_message[100];
|
||||
sprintf(log_message,"Host %s does not answer, sending sms",hosts[i].hostname);
|
||||
log_debug(log_message,DEBUG_BASE);
|
||||
sprintf(sms_message,"Host %s does not answer",hosts[i].hostname);
|
||||
gammu_send_sms(sms_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void termination_handler(int signum)
|
||||
@ -195,6 +195,7 @@ int main(void) {
|
||||
while (1) {
|
||||
loop_function();
|
||||
// sleep(60); /* wait 60 seconds */
|
||||
log_event("Exiting");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
|
Reference in New Issue
Block a user