diff options
| author | Nathan Kinder <nkinder@redhat.com> | 2006-04-13 23:12:16 +0000 |
|---|---|---|
| committer | Nathan Kinder <nkinder@redhat.com> | 2006-04-13 23:12:16 +0000 |
| commit | 44c865863e12df57be8d6034a3a3d6f4bf0f499b (patch) | |
| tree | 006917a14145a72266dacf16c6296c7ac54c575e /ldap/servers/snmp | |
| parent | 87dddea6af37fe0f6fda87e4a3cb584178b22dd6 (diff) | |
| download | ds-44c865863e12df57be8d6034a3a3d6f4bf0f499b.tar.gz ds-44c865863e12df57be8d6034a3a3d6f4bf0f499b.tar.xz ds-44c865863e12df57be8d6034a3a3d6f4bf0f499b.zip | |
188931 - Use system Net-SNMP libraries on Linux systems
Diffstat (limited to 'ldap/servers/snmp')
| -rw-r--r-- | ldap/servers/snmp/ldap-agent.c | 28 | ||||
| -rw-r--r-- | ldap/servers/snmp/ldap-agent.h | 1 | ||||
| -rw-r--r-- | ldap/servers/snmp/main.c | 14 |
3 files changed, 34 insertions, 9 deletions
diff --git a/ldap/servers/snmp/ldap-agent.c b/ldap/servers/snmp/ldap-agent.c index 769c3acb..fddd41d6 100644 --- a/ldap/servers/snmp/ldap-agent.c +++ b/ldap/servers/snmp/ldap-agent.c @@ -115,7 +115,10 @@ initialize_stats_table(void) netsnmp_table_registration_info *ops_table_info = NULL; netsnmp_table_registration_info *entries_table_info = NULL; netsnmp_table_registration_info *entity_table_info = NULL; + /* This is a hacky way of figuring out if we are on Net-SNMP 5.2 or later */ +#ifdef NETSNMP_CACHE_AUTO_RELOAD netsnmp_cache *stats_table_cache = NULL; +#endif if (ops_handler || entries_handler || entity_handler) { snmp_log(LOG_ERR, "initialize_stats_table called more than once.\n"); @@ -188,12 +191,19 @@ initialize_stats_table(void) entity_cb.container, 1); /* Setup cache for auto reloading of stats */ +#ifdef NETSNMP_CACHE_AUTO_RELOAD + /* This is new api as of Net-SNMP 5.2 */ stats_table_cache = netsnmp_cache_create(CACHE_REFRESH_INTERVAL, load_stats_table, NULL, dsOpsTable_oid, dsOpsTable_oid_len); stats_table_cache->flags |= NETSNMP_CACHE_DONT_FREE_EXPIRED; stats_table_cache->flags |= NETSNMP_CACHE_DONT_AUTO_RELEASE; stats_table_cache->flags |= NETSNMP_CACHE_AUTO_RELOAD; netsnmp_inject_handler(ops_handler, netsnmp_cache_handler_get(stats_table_cache)); +#else + /* Do things the old way. This is only needed for Net-SNMP 5.1 and earlier. */ + netsnmp_inject_handler(ops_handler, netsnmp_get_cache_handler(CACHE_REFRESH_INTERVAL, load_stats_table, + free_stats_table, dsOpsTable_oid, dsOpsTable_oid_len)); +#endif } /************************************************************ @@ -264,7 +274,7 @@ load_stats_table(netsnmp_cache *cache, void *foo) int stats_hdl = -1; int err; - snmp_log(LOG_DEBUG, "Reloading stats.\n"); + snmp_log(LOG_INFO, "Reloading stats.\n"); /* Initialize data for each server in conf file */ for (serv_p = server_head; serv_p != NULL; serv_p = serv_p->next) { @@ -274,7 +284,7 @@ load_stats_table(netsnmp_cache *cache, void *foo) previous_state = serv_p->server_state; previous_start = ctx->hdr_tbl.startTime; - snmp_log(LOG_DEBUG, "Opening stats file (%s) for server: %d\n", + snmp_log(LOG_INFO, "Opening stats file (%s) for server: %d\n", serv_p->stats_file, serv_p->port); /* Open the stats file */ @@ -342,6 +352,20 @@ load_stats_table(netsnmp_cache *cache, void *foo) } /************************************************************ + * free_stats_table + * + * This function doesn't need to free anything since the + * load_stats_table function doesn't allocate any memory + * itself. The cache handler requires us to have a callback + * function for freeing the cache, so here it is. + */ +void +free_stats_table(netsnmp_cache *cache, void *foo) +{ + return; +} + +/************************************************************ * dsOpsTable_get_value * * This routine is called for get requests to copy the data diff --git a/ldap/servers/snmp/ldap-agent.h b/ldap/servers/snmp/ldap-agent.h index 65a1a915..c827a74b 100644 --- a/ldap/servers/snmp/ldap-agent.h +++ b/ldap/servers/snmp/ldap-agent.h @@ -90,6 +90,7 @@ typedef struct stats_table_context_s { void init_ldap_agent(void); void initialize_stats_table(void); int load_stats_table(netsnmp_cache *, void *); + void free_stats_table(netsnmp_cache *, void *); stats_table_context *stats_table_create_row(unsigned long); stats_table_context *stats_table_find_row(unsigned long); int dsOpsTable_get_value(netsnmp_request_info *, diff --git a/ldap/servers/snmp/main.c b/ldap/servers/snmp/main.c index b42fd7eb..2fe70b4b 100644 --- a/ldap/servers/snmp/main.c +++ b/ldap/servers/snmp/main.c @@ -53,9 +53,9 @@ static int keep_running; RETSIGTYPE stop_server(int signum) { if (signum == SIGUSR1) { - snmp_log(LOG_INFO, "Detected attempt to start ldap-agent again.\n"); + snmp_log(LOG_WARNING, "Detected attempt to start ldap-agent again.\n"); } else { - snmp_log(LOG_INFO, "Received stop signal. Stopping ldap-agent...\n"); + snmp_log(LOG_WARNING, "Received stop signal. Stopping ldap-agent...\n"); keep_running = 0; } } @@ -64,7 +64,7 @@ int main (int argc, char *argv[]) { char *config_file = NULL; netsnmp_log_handler *log_hdl = NULL; - int c, log_level = LOG_INFO; + int c, log_level = LOG_WARNING; struct stat logdir_s; pid_t child_pid; FILE *pid_fp; @@ -149,13 +149,13 @@ main (int argc, char *argv[]) { exit(1); } - netsnmp_enable_filelog(log_hdl, 1); + snmp_enable_filelog((char*)log_hdl->token, 1); } else { printf("Error starting logging."); exit(1); } - snmp_log(LOG_INFO, "Starting ldap-agent...\n"); + snmp_log(LOG_WARNING, "Starting ldap-agent...\n"); /* setup agentx master */ netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, @@ -204,7 +204,7 @@ main (int argc, char *argv[]) { } /* we're up and running! */ - snmp_log(LOG_INFO, "Started ldap-agent as pid %d\n", child_pid); + snmp_log(LOG_WARNING, "Started ldap-agent as pid %d\n", child_pid); /* loop here until asked to stop */ while(keep_running) { @@ -213,7 +213,7 @@ main (int argc, char *argv[]) { /* say goodbye */ snmp_shutdown("ldap-agent"); - snmp_log(LOG_INFO, "ldap-agent stopped.\n"); + snmp_log(LOG_WARNING, "ldap-agent stopped.\n"); /* remove pidfile */ remove(pidfile); |
