checksensor nearly ready

git-svn-id: file:///home/jan/tmp/wetterstation/trunk@57 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
losinshi 2006-08-31 14:52:33 +00:00
parent 8b9576949b
commit 822e8f408d
2 changed files with 78 additions and 38 deletions

View File

@ -34,12 +34,14 @@
#define BUFFSIZE 512 #define BUFFSIZE 512
#define BUFFSIZE_EXTRA 2048
/* Variablen ---------------------------------------------------------- */ /* Variablen ---------------------------------------------------------- */
w_opts global_opts; w_opts global_opts;
static PGconn *connection = NULL; static PGconn *connection = NULL;
static char *conn_string = NULL; static char *conn_string = NULL;
static char *mail_buff = NULL;
static sens_info_list_ptr failed_sensors = NULL; static sens_info_list_ptr failed_sensors = NULL;
/* Funktionen ----------------------------------------------------------*/ /* Funktionen ----------------------------------------------------------*/
@ -227,6 +229,46 @@ static int check_sensors(){
return fail_count; return fail_count;
} }
static char *get_message(int line, void *arg){
sens_info_list_ptr info = *((sens_info_list_ptr*) arg);
if (info != NULL){
if(line == 0){
return MAIL_HEAD;
} else {
if(mail_buff == NULL)
mail_buff = malloc(sizeof(char)*BUFFSIZE_EXTRA);
snprintf(mail_buff, BUFFSIZE_EXTRA, "\r\nDer Sensor mit der ID %d hat in den letzten %d Stunden nur %d Werte geliefert!\r\nDaten zum Sensor:\r\nTyp:\t\t%s\r\nStandort:\t%s\r\nBeschreibung:\t%s\r\n", info->id, global_opts.interval, info->count, info->type_desc, info->sens_location, info->sens_desc);
*((sens_info_list_ptr*)arg) = info->next;
return mail_buff;
}
} else {
if(mail_buff != NULL)
free(mail_buff);
return NULL;
}
}
static void mail_failtures(){
server_vars *servo = get_default_servopts();
address_all_struct addresses;
int mail_err_nr = 0;
servo->host = global_opts.mail_host;
servo->port = global_opts.mail_port;
servo->ssl_use = global_opts.mail_ssl;
servo->auth_use = global_opts.mail_auth;
servo->auth_user = global_opts.mail_auth_user;
servo->auth_pass = global_opts.mail_auth_pass;
addresses.from = NULL;
addresses.to = global_opts.address_list;
addresses.cc = NULL;
addresses.bcc = NULL;
mail_err_nr = mail_message(& addresses, "Wetterstation", 0, get_message, & failed_sensors, servo);
printf("%s\n",get_mail_status_text(mail_err_nr));
}
/* Mainfkt. und diverse andere Funktionen zum beenden des Programmes ---*/ /* Mainfkt. und diverse andere Funktionen zum beenden des Programmes ---*/
/* Main-Funktion */ /* Main-Funktion */
@ -273,8 +315,10 @@ int main(int argc, char *argv[]){
DEBUGOUT2(" Datenbank = %s\n",global_opts.pg_database); DEBUGOUT2(" Datenbank = %s\n",global_opts.pg_database);
generate_conn_string(); generate_conn_string();
if(global_opts.id_from_db)
get_sensors_from_db(); get_sensors_from_db();
//check_sensors(); if(check_sensors())
mail_failtures();
clean(); clean();
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -97,19 +97,18 @@ static int read_yn(const char *line, void *arg){
} }
static int add_sens_id(const char *line, void *arg){ static int add_sens_id(const char *line, void *arg){
if (line == NULL){
*((sens_id_list_ptr*)arg) = NULL;
return 1;
} else {
sens_id_list_ptr id_new, id_temp; sens_id_list_ptr id_new, id_temp;
id_new = malloc(sizeof(sensor_id)); id_new = malloc(sizeof(sensor_id));
id_new->next = NULL; id_new->next = NULL;
id_new->id = atoi(line); id_new->id = atoi(line);
DEBUGOUT2("add ID: %d\n", atoi(line));
id_temp = *((sens_id_list_ptr*)arg); id_temp = *((sens_id_list_ptr*)arg);
if (id_temp == NULL){ if (id_temp == NULL){
id_temp = id_new; id_temp = id_new;
*((sens_id_list_ptr*)arg) = id_temp;
} else { } else {
while (id_temp->next != NULL){ while (id_temp->next != NULL){
id_temp = id_temp->next; id_temp = id_temp->next;
@ -117,24 +116,22 @@ static int add_sens_id(const char *line, void *arg){
id_temp->next = id_new; id_temp->next = id_new;
} }
return 1; return 1;
}
} }
static int add_address(const char *line, void *arg){ static int add_address(const char *line, void *arg){
if (line == NULL){
*((mail_list_ptr*)arg) = NULL;
return 1;
} else {
mail_list_ptr adr_new, adr_temp; mail_list_ptr adr_new, adr_temp;
adr_new = malloc(sizeof(address_struct)); adr_new = malloc(sizeof(address_struct));
adr_new->next = NULL; adr_new->next = NULL;
adr_new->mailbox = strdup(line); adr_new->mailbox = strdup(line);
DEBUGOUT2("add addr: %s\n", line);
adr_temp = *((mail_list_ptr*)arg); adr_temp = *((mail_list_ptr*)arg);
if (adr_temp == NULL){ if (adr_temp == NULL){
adr_temp = adr_new; adr_temp = adr_new;
*((mail_list_ptr*)arg) = adr_temp;
} else { } else {
while (adr_temp->next != NULL){ while (adr_temp->next != NULL){
adr_temp = adr_temp->next; adr_temp = adr_temp->next;
@ -142,7 +139,6 @@ static int add_address(const char *line, void *arg){
adr_temp->next = adr_new; adr_temp->next = adr_new;
} }
return 1; return 1;
}
} }