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/rdbmsDbInfoTable |
Diffstat (limited to 'RDBMS-MIB_src/rdbmsDbInfoTable')
11 files changed, 2640 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 */ |