static void
platform_string_register(int index, const char* desc, char* value)
{
    oid tree[] = { 1, 3, 6, 1, 4, 1, 42623, 1, 1, 1, 1, 1};
    tree[11] = index;

    if(!value || !value[0]) {
        return;
    }

    char* s = aim_strdup(value);

    netsnmp_handler_registration *reg =
        netsnmp_create_handler_registration(
                                            desc, NULL,
                                            tree, OID_LENGTH(tree),
                                            HANDLER_CAN_RONLY);
    netsnmp_watcher_info *winfo =
        netsnmp_create_watcher_info(
                                    s, strlen(s),
                                    ASN_OCTET_STR, WATCHER_FIXED_SIZE);
    netsnmp_register_watched_scalar( reg, winfo );
}
Exemple #2
0
/*
 * our initialization routine, automatically called by the agent 
 * (to get called, the function name must match init_FILENAME()) 
 */
void
init_serverBuilt(void)
{

    /*
     * a debugging statement.  Run the agent with -DserverBuilt to see
     * the output of this debugging statement. 
     */
    DEBUGMSGTL(("serverBuilt", "Initializing the serverBuilt module\n"));
   static oid      serverBuilt_oid[] =
        {MOD_SNMP_OID 1 , 3};

    /*
     * the line below registers our variables defined above as
     * accessible and makes them writable.  A read only version of any
     * of these registrations would merely call
     * register_read_only_int_instance() instead.  The functions
     * called below should be consistent with your MIB, however.
     * 
     * If you wanted a callback when the value was retrieved or set
     * (even though the details of doing this are handled for you),
     * you could change the NULL pointer below to a valid handler
     * function. 
     */
    netsnmp_register_watched_scalar(
        netsnmp_create_handler_registration(
            "serverBuilt", 
            NULL,
            serverBuilt_oid,
            OID_LENGTH(serverBuilt_oid),
            HANDLER_CAN_RWRITE),
        netsnmp_create_watcher_info(
            &serverBuilt_str, sizeof(serverBuilt_str),
            ASN_OCTET_STR, WATCHER_MAX_SIZE)
        );
    DEBUGMSGTL(("serverBuilt", "Done initalizing serverBuilt module\n"));
}
/**
 * @internal
 * Initialize the table ipv4InterfaceTable 
 *    (Define its contents and how it's structured)
 */
void
_ipv4InterfaceTable_initialize_interface(ipv4InterfaceTable_registration *
                                         reg_ptr, u_long flags)
{
    netsnmp_baby_steps_access_methods *access_multiplexer =
        &ipv4InterfaceTable_if_ctx.access_multiplexer;
    netsnmp_table_registration_info *tbl_info =
        &ipv4InterfaceTable_if_ctx.tbl_info;
    netsnmp_handler_registration *reginfo;
    netsnmp_mib_handler *handler;
    int             mfd_modes = 0;

    DEBUGMSGTL(("internal:ipv4InterfaceTable:_ipv4InterfaceTable_initialize_interface", "called\n"));


    /*************************************************
     *
     * save interface context for ipv4InterfaceTable
     */
    /*
     * Setting up the table's definition
     */
    netsnmp_table_helper_add_indexes(tbl_info, ASN_INTEGER,
                                               /** index: ipv4InterfaceIfIndex */
                                     0);

    /*
     * Define the minimum and maximum accessible columns.  This
     * optimizes retrival. 
     */
    tbl_info->min_column = IPV4INTERFACETABLE_MIN_COL;
    tbl_info->max_column = IPV4INTERFACETABLE_MAX_COL;

    /*
     * save users context
     */
    ipv4InterfaceTable_if_ctx.user_ctx = reg_ptr;

    /*
     * call data access initialization code
     */
    ipv4InterfaceTable_init_data(reg_ptr);

    /*
     * set up the container
     */
    _ipv4InterfaceTable_container_init(&ipv4InterfaceTable_if_ctx);
    if (NULL == ipv4InterfaceTable_if_ctx.container) {
        snmp_log(LOG_ERR,
                 "could not initialize container for ipv4InterfaceTable\n");
        return;
    }

    /*
     * access_multiplexer: REQUIRED wrapper for get request handling
     */
    access_multiplexer->object_lookup =
        _mfd_ipv4InterfaceTable_object_lookup;
    access_multiplexer->get_values = _mfd_ipv4InterfaceTable_get_values;

    /*
     * no wrappers yet
     */
    access_multiplexer->pre_request = _mfd_ipv4InterfaceTable_pre_request;
    access_multiplexer->post_request =
        _mfd_ipv4InterfaceTable_post_request;


    /*
     * REQUIRED wrappers for set request handling
     */
    access_multiplexer->object_syntax_checks =
        _mfd_ipv4InterfaceTable_check_objects;
    access_multiplexer->undo_setup = _mfd_ipv4InterfaceTable_undo_setup;
    access_multiplexer->undo_cleanup =
        _mfd_ipv4InterfaceTable_undo_cleanup;
    access_multiplexer->set_values = _mfd_ipv4InterfaceTable_set_values;
    access_multiplexer->undo_sets = _mfd_ipv4InterfaceTable_undo_values;

    /*
     * no wrappers yet
     */
    access_multiplexer->commit = _mfd_ipv4InterfaceTable_commit;
    access_multiplexer->undo_commit = _mfd_ipv4InterfaceTable_undo_commit;
    access_multiplexer->irreversible_commit =
        _mfd_ipv4InterfaceTable_irreversible_commit;

    /*************************************************
     *
     * Create a registration, save our reg data, register table.
     */
    DEBUGMSGTL(("ipv4InterfaceTable:init_ipv4InterfaceTable",
                "Registering ipv4InterfaceTable as a mibs-for-dummies table.\n"));
    handler =
        netsnmp_baby_steps_access_multiplexer_get(access_multiplexer);
    reginfo =
        netsnmp_handler_registration_create("ipv4InterfaceTable", handler,
                                            ipv4InterfaceTable_oid,
                                            ipv4InterfaceTable_oid_size,
                                            HANDLER_CAN_BABY_STEP |
                                            HANDLER_CAN_RWRITE);
    if (NULL == reginfo) {
        snmp_log(LOG_ERR, "error registering table ipv4InterfaceTable\n");
        return;
    }
    reginfo->my_reg_void = &ipv4InterfaceTable_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,
                                            ipv4InterfaceTable_if_ctx.
                                            container,
                                            TABLE_CONTAINER_KEY_NETSNMP_INDEX);
    netsnmp_inject_handler(reginfo, handler);

    /*
     * register table
     */
    netsnmp_register_table(reginfo, tbl_info);

    /*
     * register LastChanged
     */
    {
        oid             lc_oid[] = { IPV4INTERFACETABLELASTCHANGE_OID };
        netsnmp_register_watched_scalar(netsnmp_create_handler_registration
                                        ("ipv4TableLastChanged", NULL,
                                         lc_oid, OID_LENGTH(lc_oid),
                                         HANDLER_CAN_RONLY),
                                        netsnmp_create_watcher_info((void
                                                                     *)
                                                                    &ipv4InterfaceTable_if_ctx.
                                                                    last_changed,
                                                                    sizeof
                                                                    (u_long),
                                                                    ASN_TIMETICKS,
                                                                    WATCHER_FIXED_SIZE));
    }
}                               /* _ipv4InterfaceTable_initialize_interface */
/*
 * Our initialization routine, called automatically by the agent 
 * (Note that the function name must match init_FILENAME()) 
 */
void
init_statPPTP(void)
{
  netsnmp_handler_registration *reg;
  netsnmp_watcher_info         *winfo;

    static oid statPPTPStarting_oid[] = { 1,3,6,1,4,1,8072,100,1,3,1 };
    static oid statPPTPActive_oid[] = { 1,3,6,1,4,1,8072,100,1,3,2 };

  /*
   * a debugging statement.  Run the agent with -DstatPPTP to see
   * the output of this debugging statement. 
   */
  DEBUGMSGTL(("statPPTP", "Initializing the statPPTP module\n"));

	if (!triton_module_loaded("pptp"))
		return;

	pptp_get_stat(&stat_starting, &stat_active);
    /*
     * Register scalar watchers for each of the MIB objects.
     * The ASN type and RO/RW status are taken from the MIB definition,
     * but can be adjusted if needed.
     *
     * In most circumstances, the scalar watcher will handle all
     * of the necessary processing.  But the NULL parameter in the
     * netsnmp_create_handler_registration() call can be used to
     * supply a user-provided handler if necessary.
     *
     * This approach can also be used to handle Counter64, string-
     * and OID-based watched scalars (although variable-sized writeable
     * objects will need some more specialised initialisation).
     */
    DEBUGMSGTL(("statPPTP",
                "Initializing statPPTPStarting scalar integer.  Default value = %d\n",
                0));
    reg = netsnmp_create_handler_registration(
             "statPPTPStarting", NULL,
              statPPTPStarting_oid, OID_LENGTH(statPPTPStarting_oid),
              HANDLER_CAN_RONLY);
    winfo = netsnmp_create_watcher_info(
                stat_starting, sizeof(*stat_starting),
                 ASN_INTEGER, WATCHER_FIXED_SIZE);
    if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched statPPTPStarting" );
    }

    DEBUGMSGTL(("statPPTP",
                "Initializing statPPTPActive scalar integer.  Default value = %d\n",
                0));
    reg = netsnmp_create_handler_registration(
             "statPPTPActive", NULL,
              statPPTPActive_oid, OID_LENGTH(statPPTPActive_oid),
              HANDLER_CAN_RONLY);
    winfo = netsnmp_create_watcher_info(
                stat_active, sizeof(*stat_active),
                 ASN_INTEGER, WATCHER_FIXED_SIZE);
    if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched statPPTPActive" );
    }


  DEBUGMSGTL(("statPPTP",
              "Done initalizing statPPTP module\n"));
}
void
init_snmpTlstmCertToTSNTable_context(const char *contextName)
{
    oid             reg_oid[]   =  { SNMP_TLS_TM_CERT_TABLE };
    const size_t    reg_oid_len =  OID_LENGTH(reg_oid);
    netsnmp_handler_registration    *reg;
    netsnmp_table_registration_info *info;
    netsnmp_cache                   *cache;
    netsnmp_watcher_info            *watcher;
    const char *mib_map_help = 
        MAP_MIB_CONFIG_TOKEN " table persistence (internal use)";

    DEBUGMSGTL(("tlstmCertToSN:init",
                "initializing table tlstmCertToTSNTable\n"));

    reg = netsnmp_create_handler_registration
        ("tlstmCertToTSNTable", tlstmCertToTSNTable_handler,
         reg_oid, reg_oid_len,
         HANDLER_CAN_RWRITE);
    if (NULL == reg) {
        snmp_log(LOG_ERR,
                 "error creating handler registration for tlstmCertToSN\n");
        return;
    }

    if (NULL != contextName)
        reg->contextName = strdup(contextName);

    _table = netsnmp_tdata_create_table("tlstmCertToTSNTable", 0);
    if (NULL == _table) {
        snmp_log(LOG_ERR,
                 "error creating tdata table for tlstmCertToTSNTable\n");
        return;
    }
    info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    if (NULL == info) {
        snmp_log(LOG_ERR,
                 "error creating table info for tlstmCertToTSNTable\n");
        netsnmp_tdata_delete_table(_table);
        _table = NULL;
        return;
    }
    netsnmp_table_helper_add_indexes(info, 
                                     /* index: tlstmCertToTSNID */
                                     ASN_UNSIGNED,  0);

    info->min_column = SNMPTLSTMCERTTOTSN_TABLE_MIN_COL;
    info->max_column = SNMPTLSTMCERTTOTSN_TABLE_MAX_COL;

    /*
     * cache init
     */
    cache = netsnmp_cache_create(30, (NetsnmpCacheLoad*)_cache_load,
                                 (NetsnmpCacheFree*)_cache_free,
                                 reg_oid,
                                 reg_oid_len);
    if (NULL == cache) {
        snmp_log(LOG_ERR,"error creating cache for tlstmCertToTSNTable\n");
        netsnmp_tdata_delete_table(_table);
        _table = NULL;
        return;
    }
    cache->magic = (void *)_table;
    cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;

    netsnmp_tdata_register(reg, _table, info);

    if (cache) 
        netsnmp_inject_handler_before( reg, netsnmp_cache_handler_get(cache),
                                       "table_container");

    /*
     * register scalars
     */
    reg_oid[10] = 1;
    reg = netsnmp_create_handler_registration("snmpTlstmCertToTSNCount",
                                              _count_handler, reg_oid,
                                              OID_LENGTH(reg_oid),
                                              HANDLER_CAN_RONLY);
    if (NULL == reg)
        snmp_log(LOG_ERR,
                 "could not create handler for snmpTlstmCertToTSNCount\n");
    else {
        if (NULL != contextName)
            reg->contextName = strdup(contextName);

        netsnmp_register_scalar(reg);
        if (cache) 
            netsnmp_inject_handler_before(reg, netsnmp_cache_handler_get(cache),
                                          "table_container");
    }
    
    reg_oid[10] = 2;
    reg = netsnmp_create_handler_registration(
        "snmpTlstmCertToTSNTableLastChanged", NULL, reg_oid,
        OID_LENGTH(reg_oid), HANDLER_CAN_RONLY);
    watcher = netsnmp_create_watcher_info((void*)&_last_changed,
                                          sizeof(_last_changed),
                                          ASN_TIMETICKS,
                                          WATCHER_FIXED_SIZE);
    if ((NULL == reg) || (NULL == watcher))
        snmp_log(LOG_ERR,
                 "could not create handler for snmpTlstmCertToTSNCount\n");
    else {
        if (NULL != contextName)
            reg->contextName = strdup(contextName);
        netsnmp_register_watched_scalar(reg, watcher);
    }

    /*
     * persistence
     */
    register_config_handler(NULL, MAP_MIB_CONFIG_TOKEN, _parse_mib_maps, NULL,
                            mib_map_help);
    if (snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
                               _save_maps, NULL) != SNMP_ERR_NOERROR)
        snmp_log(LOG_ERR, "error registering for STORE_DATA callback "
                 "for certToTSN\n");

}
/*
 * Our initialization routine, called automatically by the agent 
 * (Note that the function name must match init_FILENAME()) 
 */
void
init_gpDroneMIB(void)
{
  netsnmp_handler_registration *reg;

	//Series of OIDs and variable watchers. Not all of them are fully implemented thought :(
    const oid sysAircraftID_oid[] = {1,3,6,1,4,1,12620,1,1 };
  static netsnmp_watcher_info sysAircraftID_winfo;
    const oid sysAircraftType_oid[] = {1,3,6,1,4,1,12620,1,2 };
  static netsnmp_watcher_info sysAircraftType_winfo;
    const oid sysTimeUp_oid[] = { 1,3,6,1,4,1,12620,1,4 };
  static netsnmp_watcher_info sysTimeUp_winfo;
 //static netsnmp_watcher_info instPosMagneticCompass_winfo;
    const oid instPosGpsLatitude_oid[] = { 1,3,6,1,4,1,12620,2,1,5 };
  static netsnmp_watcher_info instPosGpsLatitude_winfo;
     const oid instPosGpsLongitude_oid[] = { 1,3,6,1,4,1,12620,2,1,6 };
  static netsnmp_watcher_info instPosGpsLongitude_winfo;
    const oid instPosAltitude_oid[] = { 1,3,6,1,4,1,12620,2,1,7 };
  static netsnmp_watcher_info instPosAltitude_winfo;
    const oid instClTime_oid[] = { 1,3,6,1,4,1,12620,2,2,1 };
  static netsnmp_watcher_info instClTime_winfo;
   const oid instSpeedGround_oid[] = { 1,3,6,1,4,1,12620,2,3,3 };
  static netsnmp_watcher_info instSpeedGround_winfo;
   const oid instSpeedVertical_oid[] = { 1,3,6,1,4,1,12620,2,3,4 };
   static netsnmp_watcher_info instSpeedVertical_winfo;
   const oid lgSetPosition_oid[] = { 1,3,6,1,4,1,12620,7,3 };
  static netsnmp_watcher_info lgSetPosition_winfo;
    const oid lightNum_oid[] = { 1,3,6,1,4,1,12620,5,1 };
  static netsnmp_watcher_info lightNum_winfo;
//New variable (not in the original MIB definition)...
    const oid instTotalFuel_oid[] = { 1,3,6,1,4,1,12620,2,5 };
  static netsnmp_watcher_info instTotalFuel_winfo;


  DEBUGMSGTL(("gpDroneMIB", "Initializing the gpDroneMIB module\n"));

/*
	Now we register the variables of the MIB...
*/

/*sysAircraftID*/
    DEBUGMSGTL(("gpDroneMIB",
                "Initializing sysAircraftID scalar octet string.  Default value = %s\n",
                sysAircraftID));
    reg = netsnmp_create_handler_registration(
             "sysAircraftID", NULL,
              sysAircraftID_oid, OID_LENGTH(sysAircraftID_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&sysAircraftID_winfo, sysAircraftID, strlen(sysAircraftID),
			      ASN_OCTET_STR, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &sysAircraftID_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched sysAircraftID" );
    }
/*end sysAircraftID*/

    fetch_string("sysAircraftType",sysAircraftType);
/*sysAircraftType*/
    DEBUGMSGTL(("gpDroneMIB",
                "Initializing sysAircraftType scalar octet string.  Default value = %s\n",
                sysAircraftType));
    reg = netsnmp_create_handler_registration(
             "sysAircraftType", NULL,
              sysAircraftType_oid, OID_LENGTH(sysAircraftType_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&sysAircraftType_winfo, sysAircraftType, strlen(sysAircraftType),
			      ASN_OCTET_STR, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &sysAircraftType_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched sysAircraftID" );
    }
/*end sysAircraftType*/


    DEBUGMSGTL(("gpDroneMIB",
                "Initializing sysTimeUp scalar integer.  Default value = %d\n",
                sysTimeUp));
    reg = netsnmp_create_handler_registration(
             "sysTimeUp", sysTimeUpHandler,
              sysTimeUp_oid, OID_LENGTH(sysTimeUp_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&sysTimeUp_winfo, &sysTimeUp, sizeof(u_long),
			      ASN_TIMETICKS, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &sysTimeUp_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched sysTimeUp" );
    }

/*instPosGpsLatitude*/
    DEBUGMSGTL(("gpDroneMIB",
                "Initializing instPosGpsLatitude scalar octet string.  Default value = %s\n",
                instPosGpsLatitude));
    reg = netsnmp_create_handler_registration(
             "instPosGpsLatitude", instPosGpsLatitudeHandler,
              instPosGpsLatitude_oid, OID_LENGTH(instPosGpsLatitude_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&instPosGpsLatitude_winfo, instPosGpsLatitude, strlen(instPosGpsLatitude),
			      ASN_OCTET_STR, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &instPosGpsLatitude_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched instPosGpsLatitude" );
    }
/*end instPosGpsLatitude*/
/*instPosGpsLongitude*/
    DEBUGMSGTL(("gpDroneMIB",
                "Initializing instPosGpsLongitude scalar octet string.  Default value = %s\n",
                instPosGpsLongitude));
    reg = netsnmp_create_handler_registration(
             "instPosGpsLongitude", instPosGpsLongitudeHandler,
              instPosGpsLongitude_oid, OID_LENGTH(instPosGpsLongitude_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&instPosGpsLongitude_winfo, instPosGpsLongitude, strlen(instPosGpsLongitude),
                              ASN_OCTET_STR, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &instPosGpsLongitude_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" );
    }
/*end instPosGpsLongitude*/

/*instPosAltitude*/
    DEBUGMSGTL(("gpDroneMIB",
                "Initializing instPosAltitude scalar octet string.  Default value = %s\n",
                instPosAltitude));
    reg = netsnmp_create_handler_registration(
             "instPosAltitude", instPosAltitudeHandler,
              instPosAltitude_oid, OID_LENGTH(instPosAltitude_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&instPosAltitude_winfo, instPosAltitude, strlen(instPosAltitude),
                              ASN_OCTET_STR, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &instPosAltitude_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" );
    }
/*end instPosAltitude*/

/*instSpeedGround*/
    DEBUGMSGTL(("gpDroneMIB",
                "Initializing instSpeedGround scalar octet string.  Default value = %s\n",
                instSpeedGround));
    reg = netsnmp_create_handler_registration(
             "instSpeedGround", instSpeedGroundHandler,
              instSpeedGround_oid, OID_LENGTH(instSpeedGround_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&instSpeedGround_winfo, instSpeedGround, strlen(instSpeedGround),
                              ASN_OCTET_STR, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &instSpeedGround_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" );
    }
/*end instSpeedGround*/

/*instSpeedVertical*/
    DEBUGMSGTL(("gpDroneMIB",
                "Initializing instSpeedVertical scalar octet string.  Default value = %s\n",
                instSpeedVertical));
    reg = netsnmp_create_handler_registration(
             "instSpeedVertical", instSpeedVerticalHandler,
              instSpeedVertical_oid, OID_LENGTH(instSpeedVertical_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&instSpeedVertical_winfo, instSpeedVertical, strlen(instSpeedVertical),
                              ASN_OCTET_STR, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &instSpeedVertical_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" );
    }
/*end instSpeedVertical*/



/*instClTime*/
    DEBUGMSGTL(("gpDroneMIB",
                "Initializing instClTime scalar octet string.  Default value = %s\n",
                instClTime));
    reg = netsnmp_create_handler_registration(
             "instClTime", instClTimeHandler,
              instClTime_oid, OID_LENGTH(instClTime_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&instClTime_winfo, instClTime, strlen(instClTime),
                              ASN_OCTET_STR, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &instClTime_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" );
    }
/*end instClTime*/

    DEBUGMSGTL(("gpDroneMIB",
                "Initializing lightNum scalar integer.  Default value = %d\n",
                lightNum));
    reg = netsnmp_create_handler_registration(
             "lightNum", NULL,
              lightNum_oid, OID_LENGTH(lightNum_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&lightNum_winfo, &lightNum, sizeof(long),
			      ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &lightNum_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched lightNum" );
    }

    DEBUGMSGTL(("gpDroneMIB",
                "Initializing lgSetPosition scalar integer.  Default value = %d\n",
                lgSetPosition));
    reg = netsnmp_create_handler_registration(
             "lgSetPosition", lgSetPositionHandler,
              lgSetPosition_oid, OID_LENGTH(lgSetPosition_oid),
              HANDLER_CAN_RWRITE);
    netsnmp_init_watcher_info(&lgSetPosition_winfo, &lgSetPosition, sizeof(long),
			      ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &lgSetPosition_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched lgSetPosition" );
    }


//New fuel variable...

    DEBUGMSGTL(("gpDroneMIB",
                "Initializing instTotalFuel scalar octet string.  Default value = %s\n",
                instTotalFuel));
    reg = netsnmp_create_handler_registration(
             "instTotalFuel", instTotalFuelHandler,
              instTotalFuel_oid, OID_LENGTH(instTotalFuel_oid),
              HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(&instTotalFuel_winfo, instTotalFuel, strlen(instTotalFuel),
                              ASN_OCTET_STR, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, &instTotalFuel_winfo ) < 0 ) {
        snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" );
    }






  /* here we initialize all the tables we're planning on supporting */
  initialize_table_lightingTable();

  DEBUGMSGTL(("gpDroneMIB",
              "Done initalizing gpDroneMIB module\n"));
}
Exemple #7
0
/** Initializes the sysORTable module */
void
init_sysORTable(void)
{
    const oid sysORLastChange_oid[] = { 1, 3, 6, 1, 2, 1, 1, 8 };
    const oid sysORTable_oid[] = { 1, 3, 6, 1, 2, 1, 1, 9 };

    sysORTable_table_info =
        SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);

    table = netsnmp_container_find("sysORTable:table_container");

    if (sysORTable_table_info == NULL || table == NULL) {
        SNMP_FREE(sysORTable_table_info);
        CONTAINER_FREE(table);
        return;
    }
    table->container_name = strdup("sysORTable");

    netsnmp_table_helper_add_indexes(sysORTable_table_info,
                                     ASN_INTEGER, /** index: sysORIndex */
                                     0);
    sysORTable_table_info->min_column = COLUMN_SYSORID;
    sysORTable_table_info->max_column = COLUMN_SYSORUPTIME;

    sysORLastChange_reg =
        netsnmp_create_handler_registration(
            "mibII/sysORLastChange", NULL,
            sysORLastChange_oid, OID_LENGTH(sysORLastChange_oid),
            HANDLER_CAN_RONLY);
    netsnmp_init_watcher_info(
	    &sysORLastChange_winfo,
            &sysORLastChange, sizeof(u_long),
            ASN_TIMETICKS, WATCHER_FIXED_SIZE);
    netsnmp_register_watched_scalar(sysORLastChange_reg,
				    &sysORLastChange_winfo);

    sysORTable_reg =
        netsnmp_create_handler_registration(
            "mibII/sysORTable", sysORTable_handler,
            sysORTable_oid, OID_LENGTH(sysORTable_oid), HANDLER_CAN_RONLY);
    netsnmp_container_table_register(sysORTable_reg, sysORTable_table_info,
                                     table, TABLE_CONTAINER_KEY_NETSNMP_INDEX);

    sysORLastChange = netsnmp_get_agent_uptime();

    /*
     * Initialise the contents of the table here
     */
    netsnmp_sysORTable_foreach(&register_foreach, NULL);

    /*
     * Register callbacks
     */
    snmp_register_callback(SNMP_CALLBACK_APPLICATION,
                           SNMPD_CALLBACK_REG_SYSOR, register_cb, NULL);
    snmp_register_callback(SNMP_CALLBACK_APPLICATION,
                           SNMPD_CALLBACK_UNREG_SYSOR, unregister_cb, NULL);

#ifdef USING_MIBII_SYSTEM_MIB_MODULE
    if (++system_module_count == 3)
        REGISTER_SYSOR_TABLE(system_module_oid, system_module_oid_len,
                             "The MIB module for SNMPv2 entities");
#endif
}
Exemple #8
0
void
init_system_mib(void)
{

#ifdef HAVE_UNAME
    struct utsname  utsName;

    uname(&utsName);
    snprintf(version_descr, sizeof(version_descr),
            "%s %s %s %s %s", utsName.sysname,
            utsName.nodename, utsName.release, utsName.version,
            utsName.machine);
    version_descr[ sizeof(version_descr)-1 ] = 0;
#else
#if HAVE_EXECV
    struct extensible extmp;

    /*
     * set default values of system stuff 
     */
    if (asprintf(&extmp.command, "%s -a", UNAMEPROG) < 0)
        extmp.command = NULL;
    /*
     * setup defaults 
     */
    extmp.type = EXECPROC;
    extmp.next = NULL;
    exec_command(&extmp);
    strlcpy(version_descr, extmp.output, sizeof(version_descr));
    if (strlen(version_descr) >= 1)
        version_descr[strlen(version_descr) - 1] = 0; /* chomp new line */
#else
#if (defined (WIN32) && defined (HAVE_WIN32_PLATFORM_SDK)) || defined (mingw32)
    windowsOSVersionString(version_descr, sizeof(version_descr));
#else
    strcpy(version_descr, "unknown");
#endif
#endif
#endif

#ifdef HAVE_GETHOSTNAME
    gethostname(sysName, sizeof(sysName));
#else
#ifdef HAVE_UNAME
    strlcpy(sysName, utsName.nodename, sizeof(sysName));
#else
#if defined (HAVE_EXECV) && !defined (mingw32)
    if (asprintf(&extmp.command, "%s -n", UNAMEPROG) < 0)
        extmp.command = NULL;
    /*
     * setup defaults 
     */
    extmp.type = EXECPROC;
    extmp.next = NULL;
    exec_command(&extmp);
    strlcpy(sysName, extmp.output, sizeof(sysName));
    if (strlen(sysName) >= 1)
        sysName[strlen(sysName) - 1] = 0; /* chomp new line */
#else
    strcpy(sysName, "unknown");
#endif                          /* HAVE_EXECV */
#endif                          /* HAVE_UNAME */
#endif                          /* HAVE_GETHOSTNAME */

#if (defined (WIN32) && defined (HAVE_WIN32_PLATFORM_SDK)) || defined (mingw32)
    {
      HKEY hKey;
      /* Default sysContact is the registered windows user */
      if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                       "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0,
                       KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
          char registeredOwner[256] = "";
          DWORD registeredOwnerSz = 256;
          if (RegQueryValueEx(hKey, "RegisteredOwner", NULL, NULL,
                              (LPBYTE)registeredOwner,
                              &registeredOwnerSz) == ERROR_SUCCESS) {
              strlcpy(sysContact, registeredOwner, sizeof(sysContact));
          }
          RegCloseKey(hKey);
      }
    }
#endif

    /* default sysObjectID */
    memcpy(sysObjectID, version_sysoid, version_sysoid_len * sizeof(oid));
    sysObjectIDByteLength = version_sysoid_len * sizeof(oid);

    {
        const oid sysDescr_oid[] = { 1, 3, 6, 1, 2, 1, 1, 1 };
        static netsnmp_watcher_info sysDescr_winfo;
        netsnmp_register_watched_scalar(
            netsnmp_create_handler_registration(
                "mibII/sysDescr", NULL, sysDescr_oid, OID_LENGTH(sysDescr_oid),
                HANDLER_CAN_RONLY),
            netsnmp_init_watcher_info(&sysDescr_winfo, version_descr, 0,
				      ASN_OCTET_STR, WATCHER_SIZE_STRLEN));
    }
    {
        const oid sysObjectID_oid[] = { 1, 3, 6, 1, 2, 1, 1, 2 };
        static netsnmp_watcher_info sysObjectID_winfo;
        netsnmp_register_watched_scalar(
            netsnmp_create_handler_registration(
                "mibII/sysObjectID", NULL,
                sysObjectID_oid, OID_LENGTH(sysObjectID_oid),
                HANDLER_CAN_RONLY),
            netsnmp_init_watcher_info6(
		&sysObjectID_winfo, sysObjectID, 0, ASN_OBJECT_ID,
                WATCHER_MAX_SIZE | WATCHER_SIZE_IS_PTR,
                MAX_OID_LEN, &sysObjectIDByteLength));
    }
    {
        const oid sysUpTime_oid[] = { 1, 3, 6, 1, 2, 1, 1, 3 };
        netsnmp_register_scalar(
            netsnmp_create_handler_registration(
                "mibII/sysUpTime", handle_sysUpTime,
                sysUpTime_oid, OID_LENGTH(sysUpTime_oid),
                HANDLER_CAN_RONLY));
    }
    {
        const oid sysContact_oid[] = { 1, 3, 6, 1, 2, 1, 1, 4 };
        static netsnmp_watcher_info sysContact_winfo;
#ifndef NETSNMP_NO_WRITE_SUPPORT
        netsnmp_register_watched_scalar(
            netsnmp_create_update_handler_registration(
                "mibII/sysContact", sysContact_oid, OID_LENGTH(sysContact_oid), 
                HANDLER_CAN_RWRITE, &sysContactSet),
            netsnmp_init_watcher_info(
                &sysContact_winfo, sysContact, SYS_STRING_LEN - 1,
                ASN_OCTET_STR, WATCHER_MAX_SIZE | WATCHER_SIZE_STRLEN));
#else  /* !NETSNMP_NO_WRITE_SUPPORT */
        netsnmp_register_watched_scalar(
            netsnmp_create_update_handler_registration(
                "mibII/sysContact", sysContact_oid, OID_LENGTH(sysContact_oid),
                HANDLER_CAN_RONLY, &sysContactSet),
            netsnmp_init_watcher_info(
                &sysContact_winfo, sysContact, SYS_STRING_LEN - 1,
                ASN_OCTET_STR, WATCHER_MAX_SIZE | WATCHER_SIZE_STRLEN));
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
    }
    {
        const oid sysName_oid[] = { 1, 3, 6, 1, 2, 1, 1, 5 };
        static netsnmp_watcher_info sysName_winfo;
#ifndef NETSNMP_NO_WRITE_SUPPORT
        netsnmp_register_watched_scalar(
            netsnmp_create_update_handler_registration(
                "mibII/sysName", sysName_oid, OID_LENGTH(sysName_oid),
                HANDLER_CAN_RWRITE, &sysNameSet),
            netsnmp_init_watcher_info(
                &sysName_winfo, sysName, SYS_STRING_LEN - 1, ASN_OCTET_STR,
                WATCHER_MAX_SIZE | WATCHER_SIZE_STRLEN));
#else  /* !NETSNMP_NO_WRITE_SUPPORT */
        netsnmp_register_watched_scalar(
            netsnmp_create_update_handler_registration(
                "mibII/sysName", sysName_oid, OID_LENGTH(sysName_oid),
                HANDLER_CAN_RONLY, &sysNameSet),
            netsnmp_init_watcher_info(
                &sysName_winfo, sysName, SYS_STRING_LEN - 1, ASN_OCTET_STR,
                WATCHER_MAX_SIZE | WATCHER_SIZE_STRLEN));
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
    }
    {
        const oid sysLocation_oid[] = { 1, 3, 6, 1, 2, 1, 1, 6 };
        static netsnmp_watcher_info sysLocation_winfo;
#ifndef NETSNMP_NO_WRITE_SUPPORT
        netsnmp_register_watched_scalar(
            netsnmp_create_update_handler_registration(
                "mibII/sysLocation", sysLocation_oid,
                OID_LENGTH(sysLocation_oid),
                HANDLER_CAN_RWRITE, &sysLocationSet),
            netsnmp_init_watcher_info(
		&sysLocation_winfo, sysLocation, SYS_STRING_LEN - 1,
		ASN_OCTET_STR, WATCHER_MAX_SIZE | WATCHER_SIZE_STRLEN));
#else  /* !NETSNMP_NO_WRITE_SUPPORT */
        netsnmp_register_watched_scalar(
            netsnmp_create_update_handler_registration(
                "mibII/sysLocation", sysLocation_oid,
                OID_LENGTH(sysLocation_oid),
                HANDLER_CAN_RONLY, &sysLocationSet),
            netsnmp_init_watcher_info(
		&sysLocation_winfo, sysLocation, SYS_STRING_LEN - 1,
		ASN_OCTET_STR, WATCHER_MAX_SIZE | WATCHER_SIZE_STRLEN));
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
    }
    {
        const oid sysServices_oid[] = { 1, 3, 6, 1, 2, 1, 1, 7 };
        netsnmp_register_read_only_int_scalar(
            "mibII/sysServices", sysServices_oid, OID_LENGTH(sysServices_oid),
            &sysServices, handle_sysServices);
    }
    if (++system_module_count == 3)
        REGISTER_SYSOR_ENTRY(system_module_oid,
                             "The MIB module for SNMPv2 entities");

    sysContactSet = sysLocationSet = sysNameSet = 0;

    /*
     * register our config handlers 
     */
    snmpd_register_config_handler("sysdescr",
                                  system_parse_config_sysdescr, NULL,
                                  "description");
    snmpd_register_config_handler("syslocation",
                                  system_parse_config_sysloc, NULL,
                                  "location");
    snmpd_register_config_handler("syscontact", system_parse_config_syscon,
                                  NULL, "contact-name");
    snmpd_register_config_handler("sysname", system_parse_config_sysname,
                                  NULL, "node-name");
    snmpd_register_config_handler("psyslocation",
                                  system_parse_config_sysloc, NULL, NULL);
    snmpd_register_config_handler("psyscontact",
                                  system_parse_config_syscon, NULL, NULL);
    snmpd_register_config_handler("psysname", system_parse_config_sysname,
                                  NULL, NULL);
    snmpd_register_config_handler("sysservices",
                                  system_parse_config_sysServices, NULL,
                                  "NUMBER");
    snmpd_register_config_handler("sysobjectid",
                                  system_parse_config_sysObjectID, NULL,
                                  "OID");
    snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
                           system_store, NULL);
}