diff options
author | Joshua Tolley | 2010-11-26 17:22:01 +0000 |
---|---|---|
committer | Joshua Tolley | 2010-11-26 17:22:01 +0000 |
commit | fe9d8f21bbdfb442b8233b4627a0c67dc458a8bd (patch) | |
tree | a88daa49fc47e64777af3d331cf142e0604c2d48 /RDBMS-MIB_src |
Diffstat (limited to 'RDBMS-MIB_src')
98 files changed, 21713 insertions, 0 deletions
diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/README b/RDBMS-MIB_src/rdbmsDbInfoTable/README new file mode 100644 index 0000000..c4a8778 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/README @@ -0,0 +1 @@ +For PostgreSQL version 8.0.x the rdbmsDbInfoSize* fields are returned as 0, because that information is unavailable. diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable.c b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable.c new file mode 100644 index 0000000..7bc63ef --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable.c @@ -0,0 +1,123 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable.c,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbInfoTable.h" +#include "rdbmsDbInfoTable_interface.h" + +oid rdbmsDbInfoTable_oid[] = { RDBMSDBINFOTABLE_OID }; +int rdbmsDbInfoTable_oid_size = OID_LENGTH(rdbmsDbInfoTable_oid); + +void initialize_table_rdbmsDbInfoTable(void); + + +/** + * Initializes the rdbmsDbInfoTable module + */ +void +init_rdbmsDbInfoTable(void) +{ + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:init_rdbmsDbInfoTable","called\n")); + + /* + * TODO:300:o: Perform rdbmsDbInfoTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("rdbmsDbInfoTable")) + initialize_table_rdbmsDbInfoTable(); + +} /* init_rdbmsDbInfoTable */ + +/** + * Initialize the table rdbmsDbInfoTable + * (Define its contents and how it's structured) + */ +void +initialize_table_rdbmsDbInfoTable(void) +{ + rdbmsDbInfoTable_registration_ptr user_context; + u_long flags; + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:initialize_table_rdbmsDbInfoTable","called\n")); + + /* + * TODO:301:o: Perform rdbmsDbInfoTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize rdbmsDbInfoTable user context + * if you'd like to pass in a pointer to some data for this + * table, allocate or set it up here. + */ + /* + * a netsnmp_data_list is a simple way to store void pointers. A simple + * string token is used to add, find or remove pointers. + */ + user_context = netsnmp_create_data_list("rdbmsDbInfoTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _rdbmsDbInfoTable_initialize_interface(user_context, flags); +} /* initialize_table_rdbmsDbInfoTable */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +rdbmsDbInfoTable_pre_request(rdbmsDbInfoTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_pre_request","called\n")); + + /* + * TODO:510:o: Perform rdbmsDbInfoTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsDbInfoTable_pre_request */ + +/** + * post-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error (ignored) + */ +int +rdbmsDbInfoTable_post_request(rdbmsDbInfoTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_post_request","called\n")); + + /* + * TODO:511:o: Perform rdbmsDbInfoTable pos-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsDbInfoTable_post_request */ + + +/** @{ */ diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable.h b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable.h new file mode 100644 index 0000000..321aa86 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable.h @@ -0,0 +1,223 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable.h,v 1.5 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBINFOTABLE_H +#define RDBMSDBINFOTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @defgroup misc misc: Miscelaneous routines + * + * @{ + */ +#include <net-snmp/library/asn1.h> + +/* other required module components */ + /* *INDENT-OFF* */ +config_require(RDBMS-MIB/rdbmsDbInfoTable/rdbmsDbInfoTable_interface); +config_require(RDBMS-MIB/rdbmsDbInfoTable/rdbmsDbInfoTable_data_access); +config_require(RDBMS-MIB/rdbmsDbInfoTable/rdbmsDbInfoTable_data_get); + /* *INDENT-ON* */ + +/* OID and column number definitions for */ +#include "rdbmsDbInfoTable_oids.h" + +/* enum definions */ +#include "rdbmsDbInfoTable_enums.h" + +/* ********************************************************************* + * function declarations + */ +void init_rdbmsDbInfoTable(void); + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbInfoTable is subid 2 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.2, length: 9 +*/ +/* ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review rdbmsDbInfoTable registration context. + */ +typedef netsnmp_data_list * rdbmsDbInfoTable_registration_ptr; + +/**********************************************************************/ +/* + * TODO:110:r: |-> Review rdbmsDbInfoTable data context structure. + * This structure is used to represent the data for rdbmsDbInfoTable. + */ +/* + * This structure contains storage for all the columns defined in the + * rdbmsDbInfoTable. + */ +typedef struct rdbmsDbInfoTable_data_s { + + /* + * rdbmsDbInfoProductName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ + char rdbmsDbInfoProductName[255]; +size_t rdbmsDbInfoProductName_len; /* # of char elements, not bytes */ + + /* + * rdbmsDbInfoVersion(2)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ + char rdbmsDbInfoVersion[255]; +size_t rdbmsDbInfoVersion_len; /* # of char elements, not bytes */ + + /* + * rdbmsDbInfoSizeUnits(3)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h + */ + u_long rdbmsDbInfoSizeUnits; + + /* + * rdbmsDbInfoSizeAllocated(4)/INTEGER/ASN_INTEGER/long(long)//l/A/W/e/R/d/h + */ + long rdbmsDbInfoSizeAllocated; + + /* + * rdbmsDbInfoSizeUsed(5)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/R/d/h + */ + long rdbmsDbInfoSizeUsed; + + /* + * rdbmsDbInfoLastBackup(6)/DateAndTime/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ +/* char rdbmsDbInfoLastBackup[255]; +size_t rdbmsDbInfoLastBackup_len; *//* # of char elements, not bytes */ + int lastBackupYear; + int lastBackupMonth; + int lastBackupDay; + int lastBackupHour; + int lastBackupMinutes; + int lastBackupSeconds; + /* the terminology here was stolen from net-snmp */ + int lastBackupDeciSeconds; + + int utc_offset_direction; + int utc_offset_hours; + int utc_offset_minutes; +} rdbmsDbInfoTable_data; + + +/* + * TODO:120:r: |-> Review rdbmsDbInfoTable mib index. + * This structure is used to represent the index for rdbmsDbInfoTable. + */ +typedef struct rdbmsDbInfoTable_mib_index_s { + + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long rdbmsDbIndex; + + +} rdbmsDbInfoTable_mib_index; + + /* + * TODO:121:r: | |-> Review rdbmsDbInfoTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. +*/ +#define MAX_rdbmsDbInfoTable_IDX_LEN 1 + + +/* ********************************************************************* + * TODO:130:o: |-> Review rdbmsDbInfoTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * rdbmsDbInfoTable_rowreq_ctx pointer. + */ +typedef struct rdbmsDbInfoTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_rdbmsDbInfoTable_IDX_LEN]; + + rdbmsDbInfoTable_mib_index tbl_idx; + + rdbmsDbInfoTable_data data; + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * implementor's context pointer (provided during registration) + */ + rdbmsDbInfoTable_registration_ptr rdbmsDbInfoTable_reg; + + /* + * TODO:131:o: | |-> Add useful data to rdbmsDbInfoTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *rdbmsDbInfoTable_data_list; + +} rdbmsDbInfoTable_rowreq_ctx; + +typedef struct rdbmsDbInfoTable_ref_rowreq_ctx_s { + rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx; +} rdbmsDbInfoTable_ref_rowreq_ctx; + +/* ********************************************************************* + * function prototypes + */ + int rdbmsDbInfoTable_pre_request(rdbmsDbInfoTable_registration_ptr user_context); + int rdbmsDbInfoTable_post_request(rdbmsDbInfoTable_registration_ptr user_context); + + +extern oid rdbmsDbInfoTable_oid[]; +extern int rdbmsDbInfoTable_oid_size; + + +#include "rdbmsDbInfoTable_interface.h" +#include "rdbmsDbInfoTable_data_access.h" +#include "rdbmsDbInfoTable_data_get.h" + +/* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBINFOTABLE_H */ diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_access.c b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_access.c new file mode 100644 index 0000000..00755f1 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_access.c @@ -0,0 +1,418 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable_data_access.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable_data_access.c,v 1.9 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbInfoTable.h" +#include "rdbmsDbInfoTable_data_access.h" + +const char *rdbmsDbInfoProductName = { "PostgreSQL" }; + +/** @defgroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbInfoTable is subid 2 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.2, length: 9 +*/ + +/** + * initialization for rdbmsDbInfoTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param rdbmsDbInfoTable_reg + * Pointer to rdbmsDbInfoTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +rdbmsDbInfoTable_init_data(rdbmsDbInfoTable_registration_ptr rdbmsDbInfoTable_reg) +{ + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_init_data","called\n")); + + /* + * TODO:303:o: Initialize rdbmsDbInfoTable data. + */ + + return MFD_SUCCESS; +} /* rdbmsDbInfoTable_init_data */ + +/** + * container-cached overview + * + */ + +/*********************************************************************** + * + * cache + * + ***********************************************************************/ +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +rdbmsDbInfoTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache) +{ + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_container_init","called\n")); + + if((NULL == cache) || (NULL == container_ptr_ptr)) { + snmp_log(LOG_ERR,"bad params to rdbmsDbInfoTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + /* + * TODO:345:A: Set up rdbmsDbInfoTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = RDBMSDBINFOTABLE_CACHE_TIMEOUT; /* seconds */ +} /* rdbmsDbInfoTable_container_init */ + +/** + * load cache data + * + * TODO:350:M: Implement rdbmsDbInfoTable cache load + * + * @param container container to which items should be inserted + * + * @retval MFD_SUCCESS : success. + * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source + * @retval MFD_ERROR : other error. + * + * This function is called to cache the index(es) (and data, optionally) + * for the every row in the data set. + * + * @remark + * While loading the cache, the only important thing is the indexes. + * If access to your data is cheap/fast (e.g. you have a pointer to a + * structure in memory), it would make sense to update the data here. + * If, however, the accessing the data invovles more work (e.g. parsing + * some other existing data, or peforming calculations to derive the data), + * then you can limit yourself to setting the indexes and saving any + * information you will need later. Then use the saved information in + * rdbmsDbInfoTable_row_prep() for populating data. + * + * @note + * If you need consistency between rows (like you want statistics + * for each row to be from the same time frame), you should set all + * data here. + * + */ +int +rdbmsDbInfoTable_cache_load(netsnmp_container *container) +{ + rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx; + size_t count = 0; + int i, resultCount, errorCode = MFD_SUCCESS, tmpInt; + PGresult *pg_db_qry, *pgsnmpd_tbl_qry; + char *db_oid, *tmpString; + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_cache_load","called\n")); + + if (PQstatus(dbconn) == CONNECTION_OK) + if (PQserverVersion(dbconn) < 80100) + pg_db_qry = PQexec(dbconn, "SELECT oid, version(), 0 FROM pg_database"); + else + pg_db_qry = PQexec(dbconn, "SELECT oid, version(), pg_database_size(datname) FROM pg_database"); + else { + snmp_log(LOG_ERR, "Can't get connected to the database"); + return MFD_RESOURCE_UNAVAILABLE; + } + if (PQresultStatus(pg_db_qry) != PGRES_TUPLES_OK) { + snmp_log(LOG_ERR, "Didn't get any results from the database"); + PQclear(pg_db_qry); + /* It's probably an error if I didn't find *any* information */ + return MFD_RESOURCE_UNAVAILABLE; + } + + resultCount = PQntuples(pg_db_qry); + + + /* + * TODO:351:M: |-> Load/update data in the rdbmsDbInfoTable container. + * loop over your rdbmsDbInfoTable data, allocate a rowreq context, + * set the index(es) [and data, optionally] and insert into + * the container. + */ + for (i = 0; i < resultCount; i++) { + + /* + * TODO:352:M: | |-> set indexes in new rdbmsDbInfoTable rowreq context. + */ + rowreq_ctx = rdbmsDbInfoTable_allocate_rowreq_ctx(); + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "memory allocation failed\n"); + return MFD_RESOURCE_UNAVAILABLE; + } + db_oid = PQgetvalue(pg_db_qry, i, 0); + if(MFD_SUCCESS != rdbmsDbInfoTable_indexes_set(rowreq_ctx + , atol(db_oid) + )) { + snmp_log(LOG_ERR,"error setting index while loading " + "rdbmsDbInfoTable cache.\n"); + rdbmsDbInfoTable_release_rowreq_ctx(rowreq_ctx); + continue; + } + + /* + * TODO:352:r: | |-> populate rdbmsDbInfoTable data context. + * Populate data context here. (optionally, delay until row prep) + */ + + rowreq_ctx->data.rdbmsDbInfoProductName_len = 255; + rowreq_ctx->data.rdbmsDbInfoVersion_len = 255; + + pgsnmpd_tbl_qry = NULL; + tmpInt = sizeof("SELECT EXTRACT(YEAR FROM last_backup), EXTRACT(MONTH FROM last_backup), EXTRACT(DAY FROM last_backup), EXTRACT(HOUR FROM last_backup), EXTRACT(MINUTE FROM last_backup), EXTRACT(SECOND FROM last_backup), EXTRACT(MILLISECOND FROM last_backup), EXTRACT(TIMEZONE_HOUR FROM last_backup), EXTRACT(TIMEZONE_MINUTE FROM last_backup) FROM pgsnmpd_rdbmsDbTable WHERE database_oid = %s") + sizeof(*db_oid); + tmpString = calloc(tmpInt, sizeof(char*)); + if (tmpString == NULL) snmp_log(LOG_ERR, "Couldn't allocate memory to query pgsnmpd-specific database table\n"); + else { + snmp_log(LOG_INFO, "Gathering rdbmsDbTable information from pgsnmpd_rdbmsDbTable\n"); + snprintf(tmpString, sizeof(char*) * tmpInt, "SELECT EXTRACT(YEAR FROM last_backup), EXTRACT(MONTH FROM last_backup), EXTRACT(DAY FROM last_backup), EXTRACT(HOUR FROM last_backup), EXTRACT(MINUTE FROM last_backup), EXTRACT(SECOND FROM last_backup), EXTRACT(MILLISECOND FROM last_backup), EXTRACT(TIMEZONE_HOUR FROM last_backup), EXTRACT(TIMEZONE_MINUTE FROM last_backup) FROM pgsnmpd_rdbmsDbTable WHERE database_oid = %s", db_oid); + pgsnmpd_tbl_qry = PQexec(dbconn, tmpString); + /* Ignore errors so that pgsnmpd will run without this table being available. Note that this error is INFO level, + * instead of something higher, because we're designed to work without this table */ + + if (PQresultStatus(pgsnmpd_tbl_qry) == PGRES_TUPLES_OK && PQntuples(pgsnmpd_tbl_qry) > 0) { + rowreq_ctx->data.lastBackupYear = atoi(PQgetvalue(pgsnmpd_tbl_qry, 0, 0)); + rowreq_ctx->data.lastBackupMonth = atoi(PQgetvalue(pgsnmpd_tbl_qry, 0, 1)); + rowreq_ctx->data.lastBackupDay = atoi(PQgetvalue(pgsnmpd_tbl_qry, 0, 2)); + rowreq_ctx->data.lastBackupHour = atoi(PQgetvalue(pgsnmpd_tbl_qry, 0, 3)); + rowreq_ctx->data.lastBackupMinutes = atoi(PQgetvalue(pgsnmpd_tbl_qry, 0, 4)); + rowreq_ctx->data.lastBackupSeconds = atoi(PQgetvalue(pgsnmpd_tbl_qry, 0, 5)); + rowreq_ctx->data.lastBackupDeciSeconds = atoi(PQgetvalue(pgsnmpd_tbl_qry, 0, 6)); + rowreq_ctx->data.utc_offset_hours = abs(atoi(PQgetvalue(pgsnmpd_tbl_qry, 0, 7))); + rowreq_ctx->data.utc_offset_minutes = atoi(PQgetvalue(pgsnmpd_tbl_qry, 0, 8)); + tmpInt = rowreq_ctx->data.utc_offset_hours * 60 + rowreq_ctx->data.utc_offset_minutes; + if (tmpInt == 0) rowreq_ctx->data.utc_offset_direction = 0; + else + rowreq_ctx->data.utc_offset_direction = (tmpInt > 0 ? 1 : -1); + } + else snmp_log(LOG_INFO, "Unable to find relevant data in pgsnmpd_rdbmsDbTable\n"); + free(tmpString); + } + + /* + * TRANSIENT or semi-TRANSIENT data: + * copy data or save any info needed to do it in row_prep. + */ + /* + * setup/save data for rdbmsDbInfoProductName + * rdbmsDbInfoProductName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ + /* + * TODO:246:r: |-> Define rdbmsDbInfoProductName mapping. + * Map values between raw/native values and MIB values + * + * if(MFD_SUCCESS != + * rdbmsDbInfoProductName_map(&rowreq_ctx->data.rdbmsDbInfoProductName, &rowreq_ctx->data.rdbmsDbInfoProductName_len, + * rdbmsDbInfoProductName, rdbmsDbInfoProductName_len, 0)) { + * return MFD_ERROR; + * } + */ + /* + * make sure there is enough space for rdbmsDbInfoProductName data + */ + if ((NULL == rowreq_ctx->data.rdbmsDbInfoProductName) || + (rowreq_ctx->data.rdbmsDbInfoProductName_len < (strlen(rdbmsDbInfoProductName) * sizeof(rowreq_ctx->data.rdbmsDbInfoProductName[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + errorCode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsDbInfoProductName_len = strlen(rdbmsDbInfoProductName) * sizeof(rowreq_ctx->data.rdbmsDbInfoProductName[0]); + memcpy( rowreq_ctx->data.rdbmsDbInfoProductName, rdbmsDbInfoProductName, rowreq_ctx->data.rdbmsDbInfoProductName_len ); + + /* + * setup/save data for rdbmsDbInfoVersion + * rdbmsDbInfoVersion(2)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ + /* + * TODO:246:r: |-> Define rdbmsDbInfoVersion mapping. + * Map values between raw/native values and MIB values + * + * if(MFD_SUCCESS != + * rdbmsDbInfoVersion_map(&rowreq_ctx->data.rdbmsDbInfoVersion, &rowreq_ctx->data.rdbmsDbInfoVersion_len, + * rdbmsDbInfoVersion, rdbmsDbInfoVersion_len, 0)) { + * return MFD_ERROR; + * } + */ + /* + * make sure there is enough space for rdbmsDbInfoVersion data + */ + tmpString = PQgetvalue(pg_db_qry, i, 1); + tmpInt = strlen(tmpString); + if ((NULL == rowreq_ctx->data.rdbmsDbInfoVersion) || + (rowreq_ctx->data.rdbmsDbInfoVersion_len < (tmpInt * sizeof(rowreq_ctx->data.rdbmsDbInfoVersion[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + errorCode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsDbInfoVersion_len = tmpInt * sizeof(rowreq_ctx->data.rdbmsDbInfoVersion[0]); + memcpy( rowreq_ctx->data.rdbmsDbInfoVersion, tmpString, rowreq_ctx->data.rdbmsDbInfoVersion_len ); + + /* + * setup/save data for rdbmsDbInfoSizeUnits + * rdbmsDbInfoSizeUnits(3)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h + */ + /* + * TODO:246:r: |-> Define rdbmsDbInfoSizeUnits mapping. + * Map values between raw/native values and MIB values + * + * enums usually need mapping. + */ + if(MFD_SUCCESS != + rdbmsDbInfoSizeUnits_map(&rowreq_ctx->data.rdbmsDbInfoSizeUnits, INTERNAL_RDBMSDBINFOSIZEUNITS_BYTES)) { + errorCode = MFD_ERROR; + break; + } + + /* + * setup/save data for rdbmsDbInfoSizeAllocated + * rdbmsDbInfoSizeAllocated(4)/INTEGER/ASN_INTEGER/long(long)//l/A/W/e/R/d/h + */ + /* + * TODO:246:r: |-> Define rdbmsDbInfoSizeAllocated mapping. + * Map values between raw/native values and MIB values + * + * Integer based value can usually just do a direct copy. + */ + rowreq_ctx->data.rdbmsDbInfoSizeAllocated = strtoul(PQgetvalue(pg_db_qry, i, 2), NULL, 10); + + /* + * setup/save data for rdbmsDbInfoSizeUsed + * rdbmsDbInfoSizeUsed(5)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/R/d/h + */ + /* + * TODO:246:r: |-> Define rdbmsDbInfoSizeUsed mapping. + * Map values between raw/native values and MIB values + * + * Integer based value can usually just do a direct copy. + */ + rowreq_ctx->data.rdbmsDbInfoSizeUsed = strtoul(PQgetvalue(pg_db_qry, i, 2), NULL, 10); + + /* + * insert into table container + */ + CONTAINER_INSERT(container, rowreq_ctx); + ++count; + PQclear(pgsnmpd_tbl_qry); + } + + DEBUGMSGT(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_cache_load", + "inserted %d records\n", count)); + + PQclear(pg_db_qry); + return errorCode; +} /* rdbmsDbInfoTable_cache_load */ + +/** + * cache clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +rdbmsDbInfoTable_cache_free(netsnmp_container *container) +{ + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_cache_free","called\n")); + + /* + * TODO:380:M: Free rdbmsDbInfoTable cache. + */ +} /* rdbmsDbInfoTable_cache_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +rdbmsDbInfoTable_row_prep( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_row_prep","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* rdbmsDbInfoTable_row_prep */ + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_access.h b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_access.h new file mode 100644 index 0000000..5931bcf --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_access.h @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable_data_access.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable_data_access.h,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBINFOTABLE_DATA_ACCESS_H +#define RDBMSDBINFOTABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ********************************************************************* + * function declarations + */ + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbInfoTable is subid 2 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.2, length: 9 +*/ + + + int rdbmsDbInfoTable_init_data(rdbmsDbInfoTable_registration_ptr rdbmsDbInfoTable_reg); + + +/* + * TODO:180:o: Review rdbmsDbInfoTable cache timeout. + * The number of seconds before the cache times out + */ +#define RDBMSDBINFOTABLE_CACHE_TIMEOUT 60 + +void rdbmsDbInfoTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache); +int rdbmsDbInfoTable_cache_load(netsnmp_container *container); +void rdbmsDbInfoTable_cache_free(netsnmp_container *container); + + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ +/* ********************************************************************* + * Since we have no idea how you really access your data, we'll go with + * a worst case example: a flat text file. + */ +#define MAX_LINE_SIZE 256 + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + int rdbmsDbInfoTable_row_prep( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBINFOTABLE_DATA_ACCESS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_get.c b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_get.c new file mode 100644 index 0000000..5da7220 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_get.c @@ -0,0 +1,847 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable_data_get.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable_data_get.c,v 1.5 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsDbInfoTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement rdbmsDbInfoTable get routines. + * TODO:240:M: Implement rdbmsDbInfoTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbInfoTable is subid 2 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.2, length: 9 +*/ + +/* --------------------------------------------------------------------- + * TODO:200:r: Implement rdbmsDbInfoTable data context functions. + */ + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This convenience function is useful for setting all the MIB index + * components with a single function call. It is assume that the C values + * have already been mapped from their native/rawformat to the MIB format. + */ +int +rdbmsDbInfoTable_indexes_set_tbl_idx(rdbmsDbInfoTable_mib_index *tbl_idx, long rdbmsDbIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_indexes_set_tbl_idx","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->rdbmsDbIndex = rdbmsDbIndex_val; + + + return MFD_SUCCESS; +} /* rdbmsDbInfoTable_indexes_set_tbl_idx */ + +/** + * @internal + * set row context indexes + * + * @param reqreq_ctx the row context that needs updated indexes + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This function sets the mib indexs, then updates the oid indexs + * from the mib index. + */ +int +rdbmsDbInfoTable_indexes_set(rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_indexes_set","called\n")); + + if(MFD_SUCCESS != rdbmsDbInfoTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx + , rdbmsDbIndex_val + )) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if(0 != rdbmsDbInfoTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsDbInfoTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbInfoEntry.rdbmsDbInfoProductName + * rdbmsDbInfoProductName is subid 1 of rdbmsDbInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.2.1.1 + * Description: +The textual product name of the server that created or last + restructured this database. The format is product specific. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbInfoProductName.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbInfoProductName_map(char **mib_rdbmsDbInfoProductName_val_ptr_ptr, size_t *mib_rdbmsDbInfoProductName_val_ptr_len_ptr, char *raw_rdbmsDbInfoProductName_val_ptr, size_t raw_rdbmsDbInfoProductName_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbInfoProductName_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbInfoProductName_val_ptr_ptr) && (NULL != mib_rdbmsDbInfoProductName_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoProductName_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbInfoProductName non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbInfoProductName_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbInfoProductName_val_ptr_ptr) || (*mib_rdbmsDbInfoProductName_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbInfoProductName_val_ptr_ptr = realloc( *mib_rdbmsDbInfoProductName_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbInfoProductName_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbInfoProductName_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbInfoProductName_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbInfoProductName_val_ptr_ptr, raw_rdbmsDbInfoProductName_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbInfoProductName_map */ + +/** + * Extract the current value of the rdbmsDbInfoProductName data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbInfoProductName_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsDbInfoProductName_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbInfoProductName. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbInfoProductName_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbInfoProductName_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbInfoProductName_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbInfoProductName_val_ptr_ptr, size_t *rdbmsDbInfoProductName_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbInfoProductName_val_ptr_ptr) && (NULL != *rdbmsDbInfoProductName_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbInfoProductName_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoProductName_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbInfoProductName data. + * set (* rdbmsDbInfoProductName_val_ptr_ptr ) and (* rdbmsDbInfoProductName_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbInfoProductName data + */ + if ((NULL == (* rdbmsDbInfoProductName_val_ptr_ptr )) || + ((* rdbmsDbInfoProductName_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbInfoProductName_len * sizeof((* rdbmsDbInfoProductName_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbInfoProductName data + */ + (* rdbmsDbInfoProductName_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbInfoProductName_len * sizeof((* rdbmsDbInfoProductName_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbInfoProductName_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbInfoProductName_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbInfoProductName_len * sizeof((* rdbmsDbInfoProductName_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbInfoProductName_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbInfoProductName, (* rdbmsDbInfoProductName_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbInfoProductName_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbInfoEntry.rdbmsDbInfoVersion + * rdbmsDbInfoVersion is subid 2 of rdbmsDbInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.2.1.2 + * Description: +The version number of the server that created or last + restructured this database. The format is product specific. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbInfoVersion.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbInfoVersion_map(char **mib_rdbmsDbInfoVersion_val_ptr_ptr, size_t *mib_rdbmsDbInfoVersion_val_ptr_len_ptr, char *raw_rdbmsDbInfoVersion_val_ptr, size_t raw_rdbmsDbInfoVersion_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbInfoVersion_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbInfoVersion_val_ptr_ptr) && (NULL != mib_rdbmsDbInfoVersion_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoVersion_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbInfoVersion non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbInfoVersion_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbInfoVersion_val_ptr_ptr) || (*mib_rdbmsDbInfoVersion_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbInfoVersion_val_ptr_ptr = realloc( *mib_rdbmsDbInfoVersion_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbInfoVersion_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbInfoVersion_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbInfoVersion_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbInfoVersion_val_ptr_ptr, raw_rdbmsDbInfoVersion_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbInfoVersion_map */ + +/** + * Extract the current value of the rdbmsDbInfoVersion data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbInfoVersion_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsDbInfoVersion_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbInfoVersion. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbInfoVersion_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbInfoVersion_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbInfoVersion_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbInfoVersion_val_ptr_ptr, size_t *rdbmsDbInfoVersion_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbInfoVersion_val_ptr_ptr) && (NULL != *rdbmsDbInfoVersion_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbInfoVersion_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoVersion_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbInfoVersion data. + * set (* rdbmsDbInfoVersion_val_ptr_ptr ) and (* rdbmsDbInfoVersion_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbInfoVersion data + */ + if ((NULL == (* rdbmsDbInfoVersion_val_ptr_ptr )) || + ((* rdbmsDbInfoVersion_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbInfoVersion_len * sizeof((* rdbmsDbInfoVersion_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbInfoVersion data + */ + (* rdbmsDbInfoVersion_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbInfoVersion_len * sizeof((* rdbmsDbInfoVersion_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbInfoVersion_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbInfoVersion_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbInfoVersion_len * sizeof((* rdbmsDbInfoVersion_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbInfoVersion_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbInfoVersion, (* rdbmsDbInfoVersion_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbInfoVersion_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbInfoEntry.rdbmsDbInfoSizeUnits + * rdbmsDbInfoSizeUnits is subid 3 of rdbmsDbInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.2.1.3 + * Description: +Identification of the units used to measure the size of this + database in rdbmsDbInfoSizeAllocated and rdbmsDbInfoSizeUsed. + bytes(1) indicates individual bytes, kbytes(2) indicates + units of kilobytes, mbytes(3) indicates units of megabytes, + gbytes(4) indicates units of gigabytes, and tbytes(5) + indicates units of terabytes. All are binary multiples -- 1K + = 1024. If writable, changes here are reflected in the get + values of the associated objects. + * + * Attributes: + * accessible 1 isscalar 0 enums 1 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * Enum range: 4/8. Values: bytes(1), kbytes(2), mbytes(3), gbytes(4), tbytes(5) + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbInfoSizeUnits.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbInfoSizeUnits_map(u_long *mib_rdbmsDbInfoSizeUnits_val_ptr, u_long raw_rdbmsDbInfoSizeUnits_val) +{ + netsnmp_assert(NULL != mib_rdbmsDbInfoSizeUnits_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoSizeUnits_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsDbInfoSizeUnits enum mapping. + * uses INTERNAL_* macros defined in the header files + */ + switch(raw_rdbmsDbInfoSizeUnits_val) { + case INTERNAL_RDBMSDBINFOSIZEUNITS_BYTES: + *mib_rdbmsDbInfoSizeUnits_val_ptr = RDBMSDBINFOSIZEUNITS_BYTES; + break; + + case INTERNAL_RDBMSDBINFOSIZEUNITS_KBYTES: + *mib_rdbmsDbInfoSizeUnits_val_ptr = RDBMSDBINFOSIZEUNITS_KBYTES; + break; + + case INTERNAL_RDBMSDBINFOSIZEUNITS_MBYTES: + *mib_rdbmsDbInfoSizeUnits_val_ptr = RDBMSDBINFOSIZEUNITS_MBYTES; + break; + + case INTERNAL_RDBMSDBINFOSIZEUNITS_GBYTES: + *mib_rdbmsDbInfoSizeUnits_val_ptr = RDBMSDBINFOSIZEUNITS_GBYTES; + break; + + case INTERNAL_RDBMSDBINFOSIZEUNITS_TBYTES: + *mib_rdbmsDbInfoSizeUnits_val_ptr = RDBMSDBINFOSIZEUNITS_TBYTES; + break; + + default: + snmp_log(LOG_ERR, "couldn't map value %ld for rdbmsDbInfoSizeUnits\n", raw_rdbmsDbInfoSizeUnits_val ); + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsDbInfoSizeUnits_map */ + +/** + * Extract the current value of the rdbmsDbInfoSizeUnits data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbInfoSizeUnits_val_ptr + * Pointer to storage for a long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsDbInfoSizeUnits_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsDbInfoSizeUnits_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsDbInfoSizeUnits_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoSizeUnits_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbInfoSizeUnits data. + * set (* rdbmsDbInfoSizeUnits_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsDbInfoSizeUnits_val_ptr ) = rowreq_ctx->data.rdbmsDbInfoSizeUnits; + + return MFD_SUCCESS; +} /* rdbmsDbInfoSizeUnits_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbInfoEntry.rdbmsDbInfoSizeAllocated + * rdbmsDbInfoSizeAllocated is subid 4 of rdbmsDbInfoEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.2.1.4 + * Description: +The estimated size of this database (in + rdbmsDbInfoSizeUnits), which is the disk space that has been + allocated to it and is no longer available to users on this + host. rdbmsDbInfoSize does not necessarily indicate the + amount of space actually in use for database data. Some + databases may support extending allocated size, and others + may not. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 0 + * settable 1 + * + * Ranges: 1 - 2147483647; + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbInfoSizeAllocated.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbInfoSizeAllocated_map(long *mib_rdbmsDbInfoSizeAllocated_val_ptr, long raw_rdbmsDbInfoSizeAllocated_val) +{ + netsnmp_assert(NULL != mib_rdbmsDbInfoSizeAllocated_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoSizeAllocated_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsDbInfoSizeAllocated mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsDbInfoSizeAllocated_val_ptr) = raw_rdbmsDbInfoSizeAllocated_val; + + return MFD_SUCCESS; +} /* rdbmsDbInfoSizeAllocated_map */ + +/** + * Extract the current value of the rdbmsDbInfoSizeAllocated data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbInfoSizeAllocated_val_ptr + * Pointer to storage for a long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsDbInfoSizeAllocated_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbInfoSizeAllocated_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsDbInfoSizeAllocated_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoSizeAllocated_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbInfoSizeAllocated data. + * set (* rdbmsDbInfoSizeAllocated_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsDbInfoSizeAllocated_val_ptr ) = rowreq_ctx->data.rdbmsDbInfoSizeAllocated; + + return MFD_SUCCESS; +} /* rdbmsDbInfoSizeAllocated_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbInfoEntry.rdbmsDbInfoSizeUsed + * rdbmsDbInfoSizeUsed is subid 5 of rdbmsDbInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.2.1.5 + * Description: +The estimated size of this database, in rdbmsDbInfoSizeUnits, + which is actually in use for database data. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 0 + * settable 0 + * + * Ranges: 1 - 2147483647; + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbInfoSizeUsed.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbInfoSizeUsed_map(long *mib_rdbmsDbInfoSizeUsed_val_ptr, long raw_rdbmsDbInfoSizeUsed_val) +{ + netsnmp_assert(NULL != mib_rdbmsDbInfoSizeUsed_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoSizeUsed_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsDbInfoSizeUsed mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsDbInfoSizeUsed_val_ptr) = raw_rdbmsDbInfoSizeUsed_val; + + return MFD_SUCCESS; +} /* rdbmsDbInfoSizeUsed_map */ + +/** + * Extract the current value of the rdbmsDbInfoSizeUsed data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbInfoSizeUsed_val_ptr + * Pointer to storage for a long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsDbInfoSizeUsed_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbInfoSizeUsed_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsDbInfoSizeUsed_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoSizeUsed_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbInfoSizeUsed data. + * set (* rdbmsDbInfoSizeUsed_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsDbInfoSizeUsed_val_ptr ) = rowreq_ctx->data.rdbmsDbInfoSizeUsed; + + return MFD_SUCCESS; +} /* rdbmsDbInfoSizeUsed_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbInfoEntry.rdbmsDbInfoLastBackup + * rdbmsDbInfoLastBackup is subid 6 of rdbmsDbInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.2.1.6 + * Description: +The date and time that the latest complete or partial backup + of the database was taken. If a database has never been + backed up, then attempts to access this object will + result in either noSuchName (SNMPv1) or noSuchInstance + (SNMPv2). + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 2d-1d-1d,1d:1d:1d.1d,1a1d:1d + * + * Ranges: 8, 11; + * + * Its syntax is DateAndTime (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 11) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbInfoLastBackup.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbInfoLastBackup_map(char **mib_rdbmsDbInfoLastBackup_val_ptr_ptr, size_t *mib_rdbmsDbInfoLastBackup_val_ptr_len_ptr, char *raw_rdbmsDbInfoLastBackup_val_ptr, size_t raw_rdbmsDbInfoLastBackup_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbInfoLastBackup_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbInfoLastBackup_val_ptr_ptr) && (NULL != mib_rdbmsDbInfoLastBackup_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoLastBackup_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbInfoLastBackup non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbInfoLastBackup_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbInfoLastBackup_val_ptr_ptr) || (*mib_rdbmsDbInfoLastBackup_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbInfoLastBackup_val_ptr_ptr = realloc( *mib_rdbmsDbInfoLastBackup_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbInfoLastBackup_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbInfoLastBackup_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbInfoLastBackup_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbInfoLastBackup_val_ptr_ptr, raw_rdbmsDbInfoLastBackup_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbInfoLastBackup_map */ + +/** + * Extract the current value of the rdbmsDbInfoLastBackup data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbInfoLastBackup_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsDbInfoLastBackup_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbInfoLastBackup. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbInfoLastBackup_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbInfoLastBackup_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbInfoLastBackup_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbInfoLastBackup_val_ptr_ptr, size_t *rdbmsDbInfoLastBackup_val_ptr_len_ptr ) +{ + /* temporary storage for date. If you have any of this data available + directly, use it instead. */ +/* int year, month, day, hour, minutes, seconds, deci_seconds; + * int rc, utc_offset_direction, utc_offset_hours, utc_offset_minutes; */ + int rc; + + /** we should have a pointer and enough storage */ + /* Josh changed mib2c's template from rdbmsDbInfoLastBackup_ptr_ptr and rdbmsDbInfoLastBackup_len_ptr to rdbmsDbInfoLastBackup_val_ptr_ptr and + * rdbmsDbInfoLastBackup_val_ptr_len_ptr respectively, both here and in the call to netsnmp_dateandtime_set_buf_from_vars. I'm not sure this was + * the right thing to do, but it does appear to work */ + netsnmp_assert( (NULL != rdbmsDbInfoLastBackup_val_ptr_ptr) && (NULL != *rdbmsDbInfoLastBackup_val_ptr_ptr)); + netsnmp_assert( (NULL != rdbmsDbInfoLastBackup_val_ptr_len_ptr) && ((* rdbmsDbInfoLastBackup_val_ptr_len_ptr) >= 11)); + + /* + * TODO:231:o: |-> copy rdbmsDbInfoLastBackup data. + * get the date from your context pointer. + */ + /*return MFD_SKIP; * TODO:234:M: |-> Remove SKIP once you've set rdbmsDbInfoLastBackup data */ + + /* call convenience function to set data */ + rc = netsnmp_dateandtime_set_buf_from_vars((u_char *)*rdbmsDbInfoLastBackup_val_ptr_ptr, rdbmsDbInfoLastBackup_val_ptr_len_ptr, + rowreq_ctx->data.lastBackupYear, + rowreq_ctx->data.lastBackupMonth, + rowreq_ctx->data.lastBackupDay, + rowreq_ctx->data.lastBackupHour, + rowreq_ctx->data.lastBackupMinutes, + rowreq_ctx->data.lastBackupSeconds, + rowreq_ctx->data.lastBackupDeciSeconds, + rowreq_ctx->data.utc_offset_direction, + rowreq_ctx->data.utc_offset_hours, + rowreq_ctx->data.utc_offset_minutes ); + if(rc != SNMP_ERR_NOERROR) + return rc; + + return MFD_SUCCESS; +} /* rdbmsDbInfoLastBackup_get */ + + + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_get.h b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_get.h new file mode 100644 index 0000000..ba9adf3 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_data_get.h @@ -0,0 +1,70 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable_data_get.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable_data_get.h,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBINFOTABLE_DATA_GET_H +#define RDBMSDBINFOTABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * GET function declarations + */ + +/* ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbInfoTable is subid 2 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.2, length: 9 +*/ + /* + * indexes + */ + int rdbmsDbIndex_map(long *mib_rdbmsDbIndex_val_ptr, long raw_rdbmsDbIndex_val); + + int rdbmsDbInfoProductName_map(char **mib_rdbmsDbInfoProductName_val_ptr_ptr, size_t *mib_rdbmsDbInfoProductName_val_ptr_len_ptr, char *raw_rdbmsDbInfoProductName_val_ptr, size_t raw_rdbmsDbInfoProductName_val_ptr_len, int allow_realloc); + int rdbmsDbInfoProductName_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbInfoProductName_val_ptr_ptr, size_t *rdbmsDbInfoProductName_val_ptr_len_ptr ); + int rdbmsDbInfoVersion_map(char **mib_rdbmsDbInfoVersion_val_ptr_ptr, size_t *mib_rdbmsDbInfoVersion_val_ptr_len_ptr, char *raw_rdbmsDbInfoVersion_val_ptr, size_t raw_rdbmsDbInfoVersion_val_ptr_len, int allow_realloc); + int rdbmsDbInfoVersion_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbInfoVersion_val_ptr_ptr, size_t *rdbmsDbInfoVersion_val_ptr_len_ptr ); + int rdbmsDbInfoSizeUnits_map(u_long *mib_rdbmsDbInfoSizeUnits_val_ptr, u_long raw_rdbmsDbInfoSizeUnits_val); + int rdbmsDbInfoSizeUnits_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsDbInfoSizeUnits_val_ptr ); + int rdbmsDbInfoSizeAllocated_map(long *mib_rdbmsDbInfoSizeAllocated_val_ptr, long raw_rdbmsDbInfoSizeAllocated_val); + int rdbmsDbInfoSizeAllocated_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbInfoSizeAllocated_val_ptr ); + int rdbmsDbInfoSizeUsed_map(long *mib_rdbmsDbInfoSizeUsed_val_ptr, long raw_rdbmsDbInfoSizeUsed_val); + int rdbmsDbInfoSizeUsed_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbInfoSizeUsed_val_ptr ); + int rdbmsDbInfoLastBackup_map(char **mib_rdbmsDbInfoLastBackup_val_ptr_ptr, size_t *mib_rdbmsDbInfoLastBackup_val_ptr_len_ptr, char *raw_rdbmsDbInfoLastBackup_val_ptr, size_t raw_rdbmsDbInfoLastBackup_val_ptr_len, int allow_realloc); + int rdbmsDbInfoLastBackup_get( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbInfoLastBackup_val_ptr_ptr, size_t *rdbmsDbInfoLastBackup_val_ptr_len_ptr ); + + +int rdbmsDbInfoTable_indexes_set_tbl_idx(rdbmsDbInfoTable_mib_index *tbl_idx, long rdbmsDbIndex_val); +int rdbmsDbInfoTable_indexes_set(rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val); + + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBINFOTABLE_DATA_GET_H */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_enums.h b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_enums.h new file mode 100644 index 0000000..30b62bb --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_enums.h @@ -0,0 +1,76 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable_enums.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable_enums.h,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBINFOTABLE_ENUMS_H +#define RDBMSDBINFOTABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table rdbmsDbInfoTable + * + ************************************************************************* + *************************************************************************/ + +/************************************************************* + * constants for enums for the MIB node + * rdbmsDbInfoSizeUnits (INTEGER / ASN_INTEGER) + * + * since a Textual Convention may be referenced more than once in a + * MIB, protect againt redefinitions of the enum values. + */ +#ifndef RDBMSDBINFOSIZEUNITS_ENUMS +#define RDBMSDBINFOSIZEUNITS_ENUMS + +#define RDBMSDBINFOSIZEUNITS_BYTES 1 +#define RDBMSDBINFOSIZEUNITS_KBYTES 2 +#define RDBMSDBINFOSIZEUNITS_MBYTES 3 +#define RDBMSDBINFOSIZEUNITS_GBYTES 4 +#define RDBMSDBINFOSIZEUNITS_TBYTES 5 + + +#endif /* RDBMSDBINFOSIZEUNITS_ENUMS */ + + /* + * TODO:140:o: Define interal representation of rdbmsDbInfoSizeUnits enums. + * (used for value mapping; see notes at top of file) + */ +#define INTERNAL_RDBMSDBINFOSIZEUNITS_BYTES 1 +#define INTERNAL_RDBMSDBINFOSIZEUNITS_KBYTES 2 +#define INTERNAL_RDBMSDBINFOSIZEUNITS_MBYTES 3 +#define INTERNAL_RDBMSDBINFOSIZEUNITS_GBYTES 4 +#define INTERNAL_RDBMSDBINFOSIZEUNITS_TBYTES 5 + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBINFOTABLE_ENUMS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_interface.c b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_interface.c new file mode 100644 index 0000000..5de7a4d --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_interface.c @@ -0,0 +1,716 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable_interface.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable_interface.c,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbInfoTable.h" +#include "rdbmsDbInfoTable_interface.h" + +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbInfoTable is subid 2 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.2, length: 9 +*/ +typedef struct rdbmsDbInfoTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; /* optional cache */ + + rdbmsDbInfoTable_registration_ptr user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} rdbmsDbInfoTable_interface_ctx; + +static rdbmsDbInfoTable_interface_ctx rdbmsDbInfoTable_if_ctx; + +static void _rdbmsDbInfoTable_container_init( + rdbmsDbInfoTable_interface_ctx *if_ctx); + + +static Netsnmp_Node_Handler _mfd_rdbmsDbInfoTable_pre_request; +static Netsnmp_Node_Handler _mfd_rdbmsDbInfoTable_post_request; +static Netsnmp_Node_Handler _mfd_rdbmsDbInfoTable_object_lookup; +static Netsnmp_Node_Handler _mfd_rdbmsDbInfoTable_get_values; +/** + * @internal + * Initialize the table rdbmsDbInfoTable + * (Define its contents and how it's structured) + */ +void +_rdbmsDbInfoTable_initialize_interface(rdbmsDbInfoTable_registration_ptr reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &rdbmsDbInfoTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = &rdbmsDbInfoTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:rdbmsDbInfoTable:_rdbmsDbInfoTable_initialize_interface","called\n")); + + + /************************************************* + * + * save interface context for rdbmsDbInfoTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, + ASN_INTEGER, /** index: rdbmsDbIndex */ + 0); + + /* Define the minimum and maximum accessible columns. This + optimizes retrival. */ + tbl_info->min_column = RDBMSDBINFOTABLE_MIN_COL; + tbl_info->max_column = RDBMSDBINFOTABLE_MAX_COL; + + /* + * save users context + */ + rdbmsDbInfoTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + rdbmsDbInfoTable_init_data(reg_ptr); + + /* + * set up the container + */ + _rdbmsDbInfoTable_container_init(&rdbmsDbInfoTable_if_ctx); + if (NULL == rdbmsDbInfoTable_if_ctx.container) { + snmp_log(LOG_ERR,"could not initialize container for rdbmsDbInfoTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = _mfd_rdbmsDbInfoTable_object_lookup; + access_multiplexer->get_values = _mfd_rdbmsDbInfoTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = _mfd_rdbmsDbInfoTable_pre_request; + access_multiplexer->post_request = _mfd_rdbmsDbInfoTable_post_request; + + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("rdbmsDbInfoTable:init_rdbmsDbInfoTable", + "Registering rdbmsDbInfoTable as a mibs-for-dummies table.\n")); + handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = netsnmp_handler_registration_create("rdbmsDbInfoTable", handler, + rdbmsDbInfoTable_oid, + rdbmsDbInfoTable_oid_size, + HANDLER_CAN_BABY_STEP | + HANDLER_CAN_RONLY + ); + if(NULL == reginfo) { + snmp_log(LOG_ERR,"error registering table rdbmsDbInfoTable\n"); + return; + } + reginfo->my_reg_void = &rdbmsDbInfoTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if( access_multiplexer->object_lookup ) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if( access_multiplexer->set_values ) + mfd_modes |= BABY_STEP_SET_VALUES; + if( access_multiplexer->irreversible_commit ) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if( access_multiplexer->object_syntax_checks ) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if( access_multiplexer->pre_request ) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if( access_multiplexer->post_request ) + mfd_modes |= BABY_STEP_POST_REQUEST; + + if( access_multiplexer->undo_setup ) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if( access_multiplexer->undo_cleanup ) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if( access_multiplexer->undo_sets ) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if( access_multiplexer->row_creation ) + mfd_modes |= BABY_STEP_ROW_CREATE; + if( access_multiplexer->consistency_checks ) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if( access_multiplexer->commit ) + mfd_modes |= BABY_STEP_COMMIT; + if( access_multiplexer->undo_commit ) + mfd_modes |= BABY_STEP_UNDO_COMMIT; + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + rdbmsDbInfoTable_if_ctx.container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler( reginfo, handler ); + + /************************************************* + * + * inject cache helper + */ + if(NULL != rdbmsDbInfoTable_if_ctx.cache) { + handler = netsnmp_cache_handler_get(rdbmsDbInfoTable_if_ctx.cache); + netsnmp_inject_handler( reginfo, handler ); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); +} /* _rdbmsDbInfoTable_initialize_interface */ + +void +rdbmsDbInfoTable_valid_columns_set(netsnmp_column_info *vc) +{ + rdbmsDbInfoTable_if_ctx.tbl_info.valid_columns = vc; +} /* rdbmsDbInfoTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +rdbmsDbInfoTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsDbInfoTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_index_to_oid","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_rdbmsDbIndex, (u_char*)&mib_idx->rdbmsDbIndex, + sizeof(mib_idx->rdbmsDbIndex)); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, (size_t *)&oid_idx->len, + NULL, 0, &var_rdbmsDbIndex); + if(err) + snmp_log(LOG_ERR,"error %d converting index to oid\n", err); + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsDbInfoTable_index_to_oid */ + +/** + * extract rdbmsDbInfoTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +rdbmsDbInfoTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsDbInfoTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsDbInfoTable:rdbmsDbInfoTable_index_from_oid","called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes( oid_idx->oids, oid_idx->len, + &var_rdbmsDbIndex ); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + mib_idx->rdbmsDbIndex = *((long *)var_rdbmsDbIndex.val.string); + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsDbInfoTable_index_from_oid */ + + +/* ********************************************************************* + * @internal + * allocate resources for a rdbmsDbInfoTable_rowreq_ctx + */ +rdbmsDbInfoTable_rowreq_ctx * +rdbmsDbInfoTable_allocate_rowreq_ctx(void) +{ + rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(rdbmsDbInfoTable_rowreq_ctx); + + DEBUGMSGTL(("internal:rdbmsDbInfoTable:rdbmsDbInfoTable_allocate_rowreq_ctx","called\n")); + + if(NULL == rowreq_ctx) { + snmp_log(LOG_ERR,"Couldn't allocate memory for a " + "rdbmsDbInfoTable_rowreq_ctx.\n"); + } + + rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; + + rowreq_ctx->rdbmsDbInfoTable_data_list = NULL; + rowreq_ctx->rdbmsDbInfoTable_reg = rdbmsDbInfoTable_if_ctx.user_ctx; + + + return rowreq_ctx; +} /* rdbmsDbInfoTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a rdbmsDbInfoTable_rowreq_ctx + */ +void +rdbmsDbInfoTable_release_rowreq_ctx(rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("internal:rdbmsDbInfoTable:rdbmsDbInfoTable_release_rowreq_ctx","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + + /* + * free index oid pointer + */ + if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* rdbmsDbInfoTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbInfoTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc = rdbmsDbInfoTable_pre_request(rdbmsDbInfoTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsDbInfoTable","error %d from " + "rdbmsDbInfoTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbInfoTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbInfoTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx; + int rc = rdbmsDbInfoTable_post_request(rdbmsDbInfoTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsDbInfoTable","error %d from " + "rdbmsDbInfoTable_post_request\n", rc)); + } + + /* + * if there are no errors, check for and handle row creation/deletion + */ + rc = netsnmp_check_requests_error(requests); + if ((SNMP_ERR_NOERROR == rc) && + (NULL != + (rowreq_ctx = netsnmp_container_table_row_extract(requests)))) { + if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) { + rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; + CONTAINER_INSERT(rdbmsDbInfoTable_if_ctx.container, rowreq_ctx); + } + else if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { + CONTAINER_REMOVE(rdbmsDbInfoTable_if_ctx.container, rowreq_ctx); + rdbmsDbInfoTable_release_rowreq_ctx(rowreq_ctx); + } + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbInfoTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbInfoTable_object_lookup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsDbInfoTable:_mfd_rdbmsDbInfoTable_object_lookup","called\n")); + + /* + * get our context from mfd + * rdbmsDbInfoTable_interface_ctx *if_ctx = + * (rdbmsDbInfoTable_interface_ctx *)reginfo->my_reg_void; + */ + + if(NULL == rowreq_ctx) { + netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION); + } + else { + rdbmsDbInfoTable_row_prep(rowreq_ctx); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbInfoTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsDbInfoTable_get_column( rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsDbInfoTable:_mfd_rdbmsDbInfoTable_get_column","called\n")); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsDbInfoProductName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ + case COLUMN_RDBMSDBINFOPRODUCTNAME: + var->type = ASN_OCTET_STR; +rc = rdbmsDbInfoProductName_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* rdbmsDbInfoVersion(2)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ + case COLUMN_RDBMSDBINFOVERSION: + var->type = ASN_OCTET_STR; +rc = rdbmsDbInfoVersion_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* rdbmsDbInfoSizeUnits(3)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h */ + case COLUMN_RDBMSDBINFOSIZEUNITS: + var->val_len = sizeof(u_long); + var->type = ASN_INTEGER; +rc = rdbmsDbInfoSizeUnits_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsDbInfoSizeAllocated(4)/INTEGER/ASN_INTEGER/long(long)//l/A/W/e/R/d/h */ + case COLUMN_RDBMSDBINFOSIZEALLOCATED: + var->val_len = sizeof(long); + var->type = ASN_INTEGER; +rc = rdbmsDbInfoSizeAllocated_get(rowreq_ctx, (long *)var->val.string ); + break; + + /* rdbmsDbInfoSizeUsed(5)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/R/d/h */ + case COLUMN_RDBMSDBINFOSIZEUSED: + var->val_len = sizeof(long); + var->type = ASN_INTEGER; +rc = rdbmsDbInfoSizeUsed_get(rowreq_ctx, (long *)var->val.string ); + break; + + /* rdbmsDbInfoLastBackup(6)/DateAndTime/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ + case COLUMN_RDBMSDBINFOLASTBACKUP: + var->type = ASN_OCTET_STR; +rc = rdbmsDbInfoLastBackup_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsDbInfoTable_get_column\n", column); + break; + } + + return rc; +} /* _rdbmsDbInfoTable_get_column */ + +int +_mfd_rdbmsDbInfoTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + u_char * old_string; + void (*dataFreeHook)(void *); + int rc; + + DEBUGMSGTL(("internal:rdbmsDbInfoTable:_mfd_rdbmsDbInfoTable_get_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if(NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + else if(requests->requestvb->buf == requests->requestvb->val.string) { + if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsDbInfoTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + if(MFD_SKIP == rc) { + requests->requestvb->type = ASN_PRIV_RETRY; + rc = SNMP_ERR_NOERROR; + } + } + else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if(rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if(old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if(dataFreeHook) + (*dataFreeHook)(old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbInfoTable_get_values */ + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/* + * NOT APPLICABLE (per MIB or user setting) + */ +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +/** + * @internal + */ +static int +_cache_load(netsnmp_cache *cache, void *vmagic) +{ + DEBUGMSGTL(("internal:rdbmsDbInfoTable:_cache_load","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache for rdbmsDbInfoTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return rdbmsDbInfoTable_cache_load((netsnmp_container*)cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_item_free(rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx, void *context) +{ + DEBUGMSGTL(("internal:rdbmsDbInfoTable:_cache_item_free","called\n")); + + if(NULL == rowreq_ctx) + return; + + rdbmsDbInfoTable_release_rowreq_ctx(rowreq_ctx); +} /* _cache_item_free */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache *cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:rdbmsDbInfoTable:_cache_free","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache in rdbmsDbInfoTable_cache_free\n"); + return; + } + + container = (netsnmp_container*)cache->magic; + + /* + * call user code + */ + rdbmsDbInfoTable_cache_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *)_cache_item_free, + NULL); +} /* _cache_free */ + +/** + * @internal + * initialize the iterator container with functions or wrappers + */ +void +_rdbmsDbInfoTable_container_init(rdbmsDbInfoTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:rdbmsDbInfoTable:_rdbmsDbInfoTable_container_init","called\n")); + + /* + * set up the cache + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + rdbmsDbInfoTable_oid, + rdbmsDbInfoTable_oid_size); + + if(NULL == if_ctx->cache) { + snmp_log(LOG_ERR, "error creating cache for rdbmsDbInfoTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + rdbmsDbInfoTable_container_init(&if_ctx->container, if_ctx->cache); + if(NULL == if_ctx->container) + if_ctx->container = netsnmp_container_find("rdbmsDbInfoTable:table_container"); + if(NULL == if_ctx->container) { + snmp_log(LOG_ERR,"error creating container in " + "rdbmsDbInfoTable_container_init\n"); + return; + } + if_ctx->cache->magic = (void*)if_ctx->container; +} /* _rdbmsDbInfoTable_container_init */ + diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_interface.h b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_interface.h new file mode 100644 index 0000000..ff9df1b --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_interface.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable_interface.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable_interface.h,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBINFOTABLE_INTERFACE_H +#define RDBMSDBINFOTABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "rdbmsDbInfoTable.h" + +/* ******************************************************************** + * Table declarations + */ + +/* PUBLIC interface initialization routine */ +void _rdbmsDbInfoTable_initialize_interface(rdbmsDbInfoTable_registration_ptr user_ctx, + u_long flags); + + rdbmsDbInfoTable_rowreq_ctx * rdbmsDbInfoTable_allocate_rowreq_ctx(void); +void rdbmsDbInfoTable_release_rowreq_ctx(rdbmsDbInfoTable_rowreq_ctx *rowreq_ctx); + +int rdbmsDbInfoTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsDbInfoTable_mib_index *mib_idx); +int rdbmsDbInfoTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsDbInfoTable_mib_index *mib_idx); + +/* + * access to certain internals. use with caution! + */ +void rdbmsDbInfoTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBINFOTABLE_INTERFACE_H */ diff --git a/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_oids.h b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_oids.h new file mode 100644 index 0000000..9333aef --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbInfoTable/rdbmsDbInfoTable_oids.h @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + * rdbmsDbInfoTable_oids.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbInfoTable_oids.h,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBINFOTABLE_OIDS_H +#define RDBMSDBINFOTABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* column number definitions for table rdbmsDbInfoTable */ +#define RDBMSDBINFOTABLE_OID 1,3,6,1,2,1,39,1,2 +#define COLUMN_RDBMSDBINFOPRODUCTNAME 1 +#define COLUMN_RDBMSDBINFOVERSION 2 +#define COLUMN_RDBMSDBINFOSIZEUNITS 3 +#define COLUMN_RDBMSDBINFOSIZEALLOCATED 4 +#define COLUMN_RDBMSDBINFOSIZEUSED 5 +#define COLUMN_RDBMSDBINFOLASTBACKUP 6 + +#define RDBMSDBINFOTABLE_MIN_COL COLUMN_RDBMSDBINFOPRODUCTNAME +#define RDBMSDBINFOTABLE_MAX_COL COLUMN_RDBMSDBINFOLASTBACKUP + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBINFOTABLE_OIDS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable.c b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable.c new file mode 100644 index 0000000..f5864d0 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable.c @@ -0,0 +1,130 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsDbLimitedResourceTable.h" + +#include <net-snmp/agent/mib_modules.h> + +#include "rdbmsDbLimitedResourceTable_interface.h" + +oid rdbmsDbLimitedResourceTable_oid[] = { RDBMSDBLIMITEDRESOURCETABLE_OID }; +int rdbmsDbLimitedResourceTable_oid_size = OID_LENGTH(rdbmsDbLimitedResourceTable_oid); + +void initialize_table_rdbmsDbLimitedResourceTable(void); + + +/** + * Initializes the rdbmsDbLimitedResourceTable module + */ +void +init_rdbmsDbLimitedResourceTable(void) +{ + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:init_rdbmsDbLimitedResourceTable","called\n")); + + /* + * TODO:300:o: Perform rdbmsDbLimitedResourceTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("rdbmsDbLimitedResourceTable")) + initialize_table_rdbmsDbLimitedResourceTable(); + +} /* init_rdbmsDbLimitedResourceTable */ + +/** + * Initialize the table rdbmsDbLimitedResourceTable + * (Define its contents and how it's structured) + */ +void +initialize_table_rdbmsDbLimitedResourceTable(void) +{ + rdbmsDbLimitedResourceTable_registration_ptr user_context; + u_long flags; + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:initialize_table_rdbmsDbLimitedResourceTable","called\n")); + + /* + * TODO:301:o: Perform rdbmsDbLimitedResourceTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize rdbmsDbLimitedResourceTable user context + * if you'd like to pass in a pointer to some data for this + * table, allocate or set it up here. + */ + /* + * a netsnmp_data_list is a simple way to store void pointers. A simple + * string token is used to add, find or remove pointers. + */ + user_context = netsnmp_create_data_list("rdbmsDbLimitedResourceTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _rdbmsDbLimitedResourceTable_initialize_interface(user_context, flags); +} /* initialize_table_rdbmsDbLimitedResourceTable */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +rdbmsDbLimitedResourceTable_pre_request(rdbmsDbLimitedResourceTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_pre_request","called\n")); + + /* + * TODO:510:o: Perform rdbmsDbLimitedResourceTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceTable_pre_request */ + +/** + * post-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error (ignored) + */ +int +rdbmsDbLimitedResourceTable_post_request(rdbmsDbLimitedResourceTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_post_request","called\n")); + + /* + * TODO:511:o: Perform rdbmsDbLimitedResourceTable pos-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceTable_post_request */ + + +/** @{ */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable.h b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable.h new file mode 100644 index 0000000..952db46 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable.h @@ -0,0 +1,224 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBLIMITEDRESOURCETABLE_H +#define RDBMSDBLIMITEDRESOURCETABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @defgroup misc misc: Miscelaneous routines + * + * @{ + */ +#include <net-snmp/library/asn1.h> + +/* other required module components */ + /* *INDENT-OFF* */ +config_require(RDBMS-MIB/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_interface); +config_require(RDBMS-MIB/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_access); +config_require(RDBMS-MIB/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_get); +config_require(RDBMS-MIB/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_set); + /* *INDENT-ON* */ + +/* OID and column number definitions for */ +#include "rdbmsDbLimitedResourceTable_oids.h" + +/* enum definions */ +#include "rdbmsDbLimitedResourceTable_enums.h" + +/* ********************************************************************* + * function declarations + */ +void init_rdbmsDbLimitedResourceTable(void); + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbLimitedResourceTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbLimitedResourceTable is subid 4 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.4, length: 9 +*/ +/* ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review rdbmsDbLimitedResourceTable registration context. + */ +typedef netsnmp_data_list * rdbmsDbLimitedResourceTable_registration_ptr; + +/**********************************************************************/ +/* + * TODO:110:r: |-> Review rdbmsDbLimitedResourceTable data context structure. + * This structure is used to represent the data for rdbmsDbLimitedResourceTable. + */ +/* + * This structure contains storage for all the columns defined in the + * rdbmsDbLimitedResourceTable. + */ +typedef struct rdbmsDbLimitedResourceTable_data_s { + + /* + * rdbmsDbLimitedResourceID(2)/AutonomousType/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h + */ + oid rdbmsDbLimitedResourceID[128]; +size_t rdbmsDbLimitedResourceID_len; /* # of oid elements, not bytes */ + + /* + * rdbmsDbLimitedResourceLimit(3)/INTEGER/ASN_INTEGER/long(long)//l/A/W/e/R/d/h + */ + long rdbmsDbLimitedResourceLimit; + + /* + * rdbmsDbLimitedResourceCurrent(4)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/R/d/h + */ + long rdbmsDbLimitedResourceCurrent; + + /* + * rdbmsDbLimitedResourceHighwater(5)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/R/d/h + */ + long rdbmsDbLimitedResourceHighwater; + + /* + * rdbmsDbLimitedResourceFailures(6)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsDbLimitedResourceFailures; + + /* + * rdbmsDbLimitedResourceDescription(7)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + char rdbmsDbLimitedResourceDescription[255]; +size_t rdbmsDbLimitedResourceDescription_len; /* # of char elements, not bytes */ + +} rdbmsDbLimitedResourceTable_data; + + +/* + * TODO:120:r: |-> Review rdbmsDbLimitedResourceTable mib index. + * This structure is used to represent the index for rdbmsDbLimitedResourceTable. + */ +typedef struct rdbmsDbLimitedResourceTable_mib_index_s { + + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long rdbmsDbIndex; + + /* + * rdbmsDbLimitedResourceName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H + */ + /** 128 - 1(other indexes) - oid length(11) = 115 */ + char rdbmsDbLimitedResourceName[115]; + size_t rdbmsDbLimitedResourceName_len; + + +} rdbmsDbLimitedResourceTable_mib_index; + + /* + * TODO:121:r: | |-> Review rdbmsDbLimitedResourceTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. + * + * BE VERY CAREFUL TO TAKE INTO ACCOUNT THE MAXIMUM + * POSSIBLE LENGHT FOR EVERY VARIABLE LENGTH INDEX! + * Guessing 128 - col/entry(2) - oid len(9) +*/ +#define MAX_rdbmsDbLimitedResourceTable_IDX_LEN 117 + + +/* ********************************************************************* + * TODO:130:o: |-> Review rdbmsDbLimitedResourceTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * rdbmsDbLimitedResourceTable_rowreq_ctx pointer. + */ +typedef struct rdbmsDbLimitedResourceTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_rdbmsDbLimitedResourceTable_IDX_LEN]; + + rdbmsDbLimitedResourceTable_mib_index tbl_idx; + + rdbmsDbLimitedResourceTable_data data; + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * implementor's context pointer (provided during registration) + */ + rdbmsDbLimitedResourceTable_registration_ptr rdbmsDbLimitedResourceTable_reg; + + /* + * TODO:131:o: | |-> Add useful data to rdbmsDbLimitedResourceTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *rdbmsDbLimitedResourceTable_data_list; + +} rdbmsDbLimitedResourceTable_rowreq_ctx; + +typedef struct rdbmsDbLimitedResourceTable_ref_rowreq_ctx_s { + rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx; +} rdbmsDbLimitedResourceTable_ref_rowreq_ctx; + +/* ********************************************************************* + * function prototypes + */ + int rdbmsDbLimitedResourceTable_pre_request(rdbmsDbLimitedResourceTable_registration_ptr user_context); + int rdbmsDbLimitedResourceTable_post_request(rdbmsDbLimitedResourceTable_registration_ptr user_context); + + +extern oid rdbmsDbLimitedResourceTable_oid[]; +extern int rdbmsDbLimitedResourceTable_oid_size; + + +#include "rdbmsDbLimitedResourceTable_interface.h" +#include "rdbmsDbLimitedResourceTable_data_access.h" +#include "rdbmsDbLimitedResourceTable_data_get.h" +#include "rdbmsDbLimitedResourceTable_data_set.h" + +/* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBLIMITEDRESOURCETABLE_H */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_access.c b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_access.c new file mode 100644 index 0000000..e36e3ac --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_access.c @@ -0,0 +1,307 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_data_access.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_data_access.c,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbLimitedResourceTable.h" +#include "rdbmsDbLimitedResourceTable_data_access.h" + +/** @defgroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbLimitedResourceTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbLimitedResourceTable is subid 4 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.4, length: 9 +*/ + +/** + * initialization for rdbmsDbLimitedResourceTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param rdbmsDbLimitedResourceTable_reg + * Pointer to rdbmsDbLimitedResourceTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +rdbmsDbLimitedResourceTable_init_data(rdbmsDbLimitedResourceTable_registration_ptr rdbmsDbLimitedResourceTable_reg) +{ + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_init_data","called\n")); + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceTable_init_data */ + +/** + * container-cached overview + * + */ + +/*********************************************************************** + * + * cache + * + ***********************************************************************/ +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +rdbmsDbLimitedResourceTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache) +{ + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_container_init","called\n")); + + if((NULL == cache) || (NULL == container_ptr_ptr)) { + snmp_log(LOG_ERR,"bad params to rdbmsDbLimitedResourceTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + /* + * TODO:345:A: Set up rdbmsDbLimitedResourceTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = RDBMSDBLIMITEDRESOURCETABLE_CACHE_TIMEOUT; /* seconds */ +} /* rdbmsDbLimitedResourceTable_container_init */ + +/** + * load cache data + * + * TODO:350:M: Implement rdbmsDbLimitedResourceTable cache load + * + * @param container container to which items should be inserted + * + * @retval MFD_SUCCESS : success. + * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source + * @retval MFD_ERROR : other error. + * + * This function is called to cache the index(es) (and data, optionally) + * for the every row in the data set. + * + * @remark + * While loading the cache, the only important thing is the indexes. + * If access to your data is cheap/fast (e.g. you have a pointer to a + * structure in memory), it would make sense to update the data here. + * If, however, the accessing the data invovles more work (e.g. parsing + * some other existing data, or peforming calculations to derive the data), + * then you can limit yourself to setting the indexes and saving any + * information you will need later. Then use the saved information in + * rdbmsDbLimitedResourceTable_row_prep() for populating data. + * + * @note + * If you need consistency between rows (like you want statistics + * for each row to be from the same time frame), you should set all + * data here. + * + */ +int +rdbmsDbLimitedResourceTable_cache_load(netsnmp_container *container) +{ + rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx; + size_t count = 0; + PGresult *pg_db_qry; + int i, resultCount, errorCode = MFD_SUCCESS, tmpInt; + char *tmpString; + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_cache_load","called\n")); + + if (PQstatus(dbconn) == CONNECTION_OK) + /* We can probably add new data to the rdbmsDbLimitedResourceTable by UNION-ing new queries with this one + * SELECT <db_oid>, <item_name>, <item_limit>, <current>, <high_water>, <failures>, <description> */ + pg_db_qry = PQexec(dbconn, "SELECT oid, 'XID', 2000000000, AGE(datfrozenxid), 0, 0, 'Transactions since last vacuum' FROM pg_database"); + else { + snmp_log(LOG_ERR, "Can't get connected to the database"); + return -1; + } + if (PQresultStatus(pg_db_qry) != PGRES_TUPLES_OK) { + snmp_log(LOG_ERR, "Didn't get any results from the database"); + PQclear(pg_db_qry); + /*PQfinish(dbconn);*/ + return -1; + } + + resultCount = PQntuples(pg_db_qry); + + /* + * TODO:351:M: |-> Load/update data in the rdbmsDbLimitedResourceTable container. + * loop over your rdbmsDbLimitedResourceTable data, allocate a rowreq context, + * set the index(es) [and data, optionally] and insert into + * the container. + */ + for (i = 0; i < resultCount; i++) { + + /* + * TODO:352:M: | |-> set indexes in new rdbmsDbLimitedResourceTable rowreq context. + */ + rowreq_ctx = rdbmsDbLimitedResourceTable_allocate_rowreq_ctx(); + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "memory allocation failed\n"); + errorCode = MFD_RESOURCE_UNAVAILABLE; + break; + } + tmpInt = atoi(PQgetvalue(pg_db_qry, i, 0)); + tmpString = PQgetvalue(pg_db_qry, i, 1); + if(MFD_SUCCESS != rdbmsDbLimitedResourceTable_indexes_set(rowreq_ctx + , tmpInt + , tmpString, strlen(tmpString) + )) { + snmp_log(LOG_ERR,"error setting index while loading " + "rdbmsDbLimitedResourceTable cache.\n"); + rdbmsDbLimitedResourceTable_release_rowreq_ctx(rowreq_ctx); + continue; + } + rowreq_ctx->data.rdbmsDbLimitedResourceDescription_len = 255; + + /* COMMENTED OUT UNTIL WE HAVE PGSNMPD-MIB SO THIS VALUE CAN POINT TO SOMETING + if ((NULL == rowreq_ctx->data.rdbmsDbLimitedResourceID) || + (rowreq_ctx->data.rdbmsDbLimitedResourceID_len < (rdbmsDbLimitedResourceID_len * sizeof(rowreq_ctx->data.rdbmsDbLimitedResourceID[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + return MFD_ERROR; + } + rowreq_ctx->data.rdbmsDbLimitedResourceID_len = rdbmsDbLimitedResourceID_len * sizeof(rowreq_ctx->data.rdbmsDbLimitedResourceID[0]); + memcpy( rowreq_ctx->data.rdbmsDbLimitedResourceID, rdbmsDbLimitedResourceID, rowreq_ctx->data.rdbmsDbLimitedResourceID_len ); */ + + rowreq_ctx->data.rdbmsDbLimitedResourceLimit = atoi(PQgetvalue(pg_db_qry, i, 2)); + + rowreq_ctx->data.rdbmsDbLimitedResourceCurrent = atoi(PQgetvalue(pg_db_qry, i, 3)); + + rowreq_ctx->data.rdbmsDbLimitedResourceHighwater = atoi(PQgetvalue(pg_db_qry, i, 4)); + + rowreq_ctx->data.rdbmsDbLimitedResourceFailures = atoi(PQgetvalue(pg_db_qry, i, 5)); + + tmpString = PQgetvalue(pg_db_qry, i, 6); + tmpInt = strlen(tmpString); + if ((NULL == rowreq_ctx->data.rdbmsDbLimitedResourceDescription) || + (rowreq_ctx->data.rdbmsDbLimitedResourceDescription_len < (tmpInt * sizeof(rowreq_ctx->data.rdbmsDbLimitedResourceDescription[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + errorCode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsDbLimitedResourceDescription_len = tmpInt * sizeof(rowreq_ctx->data.rdbmsDbLimitedResourceDescription[0]); + memcpy( rowreq_ctx->data.rdbmsDbLimitedResourceDescription, tmpString, rowreq_ctx->data.rdbmsDbLimitedResourceDescription_len ); + + + /* + * insert into table container + */ + CONTAINER_INSERT(container, rowreq_ctx); + ++count; + } + + DEBUGMSGT(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_cache_load", + "inserted %d records\n", count)); + + PQclear(pg_db_qry); + return errorCode; +} /* rdbmsDbLimitedResourceTable_cache_load */ + +/** + * cache clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +rdbmsDbLimitedResourceTable_cache_free(netsnmp_container *container) +{ + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_cache_free","called\n")); + + /* + * TODO:380:M: Free rdbmsDbLimitedResourceTable cache. + */ +} /* rdbmsDbLimitedResourceTable_cache_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +rdbmsDbLimitedResourceTable_row_prep( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_row_prep","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceTable_row_prep */ + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_access.h b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_access.h new file mode 100644 index 0000000..6e24990 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_access.h @@ -0,0 +1,64 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_data_access.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_data_access.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBLIMITEDRESOURCETABLE_DATA_ACCESS_H +#define RDBMSDBLIMITEDRESOURCETABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ********************************************************************* + * function declarations + */ + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbLimitedResourceTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbLimitedResourceTable is subid 4 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.4, length: 9 +*/ + + + int rdbmsDbLimitedResourceTable_init_data(rdbmsDbLimitedResourceTable_registration_ptr rdbmsDbLimitedResourceTable_reg); + + +/* + * TODO:180:o: Review rdbmsDbLimitedResourceTable cache timeout. + * The number of seconds before the cache times out + */ +#define RDBMSDBLIMITEDRESOURCETABLE_CACHE_TIMEOUT 60 + +void rdbmsDbLimitedResourceTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache); +int rdbmsDbLimitedResourceTable_cache_load(netsnmp_container *container); +void rdbmsDbLimitedResourceTable_cache_free(netsnmp_container *container); + + int rdbmsDbLimitedResourceTable_row_prep( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBLIMITEDRESOURCETABLE_DATA_ACCESS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_get.c b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_get.c new file mode 100644 index 0000000..606fb3e --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_get.c @@ -0,0 +1,868 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_data_get.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_data_get.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsDbLimitedResourceTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement rdbmsDbLimitedResourceTable get routines. + * TODO:240:M: Implement rdbmsDbLimitedResourceTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbLimitedResourceTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbLimitedResourceTable is subid 4 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.4, length: 9 +*/ + +/* --------------------------------------------------------------------- + * TODO:200:r: Implement rdbmsDbLimitedResourceTable data context functions. + */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbLimitedResourceEntry.rdbmsDbLimitedResourceName + * rdbmsDbLimitedResourceName is subid 1 of rdbmsDbLimitedResourceEntry. + * Its status is Current, and its access level is NoAccess. + * OID: .1.3.6.1.2.1.39.1.4.1.1 + * Description: +The name of the resource, for instance 'global locks' or + 'locks for the FOO database', or 'data space on /dev/rdsk/5s0 + for FOO'. The length is limited to 64 characters to constrain + the number of sub-identifiers needed for instance + identification (and to minimize network traffic). + * + * Attributes: + * accessible 0 isscalar 0 enums 0 hasdefval 0 + * readable 0 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + * + * + * + * NOTE: NODE rdbmsDbLimitedResourceName IS NOT ACCESSIBLE + * + * + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbLimitedResourceName.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbLimitedResourceName_map(char **mib_rdbmsDbLimitedResourceName_val_ptr_ptr, size_t *mib_rdbmsDbLimitedResourceName_val_ptr_len_ptr, char *raw_rdbmsDbLimitedResourceName_val_ptr, size_t raw_rdbmsDbLimitedResourceName_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbLimitedResourceName_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbLimitedResourceName_val_ptr_ptr) && (NULL != mib_rdbmsDbLimitedResourceName_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceName_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbLimitedResourceName non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbLimitedResourceName_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbLimitedResourceName_val_ptr_ptr) || (*mib_rdbmsDbLimitedResourceName_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbLimitedResourceName_val_ptr_ptr = realloc( *mib_rdbmsDbLimitedResourceName_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbLimitedResourceName_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbLimitedResourceName_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbLimitedResourceName_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbLimitedResourceName_val_ptr_ptr, raw_rdbmsDbLimitedResourceName_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceName_map */ + + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This convenience function is useful for setting all the MIB index + * components with a single function call. It is assume that the C values + * have already been mapped from their native/rawformat to the MIB format. + */ +int +rdbmsDbLimitedResourceTable_indexes_set_tbl_idx(rdbmsDbLimitedResourceTable_mib_index *tbl_idx, long rdbmsDbIndex_val, char *rdbmsDbLimitedResourceName_val_ptr, size_t rdbmsDbLimitedResourceName_val_ptr_len) +{ + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_indexes_set_tbl_idx","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->rdbmsDbIndex = rdbmsDbIndex_val; + + /* rdbmsDbLimitedResourceName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ + tbl_idx->rdbmsDbLimitedResourceName_len = sizeof(tbl_idx->rdbmsDbLimitedResourceName); + /* + * make sure there is enough space for rdbmsDbLimitedResourceName data + */ + if ((NULL == tbl_idx->rdbmsDbLimitedResourceName) || + (tbl_idx->rdbmsDbLimitedResourceName_len < (rdbmsDbLimitedResourceName_val_ptr_len * sizeof(tbl_idx->rdbmsDbLimitedResourceName[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + return MFD_ERROR; + } + tbl_idx->rdbmsDbLimitedResourceName_len = rdbmsDbLimitedResourceName_val_ptr_len * sizeof(tbl_idx->rdbmsDbLimitedResourceName[0]); + memcpy( tbl_idx->rdbmsDbLimitedResourceName, rdbmsDbLimitedResourceName_val_ptr, tbl_idx->rdbmsDbLimitedResourceName_len ); + + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceTable_indexes_set_tbl_idx */ + +/** + * @internal + * set row context indexes + * + * @param reqreq_ctx the row context that needs updated indexes + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This function sets the mib indexs, then updates the oid indexs + * from the mib index. + */ +int +rdbmsDbLimitedResourceTable_indexes_set(rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val, char *rdbmsDbLimitedResourceName_val_ptr, size_t rdbmsDbLimitedResourceName_val_ptr_len) +{ + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_indexes_set","called\n")); + + if(MFD_SUCCESS != rdbmsDbLimitedResourceTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx + , rdbmsDbIndex_val + , rdbmsDbLimitedResourceName_val_ptr, rdbmsDbLimitedResourceName_val_ptr_len + )) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if(0 != rdbmsDbLimitedResourceTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbLimitedResourceEntry.rdbmsDbLimitedResourceID + * rdbmsDbLimitedResourceID is subid 2 of rdbmsDbLimitedResourceEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.4.1.2 + * Description: +The ID of the resource which may be described in some other + MIB (e.g., an enterprise-specific MIB module). If there is + no ID for this rdbmsDbLimitedResourceName, attempts to access + this object will return noSuchName (SNMPv1) or noSuchInstance + (SNMPv2). + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is AutonomousType (based on perltype OBJECTID) + * The net-snmp type is ASN_OBJECT_ID. The C type decl is oid (oid) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbLimitedResourceID.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbLimitedResourceID_map(oid **mib_rdbmsDbLimitedResourceID_val_ptr_ptr, size_t *mib_rdbmsDbLimitedResourceID_val_ptr_len_ptr, oid *raw_rdbmsDbLimitedResourceID_val_ptr, size_t raw_rdbmsDbLimitedResourceID_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbLimitedResourceID_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbLimitedResourceID_val_ptr_ptr) && (NULL != mib_rdbmsDbLimitedResourceID_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceID_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbLimitedResourceID non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbLimitedResourceID_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbLimitedResourceID_val_ptr_ptr) || (*mib_rdbmsDbLimitedResourceID_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbLimitedResourceID_val_ptr_ptr = realloc( *mib_rdbmsDbLimitedResourceID_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbLimitedResourceID_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbLimitedResourceID_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbLimitedResourceID_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbLimitedResourceID_val_ptr_ptr, raw_rdbmsDbLimitedResourceID_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceID_map */ + +/** + * Extract the current value of the rdbmsDbLimitedResourceID data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbLimitedResourceID_val_ptr_ptr + * Pointer to storage for a oid variable + * @param rdbmsDbLimitedResourceID_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbLimitedResourceID. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbLimitedResourceID_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbLimitedResourceID_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbLimitedResourceID_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, oid **rdbmsDbLimitedResourceID_val_ptr_ptr, size_t *rdbmsDbLimitedResourceID_val_ptr_len_ptr ) +{ + /* Until PGSNMPD-MIB exists, there's nothing to see here */ + return MFD_SKIP; + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbLimitedResourceID_val_ptr_ptr) && (NULL != *rdbmsDbLimitedResourceID_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbLimitedResourceID_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceID_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbLimitedResourceID data. + * set (* rdbmsDbLimitedResourceID_val_ptr_ptr ) and (* rdbmsDbLimitedResourceID_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbLimitedResourceID data + */ + if ((NULL == (* rdbmsDbLimitedResourceID_val_ptr_ptr )) || + ((* rdbmsDbLimitedResourceID_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbLimitedResourceID_len * sizeof((* rdbmsDbLimitedResourceID_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbLimitedResourceID data + */ + (* rdbmsDbLimitedResourceID_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbLimitedResourceID_len * sizeof((* rdbmsDbLimitedResourceID_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbLimitedResourceID_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbLimitedResourceID_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbLimitedResourceID_len * sizeof((* rdbmsDbLimitedResourceID_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbLimitedResourceID_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbLimitedResourceID, (* rdbmsDbLimitedResourceID_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceID_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbLimitedResourceEntry.rdbmsDbLimitedResourceLimit + * rdbmsDbLimitedResourceLimit is subid 3 of rdbmsDbLimitedResourceEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.4.1.3 + * Description: +The maximum value the resource use may attain. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 0 + * settable 1 + * + * Ranges: 1 - 2147483647; + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbLimitedResourceLimit.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbLimitedResourceLimit_map(long *mib_rdbmsDbLimitedResourceLimit_val_ptr, long raw_rdbmsDbLimitedResourceLimit_val) +{ + netsnmp_assert(NULL != mib_rdbmsDbLimitedResourceLimit_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceLimit_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsDbLimitedResourceLimit mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsDbLimitedResourceLimit_val_ptr) = raw_rdbmsDbLimitedResourceLimit_val; + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceLimit_map */ + +/** + * Extract the current value of the rdbmsDbLimitedResourceLimit data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbLimitedResourceLimit_val_ptr + * Pointer to storage for a long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsDbLimitedResourceLimit_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbLimitedResourceLimit_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsDbLimitedResourceLimit_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceLimit_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbLimitedResourceLimit data. + * set (* rdbmsDbLimitedResourceLimit_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsDbLimitedResourceLimit_val_ptr ) = rowreq_ctx->data.rdbmsDbLimitedResourceLimit; + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceLimit_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbLimitedResourceEntry.rdbmsDbLimitedResourceCurrent + * rdbmsDbLimitedResourceCurrent is subid 4 of rdbmsDbLimitedResourceEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.4.1.4 + * Description: +The current value for the resource. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 0 + * settable 0 + * + * Ranges: 1 - 2147483647; + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbLimitedResourceCurrent.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbLimitedResourceCurrent_map(long *mib_rdbmsDbLimitedResourceCurrent_val_ptr, long raw_rdbmsDbLimitedResourceCurrent_val) +{ + netsnmp_assert(NULL != mib_rdbmsDbLimitedResourceCurrent_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceCurrent_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsDbLimitedResourceCurrent mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsDbLimitedResourceCurrent_val_ptr) = raw_rdbmsDbLimitedResourceCurrent_val; + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceCurrent_map */ + +/** + * Extract the current value of the rdbmsDbLimitedResourceCurrent data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbLimitedResourceCurrent_val_ptr + * Pointer to storage for a long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsDbLimitedResourceCurrent_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbLimitedResourceCurrent_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsDbLimitedResourceCurrent_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceCurrent_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbLimitedResourceCurrent data. + * set (* rdbmsDbLimitedResourceCurrent_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsDbLimitedResourceCurrent_val_ptr ) = rowreq_ctx->data.rdbmsDbLimitedResourceCurrent; + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceCurrent_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbLimitedResourceEntry.rdbmsDbLimitedResourceHighwater + * rdbmsDbLimitedResourceHighwater is subid 5 of rdbmsDbLimitedResourceEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.4.1.5 + * Description: +The maximum value of the resource seen since applUpTime + was reset for the earliest server which has the database + actively opened. + + If there are two servers with the database open, and the + oldest one dies, the proper way to invalidate the value is by + resetting sysUpTime. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 0 + * settable 0 + * + * Ranges: 1 - 2147483647; + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbLimitedResourceHighwater.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbLimitedResourceHighwater_map(long *mib_rdbmsDbLimitedResourceHighwater_val_ptr, long raw_rdbmsDbLimitedResourceHighwater_val) +{ + netsnmp_assert(NULL != mib_rdbmsDbLimitedResourceHighwater_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceHighwater_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsDbLimitedResourceHighwater mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsDbLimitedResourceHighwater_val_ptr) = raw_rdbmsDbLimitedResourceHighwater_val; + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceHighwater_map */ + +/** + * Extract the current value of the rdbmsDbLimitedResourceHighwater data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbLimitedResourceHighwater_val_ptr + * Pointer to storage for a long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsDbLimitedResourceHighwater_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbLimitedResourceHighwater_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsDbLimitedResourceHighwater_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceHighwater_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbLimitedResourceHighwater data. + * set (* rdbmsDbLimitedResourceHighwater_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsDbLimitedResourceHighwater_val_ptr ) = rowreq_ctx->data.rdbmsDbLimitedResourceHighwater; + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceHighwater_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbLimitedResourceEntry.rdbmsDbLimitedResourceFailures + * rdbmsDbLimitedResourceFailures is subid 6 of rdbmsDbLimitedResourceEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.4.1.6 + * Description: +The number of times the system wanted to exceed the limit of + the resource since applUpTime was reset for the earliest + server which has the database actively opened. + + If there are two servers with the DB open, and the + oldest one dies, the proper way to invalidate the value is by + resetting sysUpTime. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbLimitedResourceFailures.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbLimitedResourceFailures_map(u_long *mib_rdbmsDbLimitedResourceFailures_val_ptr, u_long raw_rdbmsDbLimitedResourceFailures_val) +{ + netsnmp_assert(NULL != mib_rdbmsDbLimitedResourceFailures_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceFailures_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsDbLimitedResourceFailures mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsDbLimitedResourceFailures_val_ptr) = raw_rdbmsDbLimitedResourceFailures_val; + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceFailures_map */ + +/** + * Extract the current value of the rdbmsDbLimitedResourceFailures data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbLimitedResourceFailures_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsDbLimitedResourceFailures_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsDbLimitedResourceFailures_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsDbLimitedResourceFailures_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceFailures_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbLimitedResourceFailures data. + * set (* rdbmsDbLimitedResourceFailures_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsDbLimitedResourceFailures_val_ptr ) = rowreq_ctx->data.rdbmsDbLimitedResourceFailures; + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceFailures_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbLimitedResourceEntry.rdbmsDbLimitedResourceDescription + * rdbmsDbLimitedResourceDescription is subid 7 of rdbmsDbLimitedResourceEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.4.1.7 + * Description: +A description of the resource and the meaning of the integer + units used for Limit, Current, and Highwater. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 1 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbLimitedResourceDescription.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbLimitedResourceDescription_map(char **mib_rdbmsDbLimitedResourceDescription_val_ptr_ptr, size_t *mib_rdbmsDbLimitedResourceDescription_val_ptr_len_ptr, char *raw_rdbmsDbLimitedResourceDescription_val_ptr, size_t raw_rdbmsDbLimitedResourceDescription_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbLimitedResourceDescription_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbLimitedResourceDescription_val_ptr_ptr) && (NULL != mib_rdbmsDbLimitedResourceDescription_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceDescription_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbLimitedResourceDescription non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbLimitedResourceDescription_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbLimitedResourceDescription_val_ptr_ptr) || (*mib_rdbmsDbLimitedResourceDescription_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbLimitedResourceDescription_val_ptr_ptr = realloc( *mib_rdbmsDbLimitedResourceDescription_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbLimitedResourceDescription_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbLimitedResourceDescription_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbLimitedResourceDescription_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbLimitedResourceDescription_val_ptr_ptr, raw_rdbmsDbLimitedResourceDescription_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceDescription_map */ + +/** + * Extract the current value of the rdbmsDbLimitedResourceDescription data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbLimitedResourceDescription_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsDbLimitedResourceDescription_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbLimitedResourceDescription. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbLimitedResourceDescription_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbLimitedResourceDescription_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbLimitedResourceDescription_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbLimitedResourceDescription_val_ptr_ptr, size_t *rdbmsDbLimitedResourceDescription_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbLimitedResourceDescription_val_ptr_ptr) && (NULL != *rdbmsDbLimitedResourceDescription_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbLimitedResourceDescription_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceDescription_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbLimitedResourceDescription data. + * set (* rdbmsDbLimitedResourceDescription_val_ptr_ptr ) and (* rdbmsDbLimitedResourceDescription_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbLimitedResourceDescription data + */ + if ((NULL == (* rdbmsDbLimitedResourceDescription_val_ptr_ptr )) || + ((* rdbmsDbLimitedResourceDescription_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbLimitedResourceDescription_len * sizeof((* rdbmsDbLimitedResourceDescription_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbLimitedResourceDescription data + */ + (* rdbmsDbLimitedResourceDescription_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbLimitedResourceDescription_len * sizeof((* rdbmsDbLimitedResourceDescription_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbLimitedResourceDescription_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbLimitedResourceDescription_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbLimitedResourceDescription_len * sizeof((* rdbmsDbLimitedResourceDescription_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbLimitedResourceDescription_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbLimitedResourceDescription, (* rdbmsDbLimitedResourceDescription_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbLimitedResourceDescription_get */ + + + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_get.h b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_get.h new file mode 100644 index 0000000..896e133 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_get.h @@ -0,0 +1,71 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_data_get.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_data_get.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBLIMITEDRESOURCETABLE_DATA_GET_H +#define RDBMSDBLIMITEDRESOURCETABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * GET function declarations + */ + +/* ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbLimitedResourceTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbLimitedResourceTable is subid 4 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.4, length: 9 +*/ + /* + * indexes + */ + int rdbmsDbIndex_map(long *mib_rdbmsDbIndex_val_ptr, long raw_rdbmsDbIndex_val); + int rdbmsDbLimitedResourceName_map(char **mib_rdbmsDbLimitedResourceName_val_ptr_ptr, size_t *mib_rdbmsDbLimitedResourceName_val_ptr_len_ptr, char *raw_rdbmsDbLimitedResourceName_val_ptr, size_t raw_rdbmsDbLimitedResourceName_val_ptr_len, int allow_realloc); + + int rdbmsDbLimitedResourceID_map(oid **mib_rdbmsDbLimitedResourceID_val_ptr_ptr, size_t *mib_rdbmsDbLimitedResourceID_val_ptr_len_ptr, oid *raw_rdbmsDbLimitedResourceID_val_ptr, size_t raw_rdbmsDbLimitedResourceID_val_ptr_len, int allow_realloc); + int rdbmsDbLimitedResourceID_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, oid **rdbmsDbLimitedResourceID_val_ptr_ptr, size_t *rdbmsDbLimitedResourceID_val_ptr_len_ptr ); + int rdbmsDbLimitedResourceLimit_map(long *mib_rdbmsDbLimitedResourceLimit_val_ptr, long raw_rdbmsDbLimitedResourceLimit_val); + int rdbmsDbLimitedResourceLimit_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbLimitedResourceLimit_val_ptr ); + int rdbmsDbLimitedResourceCurrent_map(long *mib_rdbmsDbLimitedResourceCurrent_val_ptr, long raw_rdbmsDbLimitedResourceCurrent_val); + int rdbmsDbLimitedResourceCurrent_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbLimitedResourceCurrent_val_ptr ); + int rdbmsDbLimitedResourceHighwater_map(long *mib_rdbmsDbLimitedResourceHighwater_val_ptr, long raw_rdbmsDbLimitedResourceHighwater_val); + int rdbmsDbLimitedResourceHighwater_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, long * rdbmsDbLimitedResourceHighwater_val_ptr ); + int rdbmsDbLimitedResourceFailures_map(u_long *mib_rdbmsDbLimitedResourceFailures_val_ptr, u_long raw_rdbmsDbLimitedResourceFailures_val); + int rdbmsDbLimitedResourceFailures_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsDbLimitedResourceFailures_val_ptr ); + int rdbmsDbLimitedResourceDescription_map(char **mib_rdbmsDbLimitedResourceDescription_val_ptr_ptr, size_t *mib_rdbmsDbLimitedResourceDescription_val_ptr_len_ptr, char *raw_rdbmsDbLimitedResourceDescription_val_ptr, size_t raw_rdbmsDbLimitedResourceDescription_val_ptr_len, int allow_realloc); + int rdbmsDbLimitedResourceDescription_get( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbLimitedResourceDescription_val_ptr_ptr, size_t *rdbmsDbLimitedResourceDescription_val_ptr_len_ptr ); + + +int rdbmsDbLimitedResourceTable_indexes_set_tbl_idx(rdbmsDbLimitedResourceTable_mib_index *tbl_idx, long rdbmsDbIndex_val, char *rdbmsDbLimitedResourceName_val_ptr, size_t rdbmsDbLimitedResourceName_val_ptr_len); +int rdbmsDbLimitedResourceTable_indexes_set(rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val, char *rdbmsDbLimitedResourceName_val_ptr, size_t rdbmsDbLimitedResourceName_val_ptr_len); + + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBLIMITEDRESOURCETABLE_DATA_GET_H */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_set.c b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_set.c new file mode 100644 index 0000000..cfbcb24 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_set.c @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_data_set.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_data_set.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsDbLimitedResourceTable.h" + + +/** @defgroup data_set data_set: Routines to set data + * + * These routines are used to set the value for individual objects. The + * row context is passed, along with the new value. + * + * @{ + */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_set.h b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_set.h new file mode 100644 index 0000000..36b90b9 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_data_set.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_data_set.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_data_set.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBLIMITEDRESOURCETABLE_DATA_SET_H +#define RDBMSDBLIMITEDRESOURCETABLE_DATA_SET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * SET function declarations + */ + +/* ********************************************************************* + * SET Table declarations + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBLIMITEDRESOURCETABLE_DATA_SET_H */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_enums.h b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_enums.h new file mode 100644 index 0000000..6a25754 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_enums.h @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_enums.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_enums.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBLIMITEDRESOURCETABLE_ENUMS_H +#define RDBMSDBLIMITEDRESOURCETABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table rdbmsDbLimitedResourceTable + * + ************************************************************************* + *************************************************************************/ + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBLIMITEDRESOURCETABLE_ENUMS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_interface.c b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_interface.c new file mode 100644 index 0000000..28eb874 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_interface.c @@ -0,0 +1,747 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_interface.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_interface.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbLimitedResourceTable.h" + + +#include <net-snmp/library/container.h> + +#include "rdbmsDbLimitedResourceTable_interface.h" + +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbLimitedResourceTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbLimitedResourceTable is subid 4 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.4, length: 9 +*/ +typedef struct rdbmsDbLimitedResourceTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; /* optional cache */ + + rdbmsDbLimitedResourceTable_registration_ptr user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} rdbmsDbLimitedResourceTable_interface_ctx; + +static rdbmsDbLimitedResourceTable_interface_ctx rdbmsDbLimitedResourceTable_if_ctx; + +static void _rdbmsDbLimitedResourceTable_container_init( + rdbmsDbLimitedResourceTable_interface_ctx *if_ctx); + + +static Netsnmp_Node_Handler _mfd_rdbmsDbLimitedResourceTable_pre_request; +static Netsnmp_Node_Handler _mfd_rdbmsDbLimitedResourceTable_post_request; +static Netsnmp_Node_Handler _mfd_rdbmsDbLimitedResourceTable_object_lookup; +static Netsnmp_Node_Handler _mfd_rdbmsDbLimitedResourceTable_get_values; +/** + * @internal + * Initialize the table rdbmsDbLimitedResourceTable + * (Define its contents and how it's structured) + */ +void +_rdbmsDbLimitedResourceTable_initialize_interface(rdbmsDbLimitedResourceTable_registration_ptr reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &rdbmsDbLimitedResourceTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = &rdbmsDbLimitedResourceTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:_rdbmsDbLimitedResourceTable_initialize_interface","called\n")); + + + /************************************************* + * + * save interface context for rdbmsDbLimitedResourceTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, + ASN_INTEGER, /** index: rdbmsDbIndex */ + ASN_OCTET_STR, /** index: rdbmsDbLimitedResourceName */ + 0); + + /* Define the minimum and maximum accessible columns. This + optimizes retrival. */ + tbl_info->min_column = RDBMSDBLIMITEDRESOURCETABLE_MIN_COL; + tbl_info->max_column = RDBMSDBLIMITEDRESOURCETABLE_MAX_COL; + + /* + * save users context + */ + rdbmsDbLimitedResourceTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + rdbmsDbLimitedResourceTable_init_data(reg_ptr); + + /* + * set up the container + */ + _rdbmsDbLimitedResourceTable_container_init(&rdbmsDbLimitedResourceTable_if_ctx); + if (NULL == rdbmsDbLimitedResourceTable_if_ctx.container) { + snmp_log(LOG_ERR,"could not initialize container for rdbmsDbLimitedResourceTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = _mfd_rdbmsDbLimitedResourceTable_object_lookup; + access_multiplexer->get_values = _mfd_rdbmsDbLimitedResourceTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = _mfd_rdbmsDbLimitedResourceTable_pre_request; + access_multiplexer->post_request = _mfd_rdbmsDbLimitedResourceTable_post_request; + + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("rdbmsDbLimitedResourceTable:init_rdbmsDbLimitedResourceTable", + "Registering rdbmsDbLimitedResourceTable as a mibs-for-dummies table.\n")); + handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = netsnmp_handler_registration_create("rdbmsDbLimitedResourceTable", handler, + rdbmsDbLimitedResourceTable_oid, + rdbmsDbLimitedResourceTable_oid_size, + HANDLER_CAN_BABY_STEP | + HANDLER_CAN_RONLY + ); + if(NULL == reginfo) { + snmp_log(LOG_ERR,"error registering table rdbmsDbLimitedResourceTable\n"); + return; + } + reginfo->my_reg_void = &rdbmsDbLimitedResourceTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if( access_multiplexer->object_lookup ) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if( access_multiplexer->set_values ) + mfd_modes |= BABY_STEP_SET_VALUES; + if( access_multiplexer->irreversible_commit ) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if( access_multiplexer->object_syntax_checks ) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if( access_multiplexer->pre_request ) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if( access_multiplexer->post_request ) + mfd_modes |= BABY_STEP_POST_REQUEST; + + if( access_multiplexer->undo_setup ) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if( access_multiplexer->undo_cleanup ) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if( access_multiplexer->undo_sets ) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if( access_multiplexer->row_creation ) + mfd_modes |= BABY_STEP_ROW_CREATE; + if( access_multiplexer->consistency_checks ) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if( access_multiplexer->commit ) + mfd_modes |= BABY_STEP_COMMIT; + if( access_multiplexer->undo_commit ) + mfd_modes |= BABY_STEP_UNDO_COMMIT; + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + rdbmsDbLimitedResourceTable_if_ctx.container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler( reginfo, handler ); + + /************************************************* + * + * inject cache helper + */ + if(NULL != rdbmsDbLimitedResourceTable_if_ctx.cache) { + handler = netsnmp_cache_handler_get(rdbmsDbLimitedResourceTable_if_ctx.cache); + netsnmp_inject_handler( reginfo, handler ); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); +} /* _rdbmsDbLimitedResourceTable_initialize_interface */ + +void +rdbmsDbLimitedResourceTable_valid_columns_set(netsnmp_column_info *vc) +{ + rdbmsDbLimitedResourceTable_if_ctx.tbl_info.valid_columns = vc; +} /* rdbmsDbLimitedResourceTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +rdbmsDbLimitedResourceTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsDbLimitedResourceTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + /* + * rdbmsDbLimitedResourceName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H + */ + netsnmp_variable_list var_rdbmsDbLimitedResourceName; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + memset( &var_rdbmsDbLimitedResourceName, 0x00, sizeof(var_rdbmsDbLimitedResourceName) ); + var_rdbmsDbLimitedResourceName.type = ASN_OCTET_STR; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = &var_rdbmsDbLimitedResourceName; var_rdbmsDbLimitedResourceName.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_index_to_oid","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_rdbmsDbIndex, (u_char*)&mib_idx->rdbmsDbIndex, + sizeof(mib_idx->rdbmsDbIndex)); + + /* rdbmsDbLimitedResourceName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ + snmp_set_var_value(&var_rdbmsDbLimitedResourceName, (u_char*)&mib_idx->rdbmsDbLimitedResourceName, + mib_idx->rdbmsDbLimitedResourceName_len * sizeof(mib_idx->rdbmsDbLimitedResourceName[0])); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, (size_t *)&oid_idx->len, + NULL, 0, &var_rdbmsDbIndex); + if(err) + snmp_log(LOG_ERR,"error %d converting index to oid\n", err); + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsDbLimitedResourceTable_index_to_oid */ + +/** + * extract rdbmsDbLimitedResourceTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +rdbmsDbLimitedResourceTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsDbLimitedResourceTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + /* + * rdbmsDbLimitedResourceName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H + */ + netsnmp_variable_list var_rdbmsDbLimitedResourceName; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + memset( &var_rdbmsDbLimitedResourceName, 0x00, sizeof(var_rdbmsDbLimitedResourceName) ); + var_rdbmsDbLimitedResourceName.type = ASN_OCTET_STR; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = &var_rdbmsDbLimitedResourceName; var_rdbmsDbLimitedResourceName.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_index_from_oid","called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes( oid_idx->oids, oid_idx->len, + &var_rdbmsDbIndex ); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + mib_idx->rdbmsDbIndex = *((long *)var_rdbmsDbIndex.val.string); + /* + * NOTE: val_len is in bytes, rdbmsDbLimitedResourceName_len might not be + */ + if(var_rdbmsDbLimitedResourceName.val_len > sizeof(mib_idx->rdbmsDbLimitedResourceName)) + err = SNMP_ERR_GENERR; + else { + memcpy(mib_idx->rdbmsDbLimitedResourceName, var_rdbmsDbLimitedResourceName.val.string, var_rdbmsDbLimitedResourceName.val_len); + mib_idx->rdbmsDbLimitedResourceName_len = var_rdbmsDbLimitedResourceName.val_len / sizeof(mib_idx->rdbmsDbLimitedResourceName[0]); + } + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsDbLimitedResourceTable_index_from_oid */ + + +/* ********************************************************************* + * @internal + * allocate resources for a rdbmsDbLimitedResourceTable_rowreq_ctx + */ +rdbmsDbLimitedResourceTable_rowreq_ctx * +rdbmsDbLimitedResourceTable_allocate_rowreq_ctx(void) +{ + rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(rdbmsDbLimitedResourceTable_rowreq_ctx); + + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_allocate_rowreq_ctx","called\n")); + + if(NULL == rowreq_ctx) { + snmp_log(LOG_ERR,"Couldn't allocate memory for a " + "rdbmsDbLimitedResourceTable_rowreq_ctx.\n"); + } + + rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; + + rowreq_ctx->rdbmsDbLimitedResourceTable_data_list = NULL; + rowreq_ctx->rdbmsDbLimitedResourceTable_reg = rdbmsDbLimitedResourceTable_if_ctx.user_ctx; + + + return rowreq_ctx; +} /* rdbmsDbLimitedResourceTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a rdbmsDbLimitedResourceTable_rowreq_ctx + */ +void +rdbmsDbLimitedResourceTable_release_rowreq_ctx(rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:rdbmsDbLimitedResourceTable_release_rowreq_ctx","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + + /* + * free index oid pointer + */ + if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* rdbmsDbLimitedResourceTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbLimitedResourceTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc = rdbmsDbLimitedResourceTable_pre_request(rdbmsDbLimitedResourceTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable","error %d from " + "rdbmsDbLimitedResourceTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbLimitedResourceTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbLimitedResourceTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx; + int rc = rdbmsDbLimitedResourceTable_post_request(rdbmsDbLimitedResourceTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable","error %d from " + "rdbmsDbLimitedResourceTable_post_request\n", rc)); + } + + /* + * if there are no errors, check for and handle row creation/deletion + */ + rc = netsnmp_check_requests_error(requests); + if ((SNMP_ERR_NOERROR == rc) && + (NULL != + (rowreq_ctx = netsnmp_container_table_row_extract(requests)))) { + if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) { + rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; + CONTAINER_INSERT(rdbmsDbLimitedResourceTable_if_ctx.container, rowreq_ctx); + } + else if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { + CONTAINER_REMOVE(rdbmsDbLimitedResourceTable_if_ctx.container, rowreq_ctx); + rdbmsDbLimitedResourceTable_release_rowreq_ctx(rowreq_ctx); + } + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbLimitedResourceTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbLimitedResourceTable_object_lookup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:_mfd_rdbmsDbLimitedResourceTable_object_lookup","called\n")); + + /* + * get our context from mfd + * rdbmsDbLimitedResourceTable_interface_ctx *if_ctx = + * (rdbmsDbLimitedResourceTable_interface_ctx *)reginfo->my_reg_void; + */ + + if(NULL == rowreq_ctx) { + netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION); + } + else { + rdbmsDbLimitedResourceTable_row_prep(rowreq_ctx); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbLimitedResourceTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsDbLimitedResourceTable_get_column( rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:_mfd_rdbmsDbLimitedResourceTable_get_column","called\n")); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsDbLimitedResourceID(2)/AutonomousType/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h */ + case COLUMN_RDBMSDBLIMITEDRESOURCEID: + var->type = ASN_OBJECT_ID; +rc = rdbmsDbLimitedResourceID_get(rowreq_ctx, (oid **)&var->val.string, &var->val_len ); + break; + + /* rdbmsDbLimitedResourceLimit(3)/INTEGER/ASN_INTEGER/long(long)//l/A/W/e/R/d/h */ + case COLUMN_RDBMSDBLIMITEDRESOURCELIMIT: + var->val_len = sizeof(long); + var->type = ASN_INTEGER; +rc = rdbmsDbLimitedResourceLimit_get(rowreq_ctx, (long *)var->val.string ); + break; + + /* rdbmsDbLimitedResourceCurrent(4)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/R/d/h */ + case COLUMN_RDBMSDBLIMITEDRESOURCECURRENT: + var->val_len = sizeof(long); + var->type = ASN_INTEGER; +rc = rdbmsDbLimitedResourceCurrent_get(rowreq_ctx, (long *)var->val.string ); + break; + + /* rdbmsDbLimitedResourceHighwater(5)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/R/d/h */ + case COLUMN_RDBMSDBLIMITEDRESOURCEHIGHWATER: + var->val_len = sizeof(long); + var->type = ASN_INTEGER; +rc = rdbmsDbLimitedResourceHighwater_get(rowreq_ctx, (long *)var->val.string ); + break; + + /* rdbmsDbLimitedResourceFailures(6)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSDBLIMITEDRESOURCEFAILURES: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsDbLimitedResourceFailures_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsDbLimitedResourceDescription(7)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSDBLIMITEDRESOURCEDESCRIPTION: + var->type = ASN_OCTET_STR; +rc = rdbmsDbLimitedResourceDescription_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsDbLimitedResourceTable_get_column\n", column); + break; + } + + return rc; +} /* _rdbmsDbLimitedResourceTable_get_column */ + +int +_mfd_rdbmsDbLimitedResourceTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + u_char * old_string; + void (*dataFreeHook)(void *); + int rc; + + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:_mfd_rdbmsDbLimitedResourceTable_get_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if(NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + else if(requests->requestvb->buf == requests->requestvb->val.string) { + if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsDbLimitedResourceTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + if(MFD_SKIP == rc) { + requests->requestvb->type = ASN_PRIV_RETRY; + rc = SNMP_ERR_NOERROR; + } + } + else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if(rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if(old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if(dataFreeHook) + (*dataFreeHook)(old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbLimitedResourceTable_get_values */ + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/* + * NOT APPLICABLE (per MIB or user setting) + */ +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +/** + * @internal + */ +static int +_cache_load(netsnmp_cache *cache, void *vmagic) +{ + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:_cache_load","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache for rdbmsDbLimitedResourceTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return rdbmsDbLimitedResourceTable_cache_load((netsnmp_container*)cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_item_free(rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx, void *context) +{ + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:_cache_item_free","called\n")); + + if(NULL == rowreq_ctx) + return; + + rdbmsDbLimitedResourceTable_release_rowreq_ctx(rowreq_ctx); +} /* _cache_item_free */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache *cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:_cache_free","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache in rdbmsDbLimitedResourceTable_cache_free\n"); + return; + } + + container = (netsnmp_container*)cache->magic; + + /* + * call user code + */ + rdbmsDbLimitedResourceTable_cache_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *)_cache_item_free, + NULL); +} /* _cache_free */ + +/** + * @internal + * initialize the iterator container with functions or wrappers + */ +void +_rdbmsDbLimitedResourceTable_container_init(rdbmsDbLimitedResourceTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:rdbmsDbLimitedResourceTable:_rdbmsDbLimitedResourceTable_container_init","called\n")); + + /* + * set up the cache + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + rdbmsDbLimitedResourceTable_oid, + rdbmsDbLimitedResourceTable_oid_size); + + if(NULL == if_ctx->cache) { + snmp_log(LOG_ERR, "error creating cache for rdbmsDbLimitedResourceTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + rdbmsDbLimitedResourceTable_container_init(&if_ctx->container, if_ctx->cache); + if(NULL == if_ctx->container) + if_ctx->container = netsnmp_container_find("rdbmsDbLimitedResourceTable:table_container"); + if(NULL == if_ctx->container) { + snmp_log(LOG_ERR,"error creating container in " + "rdbmsDbLimitedResourceTable_container_init\n"); + return; + } + if_ctx->cache->magic = (void*)if_ctx->container; +} /* _rdbmsDbLimitedResourceTable_container_init */ + diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_interface.h b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_interface.h new file mode 100644 index 0000000..c76fd43 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_interface.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_interface.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_interface.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBLIMITEDRESOURCETABLE_INTERFACE_H +#define RDBMSDBLIMITEDRESOURCETABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "rdbmsDbLimitedResourceTable.h" + +/* ******************************************************************** + * Table declarations + */ + +/* PUBLIC interface initialization routine */ +void _rdbmsDbLimitedResourceTable_initialize_interface(rdbmsDbLimitedResourceTable_registration_ptr user_ctx, + u_long flags); + + rdbmsDbLimitedResourceTable_rowreq_ctx * rdbmsDbLimitedResourceTable_allocate_rowreq_ctx(void); +void rdbmsDbLimitedResourceTable_release_rowreq_ctx(rdbmsDbLimitedResourceTable_rowreq_ctx *rowreq_ctx); + +int rdbmsDbLimitedResourceTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsDbLimitedResourceTable_mib_index *mib_idx); +int rdbmsDbLimitedResourceTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsDbLimitedResourceTable_mib_index *mib_idx); + +/* + * access to certain internals. use with caution! + */ +void rdbmsDbLimitedResourceTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBLIMITEDRESOURCETABLE_INTERFACE_H */ diff --git a/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_oids.h b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_oids.h new file mode 100644 index 0000000..2d50d40 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbLimitedResourceTable/rdbmsDbLimitedResourceTable_oids.h @@ -0,0 +1,40 @@ +/*------------------------------------------------------------------------- + * rdbmsDbLimitedResourceTable_oids.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbLimitedResourceTable_oids.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBLIMITEDRESOURCETABLE_OIDS_H +#define RDBMSDBLIMITEDRESOURCETABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* column number definitions for table rdbmsDbLimitedResourceTable */ +#define RDBMSDBLIMITEDRESOURCETABLE_OID 1,3,6,1,2,1,39,1,4 +#define COLUMN_RDBMSDBLIMITEDRESOURCENAME 1 +#define COLUMN_RDBMSDBLIMITEDRESOURCEID 2 +#define COLUMN_RDBMSDBLIMITEDRESOURCELIMIT 3 +#define COLUMN_RDBMSDBLIMITEDRESOURCECURRENT 4 +#define COLUMN_RDBMSDBLIMITEDRESOURCEHIGHWATER 5 +#define COLUMN_RDBMSDBLIMITEDRESOURCEFAILURES 6 +#define COLUMN_RDBMSDBLIMITEDRESOURCEDESCRIPTION 7 + +#define RDBMSDBLIMITEDRESOURCETABLE_MIN_COL COLUMN_RDBMSDBLIMITEDRESOURCEID +#define RDBMSDBLIMITEDRESOURCETABLE_MAX_COL COLUMN_RDBMSDBLIMITEDRESOURCEDESCRIPTION + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBLIMITEDRESOURCETABLE_OIDS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable.c b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable.c new file mode 100644 index 0000000..5082c83 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable.c @@ -0,0 +1,130 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsDbParamTable.h" + +#include <net-snmp/agent/mib_modules.h> + +#include "rdbmsDbParamTable_interface.h" + +oid rdbmsDbParamTable_oid[] = { RDBMSDBPARAMTABLE_OID }; +int rdbmsDbParamTable_oid_size = OID_LENGTH(rdbmsDbParamTable_oid); + +void initialize_table_rdbmsDbParamTable(void); + + +/** + * Initializes the rdbmsDbParamTable module + */ +void +init_rdbmsDbParamTable(void) +{ + DEBUGMSGTL(("verbose:rdbmsDbParamTable:init_rdbmsDbParamTable","called\n")); + + /* + * TODO:300:o: Perform rdbmsDbParamTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("rdbmsDbParamTable")) + initialize_table_rdbmsDbParamTable(); + +} /* init_rdbmsDbParamTable */ + +/** + * Initialize the table rdbmsDbParamTable + * (Define its contents and how it's structured) + */ +void +initialize_table_rdbmsDbParamTable(void) +{ + rdbmsDbParamTable_registration_ptr user_context; + u_long flags; + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:initialize_table_rdbmsDbParamTable","called\n")); + + /* + * TODO:301:o: Perform rdbmsDbParamTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize rdbmsDbParamTable user context + * if you'd like to pass in a pointer to some data for this + * table, allocate or set it up here. + */ + /* + * a netsnmp_data_list is a simple way to store void pointers. A simple + * string token is used to add, find or remove pointers. + */ + user_context = netsnmp_create_data_list("rdbmsDbParamTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _rdbmsDbParamTable_initialize_interface(user_context, flags); +} /* initialize_table_rdbmsDbParamTable */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +rdbmsDbParamTable_pre_request(rdbmsDbParamTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_pre_request","called\n")); + + /* + * TODO:510:o: Perform rdbmsDbParamTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsDbParamTable_pre_request */ + +/** + * post-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error (ignored) + */ +int +rdbmsDbParamTable_post_request(rdbmsDbParamTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_post_request","called\n")); + + /* + * TODO:511:o: Perform rdbmsDbParamTable pos-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsDbParamTable_post_request */ + + +/** @{ */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable.h b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable.h new file mode 100644 index 0000000..bfcf5fd --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable.h @@ -0,0 +1,214 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBPARAMTABLE_H +#define RDBMSDBPARAMTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @defgroup misc misc: Miscelaneous routines + * + * @{ + */ +#include <net-snmp/library/asn1.h> + +/* other required module components */ + /* *INDENT-OFF* */ +config_require(RDBMS-MIB/rdbmsDbParamTable/rdbmsDbParamTable_interface); +config_require(RDBMS-MIB/rdbmsDbParamTable/rdbmsDbParamTable_data_access); +config_require(RDBMS-MIB/rdbmsDbParamTable/rdbmsDbParamTable_data_get); +config_require(RDBMS-MIB/rdbmsDbParamTable/rdbmsDbParamTable_data_set); + /* *INDENT-ON* */ + +/* OID and column number definitions for */ +#include "rdbmsDbParamTable_oids.h" + +/* enum definions */ +#include "rdbmsDbParamTable_enums.h" + +/* ********************************************************************* + * function declarations + */ +void init_rdbmsDbParamTable(void); + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbParamTable is subid 3 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.3, length: 9 +*/ +/* ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review rdbmsDbParamTable registration context. + */ +typedef netsnmp_data_list * rdbmsDbParamTable_registration_ptr; + +/**********************************************************************/ +/* + * TODO:110:r: |-> Review rdbmsDbParamTable data context structure. + * This structure is used to represent the data for rdbmsDbParamTable. + */ +/* + * This structure contains storage for all the columns defined in the + * rdbmsDbParamTable. + */ +typedef struct rdbmsDbParamTable_data_s { + + /* + * rdbmsDbParamID(3)/AutonomousType/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h + */ + oid rdbmsDbParamID[128]; +size_t rdbmsDbParamID_len; /* # of oid elements, not bytes */ + + /* + * rdbmsDbParamCurrValue(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + char rdbmsDbParamCurrValue[255]; +size_t rdbmsDbParamCurrValue_len; /* # of char elements, not bytes */ + + /* + * rdbmsDbParamComment(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + char rdbmsDbParamComment[255]; +size_t rdbmsDbParamComment_len; /* # of char elements, not bytes */ + +} rdbmsDbParamTable_data; + + +/* + * TODO:120:r: |-> Review rdbmsDbParamTable mib index. + * This structure is used to represent the index for rdbmsDbParamTable. + */ +typedef struct rdbmsDbParamTable_mib_index_s { + + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long rdbmsDbIndex; + + /* + * rdbmsDbParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H + */ + char rdbmsDbParamName[64]; + size_t rdbmsDbParamName_len; + + /* + * rdbmsDbParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long rdbmsDbParamSubIndex; + + +} rdbmsDbParamTable_mib_index; + + /* + * TODO:121:r: | |-> Review rdbmsDbParamTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. + * + * BE VERY CAREFUL TO TAKE INTO ACCOUNT THE MAXIMUM + * POSSIBLE LENGHT FOR EVERY VARIABLE LENGTH INDEX! + * Guessing 128 - col/entry(2) - oid len(9) +*/ +#define MAX_rdbmsDbParamTable_IDX_LEN 67 + + +/* ********************************************************************* + * TODO:130:o: |-> Review rdbmsDbParamTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * rdbmsDbParamTable_rowreq_ctx pointer. + */ +typedef struct rdbmsDbParamTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_rdbmsDbParamTable_IDX_LEN]; + + rdbmsDbParamTable_mib_index tbl_idx; + + rdbmsDbParamTable_data data; + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * implementor's context pointer (provided during registration) + */ + rdbmsDbParamTable_registration_ptr rdbmsDbParamTable_reg; + + /* + * TODO:131:o: | |-> Add useful data to rdbmsDbParamTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *rdbmsDbParamTable_data_list; + +} rdbmsDbParamTable_rowreq_ctx; + +typedef struct rdbmsDbParamTable_ref_rowreq_ctx_s { + rdbmsDbParamTable_rowreq_ctx *rowreq_ctx; +} rdbmsDbParamTable_ref_rowreq_ctx; + +/* ********************************************************************* + * function prototypes + */ + int rdbmsDbParamTable_pre_request(rdbmsDbParamTable_registration_ptr user_context); + int rdbmsDbParamTable_post_request(rdbmsDbParamTable_registration_ptr user_context); + + +extern oid rdbmsDbParamTable_oid[]; +extern int rdbmsDbParamTable_oid_size; + + +#include "rdbmsDbParamTable_interface.h" +#include "rdbmsDbParamTable_data_access.h" +#include "rdbmsDbParamTable_data_get.h" +#include "rdbmsDbParamTable_data_set.h" + +/* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBPARAMTABLE_H */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_access.c b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_access.c new file mode 100644 index 0000000..e8d09cd --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_access.c @@ -0,0 +1,394 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_data_access.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_data_access.c,v 1.6 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbParamTable.h" +#include "rdbmsDbParamTable_data_access.h" +#include "pg_array.h" + +/** @defgroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbParamTable is subid 3 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.3, length: 9 +*/ + +/** + * initialization for rdbmsDbParamTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param rdbmsDbParamTable_reg + * Pointer to rdbmsDbParamTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +rdbmsDbParamTable_init_data(rdbmsDbParamTable_registration_ptr rdbmsDbParamTable_reg) +{ + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_init_data","called\n")); + + /* + * TODO:303:o: Initialize rdbmsDbParamTable data. + */ + + return MFD_SUCCESS; +} /* rdbmsDbParamTable_init_data */ + +/** + * container-cached overview + * + */ + +/*********************************************************************** + * + * cache + * + ***********************************************************************/ +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +rdbmsDbParamTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache) +{ + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_container_init","called\n")); + + if((NULL == cache) || (NULL == container_ptr_ptr)) { + snmp_log(LOG_ERR,"bad params to rdbmsDbParamTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + /* + * TODO:345:A: Set up rdbmsDbParamTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = RDBMSDBPARAMTABLE_CACHE_TIMEOUT; /* seconds */ +} /* rdbmsDbParamTable_container_init */ + +/** + * load cache data + * + * TODO:350:M: Implement rdbmsDbParamTable cache load + * + * @param container container to which items should be inserted + * + * @retval MFD_SUCCESS : success. + * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source + * @retval MFD_ERROR : other error. + * + * This function is called to cache the index(es) (and data, optionally) + * for the every row in the data set. + * + * @remark + * While loading the cache, the only important thing is the indexes. + * If access to your data is cheap/fast (e.g. you have a pointer to a + * structure in memory), it would make sense to update the data here. + * If, however, the accessing the data invovles more work (e.g. parsing + * some other existing data, or peforming calculations to derive the data), + * then you can limit yourself to setting the indexes and saving any + * information you will need later. Then use the saved information in + * rdbmsDbParamTable_row_prep() for populating data. + * + * @note + * If you need consistency between rows (like you want statistics + * for each row to be from the same time frame), you should set all + * data here. + * + */ +int +rdbmsDbParamTable_cache_load(netsnmp_container *container) +{ + rdbmsDbParamTable_rowreq_ctx *rowreq_ctx; + size_t count = 0; + int i, j, resultCount, errorCode = MFD_SUCCESS, elements; + + long rdbmsDbParamSubIndex = 0; + PGresult *qryRes; + char **array; + + int rdbmsDbIndex; + int rdbmsDbParamCurrValue_len, rdbmsDbParamComment_len = 0, rdbmsDbParamName_len; + char rdbmsDbParamCurrValue[255], rdbmsDbParamComment[255] = { "" }, *tmp, rdbmsDbParamName[64]; + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_cache_load","called\n")); + + /* + * TODO:351:M: |-> Load/update data in the rdbmsDbParamTable container. + * loop over your rdbmsDbParamTable data, allocate a rowreq context, + * set the index(es) [and data, optionally] and insert into + * the container. + */ + + if (PQstatus(dbconn) == CONNECTION_OK) + qryRes = PQexec(dbconn, "SELECT oid, datname, datconfig FROM pg_database"); + else { + snmp_log(LOG_ERR, "Can't get connected to the database"); + return MFD_RESOURCE_UNAVAILABLE; + } + if (PQresultStatus(qryRes) != PGRES_TUPLES_OK) { + snmp_log(LOG_ERR, "Didn't get any results from the database"); + PQclear(qryRes); + /*PQfinish(dbconn);*/ + /* It's probably an error if I didn't find *any* databases */ + return MFD_RESOURCE_UNAVAILABLE; + } + + resultCount = PQntuples(qryRes); + for (i = 0; i < resultCount; i++) { + rdbmsDbIndex = atoi(PQgetvalue(qryRes, i, 0)); + array = pg_text_array_parse(PQgetvalue(qryRes, i, 2), &elements); + if (!array) { + snmp_log(LOG_INFO, "No rdbmsDbParamTable values found for database %s\n", PQgetvalue(qryRes, i, 1)); + continue; + } + for (j = 0; j < elements; j++) { + tmp = strchr(array[j], '='); + if (!tmp) continue; + memset(rdbmsDbParamName, 0, 64); + strncpy(rdbmsDbParamName, array[j], ((tmp - array[j]) < 64 ? (tmp - array[j]) : 64)); + strncpy(rdbmsDbParamCurrValue, tmp+1, 255); + rdbmsDbParamName_len = strlen(rdbmsDbParamName); + rdbmsDbParamCurrValue_len = strlen(rdbmsDbParamCurrValue); + + /* + * TODO:352:M: | |-> set indexes in new rdbmsDbParamTable rowreq context. + */ + rowreq_ctx = rdbmsDbParamTable_allocate_rowreq_ctx(); + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "memory allocation failed\n"); + errorCode = MFD_RESOURCE_UNAVAILABLE; + break; + } + if(MFD_SUCCESS != rdbmsDbParamTable_indexes_set(rowreq_ctx + , rdbmsDbIndex + , rdbmsDbParamName, rdbmsDbParamName_len + , rdbmsDbParamSubIndex + )) { + snmp_log(LOG_ERR,"error setting index while loading " + "rdbmsDbParamTable cache.\n"); + rdbmsDbParamTable_release_rowreq_ctx(rowreq_ctx); + continue; + } + + /* + * TODO:352:r: | |-> populate rdbmsDbParamTable data context. + * Populate data context here. (optionally, delay until row prep) + */ + rowreq_ctx->data.rdbmsDbParamID_len = 128; + rowreq_ctx->data.rdbmsDbParamCurrValue_len = 255; + rowreq_ctx->data.rdbmsDbParamComment_len = 255; + /* + * TRANSIENT or semi-TRANSIENT data: + * copy data or save any info needed to do it in row_prep. + */ + /* + * setup/save data for rdbmsDbParamID + * rdbmsDbParamID(3)/AutonomousType/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h + */ + /* + * TODO:246:r: |-> Define rdbmsDbParamID mapping. + * Map values between raw/native values and MIB values + * + * if(MFD_SUCCESS != + * rdbmsDbParamID_map(&rowreq_ctx->data.rdbmsDbParamID, &rowreq_ctx->data.rdbmsDbParamID_len, + * rdbmsDbParamID, rdbmsDbParamID_len, 0)) { + * return MFD_ERROR; + * } + */ + /* + * make sure there is enough space for rdbmsDbParamID data + */ + /* See comment in rdbmsDbParamID_get() -- we don't need this value + if ((NULL == rowreq_ctx->data.rdbmsDbParamID) || + (rowreq_ctx->data.rdbmsDbParamID_len < (rdbmsDbParamID_len * sizeof(rowreq_ctx->data.rdbmsDbParamID[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + errorCode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsDbParamID_len = rdbmsDbParamID_len * sizeof(rowreq_ctx->data.rdbmsDbParamID[0]); + memcpy( rowreq_ctx->data.rdbmsDbParamID, rdbmsDbParamID, rowreq_ctx->data.rdbmsDbParamID_len ); + */ + + /* + * setup/save data for rdbmsDbParamCurrValue + * rdbmsDbParamCurrValue(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + /* + * TODO:246:r: |-> Define rdbmsDbParamCurrValue mapping. + * Map values between raw/native values and MIB values + * + * if(MFD_SUCCESS != + * rdbmsDbParamCurrValue_map(&rowreq_ctx->data.rdbmsDbParamCurrValue, &rowreq_ctx->data.rdbmsDbParamCurrValue_len, + * rdbmsDbParamCurrValue, rdbmsDbParamCurrValue_len, 0)) { + * return MFD_ERROR; + * } + */ + /* + * make sure there is enough space for rdbmsDbParamCurrValue data + */ + if ((NULL == rowreq_ctx->data.rdbmsDbParamCurrValue) || + (rowreq_ctx->data.rdbmsDbParamCurrValue_len < (rdbmsDbParamCurrValue_len * sizeof(rowreq_ctx->data.rdbmsDbParamCurrValue[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + errorCode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsDbParamCurrValue_len = rdbmsDbParamCurrValue_len * sizeof(rowreq_ctx->data.rdbmsDbParamCurrValue[0]); + memcpy( rowreq_ctx->data.rdbmsDbParamCurrValue, rdbmsDbParamCurrValue, rowreq_ctx->data.rdbmsDbParamCurrValue_len ); + + /* + * setup/save data for rdbmsDbParamComment + * rdbmsDbParamComment(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + /* + * TODO:246:r: |-> Define rdbmsDbParamComment mapping. + * Map values between raw/native values and MIB values + * + * if(MFD_SUCCESS != + * rdbmsDbParamComment_map(&rowreq_ctx->data.rdbmsDbParamComment, &rowreq_ctx->data.rdbmsDbParamComment_len, + * rdbmsDbParamComment, rdbmsDbParamComment_len, 0)) { + * return MFD_ERROR; + * } + */ + /* + * make sure there is enough space for rdbmsDbParamComment data + */ + if ((NULL == rowreq_ctx->data.rdbmsDbParamComment) || + (rowreq_ctx->data.rdbmsDbParamComment_len < (rdbmsDbParamComment_len * sizeof(rowreq_ctx->data.rdbmsDbParamComment[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + errorCode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsDbParamComment_len = rdbmsDbParamComment_len * sizeof(rowreq_ctx->data.rdbmsDbParamComment[0]); + memcpy( rowreq_ctx->data.rdbmsDbParamComment, rdbmsDbParamComment, rowreq_ctx->data.rdbmsDbParamComment_len ); + + + /* + * insert into table container + */ + CONTAINER_INSERT(container, rowreq_ctx); + ++count; + } + pg_text_array_free(array, elements); + } + + DEBUGMSGT(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_cache_load", + "inserted %d records\n", count)); + + PQclear(qryRes); + return errorCode; +} /* rdbmsDbParamTable_cache_load */ + +/** + * cache clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +rdbmsDbParamTable_cache_free(netsnmp_container *container) +{ + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_cache_free","called\n")); + + /* + * TODO:380:M: Free rdbmsDbParamTable cache. + */ +} /* rdbmsDbParamTable_cache_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +rdbmsDbParamTable_row_prep( rdbmsDbParamTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_row_prep","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* rdbmsDbParamTable_row_prep */ + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_access.h b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_access.h new file mode 100644 index 0000000..5bdccf1 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_access.h @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_data_access.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_data_access.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBPARAMTABLE_DATA_ACCESS_H +#define RDBMSDBPARAMTABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ********************************************************************* + * function declarations + */ + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbParamTable is subid 3 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.3, length: 9 +*/ + + + int rdbmsDbParamTable_init_data(rdbmsDbParamTable_registration_ptr rdbmsDbParamTable_reg); + + +/* + * TODO:180:o: Review rdbmsDbParamTable cache timeout. + * The number of seconds before the cache times out + */ +#define RDBMSDBPARAMTABLE_CACHE_TIMEOUT 60 + +void rdbmsDbParamTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache); +int rdbmsDbParamTable_cache_load(netsnmp_container *container); +void rdbmsDbParamTable_cache_free(netsnmp_container *container); + + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ +/* ********************************************************************* + * Since we have no idea how you really access your data, we'll go with + * a worst case example: a flat text file. + */ +#define MAX_LINE_SIZE 256 + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + int rdbmsDbParamTable_row_prep( rdbmsDbParamTable_rowreq_ctx *rowreq_ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBPARAMTABLE_DATA_ACCESS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_get.c b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_get.c new file mode 100644 index 0000000..77537a2 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_get.c @@ -0,0 +1,732 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_data_get.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_data_get.c,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsDbParamTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement rdbmsDbParamTable get routines. + * TODO:240:M: Implement rdbmsDbParamTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbParamTable is subid 3 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.3, length: 9 +*/ + +/* --------------------------------------------------------------------- + * TODO:200:r: Implement rdbmsDbParamTable data context functions. + */ + + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbParamEntry.rdbmsDbParamName + * rdbmsDbParamName is subid 1 of rdbmsDbParamEntry. + * Its status is Current, and its access level is NoAccess. + * OID: .1.3.6.1.2.1.39.1.3.1.1 + * Description: +The name of a configuration parameter for a database. This + name is product-specific. The length is limited to 64 + characters to constrain the number of sub-identifiers needed + for instance identification (and to minimize network + traffic). + * + * Attributes: + * accessible 0 isscalar 0 enums 0 hasdefval 0 + * readable 0 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 255a + * + * Ranges: 1 - 64; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 64) + * + * + * + * NOTE: NODE rdbmsDbParamName IS NOT ACCESSIBLE + * + * + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbParamName.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbParamName_map(char **mib_rdbmsDbParamName_val_ptr_ptr, size_t *mib_rdbmsDbParamName_val_ptr_len_ptr, char *raw_rdbmsDbParamName_val_ptr, size_t raw_rdbmsDbParamName_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbParamName_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbParamName_val_ptr_ptr) && (NULL != mib_rdbmsDbParamName_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamName_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbParamName non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbParamName_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbParamName_val_ptr_ptr) || (*mib_rdbmsDbParamName_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbParamName_val_ptr_ptr = realloc( *mib_rdbmsDbParamName_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbParamName_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbParamName_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbParamName_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbParamName_val_ptr_ptr, raw_rdbmsDbParamName_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbParamName_map */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbParamEntry.rdbmsDbParamSubIndex + * rdbmsDbParamSubIndex is subid 2 of rdbmsDbParamEntry. + * Its status is Current, and its access level is NoAccess. + * OID: .1.3.6.1.2.1.39.1.3.1.2 + * Description: +The subindex value for this parameter. If the parameter is + naturally considered to contain a variable number of members + of a class, e.g. members of the DBA user group, or files + which are part of the database, then it must be presented as + a set of rows. If, on the other hand, the parameter + represents a set of choices from a class, e.g. the + permissions on a file or the options chosen out of the set of + all options allowed, AND is guaranteed to always fit in the + 255 character length of a DisplayString, then it may be + presented as a comma separated list with a subindex value of + one. Zero may not be used as a value. + * + * Attributes: + * accessible 0 isscalar 0 enums 0 hasdefval 0 + * readable 0 iscolumn 1 ranges 1 hashint 0 + * settable 0 + * + * Ranges: 1 - 2147483647; + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + * + * + * + * NOTE: NODE rdbmsDbParamSubIndex IS NOT ACCESSIBLE + * + * + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbParamSubIndex.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbParamSubIndex_map(long *mib_rdbmsDbParamSubIndex_val_ptr, long raw_rdbmsDbParamSubIndex_val) +{ + netsnmp_assert(NULL != mib_rdbmsDbParamSubIndex_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamSubIndex_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsDbParamSubIndex mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsDbParamSubIndex_val_ptr) = raw_rdbmsDbParamSubIndex_val; + + return MFD_SUCCESS; +} /* rdbmsDbParamSubIndex_map */ + + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This convenience function is useful for setting all the MIB index + * components with a single function call. It is assume that the C values + * have already been mapped from their native/rawformat to the MIB format. + */ +int +rdbmsDbParamTable_indexes_set_tbl_idx(rdbmsDbParamTable_mib_index *tbl_idx, long rdbmsDbIndex_val, char *rdbmsDbParamName_val_ptr, size_t rdbmsDbParamName_val_ptr_len, long rdbmsDbParamSubIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_indexes_set_tbl_idx","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->rdbmsDbIndex = rdbmsDbIndex_val; + + /* rdbmsDbParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ + tbl_idx->rdbmsDbParamName_len = sizeof(tbl_idx->rdbmsDbParamName); + /* + * make sure there is enough space for rdbmsDbParamName data + */ + if ((NULL == tbl_idx->rdbmsDbParamName) || + (tbl_idx->rdbmsDbParamName_len < (rdbmsDbParamName_val_ptr_len * sizeof(tbl_idx->rdbmsDbParamName[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + return MFD_ERROR; + } + tbl_idx->rdbmsDbParamName_len = rdbmsDbParamName_val_ptr_len * sizeof(tbl_idx->rdbmsDbParamName[0]); + memcpy( tbl_idx->rdbmsDbParamName, rdbmsDbParamName_val_ptr, tbl_idx->rdbmsDbParamName_len ); + + /* rdbmsDbParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->rdbmsDbParamSubIndex = rdbmsDbParamSubIndex_val; + + + return MFD_SUCCESS; +} /* rdbmsDbParamTable_indexes_set_tbl_idx */ + +/** + * @internal + * set row context indexes + * + * @param reqreq_ctx the row context that needs updated indexes + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This function sets the mib indexs, then updates the oid indexs + * from the mib index. + */ +int +rdbmsDbParamTable_indexes_set(rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val, char *rdbmsDbParamName_val_ptr, size_t rdbmsDbParamName_val_ptr_len, long rdbmsDbParamSubIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_indexes_set","called\n")); + + if(MFD_SUCCESS != rdbmsDbParamTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx + , rdbmsDbIndex_val + , rdbmsDbParamName_val_ptr, rdbmsDbParamName_val_ptr_len + , rdbmsDbParamSubIndex_val + )) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if(0 != rdbmsDbParamTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsDbParamTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbParamEntry.rdbmsDbParamID + * rdbmsDbParamID is subid 3 of rdbmsDbParamEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.3.1.3 + * Description: +The ID of the parameter which may be described in some other + MIB (e.g., an enterprise-specific MIB module). If there is + no ID for this rdbmsDbParamName, attempts to access this + object will return noSuchName (SNMPv1) or noSuchInstance + (SNMPv2). + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is AutonomousType (based on perltype OBJECTID) + * The net-snmp type is ASN_OBJECT_ID. The C type decl is oid (oid) + * This data type requires a length. (Max 2147483647) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbParamID.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbParamID_map(oid **mib_rdbmsDbParamID_val_ptr_ptr, size_t *mib_rdbmsDbParamID_val_ptr_len_ptr, oid *raw_rdbmsDbParamID_val_ptr, size_t raw_rdbmsDbParamID_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbParamID_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbParamID_val_ptr_ptr) && (NULL != mib_rdbmsDbParamID_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamID_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbParamID non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbParamID_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbParamID_val_ptr_ptr) || (*mib_rdbmsDbParamID_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbParamID_val_ptr_ptr = realloc( *mib_rdbmsDbParamID_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbParamID_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbParamID_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbParamID_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbParamID_val_ptr_ptr, raw_rdbmsDbParamID_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbParamID_map */ + +/** + * Extract the current value of the rdbmsDbParamID data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbParamID_val_ptr_ptr + * Pointer to storage for a oid variable + * @param rdbmsDbParamID_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbParamID. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbParamID_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbParamID_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbParamID_get( rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, oid **rdbmsDbParamID_val_ptr_ptr, size_t *rdbmsDbParamID_val_ptr_len_ptr ) +{ + /* Until we have a parameter with multiple values that won't fit into + * a 255 character string when rendered as a comma-separated list, we + * don't need a value at this OID */ + return MFD_SKIP; + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbParamID_val_ptr_ptr) && (NULL != *rdbmsDbParamID_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbParamID_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamID_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbParamID data. + * set (* rdbmsDbParamID_val_ptr_ptr ) and (* rdbmsDbParamID_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbParamID data + */ + if ((NULL == (* rdbmsDbParamID_val_ptr_ptr )) || + ((* rdbmsDbParamID_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbParamID_len * sizeof((* rdbmsDbParamID_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbParamID data + */ + (* rdbmsDbParamID_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbParamID_len * sizeof((* rdbmsDbParamID_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbParamID_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbParamID_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbParamID_len * sizeof((* rdbmsDbParamID_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbParamID_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbParamID, (* rdbmsDbParamID_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbParamID_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbParamEntry.rdbmsDbParamCurrValue + * rdbmsDbParamCurrValue is subid 4 of rdbmsDbParamEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.3.1.4 + * Description: +The value for a configuration parameter now in effect, the + actual setting for the database. While there may multiple + values in the temporal domain of interest (for instance, the + + value to take effect at the next restart), this is the + current setting. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 1 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbParamCurrValue.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbParamCurrValue_map(char **mib_rdbmsDbParamCurrValue_val_ptr_ptr, size_t *mib_rdbmsDbParamCurrValue_val_ptr_len_ptr, char *raw_rdbmsDbParamCurrValue_val_ptr, size_t raw_rdbmsDbParamCurrValue_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbParamCurrValue_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbParamCurrValue_val_ptr_ptr) && (NULL != mib_rdbmsDbParamCurrValue_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamCurrValue_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbParamCurrValue non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbParamCurrValue_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbParamCurrValue_val_ptr_ptr) || (*mib_rdbmsDbParamCurrValue_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbParamCurrValue_val_ptr_ptr = realloc( *mib_rdbmsDbParamCurrValue_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbParamCurrValue_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbParamCurrValue_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbParamCurrValue_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbParamCurrValue_val_ptr_ptr, raw_rdbmsDbParamCurrValue_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbParamCurrValue_map */ + +/** + * Extract the current value of the rdbmsDbParamCurrValue data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbParamCurrValue_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsDbParamCurrValue_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbParamCurrValue. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbParamCurrValue_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbParamCurrValue_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbParamCurrValue_get( rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbParamCurrValue_val_ptr_ptr, size_t *rdbmsDbParamCurrValue_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbParamCurrValue_val_ptr_ptr) && (NULL != *rdbmsDbParamCurrValue_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbParamCurrValue_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamCurrValue_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbParamCurrValue data. + * set (* rdbmsDbParamCurrValue_val_ptr_ptr ) and (* rdbmsDbParamCurrValue_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbParamCurrValue data + */ + if ((NULL == (* rdbmsDbParamCurrValue_val_ptr_ptr )) || + ((* rdbmsDbParamCurrValue_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbParamCurrValue_len * sizeof((* rdbmsDbParamCurrValue_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbParamCurrValue data + */ + (* rdbmsDbParamCurrValue_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbParamCurrValue_len * sizeof((* rdbmsDbParamCurrValue_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbParamCurrValue_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbParamCurrValue_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbParamCurrValue_len * sizeof((* rdbmsDbParamCurrValue_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbParamCurrValue_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbParamCurrValue, (* rdbmsDbParamCurrValue_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbParamCurrValue_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbParamEntry.rdbmsDbParamComment + * rdbmsDbParamComment is subid 5 of rdbmsDbParamEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.3.1.5 + * Description: +Annotation which describes the purpose of a configuration + parameter or the reason for a particular parameter's + setting. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 1 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbParamComment.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbParamComment_map(char **mib_rdbmsDbParamComment_val_ptr_ptr, size_t *mib_rdbmsDbParamComment_val_ptr_len_ptr, char *raw_rdbmsDbParamComment_val_ptr, size_t raw_rdbmsDbParamComment_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbParamComment_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbParamComment_val_ptr_ptr) && (NULL != mib_rdbmsDbParamComment_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamComment_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbParamComment non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbParamComment_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbParamComment_val_ptr_ptr) || (*mib_rdbmsDbParamComment_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbParamComment_val_ptr_ptr = realloc( *mib_rdbmsDbParamComment_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbParamComment_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbParamComment_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbParamComment_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbParamComment_val_ptr_ptr, raw_rdbmsDbParamComment_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbParamComment_map */ + +/** + * Extract the current value of the rdbmsDbParamComment data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbParamComment_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsDbParamComment_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbParamComment. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbParamComment_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbParamComment_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbParamComment_get( rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbParamComment_val_ptr_ptr, size_t *rdbmsDbParamComment_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbParamComment_val_ptr_ptr) && (NULL != *rdbmsDbParamComment_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbParamComment_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamComment_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbParamComment data. + * set (* rdbmsDbParamComment_val_ptr_ptr ) and (* rdbmsDbParamComment_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbParamComment data + */ + if ((NULL == (* rdbmsDbParamComment_val_ptr_ptr )) || + ((* rdbmsDbParamComment_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbParamComment_len * sizeof((* rdbmsDbParamComment_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbParamComment data + */ + (* rdbmsDbParamComment_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbParamComment_len * sizeof((* rdbmsDbParamComment_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbParamComment_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbParamComment_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbParamComment_len * sizeof((* rdbmsDbParamComment_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbParamComment_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbParamComment, (* rdbmsDbParamComment_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbParamComment_get */ + + + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_get.h b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_get.h new file mode 100644 index 0000000..d9ac635 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_get.h @@ -0,0 +1,65 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_data_get.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_data_get.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBPARAMTABLE_DATA_GET_H +#define RDBMSDBPARAMTABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * GET function declarations + */ + +/* ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbParamTable is subid 3 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.3, length: 9 +*/ + /* + * indexes + */ + int rdbmsDbParamName_map(char **mib_rdbmsDbParamName_val_ptr_ptr, size_t *mib_rdbmsDbParamName_val_ptr_len_ptr, char *raw_rdbmsDbParamName_val_ptr, size_t raw_rdbmsDbParamName_val_ptr_len, int allow_realloc); + int rdbmsDbParamSubIndex_map(long *mib_rdbmsDbParamSubIndex_val_ptr, long raw_rdbmsDbParamSubIndex_val); + + int rdbmsDbParamID_map(oid **mib_rdbmsDbParamID_val_ptr_ptr, size_t *mib_rdbmsDbParamID_val_ptr_len_ptr, oid *raw_rdbmsDbParamID_val_ptr, size_t raw_rdbmsDbParamID_val_ptr_len, int allow_realloc); + int rdbmsDbParamID_get( rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, oid **rdbmsDbParamID_val_ptr_ptr, size_t *rdbmsDbParamID_val_ptr_len_ptr ); + int rdbmsDbParamCurrValue_map(char **mib_rdbmsDbParamCurrValue_val_ptr_ptr, size_t *mib_rdbmsDbParamCurrValue_val_ptr_len_ptr, char *raw_rdbmsDbParamCurrValue_val_ptr, size_t raw_rdbmsDbParamCurrValue_val_ptr_len, int allow_realloc); + int rdbmsDbParamCurrValue_get( rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbParamCurrValue_val_ptr_ptr, size_t *rdbmsDbParamCurrValue_val_ptr_len_ptr ); + int rdbmsDbParamComment_map(char **mib_rdbmsDbParamComment_val_ptr_ptr, size_t *mib_rdbmsDbParamComment_val_ptr_len_ptr, char *raw_rdbmsDbParamComment_val_ptr, size_t raw_rdbmsDbParamComment_val_ptr_len, int allow_realloc); + int rdbmsDbParamComment_get( rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbParamComment_val_ptr_ptr, size_t *rdbmsDbParamComment_val_ptr_len_ptr ); + + +int rdbmsDbParamTable_indexes_set_tbl_idx(rdbmsDbParamTable_mib_index *tbl_idx, long rdbmsDbIndex_val, char *rdbmsDbParamName_val_ptr, size_t rdbmsDbParamName_val_ptr_len, long rdbmsDbParamSubIndex_val); +int rdbmsDbParamTable_indexes_set(rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val, char *rdbmsDbParamName_val_ptr, size_t rdbmsDbParamName_val_ptr_len, long rdbmsDbParamSubIndex_val); + + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBPARAMTABLE_DATA_GET_H */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_set.c b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_set.c new file mode 100644 index 0000000..073d8c9 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_set.c @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_data_set.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_data_set.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsDbParamTable.h" + + +/** @defgroup data_set data_set: Routines to set data + * + * These routines are used to set the value for individual objects. The + * row context is passed, along with the new value. + * + * @{ + */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_set.h b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_set.h new file mode 100644 index 0000000..228dfeb --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_data_set.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_data_set.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_data_set.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBPARAMTABLE_DATA_SET_H +#define RDBMSDBPARAMTABLE_DATA_SET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * SET function declarations + */ + +/* ********************************************************************* + * SET Table declarations + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBPARAMTABLE_DATA_SET_H */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_enums.h b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_enums.h new file mode 100644 index 0000000..8423de9 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_enums.h @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_enums.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_enums.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBPARAMTABLE_ENUMS_H +#define RDBMSDBPARAMTABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table rdbmsDbParamTable + * + ************************************************************************* + *************************************************************************/ + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBPARAMTABLE_ENUMS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_interface.c b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_interface.c new file mode 100644 index 0000000..0603155 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_interface.c @@ -0,0 +1,739 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_interface.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_interface.c,v 1.3 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbParamTable.h" +#include "rdbmsDbParamTable_interface.h" + +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbParamTable is subid 3 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.3, length: 9 +*/ +typedef struct rdbmsDbParamTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; /* optional cache */ + + rdbmsDbParamTable_registration_ptr user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} rdbmsDbParamTable_interface_ctx; + +static rdbmsDbParamTable_interface_ctx rdbmsDbParamTable_if_ctx; + +static void _rdbmsDbParamTable_container_init( + rdbmsDbParamTable_interface_ctx *if_ctx); + + +static Netsnmp_Node_Handler _mfd_rdbmsDbParamTable_pre_request; +static Netsnmp_Node_Handler _mfd_rdbmsDbParamTable_post_request; +static Netsnmp_Node_Handler _mfd_rdbmsDbParamTable_object_lookup; +static Netsnmp_Node_Handler _mfd_rdbmsDbParamTable_get_values; +/** + * @internal + * Initialize the table rdbmsDbParamTable + * (Define its contents and how it's structured) + */ +void +_rdbmsDbParamTable_initialize_interface(rdbmsDbParamTable_registration_ptr reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &rdbmsDbParamTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = &rdbmsDbParamTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:rdbmsDbParamTable:_rdbmsDbParamTable_initialize_interface","called\n")); + + + /************************************************* + * + * save interface context for rdbmsDbParamTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, + ASN_INTEGER, /** index: rdbmsDbIndex */ + ASN_OCTET_STR, /** index: rdbmsDbParamName */ + ASN_INTEGER, /** index: rdbmsDbParamSubIndex */ + 0); + + /* Define the minimum and maximum accessible columns. This + optimizes retrival. */ + tbl_info->min_column = RDBMSDBPARAMTABLE_MIN_COL; + tbl_info->max_column = RDBMSDBPARAMTABLE_MAX_COL; + + /* + * save users context + */ + rdbmsDbParamTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + rdbmsDbParamTable_init_data(reg_ptr); + + /* + * set up the container + */ + _rdbmsDbParamTable_container_init(&rdbmsDbParamTable_if_ctx); + if (NULL == rdbmsDbParamTable_if_ctx.container) { + snmp_log(LOG_ERR,"could not initialize container for rdbmsDbParamTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = _mfd_rdbmsDbParamTable_object_lookup; + access_multiplexer->get_values = _mfd_rdbmsDbParamTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = _mfd_rdbmsDbParamTable_pre_request; + access_multiplexer->post_request = _mfd_rdbmsDbParamTable_post_request; + + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("rdbmsDbParamTable:init_rdbmsDbParamTable", + "Registering rdbmsDbParamTable as a mibs-for-dummies table.\n")); + handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = netsnmp_handler_registration_create("rdbmsDbParamTable", handler, + rdbmsDbParamTable_oid, + rdbmsDbParamTable_oid_size, + HANDLER_CAN_BABY_STEP | + HANDLER_CAN_RONLY + ); + if(NULL == reginfo) { + snmp_log(LOG_ERR,"error registering table rdbmsDbParamTable\n"); + return; + } + reginfo->my_reg_void = &rdbmsDbParamTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if( access_multiplexer->object_lookup ) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if( access_multiplexer->set_values ) + mfd_modes |= BABY_STEP_SET_VALUES; + if( access_multiplexer->irreversible_commit ) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if( access_multiplexer->object_syntax_checks ) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if( access_multiplexer->pre_request ) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if( access_multiplexer->post_request ) + mfd_modes |= BABY_STEP_POST_REQUEST; + + if( access_multiplexer->undo_setup ) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if( access_multiplexer->undo_cleanup ) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if( access_multiplexer->undo_sets ) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if( access_multiplexer->row_creation ) + mfd_modes |= BABY_STEP_ROW_CREATE; + if( access_multiplexer->consistency_checks ) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if( access_multiplexer->commit ) + mfd_modes |= BABY_STEP_COMMIT; + if( access_multiplexer->undo_commit ) + mfd_modes |= BABY_STEP_UNDO_COMMIT; + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + rdbmsDbParamTable_if_ctx.container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler( reginfo, handler ); + + /************************************************* + * + * inject cache helper + */ + if(NULL != rdbmsDbParamTable_if_ctx.cache) { + handler = netsnmp_cache_handler_get(rdbmsDbParamTable_if_ctx.cache); + netsnmp_inject_handler( reginfo, handler ); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); +} /* _rdbmsDbParamTable_initialize_interface */ + +void +rdbmsDbParamTable_valid_columns_set(netsnmp_column_info *vc) +{ + rdbmsDbParamTable_if_ctx.tbl_info.valid_columns = vc; +} /* rdbmsDbParamTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +rdbmsDbParamTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsDbParamTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + /* + * rdbmsDbParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H + */ + netsnmp_variable_list var_rdbmsDbParamName; + /* + * rdbmsDbParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbParamSubIndex; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + memset( &var_rdbmsDbParamName, 0x00, sizeof(var_rdbmsDbParamName) ); + var_rdbmsDbParamName.type = ASN_OCTET_STR; + memset( &var_rdbmsDbParamSubIndex, 0x00, sizeof(var_rdbmsDbParamSubIndex) ); + var_rdbmsDbParamSubIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = &var_rdbmsDbParamName; var_rdbmsDbParamName.next_variable = &var_rdbmsDbParamSubIndex; var_rdbmsDbParamSubIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_index_to_oid","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_rdbmsDbIndex, (u_char*)&mib_idx->rdbmsDbIndex, + sizeof(mib_idx->rdbmsDbIndex)); + + /* rdbmsDbParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ + snmp_set_var_value(&var_rdbmsDbParamName, (u_char*)&mib_idx->rdbmsDbParamName, + mib_idx->rdbmsDbParamName_len * sizeof(mib_idx->rdbmsDbParamName[0])); + + /* rdbmsDbParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_rdbmsDbParamSubIndex, (u_char*)&mib_idx->rdbmsDbParamSubIndex, + sizeof(mib_idx->rdbmsDbParamSubIndex)); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, (size_t *)&oid_idx->len, + NULL, 0, &var_rdbmsDbIndex); + if(err) + snmp_log(LOG_ERR,"error %d converting index to oid\n", err); + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsDbParamTable_index_to_oid */ + +/** + * extract rdbmsDbParamTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +rdbmsDbParamTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsDbParamTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + /* + * rdbmsDbParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H + */ + netsnmp_variable_list var_rdbmsDbParamName; + /* + * rdbmsDbParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbParamSubIndex; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + memset( &var_rdbmsDbParamName, 0x00, sizeof(var_rdbmsDbParamName) ); + var_rdbmsDbParamName.type = ASN_OCTET_STR; + memset( &var_rdbmsDbParamSubIndex, 0x00, sizeof(var_rdbmsDbParamSubIndex) ); + var_rdbmsDbParamSubIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = &var_rdbmsDbParamName; var_rdbmsDbParamName.next_variable = &var_rdbmsDbParamSubIndex; var_rdbmsDbParamSubIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsDbParamTable:rdbmsDbParamTable_index_from_oid","called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes( oid_idx->oids, oid_idx->len, + &var_rdbmsDbIndex ); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + mib_idx->rdbmsDbIndex = *((long *)var_rdbmsDbIndex.val.string); + /* + * NOTE: val_len is in bytes, rdbmsDbParamName_len might not be + */ + if(var_rdbmsDbParamName.val_len > sizeof(mib_idx->rdbmsDbParamName)) + err = SNMP_ERR_GENERR; + else { + memcpy(mib_idx->rdbmsDbParamName, var_rdbmsDbParamName.val.string, var_rdbmsDbParamName.val_len); + mib_idx->rdbmsDbParamName_len = var_rdbmsDbParamName.val_len / sizeof(mib_idx->rdbmsDbParamName[0]); + } + mib_idx->rdbmsDbParamSubIndex = *((long *)var_rdbmsDbParamSubIndex.val.string); + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsDbParamTable_index_from_oid */ + + +/* ********************************************************************* + * @internal + * allocate resources for a rdbmsDbParamTable_rowreq_ctx + */ +rdbmsDbParamTable_rowreq_ctx * +rdbmsDbParamTable_allocate_rowreq_ctx(void) +{ + rdbmsDbParamTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(rdbmsDbParamTable_rowreq_ctx); + + DEBUGMSGTL(("internal:rdbmsDbParamTable:rdbmsDbParamTable_allocate_rowreq_ctx","called\n")); + + if(NULL == rowreq_ctx) { + snmp_log(LOG_ERR,"Couldn't allocate memory for a " + "rdbmsDbParamTable_rowreq_ctx.\n"); + } + + rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; + + rowreq_ctx->rdbmsDbParamTable_data_list = NULL; + rowreq_ctx->rdbmsDbParamTable_reg = rdbmsDbParamTable_if_ctx.user_ctx; + + + return rowreq_ctx; +} /* rdbmsDbParamTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a rdbmsDbParamTable_rowreq_ctx + */ +void +rdbmsDbParamTable_release_rowreq_ctx(rdbmsDbParamTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("internal:rdbmsDbParamTable:rdbmsDbParamTable_release_rowreq_ctx","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + + /* + * free index oid pointer + */ + if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* rdbmsDbParamTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbParamTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc = rdbmsDbParamTable_pre_request(rdbmsDbParamTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsDbParamTable","error %d from " + "rdbmsDbParamTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbParamTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbParamTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbParamTable_rowreq_ctx *rowreq_ctx; + int rc = rdbmsDbParamTable_post_request(rdbmsDbParamTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsDbParamTable","error %d from " + "rdbmsDbParamTable_post_request\n", rc)); + } + + /* + * if there are no errors, check for and handle row creation/deletion + */ + rc = netsnmp_check_requests_error(requests); + if ((SNMP_ERR_NOERROR == rc) && + (NULL != + (rowreq_ctx = netsnmp_container_table_row_extract(requests)))) { + if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) { + rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; + CONTAINER_INSERT(rdbmsDbParamTable_if_ctx.container, rowreq_ctx); + } + else if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { + CONTAINER_REMOVE(rdbmsDbParamTable_if_ctx.container, rowreq_ctx); + rdbmsDbParamTable_release_rowreq_ctx(rowreq_ctx); + } + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbParamTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbParamTable_object_lookup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbParamTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsDbParamTable:_mfd_rdbmsDbParamTable_object_lookup","called\n")); + + /* + * get our context from mfd + * rdbmsDbParamTable_interface_ctx *if_ctx = + * (rdbmsDbParamTable_interface_ctx *)reginfo->my_reg_void; + */ + + if(NULL == rowreq_ctx) { + netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION); + } + else { + rdbmsDbParamTable_row_prep(rowreq_ctx); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbParamTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsDbParamTable_get_column( rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsDbParamTable:_mfd_rdbmsDbParamTable_get_column","called\n")); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsDbParamID(3)/AutonomousType/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h */ + case COLUMN_RDBMSDBPARAMID: + var->type = ASN_OBJECT_ID; +rc = rdbmsDbParamID_get(rowreq_ctx, (oid **)&var->val.string, &var->val_len ); + break; + + /* rdbmsDbParamCurrValue(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSDBPARAMCURRVALUE: + var->type = ASN_OCTET_STR; +rc = rdbmsDbParamCurrValue_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* rdbmsDbParamComment(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSDBPARAMCOMMENT: + var->type = ASN_OCTET_STR; +rc = rdbmsDbParamComment_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsDbParamTable_get_column\n", column); + break; + } + + return rc; +} /* _rdbmsDbParamTable_get_column */ + +int +_mfd_rdbmsDbParamTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbParamTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + u_char * old_string; + void (*dataFreeHook)(void *); + int rc; + + DEBUGMSGTL(("internal:rdbmsDbParamTable:_mfd_rdbmsDbParamTable_get_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if(NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + else if(requests->requestvb->buf == requests->requestvb->val.string) { + if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsDbParamTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + if(MFD_SKIP == rc) { + requests->requestvb->type = ASN_PRIV_RETRY; + rc = SNMP_ERR_NOERROR; + } + } + else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if(rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if(old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if(dataFreeHook) + (*dataFreeHook)(old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbParamTable_get_values */ + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/* + * NOT APPLICABLE (per MIB or user setting) + */ +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +/** + * @internal + */ +static int +_cache_load(netsnmp_cache *cache, void *vmagic) +{ + DEBUGMSGTL(("internal:rdbmsDbParamTable:_cache_load","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache for rdbmsDbParamTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return rdbmsDbParamTable_cache_load((netsnmp_container*)cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_item_free(rdbmsDbParamTable_rowreq_ctx *rowreq_ctx, void *context) +{ + DEBUGMSGTL(("internal:rdbmsDbParamTable:_cache_item_free","called\n")); + + if(NULL == rowreq_ctx) + return; + + rdbmsDbParamTable_release_rowreq_ctx(rowreq_ctx); +} /* _cache_item_free */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache *cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:rdbmsDbParamTable:_cache_free","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache in rdbmsDbParamTable_cache_free\n"); + return; + } + + container = (netsnmp_container*)cache->magic; + + /* + * call user code + */ + rdbmsDbParamTable_cache_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *)_cache_item_free, + NULL); +} /* _cache_free */ + +/** + * @internal + * initialize the iterator container with functions or wrappers + */ +void +_rdbmsDbParamTable_container_init(rdbmsDbParamTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:rdbmsDbParamTable:_rdbmsDbParamTable_container_init","called\n")); + + /* + * set up the cache + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + rdbmsDbParamTable_oid, + rdbmsDbParamTable_oid_size); + + if(NULL == if_ctx->cache) { + snmp_log(LOG_ERR, "error creating cache for rdbmsDbParamTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + rdbmsDbParamTable_container_init(&if_ctx->container, if_ctx->cache); + if(NULL == if_ctx->container) + if_ctx->container = netsnmp_container_find("rdbmsDbParamTable:table_container"); + if(NULL == if_ctx->container) { + snmp_log(LOG_ERR,"error creating container in " + "rdbmsDbParamTable_container_init\n"); + return; + } + if_ctx->cache->magic = (void*)if_ctx->container; +} /* _rdbmsDbParamTable_container_init */ + diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_interface.h b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_interface.h new file mode 100644 index 0000000..444939c --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_interface.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_interface.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_interface.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBPARAMTABLE_INTERFACE_H +#define RDBMSDBPARAMTABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "rdbmsDbParamTable.h" + +/* ******************************************************************** + * Table declarations + */ + +/* PUBLIC interface initialization routine */ +void _rdbmsDbParamTable_initialize_interface(rdbmsDbParamTable_registration_ptr user_ctx, + u_long flags); + + rdbmsDbParamTable_rowreq_ctx * rdbmsDbParamTable_allocate_rowreq_ctx(void); +void rdbmsDbParamTable_release_rowreq_ctx(rdbmsDbParamTable_rowreq_ctx *rowreq_ctx); + +int rdbmsDbParamTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsDbParamTable_mib_index *mib_idx); +int rdbmsDbParamTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsDbParamTable_mib_index *mib_idx); + +/* + * access to certain internals. use with caution! + */ +void rdbmsDbParamTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBPARAMTABLE_INTERFACE_H */ diff --git a/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_oids.h b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_oids.h new file mode 100644 index 0000000..92c43de --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbParamTable/rdbmsDbParamTable_oids.h @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + * rdbmsDbParamTable_oids.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbParamTable_oids.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBPARAMTABLE_OIDS_H +#define RDBMSDBPARAMTABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* column number definitions for table rdbmsDbParamTable */ +#define RDBMSDBPARAMTABLE_OID 1,3,6,1,2,1,39,1,3 +#define COLUMN_RDBMSDBPARAMNAME 1 +#define COLUMN_RDBMSDBPARAMSUBINDEX 2 +#define COLUMN_RDBMSDBPARAMID 3 +#define COLUMN_RDBMSDBPARAMCURRVALUE 4 +#define COLUMN_RDBMSDBPARAMCOMMENT 5 + +#define RDBMSDBPARAMTABLE_MIN_COL COLUMN_RDBMSDBPARAMID +#define RDBMSDBPARAMTABLE_MAX_COL COLUMN_RDBMSDBPARAMCOMMENT + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBPARAMTABLE_OIDS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable.c b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable.c new file mode 100644 index 0000000..aac7c37 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable.c @@ -0,0 +1,124 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbTable.h" +#include "rdbmsDbTable_interface.h" + +oid rdbmsDbTable_oid[] = { RDBMSDBTABLE_OID }; +int rdbmsDbTable_oid_size = OID_LENGTH(rdbmsDbTable_oid); + +void initialize_table_rdbmsDbTable(void); + + +/** + * Initializes the rdbmsDbTable module + */ +void +init_rdbmsDbTable(void) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:init_rdbmsDbTable","called\n")); + + /* + * TODO:300:o: Perform rdbmsDbTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("rdbmsDbTable")) + initialize_table_rdbmsDbTable(); + +} /* init_rdbmsDbTable */ + +/** + * Initialize the table rdbmsDbTable + * (Define its contents and how it's structured) + */ +void +initialize_table_rdbmsDbTable(void) +{ + rdbmsDbTable_registration_ptr user_context; + u_long flags; + + DEBUGMSGTL(("verbose:rdbmsDbTable:initialize_table_rdbmsDbTable","called\n")); + + /* + * TODO:301:o: Perform rdbmsDbTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize rdbmsDbTable user context + * if you'd like to pass in a pointer to some data for this + * table, allocate or set it up here. + */ + /* + * a netsnmp_data_list is a simple way to store void pointers. A simple + * string token is used to add, find or remove pointers. + */ + user_context = netsnmp_create_data_list("rdbmsDbTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _rdbmsDbTable_initialize_interface(user_context, flags); +} /* initialize_table_rdbmsDbTable */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +rdbmsDbTable_pre_request(rdbmsDbTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_pre_request","called\n")); + + /* + * TODO:510:o: Perform rdbmsDbTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsDbTable_pre_request */ + +/** + * post-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error (ignored) + */ +int +rdbmsDbTable_post_request(rdbmsDbTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_post_request","called\n")); + + /* + * TODO:511:o: Perform rdbmsDbTable pos-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsDbTable_post_request */ + + +/** @{ */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable.h b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable.h new file mode 100644 index 0000000..1dbdbe2 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable.h @@ -0,0 +1,220 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBTABLE_H +#define RDBMSDBTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @defgroup misc misc: Miscelaneous routines + * + * @{ + */ +#include <net-snmp/library/asn1.h> + +/* other required module components */ + /* *INDENT-OFF* */ +config_require(RDBMS-MIB/rdbmsDbTable/rdbmsDbTable_interface); +config_require(RDBMS-MIB/rdbmsDbTable/rdbmsDbTable_data_access); +config_require(RDBMS-MIB/rdbmsDbTable/rdbmsDbTable_data_get); +config_require(RDBMS-MIB/rdbmsDbTable/rdbmsDbTable_data_set); + /* *INDENT-ON* */ + +/* OID and column number definitions for */ +#include "rdbmsDbTable_oids.h" + +/* enum definions */ +#include "rdbmsDbTable_enums.h" + +/* ********************************************************************* + * function declarations + */ +void init_rdbmsDbTable(void); + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbTable is subid 1 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.1, length: 9 +*/ +/* ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review rdbmsDbTable registration context. + */ +typedef netsnmp_data_list * rdbmsDbTable_registration_ptr; + +/**********************************************************************/ +/* + * TODO:110:r: |-> Review rdbmsDbTable data context structure. + * This structure is used to represent the data for rdbmsDbTable. + */ +/* + * This structure contains storage for all the columns defined in the + * rdbmsDbTable. + */ +typedef struct rdbmsDbTable_data_s { + + /* + * rdbmsDbPrivateMibOID(2)/OBJECTID/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h + */ + oid rdbmsDbPrivateMibOID[128]; +size_t rdbmsDbPrivateMibOID_len; /* # of oid elements, not bytes */ + + /* + * rdbmsDbVendorName(3)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ + char rdbmsDbVendorName[255]; +size_t rdbmsDbVendorName_len; /* # of char elements, not bytes */ + + /* + * rdbmsDbName(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ + char rdbmsDbName[255]; +size_t rdbmsDbName_len; /* # of char elements, not bytes */ + + /* + * rdbmsDbContact(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + char rdbmsDbContact[255]; +size_t rdbmsDbContact_len; /* # of char elements, not bytes */ + +} rdbmsDbTable_data; + + +/* ********************************************************************* + * TODO:115:o: |-> Review rdbmsDbTable undo context. + * We're just going to use the same data structure for our + * undo_context. If you want to do something more efficent, + * define your typedef here. + */ +typedef rdbmsDbTable_data rdbmsDbTable_undo_data; + +/* + * TODO:120:r: |-> Review rdbmsDbTable mib index. + * This structure is used to represent the index for rdbmsDbTable. + */ +typedef struct rdbmsDbTable_mib_index_s { + + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long rdbmsDbIndex; + + +} rdbmsDbTable_mib_index; + + /* + * TODO:121:r: | |-> Review rdbmsDbTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. +*/ +#define MAX_rdbmsDbTable_IDX_LEN 1 + + +/* ********************************************************************* + * TODO:130:o: |-> Review rdbmsDbTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * rdbmsDbTable_rowreq_ctx pointer. + */ +typedef struct rdbmsDbTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_rdbmsDbTable_IDX_LEN]; + + rdbmsDbTable_mib_index tbl_idx; + + rdbmsDbTable_data data; + rdbmsDbTable_undo_data * undo; + unsigned int column_set_flags; /* flags for set columns */ + + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * implementor's context pointer (provided during registration) + */ + rdbmsDbTable_registration_ptr rdbmsDbTable_reg; + + /* + * TODO:131:o: | |-> Add useful data to rdbmsDbTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *rdbmsDbTable_data_list; + +} rdbmsDbTable_rowreq_ctx; + +typedef struct rdbmsDbTable_ref_rowreq_ctx_s { + rdbmsDbTable_rowreq_ctx *rowreq_ctx; +} rdbmsDbTable_ref_rowreq_ctx; + +/* ********************************************************************* + * function prototypes + */ + int rdbmsDbTable_pre_request(rdbmsDbTable_registration_ptr user_context); + int rdbmsDbTable_post_request(rdbmsDbTable_registration_ptr user_context); + + int rdbmsDbTable_check_dependencies(rdbmsDbTable_rowreq_ctx * rowreq_ctx); + int rdbmsDbTable_commit(rdbmsDbTable_rowreq_ctx * rowreq_ctx); + + void initialize_table_rdbmsDbTable(void); + +extern oid rdbmsDbTable_oid[]; +extern int rdbmsDbTable_oid_size; + + +#include "rdbmsDbTable_interface.h" +#include "rdbmsDbTable_data_access.h" +#include "rdbmsDbTable_data_get.h" +#include "rdbmsDbTable_data_set.h" + +/* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBTABLE_H */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_access.c b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_access.c new file mode 100644 index 0000000..d15c924 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_access.c @@ -0,0 +1,377 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_data_access.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_data_access.c,v 1.5 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbTable.h" +#include "rdbmsDbTable_data_access.h" + +/** @defgroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbTable is subid 1 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.1, length: 9 +*/ + +/** + * initialization for rdbmsDbTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param rdbmsDbTable_reg + * Pointer to rdbmsDbTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +rdbmsDbTable_init_data(rdbmsDbTable_registration_ptr rdbmsDbTable_reg) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_init_data","called\n")); + + return MFD_SUCCESS; +} /* rdbmsDbTable_init_data */ + +/** + * container-cached overview + * + */ + +/*********************************************************************** + * + * cache + * + ***********************************************************************/ +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +rdbmsDbTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_container_init","called\n")); + + if((NULL == cache) || (NULL == container_ptr_ptr)) { + snmp_log(LOG_ERR,"bad params to rdbmsDbTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + /* + * TODO:345:A: Set up rdbmsDbTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = RDBMSDBTABLE_CACHE_TIMEOUT; /* seconds */ + + /* JWT-TODO: Initialize cache with cache->flags here */ +} /* rdbmsDbTable_container_init */ + +/** + * load cache data + * + * TODO:350:M: Implement rdbmsDbTable cache load + * + * @param container container to which items should be inserted + * + * @retval MFD_SUCCESS : success. + * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source + * @retval MFD_ERROR : other error. + * + * This function is called to cache the index(es) (and data, optionally) + * for the every row in the data set. + * + * @remark + * While loading the cache, the only important thing is the indexes. + * If access to your data is cheap/fast (e.g. you have a pointer to a + * structure in memory), it would make sense to update the data here. + * If, however, the accessing the data invovles more work (e.g. parsing + * some other existing data, or peforming calculations to derive the data), + * then you can limit yourself to setting the indexes and saving any + * information you will need later. Then use the saved information in + * rdbmsDbTable_row_prep() for populating data. + * + * @note + * If you need consistency between rows (like you want statistics + * for each row to be from the same time frame), you should set all + * data here. + * + */ +int +rdbmsDbTable_cache_load(netsnmp_container *container) +{ + rdbmsDbTable_rowreq_ctx *rowreq_ctx; + oid rdbmsDbPrivateMibOID[128] = { 1,3,6,1,4,1,27645 }; + int i, resultCount, errorcode = MFD_SUCCESS, tmpInt; + PGresult *pg_db_qry, *pgsnmpd_tbl_qry; + char *tmpString, *db_oid, *vendor_name, *contact_name; + int vendor_name_len, contact_name_len; + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_cache_load","called\n")); + + /* + * TODO:351:M: |-> Load/update data in the rdbmsDbTable container. + * loop over your rdbmsDbTable data, allocate a rowreq context, + * set the index(es) [and data, optionally] and insert into + * the container. */ + + if (PQstatus(dbconn) == CONNECTION_OK) + pg_db_qry = PQexec(dbconn, "SELECT oid, datname FROM pg_database"); + else { + snmp_log(LOG_ERR, "Can't get connected to the database"); + return MFD_RESOURCE_UNAVAILABLE; + } + if (PQresultStatus(pg_db_qry) != PGRES_TUPLES_OK) { + snmp_log(LOG_ERR, "Didn't get any results from the database"); + PQclear(pg_db_qry); + /*PQfinish(dbconn); */ + /* It's probably an error if I didn't find *any* databases */ + return MFD_RESOURCE_UNAVAILABLE; + } + + resultCount = PQntuples(pg_db_qry); + + for (i = 0; i < resultCount; i++) { + + /* + * TODO:352:M: | |-> set indexes in new rdbmsDbTable rowreq context. + */ + rowreq_ctx = rdbmsDbTable_allocate_rowreq_ctx(); + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "memory allocation failed\n"); + errorcode = MFD_RESOURCE_UNAVAILABLE; + break; + } + db_oid = PQgetvalue(pg_db_qry, i, 0); + if(MFD_SUCCESS != rdbmsDbTable_indexes_set(rowreq_ctx + ,atol(db_oid) + )) { + snmp_log(LOG_ERR,"error setting index while loading " + "rdbmsDbTable cache.\n"); + rdbmsDbTable_release_rowreq_ctx(rowreq_ctx); + continue; + } + + /* + * TODO:352:r: | |-> populate rdbmsDbTable data context. + * Populate data context here. (optionally, delay until row prep) + */ + + rowreq_ctx->data.rdbmsDbPrivateMibOID_len = 128; + rowreq_ctx->data.rdbmsDbVendorName_len = 255; + rowreq_ctx->data.rdbmsDbName_len = 255; + rowreq_ctx->data.rdbmsDbContact_len = 255; + + contact_name = NULL; + contact_name_len = 0; + vendor_name = NULL; + vendor_name_len = 0; + + /* Note that this queries pgsnmpd_rdbmsDbTable once per database. This could + * be more efficient by only querying once if it can't find the table (being + * sure that the table didn't exist, as opposed to simply an entry for that + * database not existing in the table). It could also be rewritten so that + * only one query is issued, joining pg_database and pgsnmpd_rdbmsDbTable, but + * that would have to be smart enough to know of the pgsnmpd table existed + * and not do the join if it didn't */ + pgsnmpd_tbl_qry = NULL; + tmpInt = sizeof("SELECT vendor_name, contact_name FROM pgsnmpd_rdbmsDbTable WHERE database_oid = ") + sizeof(*db_oid); + tmpString = calloc(tmpInt, sizeof(char*)); + if (tmpString == NULL) snmp_log(LOG_ERR, "Couldn't allocate memory to query pgsnmpd-specific database table\n"); + else { + snmp_log(LOG_INFO, "Gathering rdbmsDbTable information from pgsnmpd_rdbmsDbTable\n"); + snprintf(tmpString, sizeof(char*) * tmpInt, "SELECT vendor_name, contact_name FROM pgsnmpd_rdbmsDbTable WHERE database_oid = %s", db_oid); + pgsnmpd_tbl_qry = PQexec(dbconn, tmpString); + /* Ignore errors so that pgsnmpd will run without this table being available */ + if (PQresultStatus(pgsnmpd_tbl_qry) == PGRES_TUPLES_OK && PQntuples(pgsnmpd_tbl_qry) > 0) { + vendor_name = PQgetvalue(pgsnmpd_tbl_qry, 0, 0); + vendor_name_len = strlen(vendor_name); + contact_name = PQgetvalue(pgsnmpd_tbl_qry, 0, 1); + contact_name_len = strlen(contact_name); + } + /* Note that this error is INFO level, instead of something higher, because we're designed to work without this table */ + else snmp_log(LOG_INFO, "Unable to find relevant data in pgsnmpd_rdbmsDbTable\n"); + } + + /* + * TODO:246:r: |-> Define rdbmsDbPrivateMibOID mapping. + * Map values between raw/native values and MIB values + * + * if(MFD_SUCCESS != + * rdbmsDbPrivateMibOID_map(&rowreq_ctx->data.rdbmsDbPrivateMibOID, &rowreq_ctx->data.rdbmsDbPrivateMibOID_len, + * rdbmsDbPrivateMibOID, rdbmsDbPrivateMibOID_len, 0)) { + * return MFD_ERROR; + * } + */ + if ((NULL == rowreq_ctx->data.rdbmsDbPrivateMibOID) || + (rowreq_ctx->data.rdbmsDbPrivateMibOID_len < (1 * sizeof(rowreq_ctx->data.rdbmsDbPrivateMibOID[0])))) { + snmp_log(LOG_ERR,"not enough space for rdbmsDbTable.rdbmsDbPrivateMibOID value.\n"); + errorcode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsDbPrivateMibOID_len = 8; + rdbmsDbPrivateMibOID[7] = (oid) atoi(PQgetvalue(pg_db_qry, i, 0)); + memcpy( rowreq_ctx->data.rdbmsDbPrivateMibOID, rdbmsDbPrivateMibOID, 8 * sizeof(rdbmsDbPrivateMibOID[0])); + + /* + * TODO:246:r: |-> Define rdbmsDbVendorName mapping. + */ + if ((NULL == rowreq_ctx->data.rdbmsDbVendorName) || + (rowreq_ctx->data.rdbmsDbVendorName_len < (10 * sizeof(rowreq_ctx->data.rdbmsDbVendorName[0])))) { + snmp_log(LOG_ERR,"not enough space for rdbmsDbTable.rdbmsDbVendorName value\n"); + errorcode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsDbVendorName_len = vendor_name_len; + memcpy( rowreq_ctx->data.rdbmsDbVendorName, vendor_name, vendor_name_len); + + /* + * TODO:246:r: |-> Define rdbmsDbName mapping. + */ + if ((NULL == rowreq_ctx->data.rdbmsDbName) || + (rowreq_ctx->data.rdbmsDbName_len < (100 * sizeof(rowreq_ctx->data.rdbmsDbName[0])))) { + snmp_log(LOG_ERR,"not enough space for rdbmsDbTable.rdbmsDbName value\n"); + errorcode = MFD_ERROR; + break; + } + tmpString = PQgetvalue(pg_db_qry, i, 1); + rowreq_ctx->data.rdbmsDbName_len = strlen(tmpString) * sizeof(rowreq_ctx->data.rdbmsDbName[0]); + strncpy(rowreq_ctx->data.rdbmsDbName, tmpString, rowreq_ctx->data.rdbmsDbName_len); + + /* + * TODO:246:r: |-> Define rdbmsDbContact mapping. + */ + if ((NULL == rowreq_ctx->data.rdbmsDbContact) || + (rowreq_ctx->data.rdbmsDbContact_len < (100 * sizeof(rowreq_ctx->data.rdbmsDbContact[0])))) { + snmp_log(LOG_ERR,"not enough space for rdbmsDbTable.rdbmsDbContact value\n"); + errorcode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsDbContact_len = contact_name_len; + memcpy( rowreq_ctx->data.rdbmsDbContact, contact_name, contact_name_len); + + + /* + * insert into table container + */ + CONTAINER_INSERT(container, rowreq_ctx); + + if (pgsnmpd_tbl_qry != NULL) PQclear(pgsnmpd_tbl_qry); + } + + DEBUGMSGT(("verbose:rdbmsDbTable:rdbmsDbTable_cache_load", + "inserted some records\n")); + + PQclear(pg_db_qry); + return errorcode; +} /* rdbmsDbTable_cache_load */ + +/** + * cache clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +rdbmsDbTable_cache_free(netsnmp_container *container) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_cache_free","called\n")); + + /* + * TODO:380:M: Free rdbmsDbTable cache. + */ +} /* rdbmsDbTable_cache_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +rdbmsDbTable_row_prep( rdbmsDbTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_row_prep","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* rdbmsDbTable_row_prep */ + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_access.h b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_access.h new file mode 100644 index 0000000..cdf1cac --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_access.h @@ -0,0 +1,64 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_data_access.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_data_access.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBTABLE_DATA_ACCESS_H +#define RDBMSDBTABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ********************************************************************* + * function declarations + */ + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbTable is subid 1 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.1, length: 9 +*/ + + + int rdbmsDbTable_init_data(rdbmsDbTable_registration_ptr rdbmsDbTable_reg); + + +/* + * TODO:180:o: Review rdbmsDbTable cache timeout. + * The number of seconds before the cache times out + */ +#define RDBMSDBTABLE_CACHE_TIMEOUT 60 + +void rdbmsDbTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache); +int rdbmsDbTable_cache_load(netsnmp_container *container); +void rdbmsDbTable_cache_free(netsnmp_container *container); + +int rdbmsDbTable_row_prep( rdbmsDbTable_rowreq_ctx *rowreq_ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBTABLE_DATA_ACCESS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_get.c b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_get.c new file mode 100644 index 0000000..b6a7207 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_get.c @@ -0,0 +1,763 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_data_get.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_data_get.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement rdbmsDbTable get routines. + * TODO:240:M: Implement rdbmsDbTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbTable is subid 1 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.1, length: 9 +*/ + +/* --------------------------------------------------------------------- + * TODO:200:r: Implement rdbmsDbTable data context functions. + */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbEntry.rdbmsDbIndex + * rdbmsDbIndex is subid 1 of rdbmsDbEntry. + * Its status is Current, and its access level is NoAccess. + * OID: .1.3.6.1.2.1.39.1.1.1.1 + * Description: +A numeric index, unique among all the databases from all + products on this host. This value is a surrogate for the + conceptually unique key, which is {PrivateMibOID, + databasename} + * + * Attributes: + * accessible 0 isscalar 0 enums 0 hasdefval 0 + * readable 0 iscolumn 1 ranges 1 hashint 0 + * settable 0 + * + * Ranges: 1 - 2147483647; + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + * + * + * + * NOTE: NODE rdbmsDbIndex IS NOT ACCESSIBLE + * + * + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbIndex.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbIndex_map(long *mib_rdbmsDbIndex_val_ptr, long raw_rdbmsDbIndex_val) +{ + netsnmp_assert(NULL != mib_rdbmsDbIndex_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbIndex_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsDbIndex mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsDbIndex_val_ptr) = raw_rdbmsDbIndex_val; + + return MFD_SUCCESS; +} /* rdbmsDbIndex_map */ + + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This convenience function is useful for setting all the MIB index + * components with a single function call. It is assume that the C values + * have already been mapped from their native/rawformat to the MIB format. + */ +int +rdbmsDbTable_indexes_set_tbl_idx(rdbmsDbTable_mib_index *tbl_idx, long rdbmsDbIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_indexes_set_tbl_idx","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->rdbmsDbIndex = rdbmsDbIndex_val; + + + return MFD_SUCCESS; +} /* rdbmsDbTable_indexes_set_tbl_idx */ + +/** + * @internal + * set row context indexes + * + * @param reqreq_ctx the row context that needs updated indexes + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This function sets the mib indexs, then updates the oid indexs + * from the mib index. + */ +int +rdbmsDbTable_indexes_set(rdbmsDbTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_indexes_set","called\n")); + + if(MFD_SUCCESS != rdbmsDbTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx + , rdbmsDbIndex_val + )) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if(0 != rdbmsDbTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsDbTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbEntry.rdbmsDbPrivateMibOID + * rdbmsDbPrivateMibOID is subid 2 of rdbmsDbEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.1.1.2 + * Description: +The authoritative identification for the private MIB for + this database, presumably based on the vendor, e.g., { + enterprises 111 <optional subidentifiers>} for Oracle + databases, {enterprises 757 <optional subidentifiers>} for + Ingres databases, { enterprises 897 <optional + subidentifiers>} for Sybase databases, etc. + + If no OBJECT IDENTIFIER exists for the private MIB, attempts + + to access this object will return noSuchName (SNMPv1) + or noSuchInstance (SNMPv2). + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is OBJECTID (based on perltype OBJECTID) + * The net-snmp type is ASN_OBJECT_ID. The C type decl is oid (oid) + * This data type requires a length. (Max 2147483647) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbPrivateMibOID.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbPrivateMibOID_map(oid **mib_rdbmsDbPrivateMibOID_val_ptr_ptr, size_t *mib_rdbmsDbPrivateMibOID_val_ptr_len_ptr, + oid *raw_rdbmsDbPrivateMibOID_val_ptr, size_t raw_rdbmsDbPrivateMibOID_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbPrivateMibOID_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbPrivateMibOID_val_ptr_ptr) && (NULL != mib_rdbmsDbPrivateMibOID_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbPrivateMibOID_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbPrivateMibOID non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbPrivateMibOID_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbPrivateMibOID_val_ptr_ptr) || (*mib_rdbmsDbPrivateMibOID_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbPrivateMibOID_val_ptr_ptr = realloc( *mib_rdbmsDbPrivateMibOID_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbPrivateMibOID_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbPrivateMibOID_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbPrivateMibOID_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbPrivateMibOID_val_ptr_ptr, raw_rdbmsDbPrivateMibOID_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbPrivateMibOID_map */ + +/** + * Extract the current value of the rdbmsDbPrivateMibOID data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbPrivateMibOID_val_ptr_ptr + * Pointer to storage for a oid variable + * @param rdbmsDbPrivateMibOID_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbPrivateMibOID. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbPrivateMibOID_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbPrivateMibOID_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbPrivateMibOID_get( rdbmsDbTable_rowreq_ctx *rowreq_ctx, oid **rdbmsDbPrivateMibOID_val_ptr_ptr, size_t *rdbmsDbPrivateMibOID_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbPrivateMibOID_val_ptr_ptr) && (NULL != *rdbmsDbPrivateMibOID_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbPrivateMibOID_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbPrivateMibOID_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbPrivateMibOID data. + * set (* rdbmsDbPrivateMibOID_val_ptr_ptr ) and (* rdbmsDbPrivateMibOID_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbPrivateMibOID data + */ + if ((NULL == (* rdbmsDbPrivateMibOID_val_ptr_ptr )) || + ((* rdbmsDbPrivateMibOID_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbPrivateMibOID_len * sizeof((* rdbmsDbPrivateMibOID_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbPrivateMibOID data + */ + (* rdbmsDbPrivateMibOID_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbPrivateMibOID_len * sizeof((* rdbmsDbPrivateMibOID_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbPrivateMibOID_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbPrivateMibOID_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbPrivateMibOID_len * sizeof((* rdbmsDbPrivateMibOID_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbPrivateMibOID_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbPrivateMibOID, (* rdbmsDbPrivateMibOID_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbPrivateMibOID_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbEntry.rdbmsDbVendorName + * rdbmsDbVendorName is subid 3 of rdbmsDbEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.1.1.3 + * Description: +The name of the vendor whose RDBMS manages this database, + for informational purposes. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbVendorName.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbVendorName_map(char **mib_rdbmsDbVendorName_val_ptr_ptr, size_t *mib_rdbmsDbVendorName_val_ptr_len_ptr, char *raw_rdbmsDbVendorName_val_ptr, size_t raw_rdbmsDbVendorName_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbVendorName_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbVendorName_val_ptr_ptr) && (NULL != mib_rdbmsDbVendorName_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbVendorName_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbVendorName non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbVendorName_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbVendorName_val_ptr_ptr) || (*mib_rdbmsDbVendorName_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbVendorName_val_ptr_ptr = realloc( *mib_rdbmsDbVendorName_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbVendorName_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbVendorName_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbVendorName_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbVendorName_val_ptr_ptr, raw_rdbmsDbVendorName_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbVendorName_map */ + +/** + * Extract the current value of the rdbmsDbVendorName data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbVendorName_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsDbVendorName_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbVendorName. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbVendorName_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbVendorName_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbVendorName_get( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbVendorName_val_ptr_ptr, size_t *rdbmsDbVendorName_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbVendorName_val_ptr_ptr) && (NULL != *rdbmsDbVendorName_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbVendorName_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbVendorName_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbVendorName data. + * set (* rdbmsDbVendorName_val_ptr_ptr ) and (* rdbmsDbVendorName_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbVendorName data + */ + if ((NULL == (* rdbmsDbVendorName_val_ptr_ptr )) || + ((* rdbmsDbVendorName_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbVendorName_len * sizeof((* rdbmsDbVendorName_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbVendorName data + */ + (* rdbmsDbVendorName_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbVendorName_len * sizeof((* rdbmsDbVendorName_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbVendorName_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbVendorName_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbVendorName_len * sizeof((* rdbmsDbVendorName_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbVendorName_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbVendorName, (* rdbmsDbVendorName_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbVendorName_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbEntry.rdbmsDbName + * rdbmsDbName is subid 4 of rdbmsDbEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.1.1.4 + * Description: +The name of this database, in a product specific format. The + product may need to qualify the name in some way to resolve + conflicts if it is possible for a database name to be + duplicated on a host. It might be necessary to construct a + hierarchical name embedding the RDBMS instance/installation + on the host, and/or the owner of the database. For instance, + '/test-installation/database-owner/database-name'. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbName.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbName_map(char **mib_rdbmsDbName_val_ptr_ptr, size_t *mib_rdbmsDbName_val_ptr_len_ptr, char *raw_rdbmsDbName_val_ptr, size_t raw_rdbmsDbName_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbName_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbName_val_ptr_ptr) && (NULL != mib_rdbmsDbName_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbName_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbName non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbName_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbName_val_ptr_ptr) || (*mib_rdbmsDbName_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbName_val_ptr_ptr = realloc( *mib_rdbmsDbName_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbName_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbName_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbName_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbName_val_ptr_ptr, raw_rdbmsDbName_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbName_map */ + +/** + * Extract the current value of the rdbmsDbName data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbName_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsDbName_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbName. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbName_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbName_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbName_get( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbName_val_ptr_ptr, size_t *rdbmsDbName_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbName_val_ptr_ptr) && (NULL != *rdbmsDbName_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbName_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbName_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbName data. + * set (* rdbmsDbName_val_ptr_ptr ) and (* rdbmsDbName_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbName data + */ + if ((NULL == (* rdbmsDbName_val_ptr_ptr )) || + ((* rdbmsDbName_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbName_len * sizeof((* rdbmsDbName_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbName data + */ + (* rdbmsDbName_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbName_len * sizeof((* rdbmsDbName_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbName_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbName_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbName_len * sizeof((* rdbmsDbName_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbName_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbName, (* rdbmsDbName_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbName_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbEntry.rdbmsDbContact + * rdbmsDbContact is subid 5 of rdbmsDbEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.1.1.5 + * Description: +The textual identification of the contact person for this + managed database, together with information on how to contact + this person. + + Note: if there is no server associated with this database, an + agent may need to keep this in other persistent storage, + e.g., a configuration file. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 1 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsDbContact.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsDbContact_map(char **mib_rdbmsDbContact_val_ptr_ptr, size_t *mib_rdbmsDbContact_val_ptr_len_ptr, char *raw_rdbmsDbContact_val_ptr, size_t raw_rdbmsDbContact_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsDbContact_val_ptr); + netsnmp_assert((NULL != mib_rdbmsDbContact_val_ptr_ptr) && (NULL != mib_rdbmsDbContact_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbContact_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsDbContact non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsDbContact_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsDbContact_val_ptr_ptr) || (*mib_rdbmsDbContact_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsDbContact_val_ptr_ptr = realloc( *mib_rdbmsDbContact_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsDbContact_val_ptr_ptr)); + if(NULL == *mib_rdbmsDbContact_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsDbContact_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsDbContact_val_ptr_ptr, raw_rdbmsDbContact_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsDbContact_map */ + +/** + * Extract the current value of the rdbmsDbContact data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbContact_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsDbContact_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsDbContact. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsDbContact_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsDbContact_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsDbContact_get( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbContact_val_ptr_ptr, size_t *rdbmsDbContact_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsDbContact_val_ptr_ptr) && (NULL != *rdbmsDbContact_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsDbContact_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbContact_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsDbContact data. + * set (* rdbmsDbContact_val_ptr_ptr ) and (* rdbmsDbContact_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsDbContact data + */ + if ((NULL == (* rdbmsDbContact_val_ptr_ptr )) || + ((* rdbmsDbContact_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsDbContact_len * sizeof((* rdbmsDbContact_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsDbContact data + */ + (* rdbmsDbContact_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsDbContact_len * sizeof((* rdbmsDbContact_val_ptr_ptr )[0])); + if(NULL == (* rdbmsDbContact_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsDbContact_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsDbContact_len * sizeof((* rdbmsDbContact_val_ptr_ptr )[0]); + memcpy( (* rdbmsDbContact_val_ptr_ptr ), rowreq_ctx->data.rdbmsDbContact, (* rdbmsDbContact_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsDbContact_get */ + + + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_get.h b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_get.h new file mode 100644 index 0000000..a4af810 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_get.h @@ -0,0 +1,66 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_data_get.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_data_get.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBTABLE_DATA_GET_H +#define RDBMSDBTABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * GET function declarations + */ + +/* ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbTable is subid 1 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.1, length: 9 +*/ + /* + * indexes + */ + int rdbmsDbIndex_map(long *mib_rdbmsDbIndex_val_ptr, long raw_rdbmsDbIndex_val); + + int rdbmsDbPrivateMibOID_map(oid **mib_rdbmsDbPrivateMibOID_val_ptr_ptr, size_t *mib_rdbmsDbPrivateMibOID_val_ptr_len_ptr, oid *raw_rdbmsDbPrivateMibOID_val_ptr, size_t raw_rdbmsDbPrivateMibOID_val_ptr_len, int allow_realloc); + int rdbmsDbPrivateMibOID_get( rdbmsDbTable_rowreq_ctx *rowreq_ctx, oid **rdbmsDbPrivateMibOID_val_ptr_ptr, size_t *rdbmsDbPrivateMibOID_val_ptr_len_ptr ); + int rdbmsDbVendorName_map(char **mib_rdbmsDbVendorName_val_ptr_ptr, size_t *mib_rdbmsDbVendorName_val_ptr_len_ptr, char *raw_rdbmsDbVendorName_val_ptr, size_t raw_rdbmsDbVendorName_val_ptr_len, int allow_realloc); + int rdbmsDbVendorName_get( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbVendorName_val_ptr_ptr, size_t *rdbmsDbVendorName_val_ptr_len_ptr ); + int rdbmsDbName_map(char **mib_rdbmsDbName_val_ptr_ptr, size_t *mib_rdbmsDbName_val_ptr_len_ptr, char *raw_rdbmsDbName_val_ptr, size_t raw_rdbmsDbName_val_ptr_len, int allow_realloc); + int rdbmsDbName_get( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbName_val_ptr_ptr, size_t *rdbmsDbName_val_ptr_len_ptr ); + int rdbmsDbContact_map(char **mib_rdbmsDbContact_val_ptr_ptr, size_t *mib_rdbmsDbContact_val_ptr_len_ptr, char *raw_rdbmsDbContact_val_ptr, size_t raw_rdbmsDbContact_val_ptr_len, int allow_realloc); + int rdbmsDbContact_get( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char **rdbmsDbContact_val_ptr_ptr, size_t *rdbmsDbContact_val_ptr_len_ptr ); + + +int rdbmsDbTable_indexes_set_tbl_idx(rdbmsDbTable_mib_index *tbl_idx, long rdbmsDbIndex_val); +int rdbmsDbTable_indexes_set(rdbmsDbTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val); + + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBTABLE_DATA_GET_H */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_set.c b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_set.c new file mode 100644 index 0000000..5293811 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_set.c @@ -0,0 +1,517 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_data_set.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_data_set.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbTable.h" + + +/** @defgroup data_set data_set: Routines to set data + * + * These routines are used to set the value for individual objects. The + * row context is passed, along with the new value. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbTable is subid 1 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.1, length: 9 +*/ + /* + * NOTE: if you update this chart, please update the versions in + * local/mib2c-conf.d/parent-set.m2i + * agent/mibgroup/helpers/baby_steps.c + * while you're at it. + */ + /* + *********************************************************************** + * Baby Steps Flow Chart (2004.06.05) * + * * + * +--------------+ +================+ U = unconditional path * + * |optional state| ||required state|| S = path for success * + * +--------------+ +================+ E = path for error * + *********************************************************************** + * + * +--------------+ + * | pre | + * | request | + * +--------------+ + * | U + * +==============+ + * +----------------|| object || + * | E || lookup || + * | +==============+ + * | | S + * | +==============+ + * | E || check || + * |<---------------|| values || + * | +==============+ + * | | S + * | +==============+ + * | +<-------|| undo || + * | | E || setup || + * | | +==============+ + * | | | S + * | | +==============+ + * | | || set ||-------------------------->+ + * | | || value || E | + * | | +==============+ | + * | | | S | + * | | +--------------+ | + * | | | check |-------------------------->| + * | | | consistency | E | + * | | +--------------+ | + * | | | S | + * | | +==============+ +==============+ | + * | | || commit ||-------->|| undo || | + * | | || || E || commit || | + * | | +==============+ +==============+ | + * | | | S U |<--------+ + * | | +--------------+ +==============+ + * | | | irreversible | || undo || + * | | | commit | || set || + * | | +--------------+ +==============+ + * | | | U U | + * | +-------------->|<------------------------+ + * | +==============+ + * | || undo || + * | || cleanup || + * | +==============+ + * +---------------------->| U + * +--------------+ + * | post | + * | request | + * +--------------+ + * + */ + +/** + * Setup up context with information needed to undo a set request. + * + * This function will be called before the individual node undo setup + * functions are called. If you need to do any undo setup that is not + * related to a specific column, you can do it here. + * + * Note that an individual node's undo_setup function will only be called + * if that node is being set to a new value. + * + * If there is any setup specific to a particular column (e.g. allocating + * memory for a string), you should do that setup in the node's undo_setup + * function, so it won't be done unless it is necessary. + * + * @param rowreq_ctx + * Pointer to the table context (rdbmsDbTable_rowreq_ctx) + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : error. set will fail. + */ +int +rdbmsDbTable_undo_setup( rdbmsDbTable_rowreq_ctx *rowreq_ctx) +{ + int rc = MFD_SUCCESS; + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_undo_setup","called\n")); + + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rowreq_ctx ); + + /* + * TODO:451:M: |-> Setup rdbmsDbTable undo. + * set up rdbmsDbTable undo information, in preparation for a set. + */ + + return rc; +} /* rdbmsDbTable_undo_setup */ + +/** + * Cleanup up context undo information. + * + * This function will be called after set/commit processing. If you + * allocated any resources in undo_setup, this is the place to release + * those resources. + * + * This function is called regardless of the success or failure of the set + * request. If you need to perform different steps for cleanup depending + * on success or failure, you can add a flag to the rowreq_ctx. + * + * @param rowreq_ctx + * Pointer to the table context (rdbmsDbTable_rowreq_ctx) + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : error + */ +int +rdbmsDbTable_undo_cleanup( rdbmsDbTable_rowreq_ctx *rowreq_ctx) +{ + int rc = MFD_SUCCESS; + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_undo_cleanup","called\n")); + + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rowreq_ctx ); + + /* + * TODO:452:M: |-> Cleanup rdbmsDbTable undo. + */ + + return rc; +} /* rdbmsDbTable_undo_cleanup */ + +/** + * commit new values. + * + * At this point, you should have done everything you can to ensure that + * this commit will not fail. + * + * Should you need different behavior depending on which columns were + * set, rowreq_ctx->column_set_flags will indicate which writeable columns were + * set. The definitions for the FLAG_* bits can be found in + * rdbmsDbTable_oids.h. + * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags. + * + * @param rdbmsDbTable_rowreq_ctx + * Pointer to the users context. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : error + */ +int +rdbmsDbTable_commit( rdbmsDbTable_rowreq_ctx *rowreq_ctx) +{ + int rc = MFD_SUCCESS; + int save_flags; + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_commit","called\n")); + + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rowreq_ctx ); + + /* + * save flags, then clear until we actually do something + */ + save_flags = rowreq_ctx->column_set_flags; + rowreq_ctx->column_set_flags = 0; + + /* + * commit rdbmsDbTable data + * 1) check the column's flag in save_flags to see if it was set. + * 2) clear the flag when you handle that column + * 3) set the column's flag in column_set_flags if it needs undo + * processing in case of a failure. + */ + if (save_flags & FLAG_RDBMSDBCONTACT) { + save_flags &= ~FLAG_RDBMSDBCONTACT; /* clear rdbmsDbContact */ + /* + * TODO:482:o: |-> commit column rdbmsDbContact. + */ + rc = -1; + if(-1 == rc) { + snmp_log(LOG_ERR,"rdbmsDbTable column rdbmsDbContact commit failed\n"); + } + else { + /* + * set flag, in case we need to undo rdbmsDbContact + */ + rowreq_ctx->column_set_flags |= FLAG_RDBMSDBCONTACT; + } + } + + if (save_flags) { + snmp_log(LOG_ERR, "unhandled columns (0x%x) in commit\n", save_flags); + return MFD_ERROR; + } + + return rc; +} /* rdbmsDbTable_commit */ + +/** + * undo commit new values. + * + * Should you need different behavior depending on which columns were + * set, rowreq_ctx->column_set_flags will indicate which writeable columns were + * set. The definitions for the FLAG_* bits can be found in + * rdbmsDbTable_oids.h. + * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags. + * + * @param rdbmsDbTable_rowreq_ctx + * Pointer to the users context. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : error + */ +int +rdbmsDbTable_undo_commit( rdbmsDbTable_rowreq_ctx *rowreq_ctx) +{ + int rc = MFD_SUCCESS; + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_undo_commit","called\n")); + + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rowreq_ctx ); + + /* + * TODO:485:M: |-> Undo rdbmsDbTable commit. + * check the column's flag in rowreq_ctx->column_set_flags to see + * if it was set during commit, then undo it. + * + * eg: if (rowreq_ctx->column_set_flags & FLAG_) {} + */ + + return rc; +} /* rdbmsDbTable_undo_commit */ + +/* + * TODO:420:r: Implement rdbmsDbTable index validation. + */ +/* + * TODO:440:M: Implement rdbmsDbTable node value checks. + * TODO:450:M: Implement rdbmsDbTable undo functions. + * TODO:460:M: Implement rdbmsDbTable set functions. + * TODO:480:M: Implement rdbmsDbTable commit functions. + */ +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsDbEntry.rdbmsDbContact + * rdbmsDbContact is subid 5 of rdbmsDbEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.1.1.5 + * Description: +The textual identification of the contact person for this + managed database, together with information on how to contact + this person. + + Note: if there is no server associated with this database, an + agent may need to keep this in other persistent storage, + e.g., a configuration file. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 1 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * Check that the proposed new value is potentially valid. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsDbContact_val_ptr + * A char containing the new value. + * @param rdbmsDbContact_val_ptr_len + * The size (in bytes) of the data pointed to by rdbmsDbContact_val_ptr + * + * @retval MFD_SUCCESS : incoming value is legal + * @retval MFD_NOT_VALID_NOW : incoming value is not valid now + * @retval MFD_NOT_VALID_EVER : incoming value is never valid + * + * This is the place to check for requirements that are not + * expressed in the mib syntax (for example, a requirement that + * is detailed in the description for an object). + * + * You should check that the requested change between the undo value and the + * new value is legal (ie, the transistion from one value to another + * is legal). + * + *@note + * This check is only to determine if the new value + * is \b potentially valid. This is the first check of many, and + * is one of the simplest ones. + * + *@note + * this is not the place to do any checks for values + * which depend on some other value in the mib. Those + * types of checks should be done in the + * rdbmsDbTable_check_dependencies() function. + * + * The following checks have already been done for you: + * The syntax is ASN_OCTET_STR + * The length is in (one of) the range set(s): 0 - 255 + * + * If there a no other checks you need to do, simply return MFD_SUCCESS. + * + */ +int +rdbmsDbContact_check_value( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char *rdbmsDbContact_val_ptr, size_t rdbmsDbContact_val_ptr_len) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbContact_check_value","called\n")); + + /** should never get a NULL pointer */ + netsnmp_assert(NULL != rowreq_ctx); + netsnmp_assert(NULL != rdbmsDbContact_val_ptr); + + /* + * TODO:441:o: |-> Check for valid rdbmsDbContact value. + */ + + return MFD_SUCCESS; /* rdbmsDbContact value not illegal */ +} /* rdbmsDbContact_check_value */ + +/** + * Save old value information + * + * @param rowreq_ctx + * Pointer to the table context (rdbmsDbTable_rowreq_ctx) + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : error. set will fail. + * + * This function will be called after the table level undo setup function + * rdbmsDbTable_undo_setup has been called. + * + *@note + * this function will only be called if a new value is set for this column. + * + * If there is any setup specific to a particular column (e.g. allocating + * memory for a string), you should do that setup in this function, so it + * won't be done unless it is necessary. + */ +int +rdbmsDbContact_undo_setup( rdbmsDbTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbContact_undo_setup","called\n")); + + /** should never get a NULL pointer */ + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:455:o: |-> Setup rdbmsDbContact undo. + */ + /* + * copy rdbmsDbContact and rdbmsDbContact_len data + * set rowreq_ctx->undo->rdbmsDbContact from rowreq_ctx->data.rdbmsDbContact + */ + memcpy( rowreq_ctx->undo->rdbmsDbContact, rowreq_ctx->data.rdbmsDbContact, + (rowreq_ctx->data.rdbmsDbContact_len * sizeof(rowreq_ctx->undo->rdbmsDbContact[0]))); + rowreq_ctx->undo->rdbmsDbContact_len = rowreq_ctx->data.rdbmsDbContact_len; + + + return MFD_SUCCESS; +} /* rdbmsDbContact_undo_setup */ + +/** + * Set the new value. + * + * @param rowreq_ctx + * Pointer to the users context. You should know how to + * manipulate the value from this object. + * @param rdbmsDbContact_val_ptr + * A char containing the new value. + * @param rdbmsDbContact_val_ptr_len + * The size (in bytes) of the data pointed to by rdbmsDbContact_val_ptr + */ +int +rdbmsDbContact_set( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char *rdbmsDbContact_val_ptr, size_t rdbmsDbContact_val_ptr_len ) +{ + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbContact_set","called\n")); + + /** should never get a NULL pointer */ + netsnmp_assert(NULL != rowreq_ctx); + netsnmp_assert(NULL != rdbmsDbContact_val_ptr); + +/* + * TODO:245:o: |-> Implement rdbmsDbContact reverse mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + /* + * TODO:461:M: |-> Set rdbmsDbContact value. + * set rdbmsDbContact value in rowreq_ctx->data + */ + memcpy( rowreq_ctx->data.rdbmsDbContact, rdbmsDbContact_val_ptr, rdbmsDbContact_val_ptr_len ); + rowreq_ctx->data.rdbmsDbContact_len = rdbmsDbContact_val_ptr_len / sizeof(rdbmsDbContact_val_ptr[0]); + + return MFD_SUCCESS; +} /* rdbmsDbContact_set */ + +/** + * undo the previous set. + * + * @param rowreq_ctx + * Pointer to the users context. + */ +int +rdbmsDbContact_undo( rdbmsDbTable_rowreq_ctx *rowreq_ctx) +{ + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbContact_undo","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:456:o: |-> Clean up rdbmsDbContact undo. + */ + /* + * copy rdbmsDbContact and rdbmsDbContact_len data + * set rowreq_ctx->data.rdbmsDbContact from rowreq_ctx->undo->rdbmsDbContact + */ + memcpy( rowreq_ctx->data.rdbmsDbContact, rowreq_ctx->undo->rdbmsDbContact, + (rowreq_ctx->undo->rdbmsDbContact_len * sizeof(rowreq_ctx->data.rdbmsDbContact[0]))); + rowreq_ctx->data.rdbmsDbContact_len = rowreq_ctx->undo->rdbmsDbContact_len; + + + return MFD_SUCCESS; +} /* rdbmsDbContact_undo */ + +/** + * check dependencies + * + * This is useful for for tables which have dependencies between columns + * (or rows, or tables). For example, two columns allocating a percentage + * of something add up 100%. + * + * Should you need different behavior depending on which columns were + * set, rowreq_ctx->column_set_flags will indicate which writeable columns were + * set. The definitions for the FLAG_* bits can be found in + * rdbmsDbTable_oids.h. + * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags. + * + * @retval MFD_SUCCESS all the changes to the row are legal + * @retval MFD_ERROR one or more changes are not legal + * + * (see README-table-rdbmsDbTable if you don't have dependencies) + */ +int +rdbmsDbTable_check_dependencies(rdbmsDbTable_rowreq_ctx *rowreq_ctx) +{ + int rc = MFD_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsDbTable:rdbmsDbTable_check_dependencies","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:470:o: Check rdbmsDbTable row dependencies. + * check that all new value are legal and consistent with each other + */ + return rc; +} /* rdbmsDbTable_check_dependencies */ + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_set.h b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_set.h new file mode 100644 index 0000000..06cd026 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_data_set.h @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_data_set.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_data_set.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBTABLE_DATA_SET_H +#define RDBMSDBTABLE_DATA_SET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * SET function declarations + */ + +/* ********************************************************************* + * SET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbTable is subid 1 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.1, length: 9 +*/ +int rdbmsDbIndex_check_index( rdbmsDbTable_rowreq_ctx *rowreq_ctx ); /* internal */ + + +int rdbmsDbTable_undo_setup( rdbmsDbTable_rowreq_ctx *rowreq_ctx); +int rdbmsDbTable_undo_cleanup( rdbmsDbTable_rowreq_ctx *rowreq_ctx); +int rdbmsDbTable_commit( rdbmsDbTable_rowreq_ctx *rowreq_ctx); +int rdbmsDbTable_undo_commit( rdbmsDbTable_rowreq_ctx *rowreq_ctx); + + +int rdbmsDbPrivateMibOID_check_value( rdbmsDbTable_rowreq_ctx *rowreq_ctx, oid *rdbmsDbPrivateMibOID_val_ptr, size_t rdbmsDbPrivateMibOID_val_ptr_len); +int rdbmsDbPrivateMibOID_undo_setup( rdbmsDbTable_rowreq_ctx *rowreq_ctx ); +int rdbmsDbPrivateMibOID_set( rdbmsDbTable_rowreq_ctx *rowreq_ctx, oid *rdbmsDbPrivateMibOID_val_ptr, size_t rdbmsDbPrivateMibOID_val_ptr_len ); +int rdbmsDbPrivateMibOID_undo( rdbmsDbTable_rowreq_ctx *rowreq_ctx ); + +int rdbmsDbVendorName_check_value( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char *rdbmsDbVendorName_val_ptr, size_t rdbmsDbVendorName_val_ptr_len); +int rdbmsDbVendorName_undo_setup( rdbmsDbTable_rowreq_ctx *rowreq_ctx ); +int rdbmsDbVendorName_set( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char *rdbmsDbVendorName_val_ptr, size_t rdbmsDbVendorName_val_ptr_len ); +int rdbmsDbVendorName_undo( rdbmsDbTable_rowreq_ctx *rowreq_ctx ); + +int rdbmsDbName_check_value( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char *rdbmsDbName_val_ptr, size_t rdbmsDbName_val_ptr_len); +int rdbmsDbName_undo_setup( rdbmsDbTable_rowreq_ctx *rowreq_ctx ); +int rdbmsDbName_set( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char *rdbmsDbName_val_ptr, size_t rdbmsDbName_val_ptr_len ); +int rdbmsDbName_undo( rdbmsDbTable_rowreq_ctx *rowreq_ctx ); + +int rdbmsDbContact_check_value( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char *rdbmsDbContact_val_ptr, size_t rdbmsDbContact_val_ptr_len); +int rdbmsDbContact_undo_setup( rdbmsDbTable_rowreq_ctx *rowreq_ctx ); +int rdbmsDbContact_set( rdbmsDbTable_rowreq_ctx *rowreq_ctx, char *rdbmsDbContact_val_ptr, size_t rdbmsDbContact_val_ptr_len ); +int rdbmsDbContact_undo( rdbmsDbTable_rowreq_ctx *rowreq_ctx ); + + +int rdbmsDbTable_check_dependencies(rdbmsDbTable_rowreq_ctx *ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBTABLE_DATA_SET_H */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_enums.h b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_enums.h new file mode 100644 index 0000000..676d383 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_enums.h @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_enums.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_enums.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBTABLE_ENUMS_H +#define RDBMSDBTABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table rdbmsDbTable + * + ************************************************************************* + *************************************************************************/ + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBTABLE_ENUMS_H */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_interface.c b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_interface.c new file mode 100644 index 0000000..8711c2c --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_interface.c @@ -0,0 +1,1238 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_interface.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_interface.c,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsDbTable.h" +#include "rdbmsDbTable_interface.h" + +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsDbTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsDbTable is subid 1 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.1, length: 9 +*/ +typedef struct rdbmsDbTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; /* optional cache */ + + rdbmsDbTable_registration_ptr user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} rdbmsDbTable_interface_ctx; + +static rdbmsDbTable_interface_ctx rdbmsDbTable_if_ctx; + +static void _rdbmsDbTable_container_init( + rdbmsDbTable_interface_ctx *if_ctx); + + +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_pre_request; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_post_request; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_object_lookup; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_get_values; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_check_objects; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_undo_setup; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_set_values; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_undo_cleanup; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_undo_values; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_commit; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_undo_commit; +static Netsnmp_Node_Handler _mfd_rdbmsDbTable_check_dependencies; + +NETSNMP_STATIC_INLINE int _rdbmsDbTable_undo_column( rdbmsDbTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ); + +rdbmsDbTable_data *rdbmsDbTable_allocate_data(void); +void rdbmsDbTable_release_data(rdbmsDbTable_data *data); + +/** + * @internal + * Initialize the table rdbmsDbTable + * (Define its contents and how it's structured) + */ +void +_rdbmsDbTable_initialize_interface(rdbmsDbTable_registration_ptr reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &rdbmsDbTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = &rdbmsDbTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:rdbmsDbTable:_rdbmsDbTable_initialize_interface","called\n")); + + + /************************************************* + * + * save interface context for rdbmsDbTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, + ASN_INTEGER, /** index: rdbmsDbIndex */ + 0); + + /* Define the minimum and maximum accessible columns. This + optimizes retrival. */ + tbl_info->min_column = RDBMSDBTABLE_MIN_COL; + tbl_info->max_column = RDBMSDBTABLE_MAX_COL; + + /* + * save users context + */ + rdbmsDbTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + rdbmsDbTable_init_data(reg_ptr); + + /* + * set up the container + */ + _rdbmsDbTable_container_init(&rdbmsDbTable_if_ctx); + if (NULL == rdbmsDbTable_if_ctx.container) { + snmp_log(LOG_ERR,"could not initialize container for rdbmsDbTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = _mfd_rdbmsDbTable_object_lookup; + access_multiplexer->get_values = _mfd_rdbmsDbTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = _mfd_rdbmsDbTable_pre_request; + access_multiplexer->post_request = _mfd_rdbmsDbTable_post_request; + + + /* + * REQUIRED wrappers for set request handling + */ + access_multiplexer->object_syntax_checks = _mfd_rdbmsDbTable_check_objects; + access_multiplexer->undo_setup = _mfd_rdbmsDbTable_undo_setup; + access_multiplexer->undo_cleanup = _mfd_rdbmsDbTable_undo_cleanup; + access_multiplexer->set_values = _mfd_rdbmsDbTable_set_values; + access_multiplexer->undo_sets = _mfd_rdbmsDbTable_undo_values; + + /* + * no wrappers yet + */ + access_multiplexer->commit = _mfd_rdbmsDbTable_commit; + access_multiplexer->undo_commit = _mfd_rdbmsDbTable_undo_commit; + + /* + * REQUIRED for tables with dependencies + */ + access_multiplexer->consistency_checks = _mfd_rdbmsDbTable_check_dependencies; + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("rdbmsDbTable:init_rdbmsDbTable", + "Registering rdbmsDbTable as a mibs-for-dummies table.\n")); + handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = netsnmp_handler_registration_create("rdbmsDbTable", handler, + rdbmsDbTable_oid, + rdbmsDbTable_oid_size, + HANDLER_CAN_BABY_STEP | + HANDLER_CAN_RWRITE + ); + if(NULL == reginfo) { + snmp_log(LOG_ERR,"error registering table rdbmsDbTable\n"); + return; + } + reginfo->my_reg_void = &rdbmsDbTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if( access_multiplexer->object_lookup ) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if( access_multiplexer->set_values ) + mfd_modes |= BABY_STEP_SET_VALUES; + if( access_multiplexer->irreversible_commit ) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if( access_multiplexer->object_syntax_checks ) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if( access_multiplexer->pre_request ) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if( access_multiplexer->post_request ) + mfd_modes |= BABY_STEP_POST_REQUEST; + + if( access_multiplexer->undo_setup ) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if( access_multiplexer->undo_cleanup ) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if( access_multiplexer->undo_sets ) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if( access_multiplexer->row_creation ) + mfd_modes |= BABY_STEP_ROW_CREATE; + if( access_multiplexer->consistency_checks ) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if( access_multiplexer->commit ) + mfd_modes |= BABY_STEP_COMMIT; + if( access_multiplexer->undo_commit ) + mfd_modes |= BABY_STEP_UNDO_COMMIT; + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + rdbmsDbTable_if_ctx.container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler( reginfo, handler ); + + /************************************************* + * + * inject cache helper + */ + if(NULL != rdbmsDbTable_if_ctx.cache) { + handler = netsnmp_cache_handler_get(rdbmsDbTable_if_ctx.cache); + netsnmp_inject_handler( reginfo, handler ); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); +} /* _rdbmsDbTable_initialize_interface */ + +void +rdbmsDbTable_valid_columns_set(netsnmp_column_info *vc) +{ + rdbmsDbTable_if_ctx.tbl_info.valid_columns = vc; +} /* rdbmsDbTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +rdbmsDbTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsDbTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_index_to_oid","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_rdbmsDbIndex, (u_char*)&mib_idx->rdbmsDbIndex, + sizeof(mib_idx->rdbmsDbIndex)); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, (size_t *)&oid_idx->len, + NULL, 0, &var_rdbmsDbIndex); + if(err) + snmp_log(LOG_ERR,"error %d converting index to oid\n", err); + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsDbTable_index_to_oid */ + +/** + * extract rdbmsDbTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +rdbmsDbTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsDbTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_index_from_oid","called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes( oid_idx->oids, oid_idx->len, + &var_rdbmsDbIndex ); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + mib_idx->rdbmsDbIndex = *((long *)var_rdbmsDbIndex.val.string); + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsDbTable_index_from_oid */ + + +/* + * rdbmsDbTable_allocate_data + * + * Purpose: create new rdbmsDbTable_data. + */ +rdbmsDbTable_data * +rdbmsDbTable_allocate_data(void) +{ + rdbmsDbTable_data *rtn = SNMP_MALLOC_TYPEDEF(rdbmsDbTable_data); + + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_allocate_data","called\n")); + + if(NULL == rtn) { + snmp_log(LOG_ERR, "unable to malloc memory for new " + "rdbmsDbTable_data.\n"); + } + + return rtn; +} /* rdbmsDbTable_allocate_data */ + +/* + * rdbmsDbTable_release_data + * + * Purpose: release rdbmsDbTable data. + */ +void +rdbmsDbTable_release_data(rdbmsDbTable_data *data) +{ + DEBUGMSGTL(("verbose:rdbmsDbTable:rdbmsDbTable_release_data","called\n")); + + free(data); +} /* rdbmsDbTable_release_data */ + +/* ********************************************************************* + * @internal + * allocate resources for a rdbmsDbTable_rowreq_ctx + */ +rdbmsDbTable_rowreq_ctx * +rdbmsDbTable_allocate_rowreq_ctx(void) +{ + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(rdbmsDbTable_rowreq_ctx); + + DEBUGMSGTL(("internal:rdbmsDbTable:rdbmsDbTable_allocate_rowreq_ctx","called\n")); + + if(NULL == rowreq_ctx) { + snmp_log(LOG_ERR,"Couldn't allocate memory for a " + "rdbmsDbTable_rowreq_ctx.\n"); + } + + rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; + + rowreq_ctx->rdbmsDbTable_data_list = NULL; + rowreq_ctx->rdbmsDbTable_reg = rdbmsDbTable_if_ctx.user_ctx; + + + return rowreq_ctx; +} /* rdbmsDbTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a rdbmsDbTable_rowreq_ctx + */ +void +rdbmsDbTable_release_rowreq_ctx(rdbmsDbTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("internal:rdbmsDbTable:rdbmsDbTable_release_rowreq_ctx","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + + if(rowreq_ctx->undo) + rdbmsDbTable_release_data(rowreq_ctx->undo); + + /* + * free index oid pointer + */ + if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* rdbmsDbTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc = rdbmsDbTable_pre_request(rdbmsDbTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsDbTable","error %d from " + "rdbmsDbTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbTable_rowreq_ctx *rowreq_ctx; + int rc = rdbmsDbTable_post_request(rdbmsDbTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsDbTable","error %d from " + "rdbmsDbTable_post_request\n", rc)); + } + + /* + * if there are no errors, check for and handle row creation/deletion + */ + rc = netsnmp_check_requests_error(requests); + if ((SNMP_ERR_NOERROR == rc) && + (NULL != + (rowreq_ctx = netsnmp_container_table_row_extract(requests)))) { + if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) { + rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; + CONTAINER_INSERT(rdbmsDbTable_if_ctx.container, rowreq_ctx); + } + else if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { + CONTAINER_REMOVE(rdbmsDbTable_if_ctx.container, rowreq_ctx); + rdbmsDbTable_release_rowreq_ctx(rowreq_ctx); + } + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsDbTable_object_lookup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_object_lookup","called\n")); + + /* + * get our context from mfd + * rdbmsDbTable_interface_ctx *if_ctx = + * (rdbmsDbTable_interface_ctx *)reginfo->my_reg_void; + */ + + if(NULL == rowreq_ctx) { + netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION); + } + else { + rdbmsDbTable_row_prep(rowreq_ctx); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsDbTable_get_column( rdbmsDbTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_get_column","called\n")); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsDbPrivateMibOID(2)/OBJECTID/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h */ + case COLUMN_RDBMSDBPRIVATEMIBOID: + var->type = ASN_OBJECT_ID; +rc = rdbmsDbPrivateMibOID_get(rowreq_ctx, (oid **)&var->val.string, &var->val_len ); + break; + + /* rdbmsDbVendorName(3)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ + case COLUMN_RDBMSDBVENDORNAME: + var->type = ASN_OCTET_STR; +rc = rdbmsDbVendorName_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* rdbmsDbName(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ + case COLUMN_RDBMSDBNAME: + var->type = ASN_OCTET_STR; +rc = rdbmsDbName_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* rdbmsDbContact(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSDBCONTACT: + var->type = ASN_OCTET_STR; +rc = rdbmsDbContact_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsDbTable_get_column\n", column); + break; + } + + return rc; +} /* _rdbmsDbTable_get_column */ + +int +_mfd_rdbmsDbTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + u_char * old_string; + void (*dataFreeHook)(void *); + int rc; + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_get_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if(NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + else if(requests->requestvb->buf == requests->requestvb->val.string) { + if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsDbTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + if(MFD_SKIP == rc) { + requests->requestvb->type = ASN_PRIV_RETRY; + rc = SNMP_ERR_NOERROR; + } + } + else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if(rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if(old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if(dataFreeHook) + (*dataFreeHook)(old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_get_values */ + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/*---------------------------------------------------------------------- + * + * SET: Syntax checks + * + *---------------------------------------------------------------------*/ +/* + * @internal + * Check the syntax for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsDbTable_check_column( rdbmsDbTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsDbTable:_rdbmsDbTable_check_column","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsDbContact(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSDBCONTACT: + rc = netsnmp_check_vb_type( var, ASN_OCTET_STR ); + if(SNMPERR_SUCCESS == rc) { + /* check that the value is in the defined range(s); inefficent + * but keeps rc value knowledge in libarary where it belongs. */ + if( 1 + && ((rc = netsnmp_check_vb_size_range(var, 0,255)) != SNMP_ERR_NOERROR) + ) { + ; /* rc set in condition */ + } + } + if(SNMPERR_SUCCESS == rc) { + rc = rdbmsDbContact_check_value( rowreq_ctx, (char *)var->val.string, var->val_len ); + if((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc) && + (MFD_NOT_VALID_NOW != rc)) { + snmp_log(LOG_ERR, "bad rc %d from rdbmsDbContact_check_value\n", rc); + rc = SNMP_ERR_GENERR; + } + } + break; + + default: /** We shouldn't get here */ + rc = SNMP_ERR_GENERR; + snmp_log(LOG_ERR, "unknown column %d in _rdbmsDbTable_check_column\n", column); + } + + return rc; +} /* _rdbmsDbTable_check_column */ + +int +_mfd_rdbmsDbTable_check_objects(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + int rc; + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_check_objects","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + + /* + * get column number from table request info, and check that column + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsDbTable_check_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + break; + } + + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_check_objects */ + + + +/*---------------------------------------------------------------------- + * + * SET: check dependencies + * + *---------------------------------------------------------------------*/ +/* + * @internal + * Check dependencies wrapper + */ +static int +_mfd_rdbmsDbTable_check_dependencies(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc; + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_check_dependencies","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + rc = rdbmsDbTable_check_dependencies(rowreq_ctx); + if(rc){ + DEBUGMSGTL(("verbose:rdbmsDbTable:mfd","error %d from " + "rdbmsDbTable_check_dependencies\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_check_dependencies */ + +/*---------------------------------------------------------------------- + * + * SET: Undo setup + * + *---------------------------------------------------------------------*/ +/* + * @internal + * Set the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsDbTable_undo_setup_column( rdbmsDbTable_rowreq_ctx *rowreq_ctx, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsDbTable:_rdbmsDbTable_undo_setup_column","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsDbContact(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSDBCONTACT: + rowreq_ctx->column_set_flags |= FLAG_RDBMSDBCONTACT; + rc = rdbmsDbContact_undo_setup(rowreq_ctx ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsDbTable_undo_setup_column\n", column); + break; + } + + return rc; +} /* _rdbmsDbTable_undo_setup_column */ + + +/** + * @internal + * undo setup + */ +int +_mfd_rdbmsDbTable_undo_setup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc; + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_undo_setup","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * allocate undo context + */ + rowreq_ctx->undo = rdbmsDbTable_allocate_data(); + if(NULL == rowreq_ctx->undo) { + /** msg already logged */ + netsnmp_request_set_error_all(requests, SNMP_ERR_RESOURCEUNAVAILABLE); + return SNMP_ERR_NOERROR; + } + + /* + * row undo setup + */ + rowreq_ctx->column_set_flags = 0; + rc = rdbmsDbTable_undo_setup(rowreq_ctx); + if (MFD_SUCCESS != rc) { + DEBUGMSGTL(("verbose:rdbmsDbTable:mfd","error %d from " + "rdbmsDbTable_undo_setup\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + else { + /* + * column undo setup + */ + netsnmp_table_request_info * tri; + for(;requests; requests = requests->next) { + /* + * set column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsDbTable_undo_setup_column(rowreq_ctx, tri->colnum); + if(MFD_SUCCESS != rc) { + DEBUGMSGTL(("verbose:rdbmsDbTable:mfd","error %d from " + "rdbmsDbTable_undo_setup_column\n", rc)); + netsnmp_set_request_error(agtreq_info, requests, SNMP_VALIDATE_ERR(rc)); + } + } /* for results */ + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_undo_setup */ + +/** + * @internal + * undo setup + */ +int +_mfd_rdbmsDbTable_undo_cleanup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + int rc; + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_undo_cleanup","called\n")); + + /* + * failed row create in early stages has no rowreq_ctx + */ + if (NULL == rowreq_ctx) + return MFD_SUCCESS; + + /* + * call user cleanup + */ + rc = rdbmsDbTable_undo_cleanup(rowreq_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("verbose:rdbmsDbTable:mfd","error %d from " + "rdbmsDbTable_undo_cleanup\n", rc)); + } + + /* + * release undo context, if needed + */ + if(rowreq_ctx->undo) { + rdbmsDbTable_release_data(rowreq_ctx->undo); + rowreq_ctx->undo = NULL; + } + + /* + * clear set flags + */ + rowreq_ctx->column_set_flags = 0; + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_undo_cleanup */ + +/*---------------------------------------------------------------------- + * + * SET: Set values + * + *---------------------------------------------------------------------*/ +/* + * @internal + * Set the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsDbTable_set_column( rdbmsDbTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsDbTable:_rdbmsDbTable_set_column","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsDbContact(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSDBCONTACT: + rowreq_ctx->column_set_flags |= FLAG_RDBMSDBCONTACT; + rc = rdbmsDbContact_set(rowreq_ctx, (char *)var->val.string, var->val_len ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsDbTable_set_column\n", column); + break; + } + + return rc; +} /* _rdbmsDbTable_set_column */ + +int +_mfd_rdbmsDbTable_set_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + int rc = SNMP_ERR_NOERROR; + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_set_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + rowreq_ctx->column_set_flags = 0; + for(;requests; requests = requests->next) { + /* + * set column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsDbTable_set_column(rowreq_ctx, + requests->requestvb, tri->colnum); + if(MFD_SUCCESS != rc) { + DEBUGMSGTL(("verbose:rdbmsDbTable:mfd","error %d from " + "rdbmsDbTable_set_column\n", rc)); + netsnmp_set_request_error(agtreq_info, requests, SNMP_VALIDATE_ERR(rc)); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_set_values */ + +/*---------------------------------------------------------------------- + * + * SET: commit + * + *---------------------------------------------------------------------*/ +/** + * @internal + * commit the values + */ +int +_mfd_rdbmsDbTable_commit(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc; + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_commit","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + rc = rdbmsDbTable_commit(rowreq_ctx); + if (MFD_SUCCESS != rc) { + DEBUGMSGTL(("verbose:rdbmsDbTable:mfd","error %d from " + "rdbmsDbTable_commit\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} + +int +_mfd_rdbmsDbTable_undo_commit(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc; + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_undo_commit","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + rc = rdbmsDbTable_undo_commit(rowreq_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("verbose:rdbmsDbTable:mfd","error %d from " + "rdbmsDbTable_undo_commit\n", rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_commit */ + +/*---------------------------------------------------------------------- + * + * SET: Undo + * + *---------------------------------------------------------------------*/ +/** + * @internal + * undo the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsDbTable_undo_column( rdbmsDbTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsDbTable:_rdbmsDbTable_undo_column","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsDbContact(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSDBCONTACT: + rc = rdbmsDbContact_undo(rowreq_ctx); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsDbTable_undo_column\n", column); + break; + } + + return rc; +} /* _rdbmsDbTable_undo_column */ + +int +_mfd_rdbmsDbTable_undo_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc; + rdbmsDbTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + + DEBUGMSGTL(("internal:rdbmsDbTable:_mfd_rdbmsDbTable_undo_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * set column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsDbTable_undo_column(rowreq_ctx, requests->requestvb, + tri->colnum); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("verbose:rdbmsDbTable:mfd","error %d from " + "rdbmsDbTable_undo_column\n", rc)); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsDbTable_undo_values */ + +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +/** + * @internal + */ +static int +_cache_load(netsnmp_cache *cache, void *vmagic) +{ + DEBUGMSGTL(("internal:rdbmsDbTable:_cache_load","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache for rdbmsDbTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return rdbmsDbTable_cache_load((netsnmp_container*)cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_item_free(rdbmsDbTable_rowreq_ctx *rowreq_ctx, void *context) +{ + DEBUGMSGTL(("internal:rdbmsDbTable:_cache_item_free","called\n")); + + if(NULL == rowreq_ctx) + return; + + rdbmsDbTable_release_rowreq_ctx(rowreq_ctx); +} /* _cache_item_free */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache *cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:rdbmsDbTable:_cache_free","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache in rdbmsDbTable_cache_free\n"); + return; + } + + container = (netsnmp_container*)cache->magic; + + /* + * call user code + */ + rdbmsDbTable_cache_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *)_cache_item_free, + NULL); +} /* _cache_free */ + +/** + * @internal + * initialize the iterator container with functions or wrappers + */ +void +_rdbmsDbTable_container_init(rdbmsDbTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:rdbmsDbTable:_rdbmsDbTable_container_init","called\n")); + + /* + * set up the cache + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + rdbmsDbTable_oid, + rdbmsDbTable_oid_size); + + if(NULL == if_ctx->cache) { + snmp_log(LOG_ERR, "error creating cache for rdbmsDbTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + rdbmsDbTable_container_init(&if_ctx->container, if_ctx->cache); + if(NULL == if_ctx->container) + if_ctx->container = netsnmp_container_find("rdbmsDbTable:table_container"); + if(NULL == if_ctx->container) { + snmp_log(LOG_ERR,"error creating container in " + "rdbmsDbTable_container_init\n"); + return; + } + if_ctx->cache->magic = (void*)if_ctx->container; +} /* _rdbmsDbTable_container_init */ + diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_interface.h b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_interface.h new file mode 100644 index 0000000..2d74fdc --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_interface.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_interface.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_interface.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBTABLE_INTERFACE_H +#define RDBMSDBTABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "rdbmsDbTable.h" + +/* ******************************************************************** + * Table declarations + */ + +/* PUBLIC interface initialization routine */ +void _rdbmsDbTable_initialize_interface(rdbmsDbTable_registration_ptr user_ctx, + u_long flags); + + rdbmsDbTable_rowreq_ctx * rdbmsDbTable_allocate_rowreq_ctx(void); +void rdbmsDbTable_release_rowreq_ctx(rdbmsDbTable_rowreq_ctx *rowreq_ctx); + +int rdbmsDbTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsDbTable_mib_index *mib_idx); +int rdbmsDbTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsDbTable_mib_index *mib_idx); + +/* + * access to certain internals. use with caution! + */ +void rdbmsDbTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBTABLE_INTERFACE_H */ diff --git a/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_oids.h b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_oids.h new file mode 100644 index 0000000..8d80497 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsDbTable/rdbmsDbTable_oids.h @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------- + * rdbmsDbTable_oids.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsDbTable_oids.h,v 1.2 2007/09/13 14:20:43 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSDBTABLE_OIDS_H +#define RDBMSDBTABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* column number definitions for table rdbmsDbTable */ +#define RDBMSDBTABLE_OID 1,3,6,1,2,1,39,1,1 +#define COLUMN_RDBMSDBINDEX 1 +#define COLUMN_RDBMSDBPRIVATEMIBOID 2 +#define COLUMN_RDBMSDBVENDORNAME 3 +#define COLUMN_RDBMSDBNAME 4 +#define COLUMN_RDBMSDBCONTACT 5 + +#define RDBMSDBTABLE_MIN_COL COLUMN_RDBMSDBPRIVATEMIBOID +#define RDBMSDBTABLE_MAX_COL COLUMN_RDBMSDBCONTACT + + /* + * change flags for writable columns + */ +#define FLAG_RDBMSDBCONTACT (0x1 << 0) + +#define FLAG_MAX_RDBMSDBTABLE 1 + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSDBTABLE_OIDS_H */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable.c b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable.c new file mode 100644 index 0000000..a911d5d --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable.c @@ -0,0 +1,130 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsRelTable.h" + +#include <net-snmp/agent/mib_modules.h> + +#include "rdbmsRelTable_interface.h" + +oid rdbmsRelTable_oid[] = { RDBMSRELTABLE_OID }; +int rdbmsRelTable_oid_size = OID_LENGTH(rdbmsRelTable_oid); + +void initialize_table_rdbmsRelTable(void); + + +/** + * Initializes the rdbmsRelTable module + */ +void +init_rdbmsRelTable(void) +{ + DEBUGMSGTL(("verbose:rdbmsRelTable:init_rdbmsRelTable","called\n")); + + /* + * TODO:300:o: Perform rdbmsRelTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("rdbmsRelTable")) + initialize_table_rdbmsRelTable(); + +} /* init_rdbmsRelTable */ + +/** + * Initialize the table rdbmsRelTable + * (Define its contents and how it's structured) + */ +void +initialize_table_rdbmsRelTable(void) +{ + rdbmsRelTable_registration_ptr user_context; + u_long flags; + + DEBUGMSGTL(("verbose:rdbmsRelTable:initialize_table_rdbmsRelTable","called\n")); + + /* + * TODO:301:o: Perform rdbmsRelTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize rdbmsRelTable user context + * if you'd like to pass in a pointer to some data for this + * table, allocate or set it up here. + */ + /* + * a netsnmp_data_list is a simple way to store void pointers. A simple + * string token is used to add, find or remove pointers. + */ + user_context = netsnmp_create_data_list("rdbmsRelTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _rdbmsRelTable_initialize_interface(user_context, flags); +} /* initialize_table_rdbmsRelTable */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +rdbmsRelTable_pre_request(rdbmsRelTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_pre_request","called\n")); + + /* + * TODO:510:o: Perform rdbmsRelTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsRelTable_pre_request */ + +/** + * post-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error (ignored) + */ +int +rdbmsRelTable_post_request(rdbmsRelTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_post_request","called\n")); + + /* + * TODO:511:o: Perform rdbmsRelTable pos-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsRelTable_post_request */ + + +/** @{ */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable.h b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable.h new file mode 100644 index 0000000..1c44b8d --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable.h @@ -0,0 +1,205 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSRELTABLE_H +#define RDBMSRELTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @defgroup misc misc: Miscelaneous routines + * + * @{ + */ +#include <net-snmp/library/asn1.h> + +/* other required module components */ + /* *INDENT-OFF* */ +config_require(RDBMS-MIB/rdbmsRelTable/rdbmsRelTable_interface); +config_require(RDBMS-MIB/rdbmsRelTable/rdbmsRelTable_data_access); +config_require(RDBMS-MIB/rdbmsRelTable/rdbmsRelTable_data_get); +config_require(RDBMS-MIB/rdbmsRelTable/rdbmsRelTable_data_set); + /* *INDENT-ON* */ + +/* OID and column number definitions for */ +#include "rdbmsRelTable_oids.h" + +/* enum definions */ +#include "rdbmsRelTable_enums.h" + +/* ********************************************************************* + * function declarations + */ +void init_rdbmsRelTable(void); + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsRelTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsRelTable is subid 9 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.9, length: 9 +*/ +/* ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review rdbmsRelTable registration context. + */ +typedef netsnmp_data_list * rdbmsRelTable_registration_ptr; + +/**********************************************************************/ +/* + * TODO:110:r: |-> Review rdbmsRelTable data context structure. + * This structure is used to represent the data for rdbmsRelTable. + */ +/* + * This structure contains storage for all the columns defined in the + * rdbmsRelTable. + */ +typedef struct rdbmsRelTable_data_s { + + /* + * rdbmsRelState(1)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h + */ + u_long rdbmsRelState; + + /* + * rdbmsRelActiveTime(2)/DateAndTime/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ + int activeTimeYear; + int activeTimeMonth; + int activeTimeDay; + int activeTimeHour; + int activeTimeMinutes; + int activeTimeSeconds; + int activeTimeDeciSeconds; + int activeTimeUtcOffsetDirection; + int activeTimeUtcOffsetHours; + int activeTimeUtcOffsetMinutes; + +} rdbmsRelTable_data; + + +/* + * TODO:120:r: |-> Review rdbmsRelTable mib index. + * This structure is used to represent the index for rdbmsRelTable. + */ +typedef struct rdbmsRelTable_mib_index_s { + + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long rdbmsDbIndex; + + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long applIndex; + + +} rdbmsRelTable_mib_index; + + /* + * TODO:121:r: | |-> Review rdbmsRelTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. +*/ +#define MAX_rdbmsRelTable_IDX_LEN 2 + + +/* ********************************************************************* + * TODO:130:o: |-> Review rdbmsRelTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * rdbmsRelTable_rowreq_ctx pointer. + */ +typedef struct rdbmsRelTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_rdbmsRelTable_IDX_LEN]; + + rdbmsRelTable_mib_index tbl_idx; + + rdbmsRelTable_data data; + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * implementor's context pointer (provided during registration) + */ + rdbmsRelTable_registration_ptr rdbmsRelTable_reg; + + /* + * TODO:131:o: | |-> Add useful data to rdbmsRelTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *rdbmsRelTable_data_list; + +} rdbmsRelTable_rowreq_ctx; + +typedef struct rdbmsRelTable_ref_rowreq_ctx_s { + rdbmsRelTable_rowreq_ctx *rowreq_ctx; +} rdbmsRelTable_ref_rowreq_ctx; + +/* ********************************************************************* + * function prototypes + */ + int rdbmsRelTable_pre_request(rdbmsRelTable_registration_ptr user_context); + int rdbmsRelTable_post_request(rdbmsRelTable_registration_ptr user_context); + + +extern oid rdbmsRelTable_oid[]; +extern int rdbmsRelTable_oid_size; + + +#include "rdbmsRelTable_interface.h" +#include "rdbmsRelTable_data_access.h" +#include "rdbmsRelTable_data_get.h" +#include "rdbmsRelTable_data_set.h" + +/* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSRELTABLE_H */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_access.c b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_access.c new file mode 100644 index 0000000..e2b6327 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_access.c @@ -0,0 +1,322 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_data_access.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_data_access.c,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsRelTable.h" +#include "rdbmsRelTable_data_access.h" + +/** @defgroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsRelTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsRelTable is subid 9 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.9, length: 9 +*/ + +/** + * initialization for rdbmsRelTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param rdbmsRelTable_reg + * Pointer to rdbmsRelTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +rdbmsRelTable_init_data(rdbmsRelTable_registration_ptr rdbmsRelTable_reg) +{ + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_init_data","called\n")); + + /* + * TODO:303:o: Initialize rdbmsRelTable data. + */ + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ + /* + * if you are the sole writer for the file, you could + * open it here. However, as stated earlier, we are assuming + * the worst case, which in this case means that the file is + * written to by someone else, and might not even exist when + * we start up. So we can't do anything here. + */ + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + + return MFD_SUCCESS; +} /* rdbmsRelTable_init_data */ + +/** + * container-cached overview + * + */ + +/*********************************************************************** + * + * cache + * + ***********************************************************************/ +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +rdbmsRelTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache) +{ + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_container_init","called\n")); + + if((NULL == cache) || (NULL == container_ptr_ptr)) { + snmp_log(LOG_ERR,"bad params to rdbmsRelTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + /* + * TODO:345:A: Set up rdbmsRelTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = RDBMSRELTABLE_CACHE_TIMEOUT; /* seconds */ +} /* rdbmsRelTable_container_init */ + +/** + * load cache data + * + * TODO:350:M: Implement rdbmsRelTable cache load + * + * @param container container to which items should be inserted + * + * @retval MFD_SUCCESS : success. + * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source + * @retval MFD_ERROR : other error. + * + * This function is called to cache the index(es) (and data, optionally) + * for the every row in the data set. + * + * @remark + * While loading the cache, the only important thing is the indexes. + * If access to your data is cheap/fast (e.g. you have a pointer to a + * structure in memory), it would make sense to update the data here. + * If, however, the accessing the data invovles more work (e.g. parsing + * some other existing data, or peforming calculations to derive the data), + * then you can limit yourself to setting the indexes and saving any + * information you will need later. Then use the saved information in + * rdbmsRelTable_row_prep() for populating data. + * + * @note + * If you need consistency between rows (like you want statistics + * for each row to be from the same time frame), you should set all + * data here. + * + */ +int +rdbmsRelTable_cache_load(netsnmp_container *container) +{ + rdbmsRelTable_rowreq_ctx *rowreq_ctx; + long applIndex = 1; + int resultCount, errorCode = MFD_SUCCESS, i, tmpInt, count = 0; + PGresult *pg_db_qry; + + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_cache_load","called\n")); + + /* + * TODO:351:M: |-> Load/update data in the rdbmsRelTable container. + * loop over your rdbmsRelTable data, allocate a rowreq context, + * set the index(es) [and data, optionally] and insert into + * the container. + */ + + if (PQstatus(dbconn) == CONNECTION_OK) + pg_db_qry = PQexec(dbconn, "SELECT datid, EXTRACT(YEAR FROM pg_postmaster_start_time()), EXTRACT(MONTH FROM pg_postmaster_start_time()), EXTRACT(DAY FROM pg_postmaster_start_time()), EXTRACT(HOUR FROM pg_postmaster_start_time()), EXTRACT(MINUTE FROM pg_postmaster_start_time()), EXTRACT(SECOND FROM pg_postmaster_start_time()), EXTRACT(MILLISECOND FROM pg_postmaster_start_time()), EXTRACT(TIMEZONE_HOUR FROM pg_postmaster_start_time()), EXTRACT(TIMEZONE_MINUTE FROM pg_postmaster_start_time()) FROM pg_stat_database"); + else { + snmp_log(LOG_ERR, "Can't get connected to the database"); + return MFD_RESOURCE_UNAVAILABLE; + } + if (PQresultStatus(pg_db_qry) != PGRES_TUPLES_OK) { + snmp_log(LOG_ERR, "Didn't get any results from the database"); + PQclear(pg_db_qry); + /*PQfinish(dbconn);*/ + /* It's probably an error if I didn't find *any* databases */ + return MFD_RESOURCE_UNAVAILABLE; + } + + resultCount = PQntuples(pg_db_qry); + + for(i = 0; i < resultCount; i++) { + + /* + * TODO:352:M: | |-> set indexes in new rdbmsRelTable rowreq context. + */ + rowreq_ctx = rdbmsRelTable_allocate_rowreq_ctx(); + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "memory allocation failed\n"); + errorCode = MFD_RESOURCE_UNAVAILABLE; + break; + } + tmpInt = atoi(PQgetvalue(pg_db_qry, i, 0)); + if(MFD_SUCCESS != rdbmsRelTable_indexes_set(rowreq_ctx + , tmpInt + , applIndex + )) { + snmp_log(LOG_ERR,"error setting index while loading " + "rdbmsRelTable cache.\n"); + rdbmsRelTable_release_rowreq_ctx(rowreq_ctx); + continue; + } + + /* + * TODO:352:r: | |-> populate rdbmsRelTable data context. + * Populate data context here. (optionally, delay until row prep) + */ + + /* All databases are active */ + if(MFD_SUCCESS != + rdbmsRelState_map(&rowreq_ctx->data.rdbmsRelState, INTERNAL_RDBMSRELSTATE_ACTIVE)) { + return MFD_ERROR; + } + + rowreq_ctx->data.activeTimeYear = atoi(PQgetvalue(pg_db_qry, i, 1)); + rowreq_ctx->data.activeTimeMonth = atoi(PQgetvalue(pg_db_qry, i, 2)); + rowreq_ctx->data.activeTimeDay = atoi(PQgetvalue(pg_db_qry, i, 3)); + rowreq_ctx->data.activeTimeHour = atoi(PQgetvalue(pg_db_qry, i, 4)); + rowreq_ctx->data.activeTimeMinutes = atoi(PQgetvalue(pg_db_qry, i, 5)); + rowreq_ctx->data.activeTimeSeconds = atoi(PQgetvalue(pg_db_qry, i, 6)); + rowreq_ctx->data.activeTimeDeciSeconds = atoi(PQgetvalue(pg_db_qry, i, 7)); + rowreq_ctx->data.activeTimeUtcOffsetHours = atoi(PQgetvalue(pg_db_qry, i, 8)); + rowreq_ctx->data.activeTimeUtcOffsetMinutes = atoi(PQgetvalue(pg_db_qry, i, 9)); + tmpInt = rowreq_ctx->data.activeTimeUtcOffsetHours * 60 + rowreq_ctx->data.activeTimeUtcOffsetMinutes; + if (tmpInt == 0) + rowreq_ctx->data.activeTimeUtcOffsetDirection = 0; + else + rowreq_ctx->data.activeTimeUtcOffsetDirection = (tmpInt > 0 ? 1 : -1); + + + /* + * insert into table container + */ + CONTAINER_INSERT(container, rowreq_ctx); + ++count; + } + + DEBUGMSGT(("verbose:rdbmsRelTable:rdbmsRelTable_cache_load", + "inserted %d records\n", count)); + + PQclear(pg_db_qry); + + return errorCode; +} /* rdbmsRelTable_cache_load */ + +/** + * cache clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +rdbmsRelTable_cache_free(netsnmp_container *container) +{ + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_cache_free","called\n")); + + /* + * TODO:380:M: Free rdbmsRelTable cache. + */ +} /* rdbmsRelTable_cache_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +rdbmsRelTable_row_prep( rdbmsRelTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_row_prep","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* rdbmsRelTable_row_prep */ + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_access.h b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_access.h new file mode 100644 index 0000000..195fa5f --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_access.h @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_data_access.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_data_access.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSRELTABLE_DATA_ACCESS_H +#define RDBMSRELTABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ********************************************************************* + * function declarations + */ + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsRelTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsRelTable is subid 9 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.9, length: 9 +*/ + + + int rdbmsRelTable_init_data(rdbmsRelTable_registration_ptr rdbmsRelTable_reg); + + +/* + * TODO:180:o: Review rdbmsRelTable cache timeout. + * The number of seconds before the cache times out + */ +#define RDBMSRELTABLE_CACHE_TIMEOUT 60 + +void rdbmsRelTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache); +int rdbmsRelTable_cache_load(netsnmp_container *container); +void rdbmsRelTable_cache_free(netsnmp_container *container); + + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ +/* ********************************************************************* + * Since we have no idea how you really access your data, we'll go with + * a worst case example: a flat text file. + */ +#define MAX_LINE_SIZE 256 + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + int rdbmsRelTable_row_prep( rdbmsRelTable_rowreq_ctx *rowreq_ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSRELTABLE_DATA_ACCESS_H */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_get.c b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_get.c new file mode 100644 index 0000000..9895a63 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_get.c @@ -0,0 +1,378 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_data_get.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_data_get.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsRelTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement rdbmsRelTable get routines. + * TODO:240:M: Implement rdbmsRelTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsRelTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsRelTable is subid 9 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.9, length: 9 +*/ + +/* --------------------------------------------------------------------- + * TODO:200:r: Implement rdbmsRelTable data context functions. + */ + + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This convenience function is useful for setting all the MIB index + * components with a single function call. It is assume that the C values + * have already been mapped from their native/rawformat to the MIB format. + */ +int +rdbmsRelTable_indexes_set_tbl_idx(rdbmsRelTable_mib_index *tbl_idx, long rdbmsDbIndex_val, long applIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_indexes_set_tbl_idx","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->rdbmsDbIndex = rdbmsDbIndex_val; + + /* applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->applIndex = applIndex_val; + + + return MFD_SUCCESS; +} /* rdbmsRelTable_indexes_set_tbl_idx */ + +/** + * @internal + * set row context indexes + * + * @param reqreq_ctx the row context that needs updated indexes + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This function sets the mib indexs, then updates the oid indexs + * from the mib index. + */ +int +rdbmsRelTable_indexes_set(rdbmsRelTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val, long applIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_indexes_set","called\n")); + + if(MFD_SUCCESS != rdbmsRelTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx + , rdbmsDbIndex_val + , applIndex_val + )) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if(0 != rdbmsRelTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsRelTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsRelEntry.rdbmsRelState + * rdbmsRelState is subid 1 of rdbmsRelEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.9.1.1 + * Description: +The state of this server's access to this database. + Active(2) means the server is actively using the database. + Available(3) means the server could use the database if + necessary. Restricted(4) means the database is in some + administratively determined state of less-than-complete + availability. Unavailable(5) means the database is not + available through this server. Other(1) means the + database/server is in some other condition, possibly + described in the vendor private MIB. + * + * Attributes: + * accessible 1 isscalar 0 enums 1 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * Enum range: 3/8. Values: other(1), active(2), available(3), restricted(4), unavailable(5) + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsRelState.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsRelState_map(u_long *mib_rdbmsRelState_val_ptr, u_long raw_rdbmsRelState_val) +{ + netsnmp_assert(NULL != mib_rdbmsRelState_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelState_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsRelState enum mapping. + * uses INTERNAL_* macros defined in the header files + */ + switch(raw_rdbmsRelState_val) { + case INTERNAL_RDBMSRELSTATE_OTHER: + *mib_rdbmsRelState_val_ptr = RDBMSRELSTATE_OTHER; + break; + + case INTERNAL_RDBMSRELSTATE_ACTIVE: + *mib_rdbmsRelState_val_ptr = RDBMSRELSTATE_ACTIVE; + break; + + case INTERNAL_RDBMSRELSTATE_AVAILABLE: + *mib_rdbmsRelState_val_ptr = RDBMSRELSTATE_AVAILABLE; + break; + + case INTERNAL_RDBMSRELSTATE_RESTRICTED: + *mib_rdbmsRelState_val_ptr = RDBMSRELSTATE_RESTRICTED; + break; + + case INTERNAL_RDBMSRELSTATE_UNAVAILABLE: + *mib_rdbmsRelState_val_ptr = RDBMSRELSTATE_UNAVAILABLE; + break; + + default: + snmp_log(LOG_ERR, "couldn't map value %ld for rdbmsRelState\n", raw_rdbmsRelState_val ); + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsRelState_map */ + +/** + * Extract the current value of the rdbmsRelState data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsRelState_val_ptr + * Pointer to storage for a long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsRelState_get( rdbmsRelTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsRelState_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsRelState_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelState_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsRelState data. + * set (* rdbmsRelState_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsRelState_val_ptr ) = rowreq_ctx->data.rdbmsRelState; + + return MFD_SUCCESS; +} /* rdbmsRelState_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsRelEntry.rdbmsRelActiveTime + * rdbmsRelActiveTime is subid 2 of rdbmsRelEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.9.1.2 + * Description: +The time the database was made active by the server. If an + instance of rdbmsRelState is not active(1), then attempts to + access the corresponding instance of this object may result + in either noSuchName (SNMPv1) or noSuchInstance (SNMPv2) + being returned by the agent. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 2d-1d-1d,1d:1d:1d.1d,1a1d:1d + * + * Ranges: 8, 11; + * + * Its syntax is DateAndTime (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 11) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsRelActiveTime.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsRelActiveTime_map(char **mib_rdbmsRelActiveTime_val_ptr_ptr, size_t *mib_rdbmsRelActiveTime_val_ptr_len_ptr, char *raw_rdbmsRelActiveTime_val_ptr, size_t raw_rdbmsRelActiveTime_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsRelActiveTime_val_ptr); + netsnmp_assert((NULL != mib_rdbmsRelActiveTime_val_ptr_ptr) && (NULL != mib_rdbmsRelActiveTime_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelActiveTime_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsRelActiveTime non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsRelActiveTime_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsRelActiveTime_val_ptr_ptr) || (*mib_rdbmsRelActiveTime_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsRelActiveTime_val_ptr_ptr = realloc( *mib_rdbmsRelActiveTime_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsRelActiveTime_val_ptr_ptr)); + if(NULL == *mib_rdbmsRelActiveTime_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsRelActiveTime_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsRelActiveTime_val_ptr_ptr, raw_rdbmsRelActiveTime_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsRelActiveTime_map */ + +/** + * Extract the current value of the rdbmsRelActiveTime data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsRelActiveTime_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsRelActiveTime_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsRelActiveTime. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsRelActiveTime_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsRelActiveTime_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsRelActiveTime_get( rdbmsRelTable_rowreq_ctx *rowreq_ctx, char **rdbmsRelActiveTime_val_ptr_ptr, size_t *rdbmsRelActiveTime_val_ptr_len_ptr ) +{ + int rc; + /** we should have a pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsRelActiveTime_val_ptr_ptr) && (NULL != *rdbmsRelActiveTime_val_ptr_ptr)); + netsnmp_assert( (NULL != rdbmsRelActiveTime_val_ptr_len_ptr) && ((* rdbmsRelActiveTime_val_ptr_len_ptr) >= 11)); + + /* + * TODO:231:o: |-> copy rdbmsRelActiveTime data. + * get the date from your context pointer. + */ + + /* call convenience function to set data */ + rc = netsnmp_dateandtime_set_buf_from_vars((u_char *)*rdbmsRelActiveTime_val_ptr_ptr, rdbmsRelActiveTime_val_ptr_len_ptr, + rowreq_ctx->data.activeTimeYear, + rowreq_ctx->data.activeTimeMonth, + rowreq_ctx->data.activeTimeDay, + rowreq_ctx->data.activeTimeHour, + rowreq_ctx->data.activeTimeMinutes, + rowreq_ctx->data.activeTimeSeconds, + rowreq_ctx->data.activeTimeDeciSeconds, + rowreq_ctx->data.activeTimeUtcOffsetDirection, + rowreq_ctx->data.activeTimeUtcOffsetHours, + rowreq_ctx->data.activeTimeUtcOffsetMinutes); + if(rc != SNMP_ERR_NOERROR) + return rc; + + + return MFD_SUCCESS; +} /* rdbmsRelActiveTime_get */ + + + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_get.h b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_get.h new file mode 100644 index 0000000..2f86b58 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_get.h @@ -0,0 +1,63 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_data_get.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_data_get.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSRELTABLE_DATA_GET_H +#define RDBMSRELTABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * GET function declarations + */ + +/* ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsRelTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsRelTable is subid 9 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.9, length: 9 +*/ + /* + * indexes + */ + int rdbmsDbIndex_map(long *mib_rdbmsDbIndex_val_ptr, long raw_rdbmsDbIndex_val); + int applIndex_map(long *mib_applIndex_val_ptr, long raw_applIndex_val); + + int rdbmsRelState_map(u_long *mib_rdbmsRelState_val_ptr, u_long raw_rdbmsRelState_val); + int rdbmsRelState_get( rdbmsRelTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsRelState_val_ptr ); + int rdbmsRelActiveTime_map(char **mib_rdbmsRelActiveTime_val_ptr_ptr, size_t *mib_rdbmsRelActiveTime_val_ptr_len_ptr, char *raw_rdbmsRelActiveTime_val_ptr, size_t raw_rdbmsRelActiveTime_val_ptr_len, int allow_realloc); + int rdbmsRelActiveTime_get( rdbmsRelTable_rowreq_ctx *rowreq_ctx, char **rdbmsRelActiveTime_val_ptr_ptr, size_t *rdbmsRelActiveTime_val_ptr_len_ptr ); + + +int rdbmsRelTable_indexes_set_tbl_idx(rdbmsRelTable_mib_index *tbl_idx, long rdbmsDbIndex_val, long applIndex_val); +int rdbmsRelTable_indexes_set(rdbmsRelTable_rowreq_ctx *rowreq_ctx, long rdbmsDbIndex_val, long applIndex_val); + + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSRELTABLE_DATA_GET_H */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_set.c b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_set.c new file mode 100644 index 0000000..a2de409 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_set.c @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_data_set.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_data_set.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsRelTable.h" + + +/** @defgroup data_set data_set: Routines to set data + * + * These routines are used to set the value for individual objects. The + * row context is passed, along with the new value. + * + * @{ + */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_set.h b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_set.h new file mode 100644 index 0000000..3b62de5 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_data_set.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_data_set.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_data_set.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSRELTABLE_DATA_SET_H +#define RDBMSRELTABLE_DATA_SET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * SET function declarations + */ + +/* ********************************************************************* + * SET Table declarations + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSRELTABLE_DATA_SET_H */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_enums.h b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_enums.h new file mode 100644 index 0000000..7415b02 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_enums.h @@ -0,0 +1,76 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_enums.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_enums.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSRELTABLE_ENUMS_H +#define RDBMSRELTABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table rdbmsRelTable + * + ************************************************************************* + *************************************************************************/ + +/************************************************************* + * constants for enums for the MIB node + * rdbmsRelState (INTEGER / ASN_INTEGER) + * + * since a Textual Convention may be referenced more than once in a + * MIB, protect againt redefinitions of the enum values. + */ +#ifndef RDBMSRELSTATE_ENUMS +#define RDBMSRELSTATE_ENUMS + +#define RDBMSRELSTATE_OTHER 1 +#define RDBMSRELSTATE_ACTIVE 2 +#define RDBMSRELSTATE_AVAILABLE 3 +#define RDBMSRELSTATE_RESTRICTED 4 +#define RDBMSRELSTATE_UNAVAILABLE 5 + + +#endif /* RDBMSRELSTATE_ENUMS */ + + /* + * TODO:140:o: Define interal representation of rdbmsRelState enums. + * (used for value mapping; see notes at top of file) + */ +#define INTERNAL_RDBMSRELSTATE_OTHER 1 +#define INTERNAL_RDBMSRELSTATE_ACTIVE 2 +#define INTERNAL_RDBMSRELSTATE_AVAILABLE 3 +#define INTERNAL_RDBMSRELSTATE_RESTRICTED 4 +#define INTERNAL_RDBMSRELSTATE_UNAVAILABLE 5 + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSRELTABLE_ENUMS_H */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_interface.c b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_interface.c new file mode 100644 index 0000000..6329fac --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_interface.c @@ -0,0 +1,712 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_interface.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_interface.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsRelTable.h" + + +#include <net-snmp/library/container.h> + +#include "rdbmsRelTable_interface.h" + +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsRelTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsRelTable is subid 9 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.9, length: 9 +*/ +typedef struct rdbmsRelTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; /* optional cache */ + + rdbmsRelTable_registration_ptr user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} rdbmsRelTable_interface_ctx; + +static rdbmsRelTable_interface_ctx rdbmsRelTable_if_ctx; + +static void _rdbmsRelTable_container_init( + rdbmsRelTable_interface_ctx *if_ctx); + + +static Netsnmp_Node_Handler _mfd_rdbmsRelTable_pre_request; +static Netsnmp_Node_Handler _mfd_rdbmsRelTable_post_request; +static Netsnmp_Node_Handler _mfd_rdbmsRelTable_object_lookup; +static Netsnmp_Node_Handler _mfd_rdbmsRelTable_get_values; +/** + * @internal + * Initialize the table rdbmsRelTable + * (Define its contents and how it's structured) + */ +void +_rdbmsRelTable_initialize_interface(rdbmsRelTable_registration_ptr reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &rdbmsRelTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = &rdbmsRelTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:rdbmsRelTable:_rdbmsRelTable_initialize_interface","called\n")); + + + /************************************************* + * + * save interface context for rdbmsRelTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, + ASN_INTEGER, /** index: rdbmsDbIndex */ + ASN_INTEGER, /** index: applIndex */ + 0); + + /* Define the minimum and maximum accessible columns. This + optimizes retrival. */ + tbl_info->min_column = RDBMSRELTABLE_MIN_COL; + tbl_info->max_column = RDBMSRELTABLE_MAX_COL; + + /* + * save users context + */ + rdbmsRelTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + rdbmsRelTable_init_data(reg_ptr); + + /* + * set up the container + */ + _rdbmsRelTable_container_init(&rdbmsRelTable_if_ctx); + if (NULL == rdbmsRelTable_if_ctx.container) { + snmp_log(LOG_ERR,"could not initialize container for rdbmsRelTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = _mfd_rdbmsRelTable_object_lookup; + access_multiplexer->get_values = _mfd_rdbmsRelTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = _mfd_rdbmsRelTable_pre_request; + access_multiplexer->post_request = _mfd_rdbmsRelTable_post_request; + + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("rdbmsRelTable:init_rdbmsRelTable", + "Registering rdbmsRelTable as a mibs-for-dummies table.\n")); + handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = netsnmp_handler_registration_create("rdbmsRelTable", handler, + rdbmsRelTable_oid, + rdbmsRelTable_oid_size, + HANDLER_CAN_BABY_STEP | + HANDLER_CAN_RONLY + ); + if(NULL == reginfo) { + snmp_log(LOG_ERR,"error registering table rdbmsRelTable\n"); + return; + } + reginfo->my_reg_void = &rdbmsRelTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if( access_multiplexer->object_lookup ) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if( access_multiplexer->set_values ) + mfd_modes |= BABY_STEP_SET_VALUES; + if( access_multiplexer->irreversible_commit ) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if( access_multiplexer->object_syntax_checks ) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if( access_multiplexer->pre_request ) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if( access_multiplexer->post_request ) + mfd_modes |= BABY_STEP_POST_REQUEST; + + if( access_multiplexer->undo_setup ) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if( access_multiplexer->undo_cleanup ) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if( access_multiplexer->undo_sets ) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if( access_multiplexer->row_creation ) + mfd_modes |= BABY_STEP_ROW_CREATE; + if( access_multiplexer->consistency_checks ) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if( access_multiplexer->commit ) + mfd_modes |= BABY_STEP_COMMIT; + if( access_multiplexer->undo_commit ) + mfd_modes |= BABY_STEP_UNDO_COMMIT; + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + rdbmsRelTable_if_ctx.container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler( reginfo, handler ); + + /************************************************* + * + * inject cache helper + */ + if(NULL != rdbmsRelTable_if_ctx.cache) { + handler = netsnmp_cache_handler_get(rdbmsRelTable_if_ctx.cache); + netsnmp_inject_handler( reginfo, handler ); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); +} /* _rdbmsRelTable_initialize_interface */ + +void +rdbmsRelTable_valid_columns_set(netsnmp_column_info *vc) +{ + rdbmsRelTable_if_ctx.tbl_info.valid_columns = vc; +} /* rdbmsRelTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +rdbmsRelTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsRelTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_applIndex; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + memset( &var_applIndex, 0x00, sizeof(var_applIndex) ); + var_applIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = &var_applIndex; var_applIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_index_to_oid","called\n")); + + /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_rdbmsDbIndex, (u_char*)&mib_idx->rdbmsDbIndex, + sizeof(mib_idx->rdbmsDbIndex)); + + /* applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_applIndex, (u_char*)&mib_idx->applIndex, + sizeof(mib_idx->applIndex)); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, (size_t *)&oid_idx->len, + NULL, 0, &var_rdbmsDbIndex); + if(err) + snmp_log(LOG_ERR,"error %d converting index to oid\n", err); + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsRelTable_index_to_oid */ + +/** + * extract rdbmsRelTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +rdbmsRelTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsRelTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsDbIndex; + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_applIndex; + + /* + * set up varbinds + */ + memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); + var_rdbmsDbIndex.type = ASN_INTEGER; + memset( &var_applIndex, 0x00, sizeof(var_applIndex) ); + var_applIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_rdbmsDbIndex.next_variable = &var_applIndex; var_applIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsRelTable:rdbmsRelTable_index_from_oid","called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes( oid_idx->oids, oid_idx->len, + &var_rdbmsDbIndex ); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + mib_idx->rdbmsDbIndex = *((long *)var_rdbmsDbIndex.val.string); + mib_idx->applIndex = *((long *)var_applIndex.val.string); + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_rdbmsDbIndex ); + + return err; +} /* rdbmsRelTable_index_from_oid */ + + +/* ********************************************************************* + * @internal + * allocate resources for a rdbmsRelTable_rowreq_ctx + */ +rdbmsRelTable_rowreq_ctx * +rdbmsRelTable_allocate_rowreq_ctx(void) +{ + rdbmsRelTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(rdbmsRelTable_rowreq_ctx); + + DEBUGMSGTL(("internal:rdbmsRelTable:rdbmsRelTable_allocate_rowreq_ctx","called\n")); + + if(NULL == rowreq_ctx) { + snmp_log(LOG_ERR,"Couldn't allocate memory for a " + "rdbmsRelTable_rowreq_ctx.\n"); + } + + rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; + + rowreq_ctx->rdbmsRelTable_data_list = NULL; + rowreq_ctx->rdbmsRelTable_reg = rdbmsRelTable_if_ctx.user_ctx; + + + return rowreq_ctx; +} /* rdbmsRelTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a rdbmsRelTable_rowreq_ctx + */ +void +rdbmsRelTable_release_rowreq_ctx(rdbmsRelTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("internal:rdbmsRelTable:rdbmsRelTable_release_rowreq_ctx","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + + /* + * free index oid pointer + */ + if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* rdbmsRelTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsRelTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc = rdbmsRelTable_pre_request(rdbmsRelTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsRelTable","error %d from " + "rdbmsRelTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsRelTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsRelTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsRelTable_rowreq_ctx *rowreq_ctx; + int rc = rdbmsRelTable_post_request(rdbmsRelTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsRelTable","error %d from " + "rdbmsRelTable_post_request\n", rc)); + } + + /* + * if there are no errors, check for and handle row creation/deletion + */ + rc = netsnmp_check_requests_error(requests); + if ((SNMP_ERR_NOERROR == rc) && + (NULL != + (rowreq_ctx = netsnmp_container_table_row_extract(requests)))) { + if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) { + rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; + CONTAINER_INSERT(rdbmsRelTable_if_ctx.container, rowreq_ctx); + } + else if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { + CONTAINER_REMOVE(rdbmsRelTable_if_ctx.container, rowreq_ctx); + rdbmsRelTable_release_rowreq_ctx(rowreq_ctx); + } + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsRelTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsRelTable_object_lookup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsRelTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsRelTable:_mfd_rdbmsRelTable_object_lookup","called\n")); + + /* + * get our context from mfd + * rdbmsRelTable_interface_ctx *if_ctx = + * (rdbmsRelTable_interface_ctx *)reginfo->my_reg_void; + */ + + if(NULL == rowreq_ctx) { + netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION); + } + else { + rdbmsRelTable_row_prep(rowreq_ctx); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsRelTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsRelTable_get_column( rdbmsRelTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsRelTable:_mfd_rdbmsRelTable_get_column","called\n")); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsRelState(1)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h */ + case COLUMN_RDBMSRELSTATE: + var->val_len = sizeof(u_long); + var->type = ASN_INTEGER; +rc = rdbmsRelState_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsRelActiveTime(2)/DateAndTime/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ + case COLUMN_RDBMSRELACTIVETIME: + var->type = ASN_OCTET_STR; +rc = rdbmsRelActiveTime_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsRelTable_get_column\n", column); + break; + } + + return rc; +} /* _rdbmsRelTable_get_column */ + +int +_mfd_rdbmsRelTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsRelTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + u_char * old_string; + void (*dataFreeHook)(void *); + int rc; + + DEBUGMSGTL(("internal:rdbmsRelTable:_mfd_rdbmsRelTable_get_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if(NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + else if(requests->requestvb->buf == requests->requestvb->val.string) { + if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsRelTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + if(MFD_SKIP == rc) { + requests->requestvb->type = ASN_PRIV_RETRY; + rc = SNMP_ERR_NOERROR; + } + } + else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if(rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if(old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if(dataFreeHook) + (*dataFreeHook)(old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsRelTable_get_values */ + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/* + * NOT APPLICABLE (per MIB or user setting) + */ +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +/** + * @internal + */ +static int +_cache_load(netsnmp_cache *cache, void *vmagic) +{ + DEBUGMSGTL(("internal:rdbmsRelTable:_cache_load","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache for rdbmsRelTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return rdbmsRelTable_cache_load((netsnmp_container*)cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_item_free(rdbmsRelTable_rowreq_ctx *rowreq_ctx, void *context) +{ + DEBUGMSGTL(("internal:rdbmsRelTable:_cache_item_free","called\n")); + + if(NULL == rowreq_ctx) + return; + + rdbmsRelTable_release_rowreq_ctx(rowreq_ctx); +} /* _cache_item_free */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache *cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:rdbmsRelTable:_cache_free","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache in rdbmsRelTable_cache_free\n"); + return; + } + + container = (netsnmp_container*)cache->magic; + + /* + * call user code + */ + rdbmsRelTable_cache_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *)_cache_item_free, + NULL); +} /* _cache_free */ + +/** + * @internal + * initialize the iterator container with functions or wrappers + */ +void +_rdbmsRelTable_container_init(rdbmsRelTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:rdbmsRelTable:_rdbmsRelTable_container_init","called\n")); + + /* + * set up the cache + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + rdbmsRelTable_oid, + rdbmsRelTable_oid_size); + + if(NULL == if_ctx->cache) { + snmp_log(LOG_ERR, "error creating cache for rdbmsRelTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + rdbmsRelTable_container_init(&if_ctx->container, if_ctx->cache); + if(NULL == if_ctx->container) + if_ctx->container = netsnmp_container_find("rdbmsRelTable:table_container"); + if(NULL == if_ctx->container) { + snmp_log(LOG_ERR,"error creating container in " + "rdbmsRelTable_container_init\n"); + return; + } + if_ctx->cache->magic = (void*)if_ctx->container; +} /* _rdbmsRelTable_container_init */ + diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_interface.h b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_interface.h new file mode 100644 index 0000000..148c92d --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_interface.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_interface.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_interface.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSRELTABLE_INTERFACE_H +#define RDBMSRELTABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "rdbmsRelTable.h" + +/* ******************************************************************** + * Table declarations + */ + +/* PUBLIC interface initialization routine */ +void _rdbmsRelTable_initialize_interface(rdbmsRelTable_registration_ptr user_ctx, + u_long flags); + + rdbmsRelTable_rowreq_ctx * rdbmsRelTable_allocate_rowreq_ctx(void); +void rdbmsRelTable_release_rowreq_ctx(rdbmsRelTable_rowreq_ctx *rowreq_ctx); + +int rdbmsRelTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsRelTable_mib_index *mib_idx); +int rdbmsRelTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsRelTable_mib_index *mib_idx); + +/* + * access to certain internals. use with caution! + */ +void rdbmsRelTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSRELTABLE_INTERFACE_H */ diff --git a/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_oids.h b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_oids.h new file mode 100644 index 0000000..371f101 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsRelTable/rdbmsRelTable_oids.h @@ -0,0 +1,35 @@ +/*------------------------------------------------------------------------- + * rdbmsRelTable_oids.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsRelTable_oids.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSRELTABLE_OIDS_H +#define RDBMSRELTABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* column number definitions for table rdbmsRelTable */ +#define RDBMSRELTABLE_OID 1,3,6,1,2,1,39,1,9 +#define COLUMN_RDBMSRELSTATE 1 +#define COLUMN_RDBMSRELACTIVETIME 2 + +#define RDBMSRELTABLE_MIN_COL COLUMN_RDBMSRELSTATE +#define RDBMSRELTABLE_MAX_COL COLUMN_RDBMSRELACTIVETIME + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSRELTABLE_OIDS_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/README b/RDBMS-MIB_src/rdbmsSrvInfoTable/README new file mode 100644 index 0000000..d2cd2fe --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/README @@ -0,0 +1 @@ +For PostgreSQL version 8.0.x, rdbmsSrvInfoStartupTime is not properly reported, because that information is unavailable. diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable.c b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable.c new file mode 100644 index 0000000..264eb69 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable.c @@ -0,0 +1,127 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsSrvInfoTable.h" + +/*#include <net-snmp/agent/mib_modules.h> */ + +#include "rdbmsSrvInfoTable_interface.h" + +oid rdbmsSrvInfoTable_oid[] = { RDBMSSRVINFOTABLE_OID }; +int rdbmsSrvInfoTable_oid_size = OID_LENGTH(rdbmsSrvInfoTable_oid); + +void initialize_table_rdbmsSrvInfoTable(void); + + +/** + * Initializes the rdbmsSrvInfoTable module + */ +void +init_rdbmsSrvInfoTable(void) +{ + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:init_rdbmsSrvInfoTable","called\n")); + + /* + * TODO:300:o: Perform rdbmsSrvInfoTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("rdbmsSrvInfoTable")) + initialize_table_rdbmsSrvInfoTable(); + +} /* init_rdbmsSrvInfoTable */ + +/** + * Initialize the table rdbmsSrvInfoTable + * (Define its contents and how it's structured) + */ +void +initialize_table_rdbmsSrvInfoTable(void) +{ + rdbmsSrvInfoTable_registration_ptr user_context; + u_long flags; + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:initialize_table_rdbmsSrvInfoTable","called\n")); + + /* + * TODO:301:o: Perform rdbmsSrvInfoTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize rdbmsSrvInfoTable user context + * if you'd like to pass in a pointer to some data for this + * table, allocate or set it up here. + */ + /* + * a netsnmp_data_list is a simple way to store void pointers. A simple + * string token is used to add, find or remove pointers. + */ + user_context = netsnmp_create_data_list("rdbmsSrvInfoTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _rdbmsSrvInfoTable_initialize_interface(user_context, flags); +} /* initialize_table_rdbmsSrvInfoTable */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +rdbmsSrvInfoTable_pre_request(rdbmsSrvInfoTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_pre_request","called\n")); + + /* + * TODO:510:o: Perform rdbmsSrvInfoTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvInfoTable_pre_request */ + +/** + * post-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error (ignored) + */ +int +rdbmsSrvInfoTable_post_request(rdbmsSrvInfoTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_post_request","called\n")); + + /* + * TODO:511:o: Perform rdbmsSrvInfoTable pos-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvInfoTable_post_request */ + + +/** @{ */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable.h b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable.h new file mode 100644 index 0000000..77389c6 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable.h @@ -0,0 +1,262 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVINFOTABLE_H +#define RDBMSSRVINFOTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @defgroup misc misc: Miscelaneous routines + * + * @{ + */ +#include <net-snmp/library/asn1.h> + +/* other required module components */ + /* *INDENT-OFF* */ +config_require(RDBMS-MIB/rdbmsSrvInfoTable/rdbmsSrvInfoTable_interface); +config_require(RDBMS-MIB/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_access); +config_require(RDBMS-MIB/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_get); +config_require(RDBMS-MIB/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_set); + /* *INDENT-ON* */ + +/* OID and column number definitions for */ +#include "rdbmsSrvInfoTable_oids.h" + +/* enum definions */ +#include "rdbmsSrvInfoTable_enums.h" + +/* ********************************************************************* + * function declarations + */ +void init_rdbmsSrvInfoTable(void); + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvInfoTable is subid 6 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.6, length: 9 +*/ +/* ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review rdbmsSrvInfoTable registration context. + */ +typedef netsnmp_data_list * rdbmsSrvInfoTable_registration_ptr; + +/**********************************************************************/ +/* + * TODO:110:r: |-> Review rdbmsSrvInfoTable data context structure. + * This structure is used to represent the data for rdbmsSrvInfoTable. + */ +/* + * This structure contains storage for all the columns defined in the + * rdbmsSrvInfoTable. + */ +typedef struct rdbmsSrvInfoTable_data_s { + + /* + * rdbmsSrvInfoStartupTime(1)/DateAndTime/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ +/* char rdbmsSrvInfoStartupTime[11]; +size_t rdbmsSrvInfoStartupTime_len; *//* # of char elements, not bytes */ + int startupYear; + int startupMonth; + int startupDay; + int startupHour; + int startupMinutes; + int startupSeconds; + int startupDeciSeconds; + int startupUtcOffsetDirection; + int startupUtcOffsetHours; + int startupUtcOffsetMinutes; + + /* + * rdbmsSrvInfoFinishedTransactions(2)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoFinishedTransactions; + + /* + * rdbmsSrvInfoDiskReads(3)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoDiskReads; + + /* + * rdbmsSrvInfoLogicalReads(4)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoLogicalReads; + + /* + * rdbmsSrvInfoDiskWrites(5)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoDiskWrites; + + /* + * rdbmsSrvInfoLogicalWrites(6)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoLogicalWrites; + + /* + * rdbmsSrvInfoPageReads(7)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoPageReads; + + /* + * rdbmsSrvInfoPageWrites(8)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoPageWrites; + + /* + * rdbmsSrvInfoDiskOutOfSpaces(9)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoDiskOutOfSpaces; + + /* + * rdbmsSrvInfoHandledRequests(10)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoHandledRequests; + + /* + * rdbmsSrvInfoRequestRecvs(11)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoRequestRecvs; + + /* + * rdbmsSrvInfoRequestSends(12)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoRequestSends; + + /* + * rdbmsSrvInfoHighwaterInboundAssociations(13)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h + */ + u_long rdbmsSrvInfoHighwaterInboundAssociations; + + /* + * rdbmsSrvInfoMaxInboundAssociations(14)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/W/e/r/d/h + */ + u_long rdbmsSrvInfoMaxInboundAssociations; + +} rdbmsSrvInfoTable_data; + + +/* + * TODO:120:r: |-> Review rdbmsSrvInfoTable mib index. + * This structure is used to represent the index for rdbmsSrvInfoTable. + */ +typedef struct rdbmsSrvInfoTable_mib_index_s { + + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long applIndex; + + +} rdbmsSrvInfoTable_mib_index; + + /* + * TODO:121:r: | |-> Review rdbmsSrvInfoTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. +*/ +#define MAX_rdbmsSrvInfoTable_IDX_LEN 1 + + +/* ********************************************************************* + * TODO:130:o: |-> Review rdbmsSrvInfoTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * rdbmsSrvInfoTable_rowreq_ctx pointer. + */ +typedef struct rdbmsSrvInfoTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_rdbmsSrvInfoTable_IDX_LEN]; + + rdbmsSrvInfoTable_mib_index tbl_idx; + + rdbmsSrvInfoTable_data data; + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * implementor's context pointer (provided during registration) + */ + rdbmsSrvInfoTable_registration_ptr rdbmsSrvInfoTable_reg; + + /* + * TODO:131:o: | |-> Add useful data to rdbmsSrvInfoTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *rdbmsSrvInfoTable_data_list; + +} rdbmsSrvInfoTable_rowreq_ctx; + +typedef struct rdbmsSrvInfoTable_ref_rowreq_ctx_s { + rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx; +} rdbmsSrvInfoTable_ref_rowreq_ctx; + +/* ********************************************************************* + * function prototypes + */ + int rdbmsSrvInfoTable_pre_request(rdbmsSrvInfoTable_registration_ptr user_context); + int rdbmsSrvInfoTable_post_request(rdbmsSrvInfoTable_registration_ptr user_context); + + +extern oid rdbmsSrvInfoTable_oid[]; +extern int rdbmsSrvInfoTable_oid_size; + + +#include "rdbmsSrvInfoTable_interface.h" +#include "rdbmsSrvInfoTable_data_access.h" +#include "rdbmsSrvInfoTable_data_get.h" +#include "rdbmsSrvInfoTable_data_set.h" + +/* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVINFOTABLE_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_access.c b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_access.c new file mode 100644 index 0000000..af424be --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_access.c @@ -0,0 +1,340 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_data_access.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_data_access.c,v 1.7 2009/06/06 04:12:10 eggyknap Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsSrvInfoTable.h" + + +#include "rdbmsSrvInfoTable_data_access.h" + +/** @defgroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvInfoTable is subid 6 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.6, length: 9 +*/ + +/** + * initialization for rdbmsSrvInfoTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param rdbmsSrvInfoTable_reg + * Pointer to rdbmsSrvInfoTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +rdbmsSrvInfoTable_init_data(rdbmsSrvInfoTable_registration_ptr rdbmsSrvInfoTable_reg) +{ + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_init_data","called\n")); + + return MFD_SUCCESS; +} /* rdbmsSrvInfoTable_init_data */ + +/** + * container-cached overview + * + */ + +/*********************************************************************** + * + * cache + * + ***********************************************************************/ +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +rdbmsSrvInfoTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache) +{ + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_container_init","called\n")); + + if((NULL == cache) || (NULL == container_ptr_ptr)) { + snmp_log(LOG_ERR,"bad params to rdbmsSrvInfoTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + /* + * TODO:345:A: Set up rdbmsSrvInfoTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = RDBMSSRVINFOTABLE_CACHE_TIMEOUT; /* seconds */ +} /* rdbmsSrvInfoTable_container_init */ + +/** + * load cache data + * + * TODO:350:M: Implement rdbmsSrvInfoTable cache load + * + * @param container container to which items should be inserted + * + * @retval MFD_SUCCESS : success. + * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source + * @retval MFD_ERROR : other error. + * + * This function is called to cache the index(es) (and data, optionally) + * for the every row in the data set. + * + * @remark + * While loading the cache, the only important thing is the indexes. + * If access to your data is cheap/fast (e.g. you have a pointer to a + * structure in memory), it would make sense to update the data here. + * If, however, the accessing the data invovles more work (e.g. parsing + * some other existing data, or peforming calculations to derive the data), + * then you can limit yourself to setting the indexes and saving any + * information you will need later. Then use the saved information in + * rdbmsSrvInfoTable_row_prep() for populating data. + * + * @note + * If you need consistency between rows (like you want statistics + * for each row to be from the same time frame), you should set all + * data here. + * + */ +int +rdbmsSrvInfoTable_cache_load(netsnmp_container *container) +{ + rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx; + size_t count = 0; + PGresult *pg_db_qry; + static int maxAssociations = 0; + + long applIndex; + int resultCount, tmpInt, rdbmsSrvInfoMaxInboundAssociations = 0, i, errorCode = MFD_SUCCESS; + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_cache_load","called\n")); + + if (PQstatus(dbconn) == CONNECTION_OK) { + pg_db_qry = PQexec(dbconn, "SELECT setting FROM pg_settings WHERE name = 'max_connections'"); + if (PQresultStatus(pg_db_qry) == PGRES_TUPLES_OK) + rdbmsSrvInfoMaxInboundAssociations = atoi(PQgetvalue(pg_db_qry, 0, 0)); + PQclear(pg_db_qry); + pg_db_qry = PQexec(dbconn, "SELECT setting FROM pg_settings WHERE name = 'superuser_reserved_connections'"); + if (PQresultStatus(pg_db_qry) == PGRES_TUPLES_OK) + rdbmsSrvInfoMaxInboundAssociations -= atoi(PQgetvalue(pg_db_qry, 0, 0)); + PQclear(pg_db_qry); + pg_db_qry = PQexec(dbconn, "SELECT count(1) FROM pg_stat_activity"); + if (PQresultStatus(pg_db_qry) == PGRES_TUPLES_OK) { + tmpInt = atoi(PQgetvalue(pg_db_qry, 0, 0)); + maxAssociations = (tmpInt > maxAssociations) ? tmpInt : maxAssociations; + } + PQclear(pg_db_qry); + if (PQserverVersion(dbconn) < 80100) + pg_db_qry = PQexec(dbconn, "SELECT datid, EXTRACT(YEAR FROM now()), EXTRACT(MONTH FROM now()), EXTRACT(DAY FROM now()), EXTRACT(HOUR FROM now()), EXTRACT(MINUTE FROM now()), EXTRACT(SECOND FROM now()), EXTRACT(MILLISECOND FROM now()), EXTRACT(TIMEZONE_HOUR FROM now()), EXTRACT(TIMEZONE_MINUTE FROM now()), xact_commit, blks_read, blks_read + blks_hit FROM pg_stat_database"); + else + pg_db_qry = PQexec(dbconn, "SELECT datid, EXTRACT(YEAR FROM pg_postmaster_start_time()), EXTRACT(MONTH FROM pg_postmaster_start_time()), EXTRACT(DAY FROM pg_postmaster_start_time()), EXTRACT(HOUR FROM pg_postmaster_start_time()), EXTRACT(MINUTE FROM pg_postmaster_start_time()), EXTRACT(SECOND FROM pg_postmaster_start_time()), EXTRACT(MILLISECOND FROM pg_postmaster_start_time()), EXTRACT(TIMEZONE_HOUR FROM pg_postmaster_start_time()), EXTRACT(TIMEZONE_MINUTE FROM pg_postmaster_start_time()), xact_commit, blks_read, blks_read + blks_hit FROM pg_stat_database"); + } + else { + snmp_log(LOG_ERR, "Can't get connected to the database"); + return -1; + } + if (PQresultStatus(pg_db_qry) != PGRES_TUPLES_OK) { + snmp_log(LOG_ERR, "Didn't get any results from the database"); + PQclear(pg_db_qry); + /*PQfinish(dbconn);*/ + return -1; + } + + resultCount = PQntuples(pg_db_qry); + + /* + * TODO:351:M: |-> Load/update data in the rdbmsSrvInfoTable container. + * loop over your rdbmsSrvInfoTable data, allocate a rowreq context, + * set the index(es) [and data, optionally] and insert into + * the container. + */ + for (i = 0; i < resultCount; i++) { + + /* + * TODO:352:M: | |-> set indexes in new rdbmsSrvInfoTable rowreq context. + */ + rowreq_ctx = rdbmsSrvInfoTable_allocate_rowreq_ctx(); + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "memory allocation failed\n"); + errorCode = MFD_RESOURCE_UNAVAILABLE; + break; + } + applIndex = atoi(PQgetvalue(pg_db_qry, i, 0)); + if(MFD_SUCCESS != rdbmsSrvInfoTable_indexes_set(rowreq_ctx + , applIndex + )) { + snmp_log(LOG_ERR,"error setting index while loading " + "rdbmsSrvInfoTable cache.\n"); + rdbmsSrvInfoTable_release_rowreq_ctx(rowreq_ctx); + continue; + } + + rowreq_ctx->data.startupYear = atoi(PQgetvalue(pg_db_qry, i, 1)); + rowreq_ctx->data.startupMonth = atoi(PQgetvalue(pg_db_qry, i, 2)); + rowreq_ctx->data.startupDay = atoi(PQgetvalue(pg_db_qry, i, 3)); + rowreq_ctx->data.startupHour = atoi(PQgetvalue(pg_db_qry, i, 4)); + rowreq_ctx->data.startupMinutes = atoi(PQgetvalue(pg_db_qry, i, 5)); + rowreq_ctx->data.startupSeconds = atoi(PQgetvalue(pg_db_qry, i, 6)); + rowreq_ctx->data.startupDeciSeconds = atoi(PQgetvalue(pg_db_qry, i, 7)); + rowreq_ctx->data.startupUtcOffsetHours = atoi(PQgetvalue(pg_db_qry, i, 8)); + rowreq_ctx->data.startupUtcOffsetMinutes = atoi(PQgetvalue(pg_db_qry, i, 9)); + tmpInt = rowreq_ctx->data.startupUtcOffsetHours * 60 + rowreq_ctx->data.startupUtcOffsetMinutes; + if (tmpInt == 0) + rowreq_ctx->data.startupUtcOffsetDirection = 0; + else + rowreq_ctx->data.startupUtcOffsetDirection = (tmpInt > 0 ? 1 : -1); + + rowreq_ctx->data.rdbmsSrvInfoFinishedTransactions = atoi(PQgetvalue(pg_db_qry, i, 10)); + + rowreq_ctx->data.rdbmsSrvInfoDiskReads = atoi(PQgetvalue(pg_db_qry, i, 11)); + + rowreq_ctx->data.rdbmsSrvInfoLogicalReads = atoi(PQgetvalue(pg_db_qry, i, 12)); + + /* Skip this unless someone comes up with a way to get these data */ + /*rowreq_ctx->data.rdbmsSrvInfoDiskWrites = rdbmsSrvInfoDiskWrites; + + rowreq_ctx->data.rdbmsSrvInfoLogicalWrites = rdbmsSrvInfoLogicalWrites; */ + + rowreq_ctx->data.rdbmsSrvInfoPageReads = rowreq_ctx->data.rdbmsSrvInfoDiskReads; + + /*rowreq_ctx->data.rdbmsSrvInfoPageWrites = rdbmsSrvInfoPageWrites; */ + + /* pgsql will have a fatal error if this happens, so the value must be 0 if we're connected to a db server */ + rowreq_ctx->data.rdbmsSrvInfoDiskOutOfSpaces = 0; + + /* rowreq_ctx->data.rdbmsSrvInfoHandledRequests = rdbmsSrvInfoHandledRequests; + + rowreq_ctx->data.rdbmsSrvInfoRequestRecvs = rdbmsSrvInfoRequestRecvs; + + rowreq_ctx->data.rdbmsSrvInfoRequestSends = rdbmsSrvInfoRequestSends; */ + + rowreq_ctx->data.rdbmsSrvInfoHighwaterInboundAssociations = maxAssociations; + + rowreq_ctx->data.rdbmsSrvInfoMaxInboundAssociations = rdbmsSrvInfoMaxInboundAssociations; + + + /* + * insert into table container + */ + CONTAINER_INSERT(container, rowreq_ctx); + ++count; + } + + + DEBUGMSGT(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_cache_load", + "inserted %d records\n", count)); + + PQclear(pg_db_qry); + return errorCode; +} /* rdbmsSrvInfoTable_cache_load */ + +/** + * cache clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +rdbmsSrvInfoTable_cache_free(netsnmp_container *container) +{ + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_cache_free","called\n")); + + /* + * TODO:380:M: Free rdbmsSrvInfoTable cache. + */ +} /* rdbmsSrvInfoTable_cache_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +rdbmsSrvInfoTable_row_prep( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_row_prep","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvInfoTable_row_prep */ + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_access.h b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_access.h new file mode 100644 index 0000000..51b463b --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_access.h @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_data_access.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_data_access.h,v 1.3 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVINFOTABLE_DATA_ACCESS_H +#define RDBMSSRVINFOTABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ********************************************************************* + * function declarations + */ + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvInfoTable is subid 6 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.6, length: 9 +*/ + + + int rdbmsSrvInfoTable_init_data(rdbmsSrvInfoTable_registration_ptr rdbmsSrvInfoTable_reg); + + +/* + * TODO:180:o: Review rdbmsSrvInfoTable cache timeout. + * The number of seconds before the cache times out + */ +#define RDBMSSRVINFOTABLE_CACHE_TIMEOUT 10 + +void rdbmsSrvInfoTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache); +int rdbmsSrvInfoTable_cache_load(netsnmp_container *container); +void rdbmsSrvInfoTable_cache_free(netsnmp_container *container); + + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ +/* ********************************************************************* + * Since we have no idea how you really access your data, we'll go with + * a worst case example: a flat text file. + */ +#define MAX_LINE_SIZE 256 + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + int rdbmsSrvInfoTable_row_prep( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVINFOTABLE_DATA_ACCESS_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_get.c b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_get.c new file mode 100644 index 0000000..e0ff3bc --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_get.c @@ -0,0 +1,1429 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_data_get.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_data_get.c,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsSrvInfoTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement rdbmsSrvInfoTable get routines. + * TODO:240:M: Implement rdbmsSrvInfoTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvInfoTable is subid 6 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.6, length: 9 +*/ + +/* --------------------------------------------------------------------- + * TODO:200:r: Implement rdbmsSrvInfoTable data context functions. + */ + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This convenience function is useful for setting all the MIB index + * components with a single function call. It is assume that the C values + * have already been mapped from their native/rawformat to the MIB format. + */ +int +rdbmsSrvInfoTable_indexes_set_tbl_idx(rdbmsSrvInfoTable_mib_index *tbl_idx, long applIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_indexes_set_tbl_idx","called\n")); + + /* applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->applIndex = applIndex_val; + + + return MFD_SUCCESS; +} /* rdbmsSrvInfoTable_indexes_set_tbl_idx */ + +/** + * @internal + * set row context indexes + * + * @param reqreq_ctx the row context that needs updated indexes + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This function sets the mib indexs, then updates the oid indexs + * from the mib index. + */ +int +rdbmsSrvInfoTable_indexes_set(rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, long applIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_indexes_set","called\n")); + + if(MFD_SUCCESS != rdbmsSrvInfoTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx + , applIndex_val + )) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if(0 != rdbmsSrvInfoTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsSrvInfoTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoStartupTime + * rdbmsSrvInfoStartupTime is subid 1 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.1 + * Description: +The date and time at which this server was last started. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 2d-1d-1d,1d:1d:1d.1d,1a1d:1d + * + * Ranges: 8, 11; + * + * Its syntax is DateAndTime (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 11) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoStartupTime.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoStartupTime_map(char **mib_rdbmsSrvInfoStartupTime_val_ptr_ptr, size_t *mib_rdbmsSrvInfoStartupTime_val_ptr_len_ptr, char *raw_rdbmsSrvInfoStartupTime_val_ptr, size_t raw_rdbmsSrvInfoStartupTime_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsSrvInfoStartupTime_val_ptr); + netsnmp_assert((NULL != mib_rdbmsSrvInfoStartupTime_val_ptr_ptr) && (NULL != mib_rdbmsSrvInfoStartupTime_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoStartupTime_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsSrvInfoStartupTime non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsSrvInfoStartupTime_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsSrvInfoStartupTime_val_ptr_ptr) || (*mib_rdbmsSrvInfoStartupTime_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsSrvInfoStartupTime_val_ptr_ptr = realloc( *mib_rdbmsSrvInfoStartupTime_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsSrvInfoStartupTime_val_ptr_ptr)); + if(NULL == *mib_rdbmsSrvInfoStartupTime_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsSrvInfoStartupTime_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsSrvInfoStartupTime_val_ptr_ptr, raw_rdbmsSrvInfoStartupTime_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsSrvInfoStartupTime_map */ + +/** + * Extract the current value of the rdbmsSrvInfoStartupTime data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoStartupTime_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsSrvInfoStartupTime_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsSrvInfoStartupTime. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsSrvInfoStartupTime_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsSrvInfoStartupTime_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsSrvInfoStartupTime_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvInfoStartupTime_val_ptr_ptr, size_t *rdbmsSrvInfoStartupTime_val_ptr_len_ptr ) +{ + int rc; + /** we should have a pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsSrvInfoStartupTime_val_ptr_ptr) && (NULL != *rdbmsSrvInfoStartupTime_val_ptr_ptr)); + netsnmp_assert( (NULL != rdbmsSrvInfoStartupTime_val_ptr_len_ptr) && ((* rdbmsSrvInfoStartupTime_val_ptr_len_ptr) >= 11)); + + /* call convenience function to set data */ + rc = netsnmp_dateandtime_set_buf_from_vars((u_char *)*rdbmsSrvInfoStartupTime_val_ptr_ptr, rdbmsSrvInfoStartupTime_val_ptr_len_ptr, + rowreq_ctx->data.startupYear, + rowreq_ctx->data.startupMonth, + rowreq_ctx->data.startupDay, + rowreq_ctx->data.startupHour, + rowreq_ctx->data.startupMinutes, + rowreq_ctx->data.startupSeconds, + rowreq_ctx->data.startupDeciSeconds, + rowreq_ctx->data.startupUtcOffsetDirection, + rowreq_ctx->data.startupUtcOffsetHours, + rowreq_ctx->data.startupUtcOffsetMinutes); + if(rc != SNMP_ERR_NOERROR) + return rc; + + + return MFD_SUCCESS; +} /* rdbmsSrvInfoStartupTime_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoFinishedTransactions + * rdbmsSrvInfoFinishedTransactions is subid 2 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.2 + * Description: +The number of transactions visible to this server that have + been completed by either commit or abort. Some database + operations, such as read-only queries, may not result in the + creation of a transaction. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is GAUGE (based on perltype GAUGE) + * The net-snmp type is ASN_GAUGE. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoFinishedTransactions.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoFinishedTransactions_map(u_long *mib_rdbmsSrvInfoFinishedTransactions_val_ptr, u_long raw_rdbmsSrvInfoFinishedTransactions_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoFinishedTransactions_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoFinishedTransactions_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoFinishedTransactions mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoFinishedTransactions_val_ptr) = raw_rdbmsSrvInfoFinishedTransactions_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoFinishedTransactions_map */ + +/** + * Extract the current value of the rdbmsSrvInfoFinishedTransactions data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoFinishedTransactions_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoFinishedTransactions_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoFinishedTransactions_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoFinishedTransactions_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoFinishedTransactions_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoFinishedTransactions data. + * set (* rdbmsSrvInfoFinishedTransactions_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoFinishedTransactions_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoFinishedTransactions; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoFinishedTransactions_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoDiskReads + * rdbmsSrvInfoDiskReads is subid 3 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.3 + * Description: +The total number of reads of database files issued to the + operating system by this server since startup. Numbers are + not comparable between products. What constitutes a + readand how it is accounted is product-specific. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoDiskReads.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoDiskReads_map(u_long *mib_rdbmsSrvInfoDiskReads_val_ptr, u_long raw_rdbmsSrvInfoDiskReads_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoDiskReads_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoDiskReads_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoDiskReads mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoDiskReads_val_ptr) = raw_rdbmsSrvInfoDiskReads_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoDiskReads_map */ + +/** + * Extract the current value of the rdbmsSrvInfoDiskReads data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoDiskReads_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoDiskReads_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoDiskReads_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoDiskReads_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoDiskReads_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoDiskReads data. + * set (* rdbmsSrvInfoDiskReads_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoDiskReads_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoDiskReads; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoDiskReads_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoLogicalReads + * rdbmsSrvInfoLogicalReads is subid 4 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.4 + * Description: +The total number of logical reads of database files made + internally by this server since startup. The values of this + object and those of rdbmsSrvInfoDiskReads reveal the effect + of caching on read operation. Numbers are not comparable + between products, and may only be meaningful when aggregated + across all servers sharing a common cache. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoLogicalReads.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoLogicalReads_map(u_long *mib_rdbmsSrvInfoLogicalReads_val_ptr, u_long raw_rdbmsSrvInfoLogicalReads_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoLogicalReads_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoLogicalReads_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoLogicalReads mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoLogicalReads_val_ptr) = raw_rdbmsSrvInfoLogicalReads_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoLogicalReads_map */ + +/** + * Extract the current value of the rdbmsSrvInfoLogicalReads data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoLogicalReads_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoLogicalReads_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoLogicalReads_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoLogicalReads_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoLogicalReads_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoLogicalReads data. + * set (* rdbmsSrvInfoLogicalReads_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoLogicalReads_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoLogicalReads; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoLogicalReads_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoDiskWrites + * rdbmsSrvInfoDiskWrites is subid 5 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.5 + * Description: +The total number of writes to database files issued to the + operating system by this server since startup. Numbers are + not comparable between products. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoDiskWrites.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoDiskWrites_map(u_long *mib_rdbmsSrvInfoDiskWrites_val_ptr, u_long raw_rdbmsSrvInfoDiskWrites_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoDiskWrites_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoDiskWrites_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoDiskWrites mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoDiskWrites_val_ptr) = raw_rdbmsSrvInfoDiskWrites_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoDiskWrites_map */ + +/** + * Extract the current value of the rdbmsSrvInfoDiskWrites data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoDiskWrites_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoDiskWrites_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoDiskWrites_val_ptr ) +{ + return MFD_SKIP; + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoDiskWrites_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoDiskWrites_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoDiskWrites data. + * set (* rdbmsSrvInfoDiskWrites_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoDiskWrites_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoDiskWrites; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoDiskWrites_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoLogicalWrites + * rdbmsSrvInfoLogicalWrites is subid 6 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.6 + * Description: +The total number of times parts of the database files have + been marked 'dirty' and in need of writing to the disk. This + value and rdbmsSrvInfoDiskWrites give some indication of the + effect of 'write-behind' strategies in reducing the number of + disk writes compared to database operations. Because the + writes may be done by servers other than those marking the + parts of the database files dirty, these values may only be + meaningful when aggregated across all servers sharing a + common cache. Numbers are not comparable between products. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoLogicalWrites.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoLogicalWrites_map(u_long *mib_rdbmsSrvInfoLogicalWrites_val_ptr, u_long raw_rdbmsSrvInfoLogicalWrites_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoLogicalWrites_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoLogicalWrites_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoLogicalWrites mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoLogicalWrites_val_ptr) = raw_rdbmsSrvInfoLogicalWrites_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoLogicalWrites_map */ + +/** + * Extract the current value of the rdbmsSrvInfoLogicalWrites data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoLogicalWrites_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoLogicalWrites_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoLogicalWrites_val_ptr ) +{ + return MFD_SKIP; + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoLogicalWrites_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoLogicalWrites_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoLogicalWrites data. + * set (* rdbmsSrvInfoLogicalWrites_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoLogicalWrites_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoLogicalWrites; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoLogicalWrites_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoPageReads + * rdbmsSrvInfoPageReads is subid 7 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.7 + * Description: +The total number of pages in database files read by this + server since startup. 'Pages' are product specific units of + disk i/o operations. This value, along with + rdbmsSrvInfoDiskReads, reveals the effect of any grouping + read-ahead that may be used to enhance performance of some + queries, such as scans. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoPageReads.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoPageReads_map(u_long *mib_rdbmsSrvInfoPageReads_val_ptr, u_long raw_rdbmsSrvInfoPageReads_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoPageReads_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoPageReads_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoPageReads mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoPageReads_val_ptr) = raw_rdbmsSrvInfoPageReads_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoPageReads_map */ + +/** + * Extract the current value of the rdbmsSrvInfoPageReads data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoPageReads_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoPageReads_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoPageReads_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoPageReads_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoPageReads_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoPageReads data. + * set (* rdbmsSrvInfoPageReads_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoPageReads_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoPageReads; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoPageReads_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoPageWrites + * rdbmsSrvInfoPageWrites is subid 8 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.8 + * Description: +The total number of pages in database files written by this + server since startup. Pages are product-specific units of + disk I/O. This value, with rdbmsSrvInfoDiskWrites, shows the + effect of write strategies that collapse logical writes of + contiguous pages into single calls to the operating system. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoPageWrites.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoPageWrites_map(u_long *mib_rdbmsSrvInfoPageWrites_val_ptr, u_long raw_rdbmsSrvInfoPageWrites_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoPageWrites_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoPageWrites_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoPageWrites mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoPageWrites_val_ptr) = raw_rdbmsSrvInfoPageWrites_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoPageWrites_map */ + +/** + * Extract the current value of the rdbmsSrvInfoPageWrites data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoPageWrites_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoPageWrites_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoPageWrites_val_ptr ) +{ + return MFD_SKIP; + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoPageWrites_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoPageWrites_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoPageWrites data. + * set (* rdbmsSrvInfoPageWrites_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoPageWrites_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoPageWrites; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoPageWrites_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoDiskOutOfSpaces + * rdbmsSrvInfoDiskOutOfSpaces is subid 9 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.9 + * Description: +The total number of times the server has been unable to + obtain disk space that it wanted, since server startup. This + would be inspected by an agent on receipt of an + rdbmsOutOfSpace trap. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoDiskOutOfSpaces.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoDiskOutOfSpaces_map(u_long *mib_rdbmsSrvInfoDiskOutOfSpaces_val_ptr, u_long raw_rdbmsSrvInfoDiskOutOfSpaces_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoDiskOutOfSpaces_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoDiskOutOfSpaces_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoDiskOutOfSpaces mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoDiskOutOfSpaces_val_ptr) = raw_rdbmsSrvInfoDiskOutOfSpaces_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoDiskOutOfSpaces_map */ + +/** + * Extract the current value of the rdbmsSrvInfoDiskOutOfSpaces data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoDiskOutOfSpaces_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoDiskOutOfSpaces_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoDiskOutOfSpaces_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoDiskOutOfSpaces_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoDiskOutOfSpaces_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoDiskOutOfSpaces data. + * set (* rdbmsSrvInfoDiskOutOfSpaces_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoDiskOutOfSpaces_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoDiskOutOfSpaces; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoDiskOutOfSpaces_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoHandledRequests + * rdbmsSrvInfoHandledRequests is subid 10 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.10 + * Description: +The total number of requests made to the server on inbound + associations. The meaning of 'requests' is product specific, + and is not comparable between products. + + This is intended to encapsulate high level semantic + operations between clients and servers, or between peers. + For instance, one request might correspond to a 'select' or + an 'insert' statement. It is not intended to capture disk + i/o described in rdbmsSrvInfoDiskReads and + rdbmsSrvInfoDiskWrites. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoHandledRequests.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoHandledRequests_map(u_long *mib_rdbmsSrvInfoHandledRequests_val_ptr, u_long raw_rdbmsSrvInfoHandledRequests_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoHandledRequests_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoHandledRequests_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoHandledRequests mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoHandledRequests_val_ptr) = raw_rdbmsSrvInfoHandledRequests_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoHandledRequests_map */ + +/** + * Extract the current value of the rdbmsSrvInfoHandledRequests data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoHandledRequests_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoHandledRequests_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoHandledRequests_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoHandledRequests_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoHandledRequests_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoHandledRequests data. + * set (* rdbmsSrvInfoHandledRequests_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoHandledRequests_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoHandledRequests; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoHandledRequests_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoRequestRecvs + * rdbmsSrvInfoRequestRecvs is subid 11 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.11 + * Description: +The number of receive operations made processing any requests + on inbound associations. The meaning of operations is product + specific, and is not comparable between products. + + This is intended to capture lower-level i/o operations than + shown by HandledRequests, between clients and servers, or + between peers. For instance, it might roughly correspond to + the amount of data given with an 'insert' statement. It is + not intended to capture disk i/o described in + rdbmsSrvInfoDiskReads and rdbmsSrvInfoDiskWrites. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoRequestRecvs.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoRequestRecvs_map(u_long *mib_rdbmsSrvInfoRequestRecvs_val_ptr, u_long raw_rdbmsSrvInfoRequestRecvs_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoRequestRecvs_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoRequestRecvs_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoRequestRecvs mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoRequestRecvs_val_ptr) = raw_rdbmsSrvInfoRequestRecvs_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoRequestRecvs_map */ + +/** + * Extract the current value of the rdbmsSrvInfoRequestRecvs data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoRequestRecvs_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoRequestRecvs_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoRequestRecvs_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoRequestRecvs_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoRequestRecvs_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoRequestRecvs data. + * set (* rdbmsSrvInfoRequestRecvs_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoRequestRecvs_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoRequestRecvs; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoRequestRecvs_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoRequestSends + * rdbmsSrvInfoRequestSends is subid 12 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.12 + * Description: +The number of send operations made processing requests + handled on inbound associations. The meaning of operations + is product specific, and is not comparable between products. + + This is intended to capture lower-level i/o operations than + shown by HandledRequests, between between clients and + servers, or between peers. It might roughly correspond to + the number of rows returned by a 'select' statement. It is + not intended to capture disk i/o described in DiskReads. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is COUNTER (based on perltype COUNTER) + * The net-snmp type is ASN_COUNTER. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoRequestSends.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoRequestSends_map(u_long *mib_rdbmsSrvInfoRequestSends_val_ptr, u_long raw_rdbmsSrvInfoRequestSends_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoRequestSends_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoRequestSends_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoRequestSends mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoRequestSends_val_ptr) = raw_rdbmsSrvInfoRequestSends_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoRequestSends_map */ + +/** + * Extract the current value of the rdbmsSrvInfoRequestSends data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoRequestSends_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoRequestSends_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoRequestSends_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoRequestSends_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoRequestSends_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoRequestSends data. + * set (* rdbmsSrvInfoRequestSends_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoRequestSends_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoRequestSends; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoRequestSends_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoHighwaterInboundAssociations + * rdbmsSrvInfoHighwaterInboundAssociations is subid 13 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.6.1.13 + * Description: +The greatest number of inbound associations that have been + simultaneously open to this server since startup. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is GAUGE (based on perltype GAUGE) + * The net-snmp type is ASN_GAUGE. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoHighwaterInboundAssociations.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoHighwaterInboundAssociations_map(u_long *mib_rdbmsSrvInfoHighwaterInboundAssociations_val_ptr, u_long raw_rdbmsSrvInfoHighwaterInboundAssociations_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoHighwaterInboundAssociations_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoHighwaterInboundAssociations_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoHighwaterInboundAssociations mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoHighwaterInboundAssociations_val_ptr) = raw_rdbmsSrvInfoHighwaterInboundAssociations_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoHighwaterInboundAssociations_map */ + +/** + * Extract the current value of the rdbmsSrvInfoHighwaterInboundAssociations data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoHighwaterInboundAssociations_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoHighwaterInboundAssociations_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoHighwaterInboundAssociations_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoHighwaterInboundAssociations_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoHighwaterInboundAssociations_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoHighwaterInboundAssociations data. + * set (* rdbmsSrvInfoHighwaterInboundAssociations_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoHighwaterInboundAssociations_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoHighwaterInboundAssociations; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoHighwaterInboundAssociations_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvInfoEntry.rdbmsSrvInfoMaxInboundAssociations + * rdbmsSrvInfoMaxInboundAssociations is subid 14 of rdbmsSrvInfoEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.6.1.14 + * Description: +The greatest number of inbound associations that can be + simultaneously open with this server. If there is no limit, + then the value should be zero. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 1 + * + * + * Its syntax is GAUGE (based on perltype GAUGE) + * The net-snmp type is ASN_GAUGE. The C type decl is u_long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvInfoMaxInboundAssociations.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvInfoMaxInboundAssociations_map(u_long *mib_rdbmsSrvInfoMaxInboundAssociations_val_ptr, u_long raw_rdbmsSrvInfoMaxInboundAssociations_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvInfoMaxInboundAssociations_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoMaxInboundAssociations_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvInfoMaxInboundAssociations mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvInfoMaxInboundAssociations_val_ptr) = raw_rdbmsSrvInfoMaxInboundAssociations_val; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoMaxInboundAssociations_map */ + +/** + * Extract the current value of the rdbmsSrvInfoMaxInboundAssociations data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvInfoMaxInboundAssociations_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +rdbmsSrvInfoMaxInboundAssociations_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoMaxInboundAssociations_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != rdbmsSrvInfoMaxInboundAssociations_val_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoMaxInboundAssociations_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvInfoMaxInboundAssociations data. + * set (* rdbmsSrvInfoMaxInboundAssociations_val_ptr ) from rowreq_ctx->data + */ + (* rdbmsSrvInfoMaxInboundAssociations_val_ptr ) = rowreq_ctx->data.rdbmsSrvInfoMaxInboundAssociations; + + return MFD_SUCCESS; +} /* rdbmsSrvInfoMaxInboundAssociations_get */ + + + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_get.h b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_get.h new file mode 100644 index 0000000..68b5b5e --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_get.h @@ -0,0 +1,86 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_data_get.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_data_get.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVINFOTABLE_DATA_GET_H +#define RDBMSSRVINFOTABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * GET function declarations + */ + +/* ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvInfoTable is subid 6 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.6, length: 9 +*/ + /* + * indexes + */ + int applIndex_map(long *mib_applIndex_val_ptr, long raw_applIndex_val); + + int rdbmsSrvInfoStartupTime_map(char **mib_rdbmsSrvInfoStartupTime_val_ptr_ptr, size_t *mib_rdbmsSrvInfoStartupTime_val_ptr_len_ptr, char *raw_rdbmsSrvInfoStartupTime_val_ptr, size_t raw_rdbmsSrvInfoStartupTime_val_ptr_len, int allow_realloc); + int rdbmsSrvInfoStartupTime_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvInfoStartupTime_val_ptr_ptr, size_t *rdbmsSrvInfoStartupTime_val_ptr_len_ptr ); + int rdbmsSrvInfoFinishedTransactions_map(u_long *mib_rdbmsSrvInfoFinishedTransactions_val_ptr, u_long raw_rdbmsSrvInfoFinishedTransactions_val); + int rdbmsSrvInfoFinishedTransactions_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoFinishedTransactions_val_ptr ); + int rdbmsSrvInfoDiskReads_map(u_long *mib_rdbmsSrvInfoDiskReads_val_ptr, u_long raw_rdbmsSrvInfoDiskReads_val); + int rdbmsSrvInfoDiskReads_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoDiskReads_val_ptr ); + int rdbmsSrvInfoLogicalReads_map(u_long *mib_rdbmsSrvInfoLogicalReads_val_ptr, u_long raw_rdbmsSrvInfoLogicalReads_val); + int rdbmsSrvInfoLogicalReads_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoLogicalReads_val_ptr ); + int rdbmsSrvInfoDiskWrites_map(u_long *mib_rdbmsSrvInfoDiskWrites_val_ptr, u_long raw_rdbmsSrvInfoDiskWrites_val); + int rdbmsSrvInfoDiskWrites_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoDiskWrites_val_ptr ); + int rdbmsSrvInfoLogicalWrites_map(u_long *mib_rdbmsSrvInfoLogicalWrites_val_ptr, u_long raw_rdbmsSrvInfoLogicalWrites_val); + int rdbmsSrvInfoLogicalWrites_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoLogicalWrites_val_ptr ); + int rdbmsSrvInfoPageReads_map(u_long *mib_rdbmsSrvInfoPageReads_val_ptr, u_long raw_rdbmsSrvInfoPageReads_val); + int rdbmsSrvInfoPageReads_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoPageReads_val_ptr ); + int rdbmsSrvInfoPageWrites_map(u_long *mib_rdbmsSrvInfoPageWrites_val_ptr, u_long raw_rdbmsSrvInfoPageWrites_val); + int rdbmsSrvInfoPageWrites_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoPageWrites_val_ptr ); + int rdbmsSrvInfoDiskOutOfSpaces_map(u_long *mib_rdbmsSrvInfoDiskOutOfSpaces_val_ptr, u_long raw_rdbmsSrvInfoDiskOutOfSpaces_val); + int rdbmsSrvInfoDiskOutOfSpaces_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoDiskOutOfSpaces_val_ptr ); + int rdbmsSrvInfoHandledRequests_map(u_long *mib_rdbmsSrvInfoHandledRequests_val_ptr, u_long raw_rdbmsSrvInfoHandledRequests_val); + int rdbmsSrvInfoHandledRequests_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoHandledRequests_val_ptr ); + int rdbmsSrvInfoRequestRecvs_map(u_long *mib_rdbmsSrvInfoRequestRecvs_val_ptr, u_long raw_rdbmsSrvInfoRequestRecvs_val); + int rdbmsSrvInfoRequestRecvs_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoRequestRecvs_val_ptr ); + int rdbmsSrvInfoRequestSends_map(u_long *mib_rdbmsSrvInfoRequestSends_val_ptr, u_long raw_rdbmsSrvInfoRequestSends_val); + int rdbmsSrvInfoRequestSends_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoRequestSends_val_ptr ); + int rdbmsSrvInfoHighwaterInboundAssociations_map(u_long *mib_rdbmsSrvInfoHighwaterInboundAssociations_val_ptr, u_long raw_rdbmsSrvInfoHighwaterInboundAssociations_val); + int rdbmsSrvInfoHighwaterInboundAssociations_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoHighwaterInboundAssociations_val_ptr ); + int rdbmsSrvInfoMaxInboundAssociations_map(u_long *mib_rdbmsSrvInfoMaxInboundAssociations_val_ptr, u_long raw_rdbmsSrvInfoMaxInboundAssociations_val); + int rdbmsSrvInfoMaxInboundAssociations_get( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, u_long * rdbmsSrvInfoMaxInboundAssociations_val_ptr ); + + +int rdbmsSrvInfoTable_indexes_set_tbl_idx(rdbmsSrvInfoTable_mib_index *tbl_idx, long applIndex_val); +int rdbmsSrvInfoTable_indexes_set(rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, long applIndex_val); + + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVINFOTABLE_DATA_GET_H */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_set.c b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_set.c new file mode 100644 index 0000000..8422736 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_set.c @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_data_set.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_data_set.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsSrvInfoTable.h" + + +/** @defgroup data_set data_set: Routines to set data + * + * These routines are used to set the value for individual objects. The + * row context is passed, along with the new value. + * + * @{ + */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_set.h b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_set.h new file mode 100644 index 0000000..1383e6e --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_data_set.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_data_set.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_data_set.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVINFOTABLE_DATA_SET_H +#define RDBMSSRVINFOTABLE_DATA_SET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * SET function declarations + */ + +/* ********************************************************************* + * SET Table declarations + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVINFOTABLE_DATA_SET_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_enums.h b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_enums.h new file mode 100644 index 0000000..16b2302 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_enums.h @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_enums.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_enums.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVINFOTABLE_ENUMS_H +#define RDBMSSRVINFOTABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table rdbmsSrvInfoTable + * + ************************************************************************* + *************************************************************************/ + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVINFOTABLE_ENUMS_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_interface.c b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_interface.c new file mode 100644 index 0000000..3ed81dc --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_interface.c @@ -0,0 +1,777 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_interface.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_interface.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" +/* include our parent header */ +#include "rdbmsSrvInfoTable.h" + + +#include <net-snmp/library/container.h> + +#include "rdbmsSrvInfoTable_interface.h" + +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvInfoTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvInfoTable is subid 6 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.6, length: 9 +*/ +typedef struct rdbmsSrvInfoTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; /* optional cache */ + + rdbmsSrvInfoTable_registration_ptr user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} rdbmsSrvInfoTable_interface_ctx; + +static rdbmsSrvInfoTable_interface_ctx rdbmsSrvInfoTable_if_ctx; + +static void _rdbmsSrvInfoTable_container_init( + rdbmsSrvInfoTable_interface_ctx *if_ctx); + + +static Netsnmp_Node_Handler _mfd_rdbmsSrvInfoTable_pre_request; +static Netsnmp_Node_Handler _mfd_rdbmsSrvInfoTable_post_request; +static Netsnmp_Node_Handler _mfd_rdbmsSrvInfoTable_object_lookup; +static Netsnmp_Node_Handler _mfd_rdbmsSrvInfoTable_get_values; +/** + * @internal + * Initialize the table rdbmsSrvInfoTable + * (Define its contents and how it's structured) + */ +void +_rdbmsSrvInfoTable_initialize_interface(rdbmsSrvInfoTable_registration_ptr reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &rdbmsSrvInfoTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = &rdbmsSrvInfoTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:_rdbmsSrvInfoTable_initialize_interface","called\n")); + + + /************************************************* + * + * save interface context for rdbmsSrvInfoTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, + ASN_INTEGER, /** index: applIndex */ + 0); + + /* Define the minimum and maximum accessible columns. This + optimizes retrival. */ + tbl_info->min_column = RDBMSSRVINFOTABLE_MIN_COL; + tbl_info->max_column = RDBMSSRVINFOTABLE_MAX_COL; + + /* + * save users context + */ + rdbmsSrvInfoTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + rdbmsSrvInfoTable_init_data(reg_ptr); + + /* + * set up the container + */ + _rdbmsSrvInfoTable_container_init(&rdbmsSrvInfoTable_if_ctx); + if (NULL == rdbmsSrvInfoTable_if_ctx.container) { + snmp_log(LOG_ERR,"could not initialize container for rdbmsSrvInfoTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = _mfd_rdbmsSrvInfoTable_object_lookup; + access_multiplexer->get_values = _mfd_rdbmsSrvInfoTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = _mfd_rdbmsSrvInfoTable_pre_request; + access_multiplexer->post_request = _mfd_rdbmsSrvInfoTable_post_request; + + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("rdbmsSrvInfoTable:init_rdbmsSrvInfoTable", + "Registering rdbmsSrvInfoTable as a mibs-for-dummies table.\n")); + handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = netsnmp_handler_registration_create("rdbmsSrvInfoTable", handler, + rdbmsSrvInfoTable_oid, + rdbmsSrvInfoTable_oid_size, + HANDLER_CAN_BABY_STEP | + HANDLER_CAN_RONLY + ); + if(NULL == reginfo) { + snmp_log(LOG_ERR,"error registering table rdbmsSrvInfoTable\n"); + return; + } + reginfo->my_reg_void = &rdbmsSrvInfoTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if( access_multiplexer->object_lookup ) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if( access_multiplexer->set_values ) + mfd_modes |= BABY_STEP_SET_VALUES; + if( access_multiplexer->irreversible_commit ) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if( access_multiplexer->object_syntax_checks ) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if( access_multiplexer->pre_request ) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if( access_multiplexer->post_request ) + mfd_modes |= BABY_STEP_POST_REQUEST; + + if( access_multiplexer->undo_setup ) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if( access_multiplexer->undo_cleanup ) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if( access_multiplexer->undo_sets ) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if( access_multiplexer->row_creation ) + mfd_modes |= BABY_STEP_ROW_CREATE; + if( access_multiplexer->consistency_checks ) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if( access_multiplexer->commit ) + mfd_modes |= BABY_STEP_COMMIT; + if( access_multiplexer->undo_commit ) + mfd_modes |= BABY_STEP_UNDO_COMMIT; + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + rdbmsSrvInfoTable_if_ctx.container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler( reginfo, handler ); + + /************************************************* + * + * inject cache helper + */ + if(NULL != rdbmsSrvInfoTable_if_ctx.cache) { + handler = netsnmp_cache_handler_get(rdbmsSrvInfoTable_if_ctx.cache); + netsnmp_inject_handler( reginfo, handler ); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); +} /* _rdbmsSrvInfoTable_initialize_interface */ + +void +rdbmsSrvInfoTable_valid_columns_set(netsnmp_column_info *vc) +{ + rdbmsSrvInfoTable_if_ctx.tbl_info.valid_columns = vc; +} /* rdbmsSrvInfoTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +rdbmsSrvInfoTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsSrvInfoTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_applIndex; + + /* + * set up varbinds + */ + memset( &var_applIndex, 0x00, sizeof(var_applIndex) ); + var_applIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_applIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_index_to_oid","called\n")); + + /* applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_applIndex, (u_char*)&mib_idx->applIndex, + sizeof(mib_idx->applIndex)); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, (size_t *)&oid_idx->len, + NULL, 0, &var_applIndex); + if(err) + snmp_log(LOG_ERR,"error %d converting index to oid\n", err); + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_applIndex ); + + return err; +} /* rdbmsSrvInfoTable_index_to_oid */ + +/** + * extract rdbmsSrvInfoTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +rdbmsSrvInfoTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsSrvInfoTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_applIndex; + + /* + * set up varbinds + */ + memset( &var_applIndex, 0x00, sizeof(var_applIndex) ); + var_applIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_applIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsSrvInfoTable:rdbmsSrvInfoTable_index_from_oid","called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes( oid_idx->oids, oid_idx->len, + &var_applIndex ); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + mib_idx->applIndex = *((long *)var_applIndex.val.string); + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_applIndex ); + + return err; +} /* rdbmsSrvInfoTable_index_from_oid */ + + +/* ********************************************************************* + * @internal + * allocate resources for a rdbmsSrvInfoTable_rowreq_ctx + */ +rdbmsSrvInfoTable_rowreq_ctx * +rdbmsSrvInfoTable_allocate_rowreq_ctx(void) +{ + rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(rdbmsSrvInfoTable_rowreq_ctx); + + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:rdbmsSrvInfoTable_allocate_rowreq_ctx","called\n")); + + if(NULL == rowreq_ctx) { + snmp_log(LOG_ERR,"Couldn't allocate memory for a " + "rdbmsSrvInfoTable_rowreq_ctx.\n"); + } + + rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; + + rowreq_ctx->rdbmsSrvInfoTable_data_list = NULL; + rowreq_ctx->rdbmsSrvInfoTable_reg = rdbmsSrvInfoTable_if_ctx.user_ctx; + + + return rowreq_ctx; +} /* rdbmsSrvInfoTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a rdbmsSrvInfoTable_rowreq_ctx + */ +void +rdbmsSrvInfoTable_release_rowreq_ctx(rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:rdbmsSrvInfoTable_release_rowreq_ctx","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + + /* + * free index oid pointer + */ + if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* rdbmsSrvInfoTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsSrvInfoTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc = rdbmsSrvInfoTable_pre_request(rdbmsSrvInfoTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsSrvInfoTable","error %d from " + "rdbmsSrvInfoTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvInfoTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsSrvInfoTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx; + int rc = rdbmsSrvInfoTable_post_request(rdbmsSrvInfoTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsSrvInfoTable","error %d from " + "rdbmsSrvInfoTable_post_request\n", rc)); + } + + /* + * if there are no errors, check for and handle row creation/deletion + */ + rc = netsnmp_check_requests_error(requests); + if ((SNMP_ERR_NOERROR == rc) && + (NULL != + (rowreq_ctx = netsnmp_container_table_row_extract(requests)))) { + if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) { + rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; + CONTAINER_INSERT(rdbmsSrvInfoTable_if_ctx.container, rowreq_ctx); + } + else if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { + CONTAINER_REMOVE(rdbmsSrvInfoTable_if_ctx.container, rowreq_ctx); + rdbmsSrvInfoTable_release_rowreq_ctx(rowreq_ctx); + } + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvInfoTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsSrvInfoTable_object_lookup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:_mfd_rdbmsSrvInfoTable_object_lookup","called\n")); + + /* + * get our context from mfd + * rdbmsSrvInfoTable_interface_ctx *if_ctx = + * (rdbmsSrvInfoTable_interface_ctx *)reginfo->my_reg_void; + */ + + if(NULL == rowreq_ctx) { + netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION); + } + else { + rdbmsSrvInfoTable_row_prep(rowreq_ctx); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvInfoTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsSrvInfoTable_get_column( rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:_mfd_rdbmsSrvInfoTable_get_column","called\n")); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsSrvInfoStartupTime(1)/DateAndTime/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ + case COLUMN_RDBMSSRVINFOSTARTUPTIME: + var->type = ASN_OCTET_STR; +rc = rdbmsSrvInfoStartupTime_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* rdbmsSrvInfoFinishedTransactions(2)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFOFINISHEDTRANSACTIONS: + var->val_len = sizeof(u_long); + var->type = ASN_GAUGE; +rc = rdbmsSrvInfoFinishedTransactions_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoDiskReads(3)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFODISKREADS: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoDiskReads_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoLogicalReads(4)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFOLOGICALREADS: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoLogicalReads_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoDiskWrites(5)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFODISKWRITES: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoDiskWrites_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoLogicalWrites(6)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFOLOGICALWRITES: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoLogicalWrites_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoPageReads(7)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFOPAGEREADS: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoPageReads_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoPageWrites(8)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFOPAGEWRITES: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoPageWrites_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoDiskOutOfSpaces(9)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFODISKOUTOFSPACES: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoDiskOutOfSpaces_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoHandledRequests(10)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFOHANDLEDREQUESTS: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoHandledRequests_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoRequestRecvs(11)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFOREQUESTRECVS: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoRequestRecvs_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoRequestSends(12)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFOREQUESTSENDS: + var->val_len = sizeof(u_long); + var->type = ASN_COUNTER; +rc = rdbmsSrvInfoRequestSends_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoHighwaterInboundAssociations(13)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVINFOHIGHWATERINBOUNDASSOCIATIONS: + var->val_len = sizeof(u_long); + var->type = ASN_GAUGE; +rc = rdbmsSrvInfoHighwaterInboundAssociations_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + /* rdbmsSrvInfoMaxInboundAssociations(14)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/W/e/r/d/h */ + case COLUMN_RDBMSSRVINFOMAXINBOUNDASSOCIATIONS: + var->val_len = sizeof(u_long); + var->type = ASN_GAUGE; +rc = rdbmsSrvInfoMaxInboundAssociations_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsSrvInfoTable_get_column\n", column); + break; + } + + return rc; +} /* _rdbmsSrvInfoTable_get_column */ + +int +_mfd_rdbmsSrvInfoTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + u_char * old_string; + void (*dataFreeHook)(void *); + int rc; + + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:_mfd_rdbmsSrvInfoTable_get_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if(NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + else if(requests->requestvb->buf == requests->requestvb->val.string) { + if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsSrvInfoTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + if(MFD_SKIP == rc) { + requests->requestvb->type = ASN_PRIV_RETRY; + rc = SNMP_ERR_NOERROR; + } + } + else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if(rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if(old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if(dataFreeHook) + (*dataFreeHook)(old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvInfoTable_get_values */ + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/* + * NOT APPLICABLE (per MIB or user setting) + */ +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +/** + * @internal + */ +static int +_cache_load(netsnmp_cache *cache, void *vmagic) +{ + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:_cache_load","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache for rdbmsSrvInfoTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return rdbmsSrvInfoTable_cache_load((netsnmp_container*)cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_item_free(rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx, void *context) +{ + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:_cache_item_free","called\n")); + + if(NULL == rowreq_ctx) + return; + + rdbmsSrvInfoTable_release_rowreq_ctx(rowreq_ctx); +} /* _cache_item_free */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache *cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:_cache_free","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache in rdbmsSrvInfoTable_cache_free\n"); + return; + } + + container = (netsnmp_container*)cache->magic; + + /* + * call user code + */ + rdbmsSrvInfoTable_cache_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *)_cache_item_free, + NULL); +} /* _cache_free */ + +/** + * @internal + * initialize the iterator container with functions or wrappers + */ +void +_rdbmsSrvInfoTable_container_init(rdbmsSrvInfoTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:rdbmsSrvInfoTable:_rdbmsSrvInfoTable_container_init","called\n")); + + /* + * set up the cache + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + rdbmsSrvInfoTable_oid, + rdbmsSrvInfoTable_oid_size); + + if(NULL == if_ctx->cache) { + snmp_log(LOG_ERR, "error creating cache for rdbmsSrvInfoTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + rdbmsSrvInfoTable_container_init(&if_ctx->container, if_ctx->cache); + if(NULL == if_ctx->container) + if_ctx->container = netsnmp_container_find("rdbmsSrvInfoTable:table_container"); + if(NULL == if_ctx->container) { + snmp_log(LOG_ERR,"error creating container in " + "rdbmsSrvInfoTable_container_init\n"); + return; + } + if_ctx->cache->magic = (void*)if_ctx->container; +} /* _rdbmsSrvInfoTable_container_init */ + diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_interface.h b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_interface.h new file mode 100644 index 0000000..6fa8668 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_interface.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_interface.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_interface.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVINFOTABLE_INTERFACE_H +#define RDBMSSRVINFOTABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "rdbmsSrvInfoTable.h" + +/* ******************************************************************** + * Table declarations + */ + +/* PUBLIC interface initialization routine */ +void _rdbmsSrvInfoTable_initialize_interface(rdbmsSrvInfoTable_registration_ptr user_ctx, + u_long flags); + + rdbmsSrvInfoTable_rowreq_ctx * rdbmsSrvInfoTable_allocate_rowreq_ctx(void); +void rdbmsSrvInfoTable_release_rowreq_ctx(rdbmsSrvInfoTable_rowreq_ctx *rowreq_ctx); + +int rdbmsSrvInfoTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsSrvInfoTable_mib_index *mib_idx); +int rdbmsSrvInfoTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsSrvInfoTable_mib_index *mib_idx); + +/* + * access to certain internals. use with caution! + */ +void rdbmsSrvInfoTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVINFOTABLE_INTERFACE_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_oids.h b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_oids.h new file mode 100644 index 0000000..c61920e --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvInfoTable/rdbmsSrvInfoTable_oids.h @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvInfoTable_oids.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvInfoTable_oids.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVINFOTABLE_OIDS_H +#define RDBMSSRVINFOTABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* column number definitions for table rdbmsSrvInfoTable */ +#define RDBMSSRVINFOTABLE_OID 1,3,6,1,2,1,39,1,6 +#define COLUMN_RDBMSSRVINFOSTARTUPTIME 1 +#define COLUMN_RDBMSSRVINFOFINISHEDTRANSACTIONS 2 +#define COLUMN_RDBMSSRVINFODISKREADS 3 +#define COLUMN_RDBMSSRVINFOLOGICALREADS 4 +#define COLUMN_RDBMSSRVINFODISKWRITES 5 +#define COLUMN_RDBMSSRVINFOLOGICALWRITES 6 +#define COLUMN_RDBMSSRVINFOPAGEREADS 7 +#define COLUMN_RDBMSSRVINFOPAGEWRITES 8 +#define COLUMN_RDBMSSRVINFODISKOUTOFSPACES 9 +#define COLUMN_RDBMSSRVINFOHANDLEDREQUESTS 10 +#define COLUMN_RDBMSSRVINFOREQUESTRECVS 11 +#define COLUMN_RDBMSSRVINFOREQUESTSENDS 12 +#define COLUMN_RDBMSSRVINFOHIGHWATERINBOUNDASSOCIATIONS 13 +#define COLUMN_RDBMSSRVINFOMAXINBOUNDASSOCIATIONS 14 + +#define RDBMSSRVINFOTABLE_MIN_COL COLUMN_RDBMSSRVINFOSTARTUPTIME +#define RDBMSSRVINFOTABLE_MAX_COL COLUMN_RDBMSSRVINFOMAXINBOUNDASSOCIATIONS + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVINFOTABLE_OIDS_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvLimitedResource/README b/RDBMS-MIB_src/rdbmsSrvLimitedResource/README new file mode 100644 index 0000000..f8fb831 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvLimitedResource/README @@ -0,0 +1,11 @@ +Note: about SrvLimitedResource + +SrvLimitedResource is supposed to contain server-specific limited +resources. We tried to think of all the limited resources we could, +and didn't find any that belonged in this table. Things like memory, +disk space, etc. are already available through the default net-snmp +implementation, and it didn't seem like a good idea to re-implement +them here. XIDs are database-specific, so they're in the +DbLimitedResource table. So the SrvLimitedResource table was left +empty until we came up with useful information we could put in it. + diff --git a/RDBMS-MIB_src/rdbmsSrvLimitedResource/rdbmsSrvLimitedResource.h b/RDBMS-MIB_src/rdbmsSrvLimitedResource/rdbmsSrvLimitedResource.h new file mode 100644 index 0000000..45302df --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvLimitedResource/rdbmsSrvLimitedResource.h @@ -0,0 +1,14 @@ +/* + +Note: about SrvLimitedResource + +SrvLimitedResource is supposed to contain server-specific limited +resources. We tried to think of all the limited resources we could, +and didn't find any that belonged in this table. Things like memory, +disk space, etc. are already available through the default net-snmp +implementation, and it didn't seem like a good idea to re-implement +them here. XIDs are database-specific, so they're in the +DbLimitedResource table. So the SrvLimitedResource table was left +empty until we came up with useful information we could put in it. + +*/ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable.c b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable.c new file mode 100644 index 0000000..3fd3799 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable.c @@ -0,0 +1,130 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsSrvParamTable.h" + +#include <net-snmp/agent/mib_modules.h> + +#include "rdbmsSrvParamTable_interface.h" + +oid rdbmsSrvParamTable_oid[] = { RDBMSSRVPARAMTABLE_OID }; +int rdbmsSrvParamTable_oid_size = OID_LENGTH(rdbmsSrvParamTable_oid); + +void initialize_table_rdbmsSrvParamTable(void); + + +/** + * Initializes the rdbmsSrvParamTable module + */ +void +init_rdbmsSrvParamTable(void) +{ + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:init_rdbmsSrvParamTable","called\n")); + + /* + * TODO:300:o: Perform rdbmsSrvParamTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("rdbmsSrvParamTable")) + initialize_table_rdbmsSrvParamTable(); + +} /* init_rdbmsSrvParamTable */ + +/** + * Initialize the table rdbmsSrvParamTable + * (Define its contents and how it's structured) + */ +void +initialize_table_rdbmsSrvParamTable(void) +{ + rdbmsSrvParamTable_registration_ptr user_context; + u_long flags; + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:initialize_table_rdbmsSrvParamTable","called\n")); + + /* + * TODO:301:o: Perform rdbmsSrvParamTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize rdbmsSrvParamTable user context + * if you'd like to pass in a pointer to some data for this + * table, allocate or set it up here. + */ + /* + * a netsnmp_data_list is a simple way to store void pointers. A simple + * string token is used to add, find or remove pointers. + */ + user_context = netsnmp_create_data_list("rdbmsSrvParamTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _rdbmsSrvParamTable_initialize_interface(user_context, flags); +} /* initialize_table_rdbmsSrvParamTable */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +rdbmsSrvParamTable_pre_request(rdbmsSrvParamTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_pre_request","called\n")); + + /* + * TODO:510:o: Perform rdbmsSrvParamTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvParamTable_pre_request */ + +/** + * post-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error (ignored) + */ +int +rdbmsSrvParamTable_post_request(rdbmsSrvParamTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_post_request","called\n")); + + /* + * TODO:511:o: Perform rdbmsSrvParamTable pos-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvParamTable_post_request */ + + +/** @{ */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable.h b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable.h new file mode 100644 index 0000000..71c728f --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable.h @@ -0,0 +1,214 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVPARAMTABLE_H +#define RDBMSSRVPARAMTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @defgroup misc misc: Miscelaneous routines + * + * @{ + */ +#include <net-snmp/library/asn1.h> + +/* other required module components */ + /* *INDENT-OFF* */ +config_require(RDBMS-MIB/rdbmsSrvParamTable/rdbmsSrvParamTable_interface); +config_require(RDBMS-MIB/rdbmsSrvParamTable/rdbmsSrvParamTable_data_access); +config_require(RDBMS-MIB/rdbmsSrvParamTable/rdbmsSrvParamTable_data_get); +config_require(RDBMS-MIB/rdbmsSrvParamTable/rdbmsSrvParamTable_data_set); + /* *INDENT-ON* */ + +/* OID and column number definitions for */ +#include "rdbmsSrvParamTable_oids.h" + +/* enum definions */ +#include "rdbmsSrvParamTable_enums.h" + +/* ********************************************************************* + * function declarations + */ +void init_rdbmsSrvParamTable(void); + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvParamTable is subid 7 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.7, length: 9 +*/ +/* ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review rdbmsSrvParamTable registration context. + */ +typedef netsnmp_data_list * rdbmsSrvParamTable_registration_ptr; + +/**********************************************************************/ +/* + * TODO:110:r: |-> Review rdbmsSrvParamTable data context structure. + * This structure is used to represent the data for rdbmsSrvParamTable. + */ +/* + * This structure contains storage for all the columns defined in the + * rdbmsSrvParamTable. + */ +typedef struct rdbmsSrvParamTable_data_s { + + /* + * rdbmsSrvParamID(3)/AutonomousType/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h + */ + oid rdbmsSrvParamID[128]; +size_t rdbmsSrvParamID_len; /* # of oid elements, not bytes */ + + /* + * rdbmsSrvParamCurrValue(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + char rdbmsSrvParamCurrValue[255]; +size_t rdbmsSrvParamCurrValue_len; /* # of char elements, not bytes */ + + /* + * rdbmsSrvParamComment(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + char rdbmsSrvParamComment[255]; +size_t rdbmsSrvParamComment_len; /* # of char elements, not bytes */ + +} rdbmsSrvParamTable_data; + + +/* + * TODO:120:r: |-> Review rdbmsSrvParamTable mib index. + * This structure is used to represent the index for rdbmsSrvParamTable. + */ +typedef struct rdbmsSrvParamTable_mib_index_s { + + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long applIndex; + + /* + * rdbmsSrvParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H + */ + char rdbmsSrvParamName[64]; + size_t rdbmsSrvParamName_len; + + /* + * rdbmsSrvParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long rdbmsSrvParamSubIndex; + + +} rdbmsSrvParamTable_mib_index; + + /* + * TODO:121:r: | |-> Review rdbmsSrvParamTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. + * + * BE VERY CAREFUL TO TAKE INTO ACCOUNT THE MAXIMUM + * POSSIBLE LENGHT FOR EVERY VARIABLE LENGTH INDEX! + * Guessing 128 - col/entry(2) - oid len(9) +*/ +#define MAX_rdbmsSrvParamTable_IDX_LEN 67 + + +/* ********************************************************************* + * TODO:130:o: |-> Review rdbmsSrvParamTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * rdbmsSrvParamTable_rowreq_ctx pointer. + */ +typedef struct rdbmsSrvParamTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_rdbmsSrvParamTable_IDX_LEN]; + + rdbmsSrvParamTable_mib_index tbl_idx; + + rdbmsSrvParamTable_data data; + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * implementor's context pointer (provided during registration) + */ + rdbmsSrvParamTable_registration_ptr rdbmsSrvParamTable_reg; + + /* + * TODO:131:o: | |-> Add useful data to rdbmsSrvParamTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *rdbmsSrvParamTable_data_list; + +} rdbmsSrvParamTable_rowreq_ctx; + +typedef struct rdbmsSrvParamTable_ref_rowreq_ctx_s { + rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx; +} rdbmsSrvParamTable_ref_rowreq_ctx; + +/* ********************************************************************* + * function prototypes + */ + int rdbmsSrvParamTable_pre_request(rdbmsSrvParamTable_registration_ptr user_context); + int rdbmsSrvParamTable_post_request(rdbmsSrvParamTable_registration_ptr user_context); + + +extern oid rdbmsSrvParamTable_oid[]; +extern int rdbmsSrvParamTable_oid_size; + + +#include "rdbmsSrvParamTable_interface.h" +#include "rdbmsSrvParamTable_data_access.h" +#include "rdbmsSrvParamTable_data_get.h" +#include "rdbmsSrvParamTable_data_set.h" + +/* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVPARAMTABLE_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_access.c b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_access.c new file mode 100644 index 0000000..74e0c76 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_access.c @@ -0,0 +1,308 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_data_access.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_data_access.c,v 1.3 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsSrvParamTable.h" +#include "rdbmsSrvParamTable_data_access.h" + +/** @defgroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvParamTable is subid 7 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.7, length: 9 +*/ + +/** + * initialization for rdbmsSrvParamTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param rdbmsSrvParamTable_reg + * Pointer to rdbmsSrvParamTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +rdbmsSrvParamTable_init_data(rdbmsSrvParamTable_registration_ptr rdbmsSrvParamTable_reg) +{ + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_init_data","called\n")); + + /* + * TODO:303:o: Initialize rdbmsSrvParamTable data. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvParamTable_init_data */ + +/** + * container-cached overview + * + */ + +/*********************************************************************** + * + * cache + * + ***********************************************************************/ +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +rdbmsSrvParamTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache) +{ + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_container_init","called\n")); + + if((NULL == cache) || (NULL == container_ptr_ptr)) { + snmp_log(LOG_ERR,"bad params to rdbmsSrvParamTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + /* + * TODO:345:A: Set up rdbmsSrvParamTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = RDBMSSRVPARAMTABLE_CACHE_TIMEOUT; /* seconds */ +} /* rdbmsSrvParamTable_container_init */ + +/** + * load cache data + * + * TODO:350:M: Implement rdbmsSrvParamTable cache load + * + * @param container container to which items should be inserted + * + * @retval MFD_SUCCESS : success. + * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source + * @retval MFD_ERROR : other error. + * + * This function is called to cache the index(es) (and data, optionally) + * for the every row in the data set. + * + * @remark + * While loading the cache, the only important thing is the indexes. + * If access to your data is cheap/fast (e.g. you have a pointer to a + * structure in memory), it would make sense to update the data here. + * If, however, the accessing the data invovles more work (e.g. parsing + * some other existing data, or peforming calculations to derive the data), + * then you can limit yourself to setting the indexes and saving any + * information you will need later. Then use the saved information in + * rdbmsSrvParamTable_row_prep() for populating data. + * + * @note + * If you need consistency between rows (like you want statistics + * for each row to be from the same time frame), you should set all + * data here. + * + */ +int +rdbmsSrvParamTable_cache_load(netsnmp_container *container) +{ + rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx; + size_t count = 0; + char rdbmsSrvParamName[64]; + size_t rdbmsSrvParamName_len; + int i, resultCount, errorCode = MFD_SUCCESS, tmpInt, rdbmsSrvParamID = 1; + PGresult *pg_db_qry; + char *tmpString; + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_cache_load","called\n")); + + if (PQstatus(dbconn) == CONNECTION_OK) + pg_db_qry = PQexec(dbconn, "SELECT name, setting, SUBSTRING(short_desc FROM 1 FOR 63) FROM pg_settings"); + else { + snmp_log(LOG_ERR, "Can't get connected to the database"); + return -1; + } + if (PQresultStatus(pg_db_qry) != PGRES_TUPLES_OK) { + snmp_log(LOG_ERR, "Didn't get any results from the database"); + PQclear(pg_db_qry); + /*PQfinish(dbconn);*/ + return -1; + } + + resultCount = PQntuples(pg_db_qry); + for (i = 0; i < resultCount; i++) { + + rowreq_ctx = rdbmsSrvParamTable_allocate_rowreq_ctx(); + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "memory allocation failed\n"); + return MFD_RESOURCE_UNAVAILABLE; + } + strncpy(rdbmsSrvParamName, PQgetvalue(pg_db_qry, i, 0), 64); + rdbmsSrvParamName[63] = '\0'; + rdbmsSrvParamName_len = strlen(rdbmsSrvParamName); + if(MFD_SUCCESS != rdbmsSrvParamTable_indexes_set(rowreq_ctx + , 1 + , rdbmsSrvParamName, rdbmsSrvParamName_len + , 1 + )) { + snmp_log(LOG_ERR,"error setting index while loading " + "rdbmsSrvParamTable cache.\n"); + rdbmsSrvParamTable_release_rowreq_ctx(rowreq_ctx); + continue; + } + rowreq_ctx->data.rdbmsSrvParamID_len = 128; + rowreq_ctx->data.rdbmsSrvParamCurrValue_len = 255; + rowreq_ctx->data.rdbmsSrvParamComment_len = 255; + + if ((NULL == rowreq_ctx->data.rdbmsSrvParamID) || + (rowreq_ctx->data.rdbmsSrvParamID_len < sizeof(rowreq_ctx->data.rdbmsSrvParamID[0]))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + errorCode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsSrvParamID_len = sizeof(rowreq_ctx->data.rdbmsSrvParamID[0]); + memcpy( rowreq_ctx->data.rdbmsSrvParamID, &rdbmsSrvParamID, rowreq_ctx->data.rdbmsSrvParamID_len ); + + tmpString = PQgetvalue(pg_db_qry, i, 1); + tmpInt = strlen(tmpString); + if ((NULL == rowreq_ctx->data.rdbmsSrvParamCurrValue) || + (rowreq_ctx->data.rdbmsSrvParamCurrValue_len < (tmpInt * sizeof(rowreq_ctx->data.rdbmsSrvParamCurrValue[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + errorCode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsSrvParamCurrValue_len = tmpInt * sizeof(rowreq_ctx->data.rdbmsSrvParamCurrValue[0]); + memcpy( rowreq_ctx->data.rdbmsSrvParamCurrValue, tmpString, rowreq_ctx->data.rdbmsSrvParamCurrValue_len ); + + tmpString = PQgetvalue(pg_db_qry, i, 2); + tmpInt = strlen(tmpString); + if ((NULL == rowreq_ctx->data.rdbmsSrvParamComment) || + (rowreq_ctx->data.rdbmsSrvParamComment_len < (tmpInt * sizeof(rowreq_ctx->data.rdbmsSrvParamComment[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + errorCode = MFD_ERROR; + break; + } + rowreq_ctx->data.rdbmsSrvParamComment_len = tmpInt * sizeof(rowreq_ctx->data.rdbmsSrvParamComment[0]); + memcpy( rowreq_ctx->data.rdbmsSrvParamComment, tmpString, rowreq_ctx->data.rdbmsSrvParamComment_len ); + + + /* + * insert into table container + */ + CONTAINER_INSERT(container, rowreq_ctx); + ++count; + } + + + DEBUGMSGT(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_cache_load", + "inserted %d records\n", count)); + PQclear(pg_db_qry); + + return MFD_SUCCESS; +} /* rdbmsSrvParamTable_cache_load */ + +/** + * cache clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +rdbmsSrvParamTable_cache_free(netsnmp_container *container) +{ + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_cache_free","called\n")); + + /* + * TODO:380:M: Free rdbmsSrvParamTable cache. + */ +} /* rdbmsSrvParamTable_cache_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +rdbmsSrvParamTable_row_prep( rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_row_prep","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvParamTable_row_prep */ + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_access.h b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_access.h new file mode 100644 index 0000000..9a51cf9 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_access.h @@ -0,0 +1,64 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_data_access.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_data_access.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVPARAMTABLE_DATA_ACCESS_H +#define RDBMSSRVPARAMTABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ********************************************************************* + * function declarations + */ + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvParamTable is subid 7 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.7, length: 9 +*/ + + + int rdbmsSrvParamTable_init_data(rdbmsSrvParamTable_registration_ptr rdbmsSrvParamTable_reg); + + +/* + * TODO:180:o: Review rdbmsSrvParamTable cache timeout. + * The number of seconds before the cache times out + */ +#define RDBMSSRVPARAMTABLE_CACHE_TIMEOUT 60 + +void rdbmsSrvParamTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache); +int rdbmsSrvParamTable_cache_load(netsnmp_container *container); +void rdbmsSrvParamTable_cache_free(netsnmp_container *container); + + int rdbmsSrvParamTable_row_prep( rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVPARAMTABLE_DATA_ACCESS_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_get.c b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_get.c new file mode 100644 index 0000000..2a4dc8b --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_get.c @@ -0,0 +1,726 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_data_get.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_data_get.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsSrvParamTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement rdbmsSrvParamTable get routines. + * TODO:240:M: Implement rdbmsSrvParamTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvParamTable is subid 7 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.7, length: 9 +*/ + +/* --------------------------------------------------------------------- + * TODO:200:r: Implement rdbmsSrvParamTable data context functions. + */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvParamEntry.rdbmsSrvParamName + * rdbmsSrvParamName is subid 1 of rdbmsSrvParamEntry. + * Its status is Current, and its access level is NoAccess. + * OID: .1.3.6.1.2.1.39.1.7.1.1 + * Description: +The name of a configuration parameter for a server. This + name is product-specific. The length is limited to 64 + characters to constrain the number of sub-identifiers needed + for instance identification (and to minimize network + traffic). + * + * Attributes: + * accessible 0 isscalar 0 enums 0 hasdefval 0 + * readable 0 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 255a + * + * Ranges: 1 - 64; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 64) + * + * + * + * NOTE: NODE rdbmsSrvParamName IS NOT ACCESSIBLE + * + * + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvParamName.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvParamName_map(char **mib_rdbmsSrvParamName_val_ptr_ptr, size_t *mib_rdbmsSrvParamName_val_ptr_len_ptr, char *raw_rdbmsSrvParamName_val_ptr, size_t raw_rdbmsSrvParamName_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsSrvParamName_val_ptr); + netsnmp_assert((NULL != mib_rdbmsSrvParamName_val_ptr_ptr) && (NULL != mib_rdbmsSrvParamName_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamName_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsSrvParamName non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsSrvParamName_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsSrvParamName_val_ptr_ptr) || (*mib_rdbmsSrvParamName_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsSrvParamName_val_ptr_ptr = realloc( *mib_rdbmsSrvParamName_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsSrvParamName_val_ptr_ptr)); + if(NULL == *mib_rdbmsSrvParamName_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsSrvParamName_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsSrvParamName_val_ptr_ptr, raw_rdbmsSrvParamName_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsSrvParamName_map */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvParamEntry.rdbmsSrvParamSubIndex + * rdbmsSrvParamSubIndex is subid 2 of rdbmsSrvParamEntry. + * Its status is Current, and its access level is NoAccess. + * OID: .1.3.6.1.2.1.39.1.7.1.2 + * Description: +The subindex value for this parameter. If the parameter is + naturally considered to contain a variable number of members + of a class, e.g. members of the DBA user group, or files + which are part of the database, then it must be presented as + a set of rows. If, on the other hand, the parameter + represents a set of choices from a class, e.g. the + permissions on a file or the options chosen out of the set of + all options allowed, AND is guaranteed to always fit in the + 255 character length of a DisplayString, then it may be + presented as a comma separated list with a subindex value of + one. Zero may not be used as a value. + * + * Attributes: + * accessible 0 isscalar 0 enums 0 hasdefval 0 + * readable 0 iscolumn 1 ranges 1 hashint 0 + * settable 0 + * + * Ranges: 1 - 2147483647; + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + * + * + * + * NOTE: NODE rdbmsSrvParamSubIndex IS NOT ACCESSIBLE + * + * + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvParamSubIndex.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvParamSubIndex_map(long *mib_rdbmsSrvParamSubIndex_val_ptr, long raw_rdbmsSrvParamSubIndex_val) +{ + netsnmp_assert(NULL != mib_rdbmsSrvParamSubIndex_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamSubIndex_map","called\n")); + + /* + * TODO:241:o: |-> Implement rdbmsSrvParamSubIndex mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_rdbmsSrvParamSubIndex_val_ptr) = raw_rdbmsSrvParamSubIndex_val; + + return MFD_SUCCESS; +} /* rdbmsSrvParamSubIndex_map */ + + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This convenience function is useful for setting all the MIB index + * components with a single function call. It is assume that the C values + * have already been mapped from their native/rawformat to the MIB format. + */ +int +rdbmsSrvParamTable_indexes_set_tbl_idx(rdbmsSrvParamTable_mib_index *tbl_idx, long applIndex_val, char *rdbmsSrvParamName_val_ptr, size_t rdbmsSrvParamName_val_ptr_len, long rdbmsSrvParamSubIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_indexes_set_tbl_idx","called\n")); + + /* applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->applIndex = applIndex_val; + + /* rdbmsSrvParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ + tbl_idx->rdbmsSrvParamName_len = sizeof(tbl_idx->rdbmsSrvParamName); + /* + * make sure there is enough space for rdbmsSrvParamName data + */ + if ((NULL == tbl_idx->rdbmsSrvParamName) || + (tbl_idx->rdbmsSrvParamName_len < (rdbmsSrvParamName_val_ptr_len * sizeof(tbl_idx->rdbmsSrvParamName[0])))) { + snmp_log(LOG_ERR,"not enough space for value\n"); + return MFD_ERROR; + } + tbl_idx->rdbmsSrvParamName_len = rdbmsSrvParamName_val_ptr_len * sizeof(tbl_idx->rdbmsSrvParamName[0]); + memcpy( tbl_idx->rdbmsSrvParamName, rdbmsSrvParamName_val_ptr, tbl_idx->rdbmsSrvParamName_len ); + + /* rdbmsSrvParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->rdbmsSrvParamSubIndex = rdbmsSrvParamSubIndex_val; + + + return MFD_SUCCESS; +} /* rdbmsSrvParamTable_indexes_set_tbl_idx */ + +/** + * @internal + * set row context indexes + * + * @param reqreq_ctx the row context that needs updated indexes + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This function sets the mib indexs, then updates the oid indexs + * from the mib index. + */ +int +rdbmsSrvParamTable_indexes_set(rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, long applIndex_val, char *rdbmsSrvParamName_val_ptr, size_t rdbmsSrvParamName_val_ptr_len, long rdbmsSrvParamSubIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_indexes_set","called\n")); + + if(MFD_SUCCESS != rdbmsSrvParamTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx + , applIndex_val + , rdbmsSrvParamName_val_ptr, rdbmsSrvParamName_val_ptr_len + , rdbmsSrvParamSubIndex_val + )) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if(0 != rdbmsSrvParamTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsSrvParamTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvParamEntry.rdbmsSrvParamID + * rdbmsSrvParamID is subid 3 of rdbmsSrvParamEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.7.1.3 + * Description: +The ID of the parameter which may be described in some + other MIB. If there is no ID for this rdbmsSrvParamName, + attempts to access this object will return noSuchName + (SNMPv1) or noSuchInstance (SNMPv2). + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is AutonomousType (based on perltype OBJECTID) + * The net-snmp type is ASN_OBJECT_ID. The C type decl is oid (oid) + * This data type requires a length. (Max 2147483647) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvParamID.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvParamID_map(oid **mib_rdbmsSrvParamID_val_ptr_ptr, size_t *mib_rdbmsSrvParamID_val_ptr_len_ptr, oid *raw_rdbmsSrvParamID_val_ptr, size_t raw_rdbmsSrvParamID_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsSrvParamID_val_ptr); + netsnmp_assert((NULL != mib_rdbmsSrvParamID_val_ptr_ptr) && (NULL != mib_rdbmsSrvParamID_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamID_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsSrvParamID non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsSrvParamID_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsSrvParamID_val_ptr_ptr) || (*mib_rdbmsSrvParamID_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsSrvParamID_val_ptr_ptr = realloc( *mib_rdbmsSrvParamID_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsSrvParamID_val_ptr_ptr)); + if(NULL == *mib_rdbmsSrvParamID_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsSrvParamID_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsSrvParamID_val_ptr_ptr, raw_rdbmsSrvParamID_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsSrvParamID_map */ + +/** + * Extract the current value of the rdbmsSrvParamID data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvParamID_val_ptr_ptr + * Pointer to storage for a oid variable + * @param rdbmsSrvParamID_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsSrvParamID. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsSrvParamID_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsSrvParamID_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsSrvParamID_get( rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, oid **rdbmsSrvParamID_val_ptr_ptr, size_t *rdbmsSrvParamID_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + return MFD_SKIP; + netsnmp_assert( (NULL != rdbmsSrvParamID_val_ptr_ptr) && (NULL != *rdbmsSrvParamID_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsSrvParamID_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamID_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvParamID data. + * set (* rdbmsSrvParamID_val_ptr_ptr ) and (* rdbmsSrvParamID_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsSrvParamID data + */ + if ((NULL == (* rdbmsSrvParamID_val_ptr_ptr )) || + ((* rdbmsSrvParamID_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsSrvParamID_len * sizeof((* rdbmsSrvParamID_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsSrvParamID data + */ + (* rdbmsSrvParamID_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsSrvParamID_len * sizeof((* rdbmsSrvParamID_val_ptr_ptr )[0])); + if(NULL == (* rdbmsSrvParamID_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsSrvParamID_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsSrvParamID_len * sizeof((* rdbmsSrvParamID_val_ptr_ptr )[0]); + memcpy( (* rdbmsSrvParamID_val_ptr_ptr ), rowreq_ctx->data.rdbmsSrvParamID, (* rdbmsSrvParamID_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsSrvParamID_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvParamEntry.rdbmsSrvParamCurrValue + * rdbmsSrvParamCurrValue is subid 4 of rdbmsSrvParamEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.7.1.4 + * Description: +The value for a configuration parameter now in effect, the + actual setting for the server. While there may multiple + values in the temporal domain of interest (for instance, the + value to take effect at the next restart), this is the + current setting. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 1 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvParamCurrValue.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvParamCurrValue_map(char **mib_rdbmsSrvParamCurrValue_val_ptr_ptr, size_t *mib_rdbmsSrvParamCurrValue_val_ptr_len_ptr, char *raw_rdbmsSrvParamCurrValue_val_ptr, size_t raw_rdbmsSrvParamCurrValue_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsSrvParamCurrValue_val_ptr); + netsnmp_assert((NULL != mib_rdbmsSrvParamCurrValue_val_ptr_ptr) && (NULL != mib_rdbmsSrvParamCurrValue_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamCurrValue_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsSrvParamCurrValue non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsSrvParamCurrValue_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsSrvParamCurrValue_val_ptr_ptr) || (*mib_rdbmsSrvParamCurrValue_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsSrvParamCurrValue_val_ptr_ptr = realloc( *mib_rdbmsSrvParamCurrValue_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsSrvParamCurrValue_val_ptr_ptr)); + if(NULL == *mib_rdbmsSrvParamCurrValue_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsSrvParamCurrValue_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsSrvParamCurrValue_val_ptr_ptr, raw_rdbmsSrvParamCurrValue_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsSrvParamCurrValue_map */ + +/** + * Extract the current value of the rdbmsSrvParamCurrValue data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvParamCurrValue_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsSrvParamCurrValue_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsSrvParamCurrValue. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsSrvParamCurrValue_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsSrvParamCurrValue_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsSrvParamCurrValue_get( rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvParamCurrValue_val_ptr_ptr, size_t *rdbmsSrvParamCurrValue_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsSrvParamCurrValue_val_ptr_ptr) && (NULL != *rdbmsSrvParamCurrValue_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsSrvParamCurrValue_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamCurrValue_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvParamCurrValue data. + * set (* rdbmsSrvParamCurrValue_val_ptr_ptr ) and (* rdbmsSrvParamCurrValue_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsSrvParamCurrValue data + */ + if ((NULL == (* rdbmsSrvParamCurrValue_val_ptr_ptr )) || + ((* rdbmsSrvParamCurrValue_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsSrvParamCurrValue_len * sizeof((* rdbmsSrvParamCurrValue_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsSrvParamCurrValue data + */ + (* rdbmsSrvParamCurrValue_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsSrvParamCurrValue_len * sizeof((* rdbmsSrvParamCurrValue_val_ptr_ptr )[0])); + if(NULL == (* rdbmsSrvParamCurrValue_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsSrvParamCurrValue_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsSrvParamCurrValue_len * sizeof((* rdbmsSrvParamCurrValue_val_ptr_ptr )[0]); + memcpy( (* rdbmsSrvParamCurrValue_val_ptr_ptr ), rowreq_ctx->data.rdbmsSrvParamCurrValue, (* rdbmsSrvParamCurrValue_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsSrvParamCurrValue_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvParamEntry.rdbmsSrvParamComment + * rdbmsSrvParamComment is subid 5 of rdbmsSrvParamEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.7.1.5 + * Description: +Annotation which describes the purpose of a configuration + parameter or the reason for a particular parameter's + setting. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 1 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvParamComment.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvParamComment_map(char **mib_rdbmsSrvParamComment_val_ptr_ptr, size_t *mib_rdbmsSrvParamComment_val_ptr_len_ptr, char *raw_rdbmsSrvParamComment_val_ptr, size_t raw_rdbmsSrvParamComment_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsSrvParamComment_val_ptr); + netsnmp_assert((NULL != mib_rdbmsSrvParamComment_val_ptr_ptr) && (NULL != mib_rdbmsSrvParamComment_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamComment_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsSrvParamComment non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsSrvParamComment_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsSrvParamComment_val_ptr_ptr) || (*mib_rdbmsSrvParamComment_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsSrvParamComment_val_ptr_ptr = realloc( *mib_rdbmsSrvParamComment_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsSrvParamComment_val_ptr_ptr)); + if(NULL == *mib_rdbmsSrvParamComment_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsSrvParamComment_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsSrvParamComment_val_ptr_ptr, raw_rdbmsSrvParamComment_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsSrvParamComment_map */ + +/** + * Extract the current value of the rdbmsSrvParamComment data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvParamComment_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsSrvParamComment_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsSrvParamComment. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsSrvParamComment_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsSrvParamComment_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsSrvParamComment_get( rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvParamComment_val_ptr_ptr, size_t *rdbmsSrvParamComment_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsSrvParamComment_val_ptr_ptr) && (NULL != *rdbmsSrvParamComment_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsSrvParamComment_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamComment_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvParamComment data. + * set (* rdbmsSrvParamComment_val_ptr_ptr ) and (* rdbmsSrvParamComment_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsSrvParamComment data + */ + if ((NULL == (* rdbmsSrvParamComment_val_ptr_ptr )) || + ((* rdbmsSrvParamComment_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsSrvParamComment_len * sizeof((* rdbmsSrvParamComment_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsSrvParamComment data + */ + (* rdbmsSrvParamComment_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsSrvParamComment_len * sizeof((* rdbmsSrvParamComment_val_ptr_ptr )[0])); + if(NULL == (* rdbmsSrvParamComment_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsSrvParamComment_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsSrvParamComment_len * sizeof((* rdbmsSrvParamComment_val_ptr_ptr )[0]); + memcpy( (* rdbmsSrvParamComment_val_ptr_ptr ), rowreq_ctx->data.rdbmsSrvParamComment, (* rdbmsSrvParamComment_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsSrvParamComment_get */ + + + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_get.h b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_get.h new file mode 100644 index 0000000..7b57da8 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_get.h @@ -0,0 +1,66 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_data_get.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_data_get.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVPARAMTABLE_DATA_GET_H +#define RDBMSSRVPARAMTABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * GET function declarations + */ + +/* ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvParamTable is subid 7 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.7, length: 9 +*/ + /* + * indexes + */ + int applIndex_map(long *mib_applIndex_val_ptr, long raw_applIndex_val); + int rdbmsSrvParamName_map(char **mib_rdbmsSrvParamName_val_ptr_ptr, size_t *mib_rdbmsSrvParamName_val_ptr_len_ptr, char *raw_rdbmsSrvParamName_val_ptr, size_t raw_rdbmsSrvParamName_val_ptr_len, int allow_realloc); + int rdbmsSrvParamSubIndex_map(long *mib_rdbmsSrvParamSubIndex_val_ptr, long raw_rdbmsSrvParamSubIndex_val); + + int rdbmsSrvParamID_map(oid **mib_rdbmsSrvParamID_val_ptr_ptr, size_t *mib_rdbmsSrvParamID_val_ptr_len_ptr, oid *raw_rdbmsSrvParamID_val_ptr, size_t raw_rdbmsSrvParamID_val_ptr_len, int allow_realloc); + int rdbmsSrvParamID_get( rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, oid **rdbmsSrvParamID_val_ptr_ptr, size_t *rdbmsSrvParamID_val_ptr_len_ptr ); + int rdbmsSrvParamCurrValue_map(char **mib_rdbmsSrvParamCurrValue_val_ptr_ptr, size_t *mib_rdbmsSrvParamCurrValue_val_ptr_len_ptr, char *raw_rdbmsSrvParamCurrValue_val_ptr, size_t raw_rdbmsSrvParamCurrValue_val_ptr_len, int allow_realloc); + int rdbmsSrvParamCurrValue_get( rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvParamCurrValue_val_ptr_ptr, size_t *rdbmsSrvParamCurrValue_val_ptr_len_ptr ); + int rdbmsSrvParamComment_map(char **mib_rdbmsSrvParamComment_val_ptr_ptr, size_t *mib_rdbmsSrvParamComment_val_ptr_len_ptr, char *raw_rdbmsSrvParamComment_val_ptr, size_t raw_rdbmsSrvParamComment_val_ptr_len, int allow_realloc); + int rdbmsSrvParamComment_get( rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvParamComment_val_ptr_ptr, size_t *rdbmsSrvParamComment_val_ptr_len_ptr ); + + +int rdbmsSrvParamTable_indexes_set_tbl_idx(rdbmsSrvParamTable_mib_index *tbl_idx, long applIndex_val, char *rdbmsSrvParamName_val_ptr, size_t rdbmsSrvParamName_val_ptr_len, long rdbmsSrvParamSubIndex_val); +int rdbmsSrvParamTable_indexes_set(rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, long applIndex_val, char *rdbmsSrvParamName_val_ptr, size_t rdbmsSrvParamName_val_ptr_len, long rdbmsSrvParamSubIndex_val); + + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVPARAMTABLE_DATA_GET_H */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_set.c b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_set.c new file mode 100644 index 0000000..296bc83 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_set.c @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_data_set.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_data_set.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsSrvParamTable.h" + + +/** @defgroup data_set data_set: Routines to set data + * + * These routines are used to set the value for individual objects. The + * row context is passed, along with the new value. + * + * @{ + */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_set.h b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_set.h new file mode 100644 index 0000000..f4248b6 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_data_set.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_data_set.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_data_set.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVPARAMTABLE_DATA_SET_H +#define RDBMSSRVPARAMTABLE_DATA_SET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * SET function declarations + */ + +/* ********************************************************************* + * SET Table declarations + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVPARAMTABLE_DATA_SET_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_enums.h b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_enums.h new file mode 100644 index 0000000..58bce16 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_enums.h @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_enums.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_enums.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVPARAMTABLE_ENUMS_H +#define RDBMSSRVPARAMTABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table rdbmsSrvParamTable + * + ************************************************************************* + *************************************************************************/ + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVPARAMTABLE_ENUMS_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_interface.c b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_interface.c new file mode 100644 index 0000000..bf54b5c --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_interface.c @@ -0,0 +1,743 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_interface.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_interface.c,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsSrvParamTable.h" + + +#include <net-snmp/library/container.h> + +#include "rdbmsSrvParamTable_interface.h" + +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvParamTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvParamTable is subid 7 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.7, length: 9 +*/ +typedef struct rdbmsSrvParamTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; /* optional cache */ + + rdbmsSrvParamTable_registration_ptr user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} rdbmsSrvParamTable_interface_ctx; + +static rdbmsSrvParamTable_interface_ctx rdbmsSrvParamTable_if_ctx; + +static void _rdbmsSrvParamTable_container_init( + rdbmsSrvParamTable_interface_ctx *if_ctx); + + +static Netsnmp_Node_Handler _mfd_rdbmsSrvParamTable_pre_request; +static Netsnmp_Node_Handler _mfd_rdbmsSrvParamTable_post_request; +static Netsnmp_Node_Handler _mfd_rdbmsSrvParamTable_object_lookup; +static Netsnmp_Node_Handler _mfd_rdbmsSrvParamTable_get_values; +/** + * @internal + * Initialize the table rdbmsSrvParamTable + * (Define its contents and how it's structured) + */ +void +_rdbmsSrvParamTable_initialize_interface(rdbmsSrvParamTable_registration_ptr reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &rdbmsSrvParamTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = &rdbmsSrvParamTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:rdbmsSrvParamTable:_rdbmsSrvParamTable_initialize_interface","called\n")); + + + /************************************************* + * + * save interface context for rdbmsSrvParamTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, + ASN_INTEGER, /** index: applIndex */ + ASN_OCTET_STR, /** index: rdbmsSrvParamName */ + ASN_INTEGER, /** index: rdbmsSrvParamSubIndex */ + 0); + + /* Define the minimum and maximum accessible columns. This + optimizes retrival. */ + tbl_info->min_column = RDBMSSRVPARAMTABLE_MIN_COL; + tbl_info->max_column = RDBMSSRVPARAMTABLE_MAX_COL; + + /* + * save users context + */ + rdbmsSrvParamTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + rdbmsSrvParamTable_init_data(reg_ptr); + + /* + * set up the container + */ + _rdbmsSrvParamTable_container_init(&rdbmsSrvParamTable_if_ctx); + if (NULL == rdbmsSrvParamTable_if_ctx.container) { + snmp_log(LOG_ERR,"could not initialize container for rdbmsSrvParamTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = _mfd_rdbmsSrvParamTable_object_lookup; + access_multiplexer->get_values = _mfd_rdbmsSrvParamTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = _mfd_rdbmsSrvParamTable_pre_request; + access_multiplexer->post_request = _mfd_rdbmsSrvParamTable_post_request; + + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("rdbmsSrvParamTable:init_rdbmsSrvParamTable", + "Registering rdbmsSrvParamTable as a mibs-for-dummies table.\n")); + handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = netsnmp_handler_registration_create("rdbmsSrvParamTable", handler, + rdbmsSrvParamTable_oid, + rdbmsSrvParamTable_oid_size, + HANDLER_CAN_BABY_STEP | + HANDLER_CAN_RONLY + ); + if(NULL == reginfo) { + snmp_log(LOG_ERR,"error registering table rdbmsSrvParamTable\n"); + return; + } + reginfo->my_reg_void = &rdbmsSrvParamTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if( access_multiplexer->object_lookup ) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if( access_multiplexer->set_values ) + mfd_modes |= BABY_STEP_SET_VALUES; + if( access_multiplexer->irreversible_commit ) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if( access_multiplexer->object_syntax_checks ) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if( access_multiplexer->pre_request ) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if( access_multiplexer->post_request ) + mfd_modes |= BABY_STEP_POST_REQUEST; + + if( access_multiplexer->undo_setup ) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if( access_multiplexer->undo_cleanup ) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if( access_multiplexer->undo_sets ) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if( access_multiplexer->row_creation ) + mfd_modes |= BABY_STEP_ROW_CREATE; + if( access_multiplexer->consistency_checks ) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if( access_multiplexer->commit ) + mfd_modes |= BABY_STEP_COMMIT; + if( access_multiplexer->undo_commit ) + mfd_modes |= BABY_STEP_UNDO_COMMIT; + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + rdbmsSrvParamTable_if_ctx.container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler( reginfo, handler ); + + /************************************************* + * + * inject cache helper + */ + if(NULL != rdbmsSrvParamTable_if_ctx.cache) { + handler = netsnmp_cache_handler_get(rdbmsSrvParamTable_if_ctx.cache); + netsnmp_inject_handler( reginfo, handler ); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); +} /* _rdbmsSrvParamTable_initialize_interface */ + +void +rdbmsSrvParamTable_valid_columns_set(netsnmp_column_info *vc) +{ + rdbmsSrvParamTable_if_ctx.tbl_info.valid_columns = vc; +} /* rdbmsSrvParamTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +rdbmsSrvParamTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsSrvParamTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_applIndex; + /* + * rdbmsSrvParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H + */ + netsnmp_variable_list var_rdbmsSrvParamName; + /* + * rdbmsSrvParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsSrvParamSubIndex; + + /* + * set up varbinds + */ + memset( &var_applIndex, 0x00, sizeof(var_applIndex) ); + var_applIndex.type = ASN_INTEGER; + memset( &var_rdbmsSrvParamName, 0x00, sizeof(var_rdbmsSrvParamName) ); + var_rdbmsSrvParamName.type = ASN_OCTET_STR; + memset( &var_rdbmsSrvParamSubIndex, 0x00, sizeof(var_rdbmsSrvParamSubIndex) ); + var_rdbmsSrvParamSubIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_applIndex.next_variable = &var_rdbmsSrvParamName; var_rdbmsSrvParamName.next_variable = &var_rdbmsSrvParamSubIndex; var_rdbmsSrvParamSubIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_index_to_oid","called\n")); + + /* applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_applIndex, (u_char*)&mib_idx->applIndex, + sizeof(mib_idx->applIndex)); + + /* rdbmsSrvParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ + snmp_set_var_value(&var_rdbmsSrvParamName, (u_char*)&mib_idx->rdbmsSrvParamName, + mib_idx->rdbmsSrvParamName_len * sizeof(mib_idx->rdbmsSrvParamName[0])); + + /* rdbmsSrvParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_rdbmsSrvParamSubIndex, (u_char*)&mib_idx->rdbmsSrvParamSubIndex, + sizeof(mib_idx->rdbmsSrvParamSubIndex)); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, (size_t *) &oid_idx->len, + NULL, 0, &var_applIndex); + if(err) + snmp_log(LOG_ERR,"error %d converting index to oid\n", err); + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_applIndex ); + + return err; +} /* rdbmsSrvParamTable_index_to_oid */ + +/** + * extract rdbmsSrvParamTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +rdbmsSrvParamTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsSrvParamTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_applIndex; + /* + * rdbmsSrvParamName(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H + */ + netsnmp_variable_list var_rdbmsSrvParamName; + /* + * rdbmsSrvParamSubIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_rdbmsSrvParamSubIndex; + + /* + * set up varbinds + */ + memset( &var_applIndex, 0x00, sizeof(var_applIndex) ); + var_applIndex.type = ASN_INTEGER; + memset( &var_rdbmsSrvParamName, 0x00, sizeof(var_rdbmsSrvParamName) ); + var_rdbmsSrvParamName.type = ASN_OCTET_STR; + memset( &var_rdbmsSrvParamSubIndex, 0x00, sizeof(var_rdbmsSrvParamSubIndex) ); + var_rdbmsSrvParamSubIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_applIndex.next_variable = &var_rdbmsSrvParamName; var_rdbmsSrvParamName.next_variable = &var_rdbmsSrvParamSubIndex; var_rdbmsSrvParamSubIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsSrvParamTable:rdbmsSrvParamTable_index_from_oid","called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes( oid_idx->oids, oid_idx->len, + &var_applIndex ); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + mib_idx->applIndex = *((long *)var_applIndex.val.string); + /* + * NOTE: val_len is in bytes, rdbmsSrvParamName_len might not be + */ + if(var_rdbmsSrvParamName.val_len > sizeof(mib_idx->rdbmsSrvParamName)) + err = SNMP_ERR_GENERR; + else { + memcpy(mib_idx->rdbmsSrvParamName, var_rdbmsSrvParamName.val.string, var_rdbmsSrvParamName.val_len); + mib_idx->rdbmsSrvParamName_len = var_rdbmsSrvParamName.val_len / sizeof(mib_idx->rdbmsSrvParamName[0]); + } + mib_idx->rdbmsSrvParamSubIndex = *((long *)var_rdbmsSrvParamSubIndex.val.string); + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_applIndex ); + + return err; +} /* rdbmsSrvParamTable_index_from_oid */ + + +/* ********************************************************************* + * @internal + * allocate resources for a rdbmsSrvParamTable_rowreq_ctx + */ +rdbmsSrvParamTable_rowreq_ctx * +rdbmsSrvParamTable_allocate_rowreq_ctx(void) +{ + rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(rdbmsSrvParamTable_rowreq_ctx); + + DEBUGMSGTL(("internal:rdbmsSrvParamTable:rdbmsSrvParamTable_allocate_rowreq_ctx","called\n")); + + if(NULL == rowreq_ctx) { + snmp_log(LOG_ERR,"Couldn't allocate memory for a " + "rdbmsSrvParamTable_rowreq_ctx.\n"); + } + + rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; + + rowreq_ctx->rdbmsSrvParamTable_data_list = NULL; + rowreq_ctx->rdbmsSrvParamTable_reg = rdbmsSrvParamTable_if_ctx.user_ctx; + + + return rowreq_ctx; +} /* rdbmsSrvParamTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a rdbmsSrvParamTable_rowreq_ctx + */ +void +rdbmsSrvParamTable_release_rowreq_ctx(rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("internal:rdbmsSrvParamTable:rdbmsSrvParamTable_release_rowreq_ctx","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + + /* + * free index oid pointer + */ + if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* rdbmsSrvParamTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsSrvParamTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc = rdbmsSrvParamTable_pre_request(rdbmsSrvParamTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsSrvParamTable","error %d from " + "rdbmsSrvParamTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvParamTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsSrvParamTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx; + int rc = rdbmsSrvParamTable_post_request(rdbmsSrvParamTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsSrvParamTable","error %d from " + "rdbmsSrvParamTable_post_request\n", rc)); + } + + /* + * if there are no errors, check for and handle row creation/deletion + */ + rc = netsnmp_check_requests_error(requests); + if ((SNMP_ERR_NOERROR == rc) && + (NULL != + (rowreq_ctx = netsnmp_container_table_row_extract(requests)))) { + if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) { + rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; + CONTAINER_INSERT(rdbmsSrvParamTable_if_ctx.container, rowreq_ctx); + } + else if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { + CONTAINER_REMOVE(rdbmsSrvParamTable_if_ctx.container, rowreq_ctx); + rdbmsSrvParamTable_release_rowreq_ctx(rowreq_ctx); + } + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvParamTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsSrvParamTable_object_lookup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsSrvParamTable:_mfd_rdbmsSrvParamTable_object_lookup","called\n")); + + /* + * get our context from mfd + * rdbmsSrvParamTable_interface_ctx *if_ctx = + * (rdbmsSrvParamTable_interface_ctx *)reginfo->my_reg_void; + */ + + if(NULL == rowreq_ctx) { + netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION); + } + else { + rdbmsSrvParamTable_row_prep(rowreq_ctx); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvParamTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsSrvParamTable_get_column( rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsSrvParamTable:_mfd_rdbmsSrvParamTable_get_column","called\n")); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsSrvParamID(3)/AutonomousType/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVPARAMID: + var->type = ASN_OBJECT_ID; +rc = rdbmsSrvParamID_get(rowreq_ctx, (oid **)&var->val.string, &var->val_len ); + break; + + /* rdbmsSrvParamCurrValue(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSSRVPARAMCURRVALUE: + var->type = ASN_OCTET_STR; +rc = rdbmsSrvParamCurrValue_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* rdbmsSrvParamComment(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSSRVPARAMCOMMENT: + var->type = ASN_OCTET_STR; +rc = rdbmsSrvParamComment_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsSrvParamTable_get_column\n", column); + break; + } + + return rc; +} /* _rdbmsSrvParamTable_get_column */ + +int +_mfd_rdbmsSrvParamTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + u_char * old_string; + void (*dataFreeHook)(void *); + int rc; + + DEBUGMSGTL(("internal:rdbmsSrvParamTable:_mfd_rdbmsSrvParamTable_get_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if(NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + else if(requests->requestvb->buf == requests->requestvb->val.string) { + if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsSrvParamTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + if(MFD_SKIP == rc) { + requests->requestvb->type = ASN_PRIV_RETRY; + rc = SNMP_ERR_NOERROR; + } + } + else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if(rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if(old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if(dataFreeHook) + (*dataFreeHook)(old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvParamTable_get_values */ + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/* + * NOT APPLICABLE (per MIB or user setting) + */ +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +/** + * @internal + */ +static int +_cache_load(netsnmp_cache *cache, void *vmagic) +{ + DEBUGMSGTL(("internal:rdbmsSrvParamTable:_cache_load","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache for rdbmsSrvParamTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return rdbmsSrvParamTable_cache_load((netsnmp_container*)cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_item_free(rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx, void *context) +{ + DEBUGMSGTL(("internal:rdbmsSrvParamTable:_cache_item_free","called\n")); + + if(NULL == rowreq_ctx) + return; + + rdbmsSrvParamTable_release_rowreq_ctx(rowreq_ctx); +} /* _cache_item_free */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache *cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:rdbmsSrvParamTable:_cache_free","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache in rdbmsSrvParamTable_cache_free\n"); + return; + } + + container = (netsnmp_container*)cache->magic; + + /* + * call user code + */ + rdbmsSrvParamTable_cache_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *)_cache_item_free, + NULL); +} /* _cache_free */ + +/** + * @internal + * initialize the iterator container with functions or wrappers + */ +void +_rdbmsSrvParamTable_container_init(rdbmsSrvParamTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:rdbmsSrvParamTable:_rdbmsSrvParamTable_container_init","called\n")); + + /* + * set up the cache + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + rdbmsSrvParamTable_oid, + rdbmsSrvParamTable_oid_size); + + if(NULL == if_ctx->cache) { + snmp_log(LOG_ERR, "error creating cache for rdbmsSrvParamTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + rdbmsSrvParamTable_container_init(&if_ctx->container, if_ctx->cache); + if(NULL == if_ctx->container) + if_ctx->container = netsnmp_container_find("rdbmsSrvParamTable:table_container"); + if(NULL == if_ctx->container) { + snmp_log(LOG_ERR,"error creating container in " + "rdbmsSrvParamTable_container_init\n"); + return; + } + if_ctx->cache->magic = (void*)if_ctx->container; +} /* _rdbmsSrvParamTable_container_init */ + diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_interface.h b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_interface.h new file mode 100644 index 0000000..b96523b --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_interface.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_interface.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_interface.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVPARAMTABLE_INTERFACE_H +#define RDBMSSRVPARAMTABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "rdbmsSrvParamTable.h" + +/* ******************************************************************** + * Table declarations + */ + +/* PUBLIC interface initialization routine */ +void _rdbmsSrvParamTable_initialize_interface(rdbmsSrvParamTable_registration_ptr user_ctx, + u_long flags); + + rdbmsSrvParamTable_rowreq_ctx * rdbmsSrvParamTable_allocate_rowreq_ctx(void); +void rdbmsSrvParamTable_release_rowreq_ctx(rdbmsSrvParamTable_rowreq_ctx *rowreq_ctx); + +int rdbmsSrvParamTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsSrvParamTable_mib_index *mib_idx); +int rdbmsSrvParamTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsSrvParamTable_mib_index *mib_idx); + +/* + * access to certain internals. use with caution! + */ +void rdbmsSrvParamTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVPARAMTABLE_INTERFACE_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_oids.h b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_oids.h new file mode 100644 index 0000000..6c7903b --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvParamTable/rdbmsSrvParamTable_oids.h @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvParamTable_oids.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvParamTable_oids.h,v 1.2 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVPARAMTABLE_OIDS_H +#define RDBMSSRVPARAMTABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* column number definitions for table rdbmsSrvParamTable */ +#define RDBMSSRVPARAMTABLE_OID 1,3,6,1,2,1,39,1,7 +#define COLUMN_RDBMSSRVPARAMNAME 1 +#define COLUMN_RDBMSSRVPARAMSUBINDEX 2 +#define COLUMN_RDBMSSRVPARAMID 3 +#define COLUMN_RDBMSSRVPARAMCURRVALUE 4 +#define COLUMN_RDBMSSRVPARAMCOMMENT 5 + +#define RDBMSSRVPARAMTABLE_MIN_COL COLUMN_RDBMSSRVPARAMID +#define RDBMSSRVPARAMTABLE_MAX_COL COLUMN_RDBMSSRVPARAMCOMMENT + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVPARAMTABLE_OIDS_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable.c b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable.c new file mode 100644 index 0000000..f713244 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable.c @@ -0,0 +1,130 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable.c,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsSrvTable.h" + +#include <net-snmp/agent/mib_modules.h> + +#include "rdbmsSrvTable_interface.h" + +oid rdbmsSrvTable_oid[] = { RDBMSSRVTABLE_OID }; +int rdbmsSrvTable_oid_size = OID_LENGTH(rdbmsSrvTable_oid); + +void initialize_table_rdbmsSrvTable(void); + + +/** + * Initializes the rdbmsSrvTable module + */ +void +init_rdbmsSrvTable(void) +{ + DEBUGMSGTL(("verbose:rdbmsSrvTable:init_rdbmsSrvTable","called\n")); + + /* + * TODO:300:o: Perform rdbmsSrvTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("rdbmsSrvTable")) + initialize_table_rdbmsSrvTable(); + +} /* init_rdbmsSrvTable */ + +/** + * Initialize the table rdbmsSrvTable + * (Define its contents and how it's structured) + */ +void +initialize_table_rdbmsSrvTable(void) +{ + rdbmsSrvTable_registration_ptr user_context; + u_long flags; + + DEBUGMSGTL(("verbose:rdbmsSrvTable:initialize_table_rdbmsSrvTable","called\n")); + + /* + * TODO:301:o: Perform rdbmsSrvTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize rdbmsSrvTable user context + * if you'd like to pass in a pointer to some data for this + * table, allocate or set it up here. + */ + /* + * a netsnmp_data_list is a simple way to store void pointers. A simple + * string token is used to add, find or remove pointers. + */ + user_context = netsnmp_create_data_list("rdbmsSrvTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _rdbmsSrvTable_initialize_interface(user_context, flags); +} /* initialize_table_rdbmsSrvTable */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +rdbmsSrvTable_pre_request(rdbmsSrvTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_pre_request","called\n")); + + /* + * TODO:510:o: Perform rdbmsSrvTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvTable_pre_request */ + +/** + * post-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error (ignored) + */ +int +rdbmsSrvTable_post_request(rdbmsSrvTable_registration_ptr user_context) +{ + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_post_request","called\n")); + + /* + * TODO:511:o: Perform rdbmsSrvTable pos-request actions. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvTable_post_request */ + + +/** @{ */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable.h b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable.h new file mode 100644 index 0000000..c2c6553 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable.h @@ -0,0 +1,205 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable.h,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVTABLE_H +#define RDBMSSRVTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @defgroup misc misc: Miscelaneous routines + * + * @{ + */ +#include <net-snmp/library/asn1.h> + +/* other required module components */ + /* *INDENT-OFF* */ +config_require(RDBMS-MIB/rdbmsSrvTable/rdbmsSrvTable_interface); +config_require(RDBMS-MIB/rdbmsSrvTable/rdbmsSrvTable_data_access); +config_require(RDBMS-MIB/rdbmsSrvTable/rdbmsSrvTable_data_get); +config_require(RDBMS-MIB/rdbmsSrvTable/rdbmsSrvTable_data_set); + /* *INDENT-ON* */ + +/* OID and column number definitions for */ +#include "rdbmsSrvTable_oids.h" + +/* enum definions */ +#include "rdbmsSrvTable_enums.h" + +/* ********************************************************************* + * function declarations + */ +void init_rdbmsSrvTable(void); + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvTable is subid 5 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.5, length: 9 +*/ +/* ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review rdbmsSrvTable registration context. + */ +typedef netsnmp_data_list * rdbmsSrvTable_registration_ptr; + +/**********************************************************************/ +/* + * TODO:110:r: |-> Review rdbmsSrvTable data context structure. + * This structure is used to represent the data for rdbmsSrvTable. + */ +/* + * This structure contains storage for all the columns defined in the + * rdbmsSrvTable. + */ +typedef struct rdbmsSrvTable_data_s { + + /* + * rdbmsSrvPrivateMibOID(1)/OBJECTID/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h + */ + oid rdbmsSrvPrivateMibOID[128]; +size_t rdbmsSrvPrivateMibOID_len; /* # of oid elements, not bytes */ + + /* + * rdbmsSrvVendorName(2)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ + char rdbmsSrvVendorName[255]; +size_t rdbmsSrvVendorName_len; /* # of char elements, not bytes */ + + /* + * rdbmsSrvProductName(3)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H + */ + char rdbmsSrvProductName[255]; +size_t rdbmsSrvProductName_len; /* # of char elements, not bytes */ + + /* + * rdbmsSrvContact(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + char rdbmsSrvContact[255]; +size_t rdbmsSrvContact_len; /* # of char elements, not bytes */ + +} rdbmsSrvTable_data; + + +/* + * TODO:120:r: |-> Review rdbmsSrvTable mib index. + * This structure is used to represent the index for rdbmsSrvTable. + */ +typedef struct rdbmsSrvTable_mib_index_s { + + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + long applIndex; + + +} rdbmsSrvTable_mib_index; + + /* + * TODO:121:r: | |-> Review rdbmsSrvTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. +*/ +#define MAX_rdbmsSrvTable_IDX_LEN 1 + + +/* ********************************************************************* + * TODO:130:o: |-> Review rdbmsSrvTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * rdbmsSrvTable_rowreq_ctx pointer. + */ +typedef struct rdbmsSrvTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_rdbmsSrvTable_IDX_LEN]; + + rdbmsSrvTable_mib_index tbl_idx; + + rdbmsSrvTable_data data; + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * implementor's context pointer (provided during registration) + */ + rdbmsSrvTable_registration_ptr rdbmsSrvTable_reg; + + /* + * TODO:131:o: | |-> Add useful data to rdbmsSrvTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *rdbmsSrvTable_data_list; + +} rdbmsSrvTable_rowreq_ctx; + +typedef struct rdbmsSrvTable_ref_rowreq_ctx_s { + rdbmsSrvTable_rowreq_ctx *rowreq_ctx; +} rdbmsSrvTable_ref_rowreq_ctx; + +/* ********************************************************************* + * function prototypes + */ + int rdbmsSrvTable_pre_request(rdbmsSrvTable_registration_ptr user_context); + int rdbmsSrvTable_post_request(rdbmsSrvTable_registration_ptr user_context); + + +extern oid rdbmsSrvTable_oid[]; +extern int rdbmsSrvTable_oid_size; + + +#include "rdbmsSrvTable_interface.h" +#include "rdbmsSrvTable_data_access.h" +#include "rdbmsSrvTable_data_get.h" +#include "rdbmsSrvTable_data_set.h" + +/* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVTABLE_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_access.c b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_access.c new file mode 100644 index 0000000..6345766 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_access.c @@ -0,0 +1,306 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_data_access.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_data_access.c,v 1.9 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsSrvTable.h" +#include "rdbmsSrvTable_data_access.h" + +/** @defgroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvTable is subid 5 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.5, length: 9 +*/ + +/** + * initialization for rdbmsSrvTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param rdbmsSrvTable_reg + * Pointer to rdbmsSrvTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +rdbmsSrvTable_init_data(rdbmsSrvTable_registration_ptr rdbmsSrvTable_reg) +{ + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_init_data","called\n")); + + /* + * TODO:303:o: Initialize rdbmsSrvTable data. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvTable_init_data */ + +/** + * container-cached overview + * + */ + +/*********************************************************************** + * + * cache + * + ***********************************************************************/ +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +rdbmsSrvTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache) +{ + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_container_init","called\n")); + + if((NULL == cache) || (NULL == container_ptr_ptr)) { + snmp_log(LOG_ERR,"bad params to rdbmsSrvTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + /* + * TODO:345:A: Set up rdbmsSrvTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = RDBMSSRVTABLE_CACHE_TIMEOUT; /* seconds */ +} /* rdbmsSrvTable_container_init */ + +/** + * load cache data + * + * TODO:350:M: Implement rdbmsSrvTable cache load + * + * @param container container to which items should be inserted + * + * @retval MFD_SUCCESS : success. + * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source + * @retval MFD_ERROR : other error. + * + * This function is called to cache the index(es) (and data, optionally) + * for the every row in the data set. + * + * @remark + * While loading the cache, the only important thing is the indexes. + * If access to your data is cheap/fast (e.g. you have a pointer to a + * structure in memory), it would make sense to update the data here. + * If, however, the accessing the data invovles more work (e.g. parsing + * some other existing data, or peforming calculations to derive the data), + * then you can limit yourself to setting the indexes and saving any + * information you will need later. Then use the saved information in + * rdbmsSrvTable_row_prep() for populating data. + * + * @note + * If you need consistency between rows (like you want statistics + * for each row to be from the same time frame), you should set all + * data here. + * + */ +int +rdbmsSrvTable_cache_load(netsnmp_container *container) +{ + rdbmsSrvTable_rowreq_ctx *rowreq_ctx; + oid rdbmsSrvPrivateMibOID[128] = { 1,3,6,1,4,1,27645 }; + size_t count = 0; + + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + + /* Eventually we'll probably want to make this actually pay attention to + * APPLICATION-MIB. For now, I'm ignoring it. When we make that change, we'll need to + * modify the other files that use applIndex (the one I'm thinking of now is rdbmsRelTable */ + long applIndex = 1; + PGresult *pgsnmpd_tbl_qry; + int vendor_len, contact_len, product_len; + char *vendor_name, *contact_name, *product_name; + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_cache_load","called\n")); + + /* + * TODO:351:M: |-> Load/update data in the rdbmsSrvTable container. + * loop over your rdbmsSrvTable data, allocate a rowreq context, + * set the index(es) [and data, optionally] and insert into + * the container. + */ + + /* There's only one server, so we only need to create one row */ + /* + * TODO:352:M: | |-> set indexes in new rdbmsSrvTable rowreq context. + */ + rowreq_ctx = rdbmsSrvTable_allocate_rowreq_ctx(); + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "memory allocation failed\n"); + return MFD_RESOURCE_UNAVAILABLE; + } + if(MFD_SUCCESS != rdbmsSrvTable_indexes_set(rowreq_ctx + , applIndex + )) { + snmp_log(LOG_ERR,"error setting index while loading " + "rdbmsSrvTable cache.\n"); + rdbmsSrvTable_release_rowreq_ctx(rowreq_ctx); + return MFD_ERROR; + } + + pgsnmpd_tbl_qry = PQexec(dbconn, "SELECT vendor_name, product_name, contact_name FROM pgsnmpd_rdbmsSrvTable"); + if (PQresultStatus(pgsnmpd_tbl_qry) == PGRES_TUPLES_OK && PQntuples(pgsnmpd_tbl_qry) > 0) { + vendor_name = PQgetvalue(pgsnmpd_tbl_qry, 0, 0); + product_name = PQgetvalue(pgsnmpd_tbl_qry, 0, 1); + contact_name = PQgetvalue(pgsnmpd_tbl_qry, 0, 2); + vendor_len = strlen(vendor_name); + product_len = strlen(product_name); + contact_len = strlen(contact_name); + } + else { + product_name = NULL; + vendor_name = NULL; + contact_name = NULL; + product_len = 0; + vendor_len = 0; + contact_len = 0; + } + + rowreq_ctx->data.rdbmsSrvVendorName_len = 255; + rowreq_ctx->data.rdbmsSrvContact_len = 255; + rowreq_ctx->data.rdbmsSrvProductName_len = 255; + + rowreq_ctx->data.rdbmsSrvPrivateMibOID_len = 8 * sizeof(rowreq_ctx->data.rdbmsSrvPrivateMibOID[0]); + memcpy( rowreq_ctx->data.rdbmsSrvPrivateMibOID, rdbmsSrvPrivateMibOID, rowreq_ctx->data.rdbmsSrvPrivateMibOID_len ); + + rowreq_ctx->data.rdbmsSrvVendorName_len = vendor_len * sizeof(rowreq_ctx->data.rdbmsSrvVendorName[0]); + memcpy( rowreq_ctx->data.rdbmsSrvVendorName, vendor_name, rowreq_ctx->data.rdbmsSrvVendorName_len ); + + rowreq_ctx->data.rdbmsSrvProductName_len = product_len * sizeof(rowreq_ctx->data.rdbmsSrvProductName[0]); + memcpy( rowreq_ctx->data.rdbmsSrvProductName, product_name, rowreq_ctx->data.rdbmsSrvProductName_len ); + + rowreq_ctx->data.rdbmsSrvContact_len = contact_len * sizeof(rowreq_ctx->data.rdbmsSrvContact[0]); + memcpy( rowreq_ctx->data.rdbmsSrvContact, contact_name, rowreq_ctx->data.rdbmsSrvContact_len ); + + PQclear(pgsnmpd_tbl_qry); + + + /* + * insert into table container + */ + CONTAINER_INSERT(container, rowreq_ctx); + ++count; + + + DEBUGMSGT(("verbose:rdbmsSrvTable:rdbmsSrvTable_cache_load", + "inserted %d records\n", count)); + + return MFD_SUCCESS; +} /* rdbmsSrvTable_cache_load */ + +/** + * cache clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +rdbmsSrvTable_cache_free(netsnmp_container *container) +{ + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_cache_free","called\n")); + + /* + * TODO:380:M: Free rdbmsSrvTable cache. + */ +} /* rdbmsSrvTable_cache_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +rdbmsSrvTable_row_prep( rdbmsSrvTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_row_prep","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* rdbmsSrvTable_row_prep */ + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_access.h b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_access.h new file mode 100644 index 0000000..a074ba0 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_access.h @@ -0,0 +1,64 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_data_access.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_data_access.h,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVTABLE_DATA_ACCESS_H +#define RDBMSSRVTABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ********************************************************************* + * function declarations + */ + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvTable is subid 5 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.5, length: 9 +*/ + + + int rdbmsSrvTable_init_data(rdbmsSrvTable_registration_ptr rdbmsSrvTable_reg); + + +/* + * TODO:180:o: Review rdbmsSrvTable cache timeout. + * The number of seconds before the cache times out + */ +#define RDBMSSRVTABLE_CACHE_TIMEOUT 60 + +void rdbmsSrvTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache); +int rdbmsSrvTable_cache_load(netsnmp_container *container); +void rdbmsSrvTable_cache_free(netsnmp_container *container); + + int rdbmsSrvTable_row_prep( rdbmsSrvTable_rowreq_ctx *rowreq_ctx); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVTABLE_DATA_ACCESS_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_get.c b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_get.c new file mode 100644 index 0000000..ce0fa3d --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_get.c @@ -0,0 +1,758 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_data_get.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_data_get.c,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsSrvTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement rdbmsSrvTable get routines. + * TODO:240:M: Implement rdbmsSrvTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvTable is subid 5 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.5, length: 9 +*/ + +/* --------------------------------------------------------------------- + * TODO:200:r: Implement rdbmsSrvTable data context functions. + */ + +/*--------------------------------------------------------------------- + * APPLICATION-MIB::applEntry.applIndex + * applIndex is subid 1 of applEntry. + * Its status is Current, and its access level is NoAccess. + * OID: .1.3.6.1.2.1.27.1.1.1 + * Description: +An index to uniquely identify the network service + application. + * + * Attributes: + * accessible 0 isscalar 0 enums 0 hasdefval 0 + * readable 0 iscolumn 1 ranges 1 hashint 0 + * settable 0 + * + * Ranges: 1 - 2147483647; + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + * + * + * + * NOTE: NODE applIndex IS NOT ACCESSIBLE + * + * + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-applIndex.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +applIndex_map(long *mib_applIndex_val_ptr, long raw_applIndex_val) +{ + netsnmp_assert(NULL != mib_applIndex_val_ptr); + + DEBUGMSGTL(("verbose:rdbmsSrvTable:applIndex_map","called\n")); + + /* + * TODO:241:o: |-> Implement applIndex mapping. + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + */ + (*mib_applIndex_val_ptr) = raw_applIndex_val; + + return MFD_SUCCESS; +} /* applIndex_map */ + + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This convenience function is useful for setting all the MIB index + * components with a single function call. It is assume that the C values + * have already been mapped from their native/rawformat to the MIB format. + */ +int +rdbmsSrvTable_indexes_set_tbl_idx(rdbmsSrvTable_mib_index *tbl_idx, long applIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_indexes_set_tbl_idx","called\n")); + + /* applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + tbl_idx->applIndex = applIndex_val; + + + return MFD_SUCCESS; +} /* rdbmsSrvTable_indexes_set_tbl_idx */ + +/** + * @internal + * set row context indexes + * + * @param reqreq_ctx the row context that needs updated indexes + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This function sets the mib indexs, then updates the oid indexs + * from the mib index. + */ +int +rdbmsSrvTable_indexes_set(rdbmsSrvTable_rowreq_ctx *rowreq_ctx, long applIndex_val) +{ + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_indexes_set","called\n")); + + if(MFD_SUCCESS != rdbmsSrvTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx + , applIndex_val + )) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if(0 != rdbmsSrvTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* rdbmsSrvTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvEntry.rdbmsSrvPrivateMibOID + * rdbmsSrvPrivateMibOID is subid 1 of rdbmsSrvEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.5.1.1 + * Description: +The authoritative identification for the private MIB for this + server, presumably based on the vendor, e.g., { enterprises + 111 <optional subidentifiers>} for Oracle servers, { + enterprises 757 <optional subidentifiers>} for Ingres + servers, { enterprises 897 <optional subidentifiers>} for + Sybase servers, etc. + + If no OBJECT IDENTIFIER exists for the private MIB, attempts + to access this object will return noSuchName (SNMPv1) + or noSuchInstance (SNMPv2). + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * + * Its syntax is OBJECTID (based on perltype OBJECTID) + * The net-snmp type is ASN_OBJECT_ID. The C type decl is oid (oid) + * This data type requires a length. (Max 2147483647) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvPrivateMibOID.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvPrivateMibOID_map(oid **mib_rdbmsSrvPrivateMibOID_val_ptr_ptr, size_t *mib_rdbmsSrvPrivateMibOID_val_ptr_len_ptr, oid *raw_rdbmsSrvPrivateMibOID_val_ptr, size_t raw_rdbmsSrvPrivateMibOID_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsSrvPrivateMibOID_val_ptr); + netsnmp_assert((NULL != mib_rdbmsSrvPrivateMibOID_val_ptr_ptr) && (NULL != mib_rdbmsSrvPrivateMibOID_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvPrivateMibOID_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsSrvPrivateMibOID non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsSrvPrivateMibOID_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsSrvPrivateMibOID_val_ptr_ptr) || (*mib_rdbmsSrvPrivateMibOID_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsSrvPrivateMibOID_val_ptr_ptr = realloc( *mib_rdbmsSrvPrivateMibOID_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsSrvPrivateMibOID_val_ptr_ptr)); + if(NULL == *mib_rdbmsSrvPrivateMibOID_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsSrvPrivateMibOID_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsSrvPrivateMibOID_val_ptr_ptr, raw_rdbmsSrvPrivateMibOID_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsSrvPrivateMibOID_map */ + +/** + * Extract the current value of the rdbmsSrvPrivateMibOID data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvPrivateMibOID_val_ptr_ptr + * Pointer to storage for a oid variable + * @param rdbmsSrvPrivateMibOID_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsSrvPrivateMibOID. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsSrvPrivateMibOID_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsSrvPrivateMibOID_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsSrvPrivateMibOID_get( rdbmsSrvTable_rowreq_ctx *rowreq_ctx, oid **rdbmsSrvPrivateMibOID_val_ptr_ptr, size_t *rdbmsSrvPrivateMibOID_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsSrvPrivateMibOID_val_ptr_ptr) && (NULL != *rdbmsSrvPrivateMibOID_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsSrvPrivateMibOID_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvPrivateMibOID_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvPrivateMibOID data. + * set (* rdbmsSrvPrivateMibOID_val_ptr_ptr ) and (* rdbmsSrvPrivateMibOID_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsSrvPrivateMibOID data + */ + if ((NULL == (* rdbmsSrvPrivateMibOID_val_ptr_ptr )) || + ((* rdbmsSrvPrivateMibOID_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsSrvPrivateMibOID_len * sizeof((* rdbmsSrvPrivateMibOID_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsSrvPrivateMibOID data + */ + (* rdbmsSrvPrivateMibOID_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsSrvPrivateMibOID_len * sizeof((* rdbmsSrvPrivateMibOID_val_ptr_ptr )[0])); + if(NULL == (* rdbmsSrvPrivateMibOID_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsSrvPrivateMibOID_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsSrvPrivateMibOID_len * sizeof((* rdbmsSrvPrivateMibOID_val_ptr_ptr )[0]); + memcpy( (* rdbmsSrvPrivateMibOID_val_ptr_ptr ), rowreq_ctx->data.rdbmsSrvPrivateMibOID, (* rdbmsSrvPrivateMibOID_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsSrvPrivateMibOID_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvEntry.rdbmsSrvVendorName + * rdbmsSrvVendorName is subid 2 of rdbmsSrvEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.5.1.2 + * Description: +The name of the vendor whose RDBMS manages this database, + for informational purposes. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvVendorName.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvVendorName_map(char **mib_rdbmsSrvVendorName_val_ptr_ptr, size_t *mib_rdbmsSrvVendorName_val_ptr_len_ptr, char *raw_rdbmsSrvVendorName_val_ptr, size_t raw_rdbmsSrvVendorName_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsSrvVendorName_val_ptr); + netsnmp_assert((NULL != mib_rdbmsSrvVendorName_val_ptr_ptr) && (NULL != mib_rdbmsSrvVendorName_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvVendorName_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsSrvVendorName non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsSrvVendorName_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsSrvVendorName_val_ptr_ptr) || (*mib_rdbmsSrvVendorName_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsSrvVendorName_val_ptr_ptr = realloc( *mib_rdbmsSrvVendorName_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsSrvVendorName_val_ptr_ptr)); + if(NULL == *mib_rdbmsSrvVendorName_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsSrvVendorName_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsSrvVendorName_val_ptr_ptr, raw_rdbmsSrvVendorName_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsSrvVendorName_map */ + +/** + * Extract the current value of the rdbmsSrvVendorName data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvVendorName_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsSrvVendorName_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsSrvVendorName. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsSrvVendorName_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsSrvVendorName_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsSrvVendorName_get( rdbmsSrvTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvVendorName_val_ptr_ptr, size_t *rdbmsSrvVendorName_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsSrvVendorName_val_ptr_ptr) && (NULL != *rdbmsSrvVendorName_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsSrvVendorName_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvVendorName_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvVendorName data. + * set (* rdbmsSrvVendorName_val_ptr_ptr ) and (* rdbmsSrvVendorName_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsSrvVendorName data + */ + if ((NULL == (* rdbmsSrvVendorName_val_ptr_ptr )) || + ((* rdbmsSrvVendorName_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsSrvVendorName_len * sizeof((* rdbmsSrvVendorName_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsSrvVendorName data + */ + (* rdbmsSrvVendorName_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsSrvVendorName_len * sizeof((* rdbmsSrvVendorName_val_ptr_ptr )[0])); + if(NULL == (* rdbmsSrvVendorName_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsSrvVendorName_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsSrvVendorName_len * sizeof((* rdbmsSrvVendorName_val_ptr_ptr )[0]); + memcpy( (* rdbmsSrvVendorName_val_ptr_ptr ), rowreq_ctx->data.rdbmsSrvVendorName, (* rdbmsSrvVendorName_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsSrvVendorName_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvEntry.rdbmsSrvProductName + * rdbmsSrvProductName is subid 3 of rdbmsSrvEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.39.1.5.1.3 + * Description: +The product name of this server. This is normally the + vendor's formal name for the product, in product specific + format. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 0 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvProductName.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvProductName_map(char **mib_rdbmsSrvProductName_val_ptr_ptr, size_t *mib_rdbmsSrvProductName_val_ptr_len_ptr, char *raw_rdbmsSrvProductName_val_ptr, size_t raw_rdbmsSrvProductName_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsSrvProductName_val_ptr); + netsnmp_assert((NULL != mib_rdbmsSrvProductName_val_ptr_ptr) && (NULL != mib_rdbmsSrvProductName_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvProductName_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsSrvProductName non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsSrvProductName_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsSrvProductName_val_ptr_ptr) || (*mib_rdbmsSrvProductName_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsSrvProductName_val_ptr_ptr = realloc( *mib_rdbmsSrvProductName_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsSrvProductName_val_ptr_ptr)); + if(NULL == *mib_rdbmsSrvProductName_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsSrvProductName_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsSrvProductName_val_ptr_ptr, raw_rdbmsSrvProductName_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsSrvProductName_map */ + +/** + * Extract the current value of the rdbmsSrvProductName data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvProductName_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsSrvProductName_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsSrvProductName. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsSrvProductName_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsSrvProductName_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsSrvProductName_get( rdbmsSrvTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvProductName_val_ptr_ptr, size_t *rdbmsSrvProductName_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsSrvProductName_val_ptr_ptr) && (NULL != *rdbmsSrvProductName_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsSrvProductName_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvProductName_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvProductName data. + * set (* rdbmsSrvProductName_val_ptr_ptr ) and (* rdbmsSrvProductName_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsSrvProductName data + */ + if ((NULL == (* rdbmsSrvProductName_val_ptr_ptr )) || + ((* rdbmsSrvProductName_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsSrvProductName_len * sizeof((* rdbmsSrvProductName_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsSrvProductName data + */ + (* rdbmsSrvProductName_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsSrvProductName_len * sizeof((* rdbmsSrvProductName_val_ptr_ptr )[0])); + if(NULL == (* rdbmsSrvProductName_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsSrvProductName_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsSrvProductName_len * sizeof((* rdbmsSrvProductName_val_ptr_ptr )[0]); + memcpy( (* rdbmsSrvProductName_val_ptr_ptr ), rowreq_ctx->data.rdbmsSrvProductName, (* rdbmsSrvProductName_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsSrvProductName_get */ + +/*--------------------------------------------------------------------- + * RDBMS-MIB::rdbmsSrvEntry.rdbmsSrvContact + * rdbmsSrvContact is subid 4 of rdbmsSrvEntry. + * Its status is Current, and its access level is ReadWrite. + * OID: .1.3.6.1.2.1.39.1.5.1.4 + * Description: +The textual identification of the contact person for this + managed server, together with information on how to contact + this person. + + Note: if there is no active server associated with this + object, an agent may need to keep this in other persistent + storage, e.g., a configuration file. + + Note that a compliant agent does not need to + allow write access to this object. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 1 + * hint: 255a + * + * Ranges: 0 - 255; + * + * Its syntax is DisplayString (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 255) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * default-node-rdbmsSrvContact.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +rdbmsSrvContact_map(char **mib_rdbmsSrvContact_val_ptr_ptr, size_t *mib_rdbmsSrvContact_val_ptr_len_ptr, char *raw_rdbmsSrvContact_val_ptr, size_t raw_rdbmsSrvContact_val_ptr_len, int allow_realloc) +{ + int converted_len; + + netsnmp_assert(NULL != raw_rdbmsSrvContact_val_ptr); + netsnmp_assert((NULL != mib_rdbmsSrvContact_val_ptr_ptr) && (NULL != mib_rdbmsSrvContact_val_ptr_len_ptr)); + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvContact_map","called\n")); + + /* + * TODO:241:r: |-> Implement rdbmsSrvContact non-integer mapping + * it is hard to autogenerate code for mapping types that are not simple + * integers, so here is an idea of what you might need to do. It will + * probably need some tweaking to get right. + */ + /* + * if the length of the raw data doesn't directly correspond with + * the length of the mib data, set converted_len to the + * space required. + */ + converted_len = raw_rdbmsSrvContact_val_ptr_len; /* assume equal */ + if((NULL == *mib_rdbmsSrvContact_val_ptr_ptr) || (*mib_rdbmsSrvContact_val_ptr_len_ptr < converted_len)) { + if(! allow_realloc) { + snmp_log(LOG_ERR,"not enough space for value mapping\n"); + return SNMP_ERR_GENERR; + } + *mib_rdbmsSrvContact_val_ptr_ptr = realloc( *mib_rdbmsSrvContact_val_ptr_ptr, converted_len * sizeof(**mib_rdbmsSrvContact_val_ptr_ptr)); + if(NULL == *mib_rdbmsSrvContact_val_ptr_ptr) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return SNMP_ERR_GENERR; + } + } + *mib_rdbmsSrvContact_val_ptr_len_ptr = converted_len; + memcpy( *mib_rdbmsSrvContact_val_ptr_ptr, raw_rdbmsSrvContact_val_ptr, converted_len ); + + return MFD_SUCCESS; +} /* rdbmsSrvContact_map */ + +/** + * Extract the current value of the rdbmsSrvContact data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param rdbmsSrvContact_val_ptr_ptr + * Pointer to storage for a char variable + * @param rdbmsSrvContact_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by rdbmsSrvContact. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*rdbmsSrvContact_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update rdbmsSrvContact_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +rdbmsSrvContact_get( rdbmsSrvTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvContact_val_ptr_ptr, size_t *rdbmsSrvContact_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != rdbmsSrvContact_val_ptr_ptr) && (NULL != *rdbmsSrvContact_val_ptr_ptr)); + netsnmp_assert( NULL != rdbmsSrvContact_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvContact_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the rdbmsSrvContact data. + * set (* rdbmsSrvContact_val_ptr_ptr ) and (* rdbmsSrvContact_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for rdbmsSrvContact data + */ + if ((NULL == (* rdbmsSrvContact_val_ptr_ptr )) || + ((* rdbmsSrvContact_val_ptr_len_ptr ) < (rowreq_ctx->data.rdbmsSrvContact_len * sizeof((* rdbmsSrvContact_val_ptr_ptr )[0])))) { + /* + * allocate space for rdbmsSrvContact data + */ + (* rdbmsSrvContact_val_ptr_ptr ) = malloc(rowreq_ctx->data.rdbmsSrvContact_len * sizeof((* rdbmsSrvContact_val_ptr_ptr )[0])); + if(NULL == (* rdbmsSrvContact_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory\n"); + return MFD_ERROR; + } + } + (* rdbmsSrvContact_val_ptr_len_ptr ) = rowreq_ctx->data.rdbmsSrvContact_len * sizeof((* rdbmsSrvContact_val_ptr_ptr )[0]); + memcpy( (* rdbmsSrvContact_val_ptr_ptr ), rowreq_ctx->data.rdbmsSrvContact, (* rdbmsSrvContact_val_ptr_len_ptr ) ); + + return MFD_SUCCESS; +} /* rdbmsSrvContact_get */ + + + +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_get.h b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_get.h new file mode 100644 index 0000000..f2d17f9 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_get.h @@ -0,0 +1,66 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_data_get.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_data_get.h,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVTABLE_DATA_GET_H +#define RDBMSSRVTABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * GET function declarations + */ + +/* ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvTable is subid 5 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.5, length: 9 +*/ + /* + * indexes + */ + int applIndex_map(long *mib_applIndex_val_ptr, long raw_applIndex_val); + + int rdbmsSrvPrivateMibOID_map(oid **mib_rdbmsSrvPrivateMibOID_val_ptr_ptr, size_t *mib_rdbmsSrvPrivateMibOID_val_ptr_len_ptr, oid *raw_rdbmsSrvPrivateMibOID_val_ptr, size_t raw_rdbmsSrvPrivateMibOID_val_ptr_len, int allow_realloc); + int rdbmsSrvPrivateMibOID_get( rdbmsSrvTable_rowreq_ctx *rowreq_ctx, oid **rdbmsSrvPrivateMibOID_val_ptr_ptr, size_t *rdbmsSrvPrivateMibOID_val_ptr_len_ptr ); + int rdbmsSrvVendorName_map(char **mib_rdbmsSrvVendorName_val_ptr_ptr, size_t *mib_rdbmsSrvVendorName_val_ptr_len_ptr, char *raw_rdbmsSrvVendorName_val_ptr, size_t raw_rdbmsSrvVendorName_val_ptr_len, int allow_realloc); + int rdbmsSrvVendorName_get( rdbmsSrvTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvVendorName_val_ptr_ptr, size_t *rdbmsSrvVendorName_val_ptr_len_ptr ); + int rdbmsSrvProductName_map(char **mib_rdbmsSrvProductName_val_ptr_ptr, size_t *mib_rdbmsSrvProductName_val_ptr_len_ptr, char *raw_rdbmsSrvProductName_val_ptr, size_t raw_rdbmsSrvProductName_val_ptr_len, int allow_realloc); + int rdbmsSrvProductName_get( rdbmsSrvTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvProductName_val_ptr_ptr, size_t *rdbmsSrvProductName_val_ptr_len_ptr ); + int rdbmsSrvContact_map(char **mib_rdbmsSrvContact_val_ptr_ptr, size_t *mib_rdbmsSrvContact_val_ptr_len_ptr, char *raw_rdbmsSrvContact_val_ptr, size_t raw_rdbmsSrvContact_val_ptr_len, int allow_realloc); + int rdbmsSrvContact_get( rdbmsSrvTable_rowreq_ctx *rowreq_ctx, char **rdbmsSrvContact_val_ptr_ptr, size_t *rdbmsSrvContact_val_ptr_len_ptr ); + + +int rdbmsSrvTable_indexes_set_tbl_idx(rdbmsSrvTable_mib_index *tbl_idx, long applIndex_val); +int rdbmsSrvTable_indexes_set(rdbmsSrvTable_rowreq_ctx *rowreq_ctx, long applIndex_val); + + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVTABLE_DATA_GET_H */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_set.c b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_set.c new file mode 100644 index 0000000..3fb2e10 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_set.c @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_data_set.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_data_set.c,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +/* standard Net-SNMP includes */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +/* include our parent header */ +#include "rdbmsSrvTable.h" + + +/** @defgroup data_set data_set: Routines to set data + * + * These routines are used to set the value for individual objects. The + * row context is passed, along with the new value. + * + * @{ + */ +/** @} */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_set.h b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_set.h new file mode 100644 index 0000000..e2b982f --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_data_set.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_data_set.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_data_set.h,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVTABLE_DATA_SET_H +#define RDBMSSRVTABLE_DATA_SET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * SET function declarations + */ + +/* ********************************************************************* + * SET Table declarations + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVTABLE_DATA_SET_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_enums.h b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_enums.h new file mode 100644 index 0000000..c2686ce --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_enums.h @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_enums.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_enums.h,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVTABLE_ENUMS_H +#define RDBMSSRVTABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table rdbmsSrvTable + * + ************************************************************************* + *************************************************************************/ + + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVTABLE_ENUMS_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_interface.c b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_interface.c new file mode 100644 index 0000000..50567f7 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_interface.c @@ -0,0 +1,701 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_interface.c + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_interface.c,v 1.5 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#include "pgsnmpd.h" + +/* include our parent header */ +#include "rdbmsSrvTable.h" +#include "rdbmsSrvTable_interface.h" + +/********************************************************************** + ********************************************************************** + *** + *** Table rdbmsSrvTable + *** + ********************************************************************** + **********************************************************************/ +/* + * rdbmsSrvTable is subid 5 of rdbmsObjects. + * Its status is Current. + * OID: .1.3.6.1.2.1.39.1.5, length: 9 +*/ +typedef struct rdbmsSrvTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; /* optional cache */ + + rdbmsSrvTable_registration_ptr user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} rdbmsSrvTable_interface_ctx; + +static rdbmsSrvTable_interface_ctx rdbmsSrvTable_if_ctx; + +static void _rdbmsSrvTable_container_init( + rdbmsSrvTable_interface_ctx *if_ctx); + + +static Netsnmp_Node_Handler _mfd_rdbmsSrvTable_pre_request; +static Netsnmp_Node_Handler _mfd_rdbmsSrvTable_post_request; +static Netsnmp_Node_Handler _mfd_rdbmsSrvTable_object_lookup; +static Netsnmp_Node_Handler _mfd_rdbmsSrvTable_get_values; +/** + * @internal + * Initialize the table rdbmsSrvTable + * (Define its contents and how it's structured) + */ +void +_rdbmsSrvTable_initialize_interface(rdbmsSrvTable_registration_ptr reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &rdbmsSrvTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = &rdbmsSrvTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:rdbmsSrvTable:_rdbmsSrvTable_initialize_interface","called\n")); + + + /************************************************* + * + * save interface context for rdbmsSrvTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, + ASN_INTEGER, /** index: applIndex */ + 0); + + /* Define the minimum and maximum accessible columns. This + optimizes retrival. */ + tbl_info->min_column = RDBMSSRVTABLE_MIN_COL; + tbl_info->max_column = RDBMSSRVTABLE_MAX_COL; + + /* + * save users context + */ + rdbmsSrvTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + rdbmsSrvTable_init_data(reg_ptr); + + /* + * set up the container + */ + _rdbmsSrvTable_container_init(&rdbmsSrvTable_if_ctx); + if (NULL == rdbmsSrvTable_if_ctx.container) { + snmp_log(LOG_ERR,"could not initialize container for rdbmsSrvTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = _mfd_rdbmsSrvTable_object_lookup; + access_multiplexer->get_values = _mfd_rdbmsSrvTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = _mfd_rdbmsSrvTable_pre_request; + access_multiplexer->post_request = _mfd_rdbmsSrvTable_post_request; + + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("rdbmsSrvTable:init_rdbmsSrvTable", + "Registering rdbmsSrvTable as a mibs-for-dummies table.\n")); + handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = netsnmp_handler_registration_create("rdbmsSrvTable", handler, + rdbmsSrvTable_oid, + rdbmsSrvTable_oid_size, + HANDLER_CAN_BABY_STEP | + HANDLER_CAN_RONLY + ); + if(NULL == reginfo) { + snmp_log(LOG_ERR,"error registering table rdbmsSrvTable\n"); + return; + } + reginfo->my_reg_void = &rdbmsSrvTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if( access_multiplexer->object_lookup ) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if( access_multiplexer->set_values ) + mfd_modes |= BABY_STEP_SET_VALUES; + if( access_multiplexer->irreversible_commit ) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if( access_multiplexer->object_syntax_checks ) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if( access_multiplexer->pre_request ) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if( access_multiplexer->post_request ) + mfd_modes |= BABY_STEP_POST_REQUEST; + + if( access_multiplexer->undo_setup ) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if( access_multiplexer->undo_cleanup ) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if( access_multiplexer->undo_sets ) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if( access_multiplexer->row_creation ) + mfd_modes |= BABY_STEP_ROW_CREATE; + if( access_multiplexer->consistency_checks ) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if( access_multiplexer->commit ) + mfd_modes |= BABY_STEP_COMMIT; + if( access_multiplexer->undo_commit ) + mfd_modes |= BABY_STEP_UNDO_COMMIT; + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + rdbmsSrvTable_if_ctx.container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler( reginfo, handler ); + + /************************************************* + * + * inject cache helper + */ + if(NULL != rdbmsSrvTable_if_ctx.cache) { + handler = netsnmp_cache_handler_get(rdbmsSrvTable_if_ctx.cache); + netsnmp_inject_handler( reginfo, handler ); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); +} /* _rdbmsSrvTable_initialize_interface */ + +void +rdbmsSrvTable_valid_columns_set(netsnmp_column_info *vc) +{ + rdbmsSrvTable_if_ctx.tbl_info.valid_columns = vc; +} /* rdbmsSrvTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +rdbmsSrvTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsSrvTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_applIndex; + + /* + * set up varbinds + */ + memset( &var_applIndex, 0x00, sizeof(var_applIndex) ); + var_applIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_applIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_index_to_oid","called\n")); + + /* applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ + snmp_set_var_value(&var_applIndex, (u_char*)&mib_idx->applIndex, + sizeof(mib_idx->applIndex)); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, (size_t *)&oid_idx->len, + NULL, 0, &var_applIndex); + if(err) + snmp_log(LOG_ERR,"error %d converting index to oid\n", err); + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_applIndex ); + + return err; +} /* rdbmsSrvTable_index_to_oid */ + +/** + * extract rdbmsSrvTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +rdbmsSrvTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsSrvTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * applIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h + */ + netsnmp_variable_list var_applIndex; + + /* + * set up varbinds + */ + memset( &var_applIndex, 0x00, sizeof(var_applIndex) ); + var_applIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_applIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:rdbmsSrvTable:rdbmsSrvTable_index_from_oid","called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes( oid_idx->oids, oid_idx->len, + &var_applIndex ); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + mib_idx->applIndex = *((long *)var_applIndex.val.string); + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_applIndex ); + + return err; +} /* rdbmsSrvTable_index_from_oid */ + + +/* ********************************************************************* + * @internal + * allocate resources for a rdbmsSrvTable_rowreq_ctx + */ +rdbmsSrvTable_rowreq_ctx * +rdbmsSrvTable_allocate_rowreq_ctx(void) +{ + rdbmsSrvTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(rdbmsSrvTable_rowreq_ctx); + + DEBUGMSGTL(("internal:rdbmsSrvTable:rdbmsSrvTable_allocate_rowreq_ctx","called\n")); + + if(NULL == rowreq_ctx) { + snmp_log(LOG_ERR,"Couldn't allocate memory for a " + "rdbmsSrvTable_rowreq_ctx.\n"); + } + + rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; + + rowreq_ctx->rdbmsSrvTable_data_list = NULL; + rowreq_ctx->rdbmsSrvTable_reg = rdbmsSrvTable_if_ctx.user_ctx; + + + return rowreq_ctx; +} /* rdbmsSrvTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a rdbmsSrvTable_rowreq_ctx + */ +void +rdbmsSrvTable_release_rowreq_ctx(rdbmsSrvTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("internal:rdbmsSrvTable:rdbmsSrvTable_release_rowreq_ctx","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + + /* + * free index oid pointer + */ + if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* rdbmsSrvTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsSrvTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc = rdbmsSrvTable_pre_request(rdbmsSrvTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsSrvTable","error %d from " + "rdbmsSrvTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsSrvTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsSrvTable_rowreq_ctx *rowreq_ctx; + int rc = rdbmsSrvTable_post_request(rdbmsSrvTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("internal:rdbmsSrvTable","error %d from " + "rdbmsSrvTable_post_request\n", rc)); + } + + /* + * if there are no errors, check for and handle row creation/deletion + */ + rc = netsnmp_check_requests_error(requests); + if ((SNMP_ERR_NOERROR == rc) && + (NULL != + (rowreq_ctx = netsnmp_container_table_row_extract(requests)))) { + if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) { + rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; + CONTAINER_INSERT(rdbmsSrvTable_if_ctx.container, rowreq_ctx); + } + else if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { + CONTAINER_REMOVE(rdbmsSrvTable_if_ctx.container, rowreq_ctx); + rdbmsSrvTable_release_rowreq_ctx(rowreq_ctx); + } + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_rdbmsSrvTable_object_lookup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsSrvTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:rdbmsSrvTable:_mfd_rdbmsSrvTable_object_lookup","called\n")); + + /* + * get our context from mfd + * rdbmsSrvTable_interface_ctx *if_ctx = + * (rdbmsSrvTable_interface_ctx *)reginfo->my_reg_void; + */ + + if(NULL == rowreq_ctx) { + netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION); + } + else { + rdbmsSrvTable_row_prep(rowreq_ctx); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_rdbmsSrvTable_get_column( rdbmsSrvTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:rdbmsSrvTable:_mfd_rdbmsSrvTable_get_column","called\n")); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* rdbmsSrvPrivateMibOID(1)/OBJECTID/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h */ + case COLUMN_RDBMSSRVPRIVATEMIBOID: + var->type = ASN_OBJECT_ID; +rc = rdbmsSrvPrivateMibOID_get(rowreq_ctx, (oid **)&var->val.string, &var->val_len ); + break; + + /* rdbmsSrvVendorName(2)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ + case COLUMN_RDBMSSRVVENDORNAME: + var->type = ASN_OCTET_STR; +rc = rdbmsSrvVendorName_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* rdbmsSrvProductName(3)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ + case COLUMN_RDBMSSRVPRODUCTNAME: + var->type = ASN_OCTET_STR; +rc = rdbmsSrvProductName_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* rdbmsSrvContact(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_RDBMSSRVCONTACT: + var->type = ASN_OCTET_STR; +rc = rdbmsSrvContact_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + default: + snmp_log(LOG_ERR,"unknown column %d in _rdbmsSrvTable_get_column\n", column); + break; + } + + return rc; +} /* _rdbmsSrvTable_get_column */ + +int +_mfd_rdbmsSrvTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + rdbmsSrvTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + u_char * old_string; + void (*dataFreeHook)(void *); + int rc; + + DEBUGMSGTL(("internal:rdbmsSrvTable:_mfd_rdbmsSrvTable_get_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if(NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + else if(requests->requestvb->buf == requests->requestvb->val.string) { + if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _rdbmsSrvTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + if(MFD_SKIP == rc) { + requests->requestvb->type = ASN_PRIV_RETRY; + rc = SNMP_ERR_NOERROR; + } + } + else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if(rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if(old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if(dataFreeHook) + (*dataFreeHook)(old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_rdbmsSrvTable_get_values */ + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/* + * NOT APPLICABLE (per MIB or user setting) + */ +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +/** + * @internal + */ +static int +_cache_load(netsnmp_cache *cache, void *vmagic) +{ + DEBUGMSGTL(("internal:rdbmsSrvTable:_cache_load","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache for rdbmsSrvTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return rdbmsSrvTable_cache_load((netsnmp_container*)cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_item_free(rdbmsSrvTable_rowreq_ctx *rowreq_ctx, void *context) +{ + DEBUGMSGTL(("internal:rdbmsSrvTable:_cache_item_free","called\n")); + + if(NULL == rowreq_ctx) + return; + + rdbmsSrvTable_release_rowreq_ctx(rowreq_ctx); +} /* _cache_item_free */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache *cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:rdbmsSrvTable:_cache_free","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache in rdbmsSrvTable_cache_free\n"); + return; + } + + container = (netsnmp_container*)cache->magic; + + /* + * call user code + */ + rdbmsSrvTable_cache_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *)_cache_item_free, + NULL); +} /* _cache_free */ + +/** + * @internal + * initialize the iterator container with functions or wrappers + */ +void +_rdbmsSrvTable_container_init(rdbmsSrvTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:rdbmsSrvTable:_rdbmsSrvTable_container_init","called\n")); + + /* + * set up the cache + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + rdbmsSrvTable_oid, + rdbmsSrvTable_oid_size); + + if(NULL == if_ctx->cache) { + snmp_log(LOG_ERR, "error creating cache for rdbmsSrvTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + rdbmsSrvTable_container_init(&if_ctx->container, if_ctx->cache); + if(NULL == if_ctx->container) + if_ctx->container = netsnmp_container_find("rdbmsSrvTable:table_container"); + if(NULL == if_ctx->container) { + snmp_log(LOG_ERR,"error creating container in " + "rdbmsSrvTable_container_init\n"); + return; + } + if_ctx->cache->magic = (void*)if_ctx->container; +} /* _rdbmsSrvTable_container_init */ + diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_interface.h b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_interface.h new file mode 100644 index 0000000..640efb4 --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_interface.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_interface.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_interface.h,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVTABLE_INTERFACE_H +#define RDBMSSRVTABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "rdbmsSrvTable.h" + +/* ******************************************************************** + * Table declarations + */ + +/* PUBLIC interface initialization routine */ +void _rdbmsSrvTable_initialize_interface(rdbmsSrvTable_registration_ptr user_ctx, + u_long flags); + + rdbmsSrvTable_rowreq_ctx * rdbmsSrvTable_allocate_rowreq_ctx(void); +void rdbmsSrvTable_release_rowreq_ctx(rdbmsSrvTable_rowreq_ctx *rowreq_ctx); + +int rdbmsSrvTable_index_to_oid(netsnmp_index *oid_idx, + rdbmsSrvTable_mib_index *mib_idx); +int rdbmsSrvTable_index_from_oid(netsnmp_index *oid_idx, + rdbmsSrvTable_mib_index *mib_idx); + +/* + * access to certain internals. use with caution! + */ +void rdbmsSrvTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVTABLE_INTERFACE_H */ diff --git a/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_oids.h b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_oids.h new file mode 100644 index 0000000..4cf34de --- /dev/null +++ b/RDBMS-MIB_src/rdbmsSrvTable/rdbmsSrvTable_oids.h @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + * rdbmsSrvTable_oids.h + * + * RDBMSMIB mib module. + * + * Copyright (c) 2004-2007, PostgreSQL Global Development Group + * Author: Joshua Tolley + * + * $Id: rdbmsSrvTable_oids.h,v 1.4 2007/09/13 14:20:44 h-saito Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef RDBMSSRVTABLE_OIDS_H +#define RDBMSSRVTABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* column number definitions for table rdbmsSrvTable */ +#define RDBMSSRVTABLE_OID 1,3,6,1,2,1,39,1,5 +#define COLUMN_RDBMSSRVPRIVATEMIBOID 1 +#define COLUMN_RDBMSSRVVENDORNAME 2 +#define COLUMN_RDBMSSRVPRODUCTNAME 3 +#define COLUMN_RDBMSSRVCONTACT 4 + +#define RDBMSSRVTABLE_MIN_COL COLUMN_RDBMSSRVPRIVATEMIBOID +#define RDBMSSRVTABLE_MAX_COL COLUMN_RDBMSSRVCONTACT + + +#ifdef __cplusplus +} +#endif + +#endif /* RDBMSSRVTABLE_OIDS_H */ |