Only in cacti-0.8.6/cactid: bootstrap diff -ruBbd cacti-0.8.5/cactid/cactid.c cacti-0.8.6/cactid/cactid.c --- cacti-0.8.5/cactid/cactid.c 2004-02-03 01:21:08.000000000 -0500 +++ cacti-0.8.6/cactid/cactid.c 2004-02-12 20:50:26.000000000 -0500 @@ -83,7 +83,7 @@ for(i=0;i= 0) { + if (read_cactid_config(conf_file, &set) >= 0) { break; } diff -ruBbd cacti-0.8.5/cactid/cactid.h cacti-0.8.6/cactid/cactid.h --- cacti-0.8.5/cactid/cactid.h 2004-02-03 01:21:08.000000000 -0500 +++ cacti-0.8.6/cactid/cactid.h 2004-02-12 19:44:14.000000000 -0500 @@ -71,12 +71,6 @@ #define STAT_DESCRIP_ERROR 99 /* Typedefs */ -typedef struct worker_struct { - int index; - pthread_t thread; - struct crew_struct *crew; -} worker_t; - typedef struct config_struct { int interval; long long out_of_range; @@ -90,7 +84,7 @@ int threads; } config_t; -typedef struct target_struct{ +typedef struct target_struct { int target_id; char result[255]; int local_data_id; @@ -109,33 +103,28 @@ char arg1[255]; char arg2[255]; char arg3[255]; - struct target_struct *next; - struct target_struct *prev; - struct target_struct *head; -}target_t; +} target_t; -typedef struct crew_struct { - int work_count; - worker_t member[MAX_THREADS]; - pthread_mutex_t mutex; - pthread_cond_t done; - pthread_cond_t go; -} crew_t; +typedef struct host_struct { + char hostname[250]; + char snmp_community[100]; + int snmp_version; + int snmp_port; + int snmp_timeout; + int ignore_host; + + void *snmp_session; +} host_t; typedef struct rrd_struct{ char rrdcmd[512]; -}rrd_t; - -typedef struct host_struct { - int host_id; - int status; -}host_t; +} rrd_t; typedef struct multi_rrd_struct{ char rrd_name[19]; char rrd_path[255]; char result[255]; -}multi_rrd_t; +} multi_rrd_t; /* Globals */ config_t set; Only in cacti-0.8.6/cactid/config: config.h Only in cacti-0.8.6/cactid/config: CVS Only in cacti-0.8.6/cactid: CVS Only in cacti-0.8.6/cactid: .deps diff -ruBbd cacti-0.8.5/cactid/poller.c cacti-0.8.6/cactid/poller.c --- cacti-0.8.5/cactid/poller.c 2004-02-03 01:21:08.000000000 -0500 +++ cacti-0.8.6/cactid/poller.c 2004-02-12 20:05:22.000000000 -0500 @@ -59,18 +59,16 @@ char cmd_result[255]; char *snmp_result; - int ignore_host = 0; int rrd_ds_counter = 0; target_t *entry; + host_t *host; multi_rrd_t *rrd_multids; MYSQL mysql; MYSQL_RES *result; MYSQL_ROW row; - void *snmp_session_ptr = NULL; - snprintf(query1, sizeof(query1), "select action,command,hostname,snmp_community,snmp_version,snmp_username,snmp_password,rrd_name,rrd_path,arg1,arg2,arg3,local_data_id,rrd_num,snmp_port,snmp_timeout from data_input_data_cache where host_id=%i order by rrd_path,rrd_name", host_id); snprintf(query2, sizeof(query2), "select hostname,snmp_community,snmp_version,snmp_port,snmp_timeout from host where id=%i", host_id); @@ -87,9 +85,19 @@ row = mysql_fetch_row(result); - /* initialize the snmp session */ - snmp_session_ptr = snmp_host_init(row[0], row[1], atoi(row[2]), atoi(row[3]), atoi(row[4])); + /* load up database values into the host struct */ + host = (host_t *) malloc(sizeof(host_t)); + if (row[0] != NULL) snprintf(host->hostname, sizeof(host->hostname), "%s", row[0]); + if (row[1] != NULL) snprintf(host->snmp_community, sizeof(host->snmp_community), "%s", row[1]); + host->snmp_version = atoi(row[2]); + host->snmp_port = atoi(row[3]); + host->snmp_timeout = atoi(row[4]); + host->ignore_host = 0; + + snmp_host_init(host); + + /* fetch a list of each poller cache item that belongs to this host */ entry = (target_t *) malloc(sizeof(target_t)); result = db_query(&mysql, query1); @@ -121,27 +129,26 @@ switch(entry->action) { case 0: - if (ignore_host == 0) { + if (!host->ignore_host) { if ((entry->snmp_version == 1) || (entry->snmp_version == 2)) { - snmp_result = snmp_get(snmp_session_ptr, entry->arg1, entry->hostname); + snmp_result = snmp_get(host, entry->arg1); snprintf(entry->result, sizeof(entry->result), "%s", snmp_result); free(snmp_result); }else{ - printf("SNMP v3 is not yet supported in cactid (host: %s)\n", entry->hostname); + printf("SNMP v3 is not yet supported in cactid (host: %s)\n", host->hostname); } - }else{ + + if (host->ignore_host) { + printf("SNMP timeout detected (%i milliseconds), ignoring host '%s'\n", host->snmp_timeout, host->hostname); snprintf(entry->result, sizeof(entry->result), "%s", "U"); } - - if (!strcmp(entry->result, "E")) { - ignore_host = 1; - printf("SNMP timeout detected (%i milliseconds), ignoring host '%s'\n", entry->snmp_timeout, entry->hostname); + }else{ snprintf(entry->result, sizeof(entry->result), "%s", "U"); } if (set.verbose >= LOW) { - printf("[%i] SNMP v%i: %s, dsname: %s, oid: %s, value: %s\n", host_id, entry->snmp_version, entry->hostname, entry->rrd_name, entry->arg1, entry->result); + printf("[%i] SNMP v%i: %s, dsname: %s, oid: %s, value: %s\n", host_id, host->snmp_version, host->hostname, entry->rrd_name, entry->arg1, entry->result); } break; @@ -227,9 +234,10 @@ } } - snmp_host_cleanup(snmp_session_ptr); + snmp_host_cleanup(host); free(entry); + free(host); mysql_free_result(result); mysql_close(&mysql); diff -ruBbd cacti-0.8.5/cactid/snmp.c cacti-0.8.6/cactid/snmp.c --- cacti-0.8.5/cactid/snmp.c 2004-02-03 01:21:08.000000000 -0500 +++ cacti-0.8.6/cactid/snmp.c 2004-02-12 20:06:02.000000000 -0500 @@ -58,41 +58,46 @@ SOCK_CLEANUP; } -void *snmp_host_init(char *snmp_host, char *snmp_comm, int ver, int snmp_port, int snmp_timeout) { - static void *sessp = NULL; +void snmp_host_init(host_t *current_host) { + void *sessp = NULL; struct snmp_session session; char hostname[BUFSIZE]; snmp_sess_init(&session); - if (ver == 2) { + if (current_host->snmp_version == 2) { session.version = SNMP_VERSION_2c; }else{ session.version = SNMP_VERSION_1; } /* net-snmp likes the hostname in 'host:port' format */ - snprintf(hostname, BUFSIZE, "%s:%i", snmp_host, snmp_port); + snprintf(hostname, BUFSIZE, "%s:%i", current_host->hostname, current_host->snmp_port); session.peername = hostname; session.retries = 3; - session.timeout = (snmp_timeout * 1000); /* net-snmp likes microseconds */ - session.community = snmp_comm; - session.community_len = strlen(snmp_comm); + session.timeout = (current_host->snmp_timeout * 1000); /* net-snmp likes microseconds */ + session.community = current_host->snmp_community; + session.community_len = strlen(current_host->snmp_community); thread_mutex_lock(LOCK_SNMP); sessp = snmp_sess_open(&session); thread_mutex_unlock(LOCK_SNMP); - return sessp; + if (!sessp) { + printf("Error initializing SNMP session for host '%s'!\n", current_host->hostname); + current_host->snmp_session = NULL; + }else{ + current_host->snmp_session = sessp; + } } -void snmp_host_cleanup(void *sessp) { - snmp_sess_close(sessp); +void snmp_host_cleanup(host_t *current_host) { + snmp_sess_close(current_host->snmp_session); } -char *snmp_get(void *sessp, char *snmp_oid, char *hostname) { +char *snmp_get(host_t *current_host, char *snmp_oid) { struct snmp_pdu *pdu = NULL; struct snmp_pdu *response = NULL; oid anOID[MAX_OID_LEN]; @@ -114,19 +119,19 @@ snmp_add_null_var(pdu, anOID, anOID_len); - if (sessp != NULL) { - status = snmp_sess_synch_response(sessp, pdu, &response); + if (current_host->snmp_session != NULL) { + status = snmp_sess_synch_response(current_host->snmp_session, pdu, &response); }else{ status = STAT_DESCRIP_ERROR; } /* No or Bad SNMP Response */ if (status == STAT_DESCRIP_ERROR) { - printf("*** SNMP No response: (%s@%s).\n", hostname, storedoid); + printf("*** SNMP No response: (%s@%s).\n", current_host->hostname, storedoid); }else if (status != STAT_SUCCESS) { - printf("*** SNMP Error: (%s@%s) Unsuccessuful (%d).\n", hostname, storedoid, status); + printf("*** SNMP Error: (%s@%s) Unsuccessuful (%d).\n", current_host->hostname, storedoid, status); }else if (status == STAT_SUCCESS && response->errstat != SNMP_ERR_NOERROR) { - printf("*** SNMP Error: (%s@%s) %s\n", hostname, storedoid, snmp_errstring(response->errstat)); + printf("*** SNMP Error: (%s@%s) %s\n", current_host->hostname, storedoid, snmp_errstring(response->errstat)); } /* Liftoff, successful poll, process it */ @@ -141,12 +146,12 @@ } if (status == STAT_TIMEOUT) { - snprintf(result_string, BUFSIZE, "%s", "E"); + current_host->ignore_host = 1; }else if (!(status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR)) { snprintf(result_string, BUFSIZE, "%s", "U"); } - if (sessp != NULL) { + if (current_host->snmp_session != NULL) { if (response != NULL) { snmp_free_pdu(response); } diff -ruBbd cacti-0.8.5/cactid/snmp.h cacti-0.8.6/cactid/snmp.h --- cacti-0.8.5/cactid/snmp.h 2004-02-03 01:21:08.000000000 -0500 +++ cacti-0.8.6/cactid/snmp.h 2004-02-12 19:24:56.000000000 -0500 @@ -25,6 +25,6 @@ void snmp_init(); void snmp_free(); -void *snmp_host_init(char *snmp_host, char *snmp_comm, int ver, int snmp_port, int snmp_timeout); -void snmp_host_cleanup(void *sessp); -char *snmp_get(void *sessp, char *snmp_oid, char *hostname); +void snmp_host_init(host_t *current_host); +void snmp_host_cleanup(host_t *current_host); +char *snmp_get(host_t *current_host, char *snmp_oid); diff -ruBbd cacti-0.8.5/cactid/util.c cacti-0.8.6/cactid/util.c --- cacti-0.8.5/cactid/util.c 2004-02-03 01:21:08.000000000 -0500 +++ cacti-0.8.6/cactid/util.c 2004-02-12 20:50:28.000000000 -0500 @@ -29,7 +29,7 @@ #include "util.h" /* read configuration file to establish local environment */ -int read_config(char *file, config_t * set) { +int read_cactid_config(char *file, config_t * set) { FILE *fp; char buff[BUFSIZE]; char p1[BUFSIZE]; diff -ruBbd cacti-0.8.5/cactid/util.h cacti-0.8.6/cactid/util.h --- cacti-0.8.5/cactid/util.h 2004-02-03 01:21:08.000000000 -0500 +++ cacti-0.8.6/cactid/util.h 2004-02-12 20:49:32.000000000 -0500 @@ -23,7 +23,7 @@ +-------------------------------------------------------------------------+ */ -int read_config(char *file, config_t * set); +int read_cactid_config(char *file, config_t * set); void config_defaults(config_t *); void timestamp(char *); int file_exists(char *filename);