checksensor nearly ready
git-svn-id: file:///home/jan/tmp/wetterstation/trunk@57 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
8b9576949b
commit
822e8f408d
|
|
@ -34,12 +34,14 @@
|
|||
|
||||
|
||||
#define BUFFSIZE 512
|
||||
#define BUFFSIZE_EXTRA 2048
|
||||
|
||||
|
||||
/* Variablen ---------------------------------------------------------- */
|
||||
w_opts global_opts;
|
||||
static PGconn *connection = NULL;
|
||||
static char *conn_string = NULL;
|
||||
static char *mail_buff = NULL;
|
||||
static sens_info_list_ptr failed_sensors = NULL;
|
||||
|
||||
/* Funktionen ----------------------------------------------------------*/
|
||||
|
|
@ -227,6 +229,46 @@ static int check_sensors(){
|
|||
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 ---*/
|
||||
|
||||
/* Main-Funktion */
|
||||
|
|
@ -273,8 +315,10 @@ int main(int argc, char *argv[]){
|
|||
DEBUGOUT2(" Datenbank = %s\n",global_opts.pg_database);
|
||||
|
||||
generate_conn_string();
|
||||
if(global_opts.id_from_db)
|
||||
get_sensors_from_db();
|
||||
//check_sensors();
|
||||
if(check_sensors())
|
||||
mail_failtures();
|
||||
|
||||
clean();
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -97,19 +97,18 @@ static int read_yn(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;
|
||||
|
||||
id_new = malloc(sizeof(sensor_id));
|
||||
id_new->next = NULL;
|
||||
id_new->id = atoi(line);
|
||||
|
||||
DEBUGOUT2("add ID: %d\n", atoi(line));
|
||||
|
||||
id_temp = *((sens_id_list_ptr*)arg);
|
||||
if (id_temp == NULL){
|
||||
id_temp = id_new;
|
||||
*((sens_id_list_ptr*)arg) = id_temp;
|
||||
} else {
|
||||
while (id_temp->next != NULL){
|
||||
id_temp = id_temp->next;
|
||||
|
|
@ -118,23 +117,21 @@ static int add_sens_id(const char *line, void *arg){
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
adr_new = malloc(sizeof(address_struct));
|
||||
adr_new->next = NULL;
|
||||
adr_new->mailbox = strdup(line);
|
||||
|
||||
DEBUGOUT2("add addr: %s\n", line);
|
||||
|
||||
adr_temp = *((mail_list_ptr*)arg);
|
||||
if (adr_temp == NULL){
|
||||
adr_temp = adr_new;
|
||||
*((mail_list_ptr*)arg) = adr_temp;
|
||||
} else {
|
||||
while (adr_temp->next != NULL){
|
||||
adr_temp = adr_temp->next;
|
||||
|
|
@ -143,7 +140,6 @@ static int add_address(const char *line, void *arg){
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue