Author: nkinder
Update of /cvs/dirsec/ldapserver/ldap/servers/snmp
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv9308/ldap/servers/snmp
Modified Files:
ldap-agent.c ldap-agent.h main.c redhat-directory.mib
Log Message:
Resolves: 207457
Summary: Convert counters to 64-bit capable Slapi_Counter type.
Index: ldap-agent.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/snmp/ldap-agent.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ldap-agent.c 18 Oct 2007 00:08:35 -0000 1.12
+++ ldap-agent.c 24 Oct 2008 22:36:59 -0000 1.13
@@ -277,6 +277,7 @@
time_t previous_start;
int previous_state;
int stats_hdl = -1;
+ sem_t *stats_sem = NULL;
snmp_log(LOG_INFO, "Reloading stats.\n");
@@ -291,8 +292,39 @@
snmp_log(LOG_INFO, "Opening stats file (%s) for server: %d\n",
serv_p->stats_file, serv_p->port);
+ /* Open and acquire semaphore */
+ if ((stats_sem = sem_open(serv_p->stats_sem_name, 0)) == SEM_FAILED) {
+ stats_sem = NULL;
+ snmp_log(LOG_INFO, "Unable to open semaphore for server: %d\n",
serv_p->port);
+ } else {
+ int i = 0;
+ int got_sem = 0;
+
+ for (i=0; i < SNMP_NUM_SEM_WAITS; i++) {
+ if (sem_trywait(stats_sem) == 0) {
+ got_sem = 1;
+ break;
+ }
+ PR_Sleep(PR_SecondsToInterval(1));
+ }
+
+ if (!got_sem) {
+ /* We're unable to get the semaphore. Assume
+ * that the server is down. */
+ snmp_log(LOG_INFO, "Unable to acquire semaphore for server:
%d\n", serv_p->port);
+ sem_close(stats_sem);
+ stats_sem = NULL;
+ }
+ }
+
/* Open the stats file */
- if ( agt_mopen_stats(serv_p->stats_file, O_RDONLY, &stats_hdl) != 0 )
{
+ if ((stats_sem == NULL) || (agt_mopen_stats(serv_p->stats_file, O_RDONLY,
&stats_hdl) != 0)) {
+ if (stats_sem) {
+ /* Release and close semaphore */
+ sem_post(stats_sem);
+ sem_close(stats_sem);
+ }
+
/* Server must be down */
serv_p->server_state = SERVER_DOWN;
/* Zero out the ops and entries tables */
@@ -313,6 +345,10 @@
snmp_log(LOG_ERR, "Error closing stats file: %s\n",
serv_p->stats_file);
+ /* Release and close semaphore */
+ sem_post(stats_sem);
+ sem_close(stats_sem);
+
/* Server must be down if the stats file hasn't been
* updated in a while */
if (difftime(time(NULL), ctx->hdr_tbl.updateTime) >=
UPDATE_THRESHOLD) {
@@ -382,135 +418,108 @@
netsnmp_index * item,
netsnmp_table_request_info *table_info)
{
+ PRUint64 *the_stat = NULL;
+ integer64 new_val;
netsnmp_variable_list *var = request->requestvb;
stats_table_context *context = (stats_table_context *) item;
switch (table_info->colnum) {
case COLUMN_DSANONYMOUSBINDS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsAnonymousBinds,
- sizeof(context->ops_tbl.dsAnonymousBinds));
+ the_stat = &context->ops_tbl.dsAnonymousBinds;
break;
case COLUMN_DSUNAUTHBINDS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsUnAuthBinds,
- sizeof(context->ops_tbl.dsUnAuthBinds));
+ the_stat = &context->ops_tbl.dsUnAuthBinds;
break;
case COLUMN_DSSIMPLEAUTHBINDS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsSimpleAuthBinds,
- sizeof(context->ops_tbl.dsSimpleAuthBinds));
+ the_stat = &context->ops_tbl.dsSimpleAuthBinds;
break;
case COLUMN_DSSTRONGAUTHBINDS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsStrongAuthBinds,
- sizeof(context->ops_tbl.dsStrongAuthBinds));
+ the_stat = &context->ops_tbl.dsStrongAuthBinds;
break;
case COLUMN_DSBINDSECURITYERRORS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *)
&context->ops_tbl.dsBindSecurityErrors,
- sizeof(context->ops_tbl.dsBindSecurityErrors));
+ the_stat = &context->ops_tbl.dsBindSecurityErrors;
break;
case COLUMN_DSINOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsInOps,
- sizeof(context->ops_tbl.dsInOps));
+ the_stat = &context->ops_tbl.dsInOps;
break;
case COLUMN_DSREADOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsReadOps,
- sizeof(context->ops_tbl.dsReadOps));
+ the_stat = &context->ops_tbl.dsReadOps;
break;
case COLUMN_DSCOMPAREOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsCompareOps,
- sizeof(context->ops_tbl.dsCompareOps));
+ the_stat = &context->ops_tbl.dsCompareOps;
break;
case COLUMN_DSADDENTRYOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsAddEntryOps,
- sizeof(context->ops_tbl.dsAddEntryOps));
+ the_stat = &context->ops_tbl.dsAddEntryOps;
break;
case COLUMN_DSREMOVEENTRYOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsRemoveEntryOps,
- sizeof(context->ops_tbl.dsRemoveEntryOps));
+ the_stat = &context->ops_tbl.dsRemoveEntryOps;
break;
case COLUMN_DSMODIFYENTRYOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsModifyEntryOps,
- sizeof(context->ops_tbl.dsModifyEntryOps));
+ the_stat = &context->ops_tbl.dsModifyEntryOps;
break;
case COLUMN_DSMODIFYRDNOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsModifyRDNOps,
- sizeof(context->ops_tbl.dsModifyRDNOps));
+ the_stat = &context->ops_tbl.dsModifyRDNOps;
break;
case COLUMN_DSLISTOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsListOps,
- sizeof(context->ops_tbl.dsListOps));
+ the_stat = &context->ops_tbl.dsListOps;
break;
case COLUMN_DSSEARCHOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsSearchOps,
- sizeof(context->ops_tbl.dsSearchOps));
+ the_stat = &context->ops_tbl.dsSearchOps;
break;
case COLUMN_DSONELEVELSEARCHOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *)
&context->ops_tbl.dsOneLevelSearchOps,
- sizeof(context->ops_tbl.dsOneLevelSearchOps));
+ the_stat = &context->ops_tbl.dsOneLevelSearchOps;
break;
case COLUMN_DSWHOLESUBTREESEARCHOPS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *)
&context->ops_tbl.dsWholeSubtreeSearchOps,
- sizeof(context->ops_tbl.dsWholeSubtreeSearchOps));
+ the_stat = &context->ops_tbl.dsWholeSubtreeSearchOps;
break;
case COLUMN_DSREFERRALS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsReferrals,
- sizeof(context->ops_tbl.dsReferrals));
+ the_stat = &context->ops_tbl.dsReferrals;
break;
case COLUMN_DSCHAININGS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsChainings,
- sizeof(context->ops_tbl.dsChainings));
+ the_stat = &context->ops_tbl.dsChainings;
break;
case COLUMN_DSSECURITYERRORS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsSecurityErrors,
- sizeof(context->ops_tbl.dsSecurityErrors));
+ the_stat = &context->ops_tbl.dsSecurityErrors;
break;
case COLUMN_DSERRORS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->ops_tbl.dsErrors,
- sizeof(context->ops_tbl.dsErrors));
+ the_stat = &context->ops_tbl.dsErrors;
break;
default:/* We shouldn't get here */
snmp_log(LOG_ERR, "Unknown column in dsOpsTable_get_value\n");
return SNMP_ERR_GENERR;
}
+
+ /* The Net-SNMP integer64 type isn't a true 64-bit value, but instead
+ * a structure containing the high and low bits separately. We need
+ * to split our value appropriately. */
+ new_val.low = *the_stat & 0x00000000ffffffff;
+ new_val.high = (*the_stat >> 32) & 0x00000000ffffffff;
+
+ snmp_set_var_typed_value(var, ASN_COUNTER64,
+ (u_char *) &new_val,
+ sizeof(new_val));
+
return SNMP_ERR_NOERROR;
}
@@ -527,45 +536,48 @@
netsnmp_index * item,
netsnmp_table_request_info *table_info)
{
+ PRUint64 *the_stat = NULL;
+ integer64 new_val;
netsnmp_variable_list *var = request->requestvb;
stats_table_context *context = (stats_table_context *) item;
switch (table_info->colnum) {
case COLUMN_DSMASTERENTRIES:
- snmp_set_var_typed_value(var, ASN_GAUGE,
- (u_char *)
&context->entries_tbl.dsMasterEntries,
- sizeof(context->entries_tbl.dsMasterEntries));
+ the_stat = &context->entries_tbl.dsMasterEntries;
break;
case COLUMN_DSCOPYENTRIES:
- snmp_set_var_typed_value(var, ASN_GAUGE,
- (u_char *) &context->entries_tbl.dsCopyEntries,
- sizeof(context->entries_tbl.dsCopyEntries));
+ the_stat = &context->entries_tbl.dsCopyEntries;
break;
case COLUMN_DSCACHEENTRIES:
- snmp_set_var_typed_value(var, ASN_GAUGE,
- (u_char *) &context->entries_tbl.dsCacheEntries,
- sizeof(context->entries_tbl.dsCacheEntries));
+ the_stat = &context->entries_tbl.dsCacheEntries;
break;
case COLUMN_DSCACHEHITS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->entries_tbl.dsCacheHits,
- sizeof(context->entries_tbl.dsCacheHits));
+ the_stat = &context->entries_tbl.dsCacheHits;
break;
case COLUMN_DSSLAVEHITS:
- snmp_set_var_typed_value(var, ASN_COUNTER,
- (u_char *) &context->entries_tbl.dsSlaveHits,
- sizeof(context->entries_tbl.dsSlaveHits));
+ the_stat = &context->entries_tbl.dsSlaveHits;
break;
default:/* We shouldn't get here */
snmp_log(LOG_ERR, "Unknown column in dsEntriesTable_get_value\n");
return SNMP_ERR_GENERR;
}
+
+ /* The Net-SNMP integer64 type isn't a true 64-bit value, but instead
+ * a structure containing the high and low bits separately. We need
+ * to split our value appropriately. */
+ new_val.low = *the_stat & 0x00000000ffffffff;
+ new_val.high = (*the_stat >> 32) & 0x00000000ffffffff;
+
+ snmp_set_var_typed_value(var, ASN_COUNTER64,
+ (u_char *) &new_val,
+ sizeof(new_val));
+
return SNMP_ERR_NOERROR;
}
Index: ldap-agent.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/snmp/ldap-agent.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ldap-agent.h 8 Oct 2008 17:29:04 -0000 1.10
+++ ldap-agent.h 24 Oct 2008 22:36:59 -0000 1.11
@@ -74,10 +74,19 @@
#include <net-snmp/library/container.h>
#include <net-snmp/agent/table_array.h>
#include "../slapd/agtmmap.h"
+#include <semaphore.h>
+#include <fcntl.h>
+
+#ifdef HPUX
+/* HP-UX doesn't define SEM_FAILED like other platforms, so
+ * * we define it ourselves. */
+#define SEM_FAILED ((sem_t *)(-1))
+#endif
#define MAXLINE 4096
#define CACHE_REFRESH_INTERVAL 15
#define UPDATE_THRESHOLD 20
+#define SNMP_NUM_SEM_WAITS 10
#define LDAP_AGENT_PIDFILE ".ldap-agent.pid"
#define LDAP_AGENT_LOGFILE "ldap-agent.log"
@@ -95,6 +104,7 @@
PRUint32 port;
int server_state;
char *stats_file;
+ char *stats_sem_name;
char *dse_ldif;
struct server_instance_s *next;
} server_instance;
Index: main.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/snmp/main.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- main.c 22 Oct 2007 18:29:55 -0000 1.15
+++ main.c 24 Oct 2008 22:36:59 -0000 1.16
@@ -355,6 +355,19 @@
instancename = NULL;
goto close_and_exit;
}
+
+ /* set the semaphore name */
+ /* ".stats" + \0 = 7 */
+ serv_p->stats_sem_name = malloc(strlen(p) + 7);
+ if (serv_p->stats_sem_name != NULL) {
+ snprintf(serv_p->stats_sem_name, strlen(p) + 7,
"%s.stats", p);
+ } else {
+ printf("ldap-agent: malloc error processing config
file\n");
+ error = 1;
+ free(instancename);
+ instancename = NULL;
+ goto close_and_exit;
+ }
}
/* Open dse.ldif */
Index: redhat-directory.mib
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/snmp/redhat-directory.mib,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- redhat-directory.mib 19 Apr 2005 22:07:42 -0000 1.3
+++ redhat-directory.mib 24 Oct 2008 22:36:59 -0000 1.4
@@ -46,7 +46,7 @@
RHDS-MIB DEFINITIONS ::= BEGIN
IMPORTS
- MODULE-IDENTITY, Counter32, Gauge32, OBJECT-TYPE
+ MODULE-IDENTITY, Counter64, Counter32, Gauge32, OBJECT-TYPE
FROM SNMPv2-SMI
DisplayString, TimeStamp, TEXTUAL-CONVENTION
FROM SNMPv2-TC
@@ -68,7 +68,7 @@
SYNTAX DisplayString
rhds MODULE-IDENTITY
- LAST-UPDATED "200503020000Z"
+ LAST-UPDATED "200810230000Z"
ORGANIZATION "Red Hat, Inc."
CONTACT-INFO
"Red Hat, Inc.
@@ -103,54 +103,54 @@
-- Bindings
dsAnonymousBinds
- Counter32,
+ Counter64,
dsUnAuthBinds
- Counter32,
+ Counter64,
dsSimpleAuthBinds
- Counter32,
+ Counter64,
dsStrongAuthBinds
- Counter32,
+ Counter64
dsBindSecurityErrors
- Counter32,
+ Counter64,
-- In-coming operations
dsInOps
- Counter32,
+ Counter64,
dsReadOps
- Counter32,
+ Counter64,
dsCompareOps
- Counter32,
+ Counter64,
dsAddEntryOps
- Counter32,
+ Counter64,
dsRemoveEntryOps
- Counter32,
+ Counter64,
dsModifyEntryOps
- Counter32,
+ Counter64,
dsModifyRDNOps
- Counter32,
+ Counter64,
dsListOps
- Counter32,
+ Counter64,
dsSearchOps
- Counter32,
+ Counter64,
dsOneLevelSearchOps
- Counter32,
+ Counter64,
dsWholeSubtreeSearchOps
- Counter32,
+ Counter64,
-- Out going operations
dsReferrals
- Counter32,
+ Counter64,
dsChainings
- Counter32,
+ Counter64,
-- Errors
dsSecurityErrors
- Counter32,
+ Counter64,
dsErrors
- Counter32
+ Counter64
}
-- CLDAP does not use binds; for A CLDAP DS the bind
@@ -172,7 +172,7 @@
-- CLDAP and LDAP DSs: dsReferrals.
dsAnonymousBinds OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -181,7 +181,7 @@
::= {dsOpsEntry 1}
dsUnAuthBinds OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -190,7 +190,7 @@
::= {dsOpsEntry 2}
dsSimpleAuthBinds OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -203,7 +203,7 @@
::= {dsOpsEntry 3}
dsStrongAuthBinds OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -217,7 +217,7 @@
::= {dsOpsEntry 4}
dsBindSecurityErrors OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -230,7 +230,7 @@
::= {dsOpsEntry 5}
dsInOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -240,7 +240,7 @@
::= {dsOpsEntry 6}
dsReadOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -252,7 +252,7 @@
::= {dsOpsEntry 7}
dsCompareOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -264,7 +264,7 @@
::= {dsOpsEntry 8}
dsAddEntryOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -276,7 +276,7 @@
::= {dsOpsEntry 9}
dsRemoveEntryOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -288,7 +288,7 @@
::= {dsOpsEntry 10}
dsModifyEntryOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -300,7 +300,7 @@
::= {dsOpsEntry 11}
dsModifyRDNOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -312,7 +312,7 @@
::= {dsOpsEntry 12}
dsListOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -324,7 +324,7 @@
::= {dsOpsEntry 13}
dsSearchOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -337,7 +337,7 @@
::= {dsOpsEntry 14}
dsOneLevelSearchOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -349,7 +349,7 @@
::= {dsOpsEntry 15}
dsWholeSubtreeSearchOps OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -361,7 +361,7 @@
::= {dsOpsEntry 16}
dsReferrals OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -373,7 +373,7 @@
::= {dsOpsEntry 17}
dsChainings OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -385,7 +385,7 @@
::= {dsOpsEntry 18}
dsSecurityErrors OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -397,7 +397,7 @@
::= {dsOpsEntry 19}
dsErrors OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -437,15 +437,15 @@
DsEntriesEntry ::= SEQUENCE {
dsMasterEntries
- Gauge32,
+ Counter64,
dsCopyEntries
- Gauge32,
+ Counter64,
dsCacheEntries
- Gauge32,
+ Counter64,
dsCacheHits
- Counter32,
+ Counter64,
dsSlaveHits
- Counter32
+ Counter64
}
-- A (C)LDAP frontend to the X.500 Directory will not have
@@ -454,7 +454,7 @@
-- directory: dsMasterEntries, dsCopyEntries, dsSlaveHits.
dsMasterEntries OBJECT-TYPE
- SYNTAX Gauge32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -462,7 +462,7 @@
::= {dsEntriesEntry 1}
dsCopyEntries OBJECT-TYPE
- SYNTAX Gauge32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -471,7 +471,7 @@
::= {dsEntriesEntry 2}
dsCacheEntries OBJECT-TYPE
- SYNTAX Gauge32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -480,8 +480,8 @@
cached partially. The negative cache is not counted."
::= {dsEntriesEntry 3}
- dsCacheHits OBJECT-TYPE
- SYNTAX Counter32
+ dsCacheHits OBJECT-TYPE
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
@@ -491,7 +491,7 @@
::= {dsEntriesEntry 4}
dsSlaveHits OBJECT-TYPE
- SYNTAX Counter32
+ SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION