From 283759753b198ffc18d172c2f5e1fbef5efb0b75 Mon Sep 17 00:00:00 2001 From: Nathan Kinder Date: Thu, 31 Mar 2005 00:10:15 +0000 Subject: Update components and SNMP config changes --- ldap/servers/slapd/agtmmap.c | 10 +++++ ldap/servers/slapd/agtmmap.h | 5 +++ ldap/servers/slapd/fedse.c | 3 +- ldap/servers/slapd/snmp_collator.c | 82 +++++++++++++++++++++++++++++++++++++- ldap/servers/slapd/snmp_collator.h | 12 ++++++ 5 files changed, 109 insertions(+), 3 deletions(-) (limited to 'ldap/servers/slapd') diff --git a/ldap/servers/slapd/agtmmap.c b/ldap/servers/slapd/agtmmap.c index c67282cb..453e999d 100644 --- a/ldap/servers/slapd/agtmmap.c +++ b/ldap/servers/slapd/agtmmap.c @@ -357,6 +357,16 @@ agt_mread_stats (int hdl, struct hdr_stats_t *pHdrInfo, struct ops_stats_t *pDsO pHdrInfo->updateTime = pfile_stats->hdr_stats.updateTime; strncpy(pHdrInfo->dsVersion, pfile_stats->hdr_stats.dsVersion, (sizeof(pHdrInfo->dsVersion)/sizeof(char)) - 1); + strncpy(pHdrInfo->dsName, pfile_stats->hdr_stats.dsName, + (sizeof(pHdrInfo->dsName)/sizeof(char)) - 1); + strncpy(pHdrInfo->dsDescription, pfile_stats->hdr_stats.dsDescription, + (sizeof(pHdrInfo->dsDescription)/sizeof(char)) - 1); + strncpy(pHdrInfo->dsOrganization, pfile_stats->hdr_stats.dsOrganization, + (sizeof(pHdrInfo->dsOrganization)/sizeof(char)) - 1); + strncpy(pHdrInfo->dsLocation, pfile_stats->hdr_stats.dsLocation, + (sizeof(pHdrInfo->dsLocation)/sizeof(char)) - 1); + strncpy(pHdrInfo->dsContact, pfile_stats->hdr_stats.dsContact, + (sizeof(pHdrInfo->dsContact)/sizeof(char)) - 1); } if (pDsOpsTbl != NULL) { diff --git a/ldap/servers/slapd/agtmmap.h b/ldap/servers/slapd/agtmmap.h index 330475e9..f3cf81d1 100644 --- a/ldap/servers/slapd/agtmmap.h +++ b/ldap/servers/slapd/agtmmap.h @@ -72,6 +72,11 @@ struct hdr_stats_t{ time_t startTime; time_t updateTime; char dsVersion[100]; + char dsName[30]; + char dsDescription[30]; + char dsOrganization[30]; + char dsLocation[30]; + char dsContact[30]; }; struct ops_stats_t{ diff --git a/ldap/servers/slapd/fedse.c b/ldap/servers/slapd/fedse.c index f636a530..bf75fc0a 100644 --- a/ldap/servers/slapd/fedse.c +++ b/ldap/servers/slapd/fedse.c @@ -105,8 +105,9 @@ static const char *internal_entries[] = "dn:cn=SNMP,cn=config\n" "objectclass:top\n" "objectclass:nsSNMP\n" - "cn:SNMP\n" + "cn:SNMP\n" "nsSNMPEnabled:on\n" + "nsSNMPName:\n" "nsSNMPOrganization:\n" "nsSNMPLocation:\n" "nsSNMPContact:\n" diff --git a/ldap/servers/slapd/snmp_collator.c b/ldap/servers/slapd/snmp_collator.c index 3c0f5e65..7613edb0 100644 --- a/ldap/servers/slapd/snmp_collator.c +++ b/ldap/servers/slapd/snmp_collator.c @@ -35,6 +35,9 @@ char *make_ds_url(char *host, int port); void print_snmp_interaction_table(); int search_interaction_table(char *dsURL, int *isnew); +static void loadConfigStats(); +static Slapi_Entry *getConfigEntry( Slapi_Entry **e ); +static void freeConfigEntry( Slapi_Entry **e ); /* snmp stats stuff */ struct agt_stats_t *stats=NULL; @@ -81,6 +84,9 @@ int snmp_collator_init(){ stats->hdr_stats.restarted = 0; stats->hdr_stats.startTime = time(0); /* This is a bit off, hope it's ok */ + /* load config stats */ + loadConfigStats(); + /* point these at the mmaped data */ g_get_global_snmp_vars()->ops_tbl.dsAnonymousBinds = &(stats->ops_stats.dsAnonymousBinds); g_get_global_snmp_vars()->ops_tbl.dsUnAuthBinds = &(stats->ops_stats.dsUnAuthBinds); @@ -380,10 +386,11 @@ int snmp_collator_start() } } - +/* read config entry for entity table data */ + /* point stats struct at mmap data */ - stats = (struct agt_stats_t *) mmap_tbl [hdl].fp; + stats = (struct agt_stats_t *) mmap_tbl [hdl].fp; /* initialize stats data */ @@ -605,7 +612,78 @@ snmp_as_entry(Slapi_Entry *e) add_counter_to_value(e,"SlaveHits",stats->entries_stats.dsSlaveHits); } +static void +loadConfigStats() { + Slapi_Entry *entry = NULL; + char *name = NULL; + char *desc = NULL; + char *org = NULL; + char *loc = NULL; + char *contact = NULL; + + /* Read attributes from SNMP config entry */ + getConfigEntry( &entry ); + if ( entry != NULL ) { + name = slapi_entry_attr_get_charptr( entry, SNMP_NAME_ATTR ); + desc = slapi_entry_attr_get_charptr( entry, SNMP_DESC_ATTR ); + org = slapi_entry_attr_get_charptr( entry, SNMP_ORG_ATTR ); + loc = slapi_entry_attr_get_charptr( entry, SNMP_LOC_ATTR ); + contact = slapi_entry_attr_get_charptr( entry, SNMP_CONTACT_ATTR ); + freeConfigEntry( &entry ); + } + + /* Load stats into table */ + if ( name != NULL) { + strncpy(stats->hdr_stats.dsName, name, + (sizeof(stats->hdr_stats.dsName)/sizeof(char)) - 1); + } + + if ( desc != NULL) { + strncpy(stats->hdr_stats.dsDescription, desc, + (sizeof(stats->hdr_stats.dsDescription)/sizeof(char)) - 1); + } + + if ( org != NULL) { + strncpy(stats->hdr_stats.dsOrganization, org, + (sizeof(stats->hdr_stats.dsOrganization)/sizeof(char)) - 1); + } + + if ( loc != NULL) { + strncpy(stats->hdr_stats.dsLocation, loc, + (sizeof(stats->hdr_stats.dsLocation)/sizeof(char)) - 1); + } + + if ( contact != NULL) { + strncpy(stats->hdr_stats.dsContact, contact, + (sizeof(stats->hdr_stats.dsContact)/sizeof(char)) - 1); + } + + /* Free strings */ + slapi_ch_free((void **) &name); + slapi_ch_free((void **) &desc); + slapi_ch_free((void **) &org); + slapi_ch_free((void **) &loc); + slapi_ch_free((void **) &contact); +} +static Slapi_Entry * +getConfigEntry( Slapi_Entry **e ) { + Slapi_DN sdn; + + slapi_sdn_init_dn_byref( &sdn, SNMP_CONFIG_DN ); + slapi_search_internal_get_entry( &sdn, NULL, e, + plugin_get_default_component_id()); + slapi_sdn_done( &sdn ); + return *e; +} + +static void +freeConfigEntry( Slapi_Entry **e ) { + if ( (e != NULL) && (*e != NULL) ) { + slapi_entry_free( *e ); + *e = NULL; + } +} diff --git a/ldap/servers/slapd/snmp_collator.h b/ldap/servers/slapd/snmp_collator.h index 77dd4bc1..d9406518 100644 --- a/ldap/servers/slapd/snmp_collator.h +++ b/ldap/servers/slapd/snmp_collator.h @@ -3,6 +3,18 @@ * Copyright (C) 2005 Red Hat, Inc. * All rights reserved. * END COPYRIGHT BLOCK **/ +/****************************************************************************** +* +* defines +* +******************************************************************************/ +#define SNMP_CONFIG_DN "cn=SNMP,cn=config" +#define SNMP_NAME_ATTR "nsSNMPName" +#define SNMP_DESC_ATTR "nsSNMPDescription" +#define SNMP_ORG_ATTR "nsSNMPOrganization" +#define SNMP_LOC_ATTR "nsSNMPLocation" +#define SNMP_CONTACT_ATTR "nsSNMPContact" + /****************************************************************************** * * function prototypes -- cgit