Beispiel #1
0
/**
 * \brief Initializes the deviceDesc module
 */
void init_deviceDesc(void)
{
    const oid deviceDesc_oid[] = { 1,3,6,1,4,1,35990,3,1,1,1 };

    g_debug("deviceDesc initializing");
    netsnmp_register_read_only_instance(
                    netsnmp_create_handler_registration(
                            "deviceDesc", handle_deviceDesc,
                            deviceDesc_oid, OID_LENGTH(deviceDesc_oid),
                    HANDLER_CAN_RONLY));
}
/**
 * \brief Initializes the deviceNatoStockNumber module
 */
void
init_deviceNatoStockNumber(void)
{
    const oid deviceNatoStockNumber_oid[] = { 1,3,6,1,4,1,35990,3,1,1,13 };

  g_debug("deviceNatoStockNumber initializing");

    netsnmp_register_read_only_instance(
                                        netsnmp_create_handler_registration("deviceNatoStockNumber", handle_deviceNatoStockNumber,
                                        deviceNatoStockNumber_oid, OID_LENGTH(deviceNatoStockNumber_oid),
                                        HANDLER_CAN_RONLY ));
}
/**
 * \brief Initializes the deviceFirmwareVersion module
 */
void init_deviceFirmwareVersion(void){

    const oid deviceFirmwareVersion_oid[] = { 1,3,6,1,4,1,35990,3,1,1,7 };

    g_debug(("deviceFirmwareVersion initializing"));

    netsnmp_register_read_only_instance(
        netsnmp_create_handler_registration("deviceFirmwareVersion", handle_deviceFirmwareVersion,
                               deviceFirmwareVersion_oid, OID_LENGTH(deviceFirmwareVersion_oid),
                               HANDLER_CAN_RONLY
        ));
}
/**
 * \brief Initializes the videoFormatNumber module
 */
void
init_videoFormatNumber(void)
{
    const oid videoFormatNumber_oid[] = { 1,3,6,1,4,1,35990,3,1,2,1 };

  g_debug(("videoFormatNumber initializing"));

   	 netsnmp_register_read_only_instance(
        netsnmp_create_handler_registration("videoFormatNumber", handle_videoFormatNumber,
                               videoFormatNumber_oid, OID_LENGTH(videoFormatNumber_oid),
                               HANDLER_CAN_RONLY
        						));
}
Beispiel #5
0
int
netsnmp_register_num_file_instance(const char *name,
                                   const oid * reg_oid, size_t reg_oid_len,
                                   const char *file_name, int asn_type, int mode,
                                   Netsnmp_Node_Handler * subhandler,
                                   const char *contextName)
{
    netsnmp_handler_registration *myreg;
    netsnmp_num_file_instance *nfi;

    if ((NULL == name) || (NULL == reg_oid) || (NULL == file_name)) {
        snmp_log(LOG_ERR, "bad parameter to netsnmp_register_num_file_instance\n");
        return MIB_REGISTRATION_FAILED;
    }

    nfi = SNMP_MALLOC_TYPEDEF(netsnmp_num_file_instance);
    if ((NULL == nfi) ||
        (NULL == (nfi->file_name = strdup(file_name)))) {
        snmp_log(LOG_ERR, "could not not allocate memory\n");
        if (NULL != nfi)
            free(nfi); /* SNMP_FREE overkill on local var */
        return MIB_REGISTRATION_FAILED;
    }

    nfi->refcnt = 1;
    myreg = get_reg(name, "file_num_handler", reg_oid, reg_oid_len, nfi,
                    mode, netsnmp_instance_num_file_handler,
                    subhandler, contextName);
    if (NULL == myreg) {
        netsnmp_num_file_instance_deref(nfi);
        return MIB_REGISTRATION_FAILED;
    }

    nfi->type = asn_type;

    if (HANDLER_CAN_RONLY == mode)
        return netsnmp_register_read_only_instance(myreg);

    return netsnmp_register_instance(myreg);
}
void
init_demo_module_10(void)
{
	/*
	 * the OID at which to register the exampleData variable.
	 */
	static oid longRunScalar_oid[] =
	    {1, 3, 6, 1, 4, 1, 42, 2, 2, 4, 4, 10, 1, 1, 0};

	/*
	 * the OID at which to register the status variable.
	 */
	static oid status_oid[] =
	    {1, 3, 6, 1, 4, 1, 42, 2, 2, 4, 4, 10, 1, 2, 0};
	
	/*
	 * the OID at which to register the refreshTime variable.
	 */
	static oid refreshTime_oid[] =
	    {1, 3, 6, 1, 4, 1, 42, 2, 2, 4, 4, 10, 1, 3, 0};

	

	netsnmp_handler_registration *myreg;

	/*
	 * A debugging statement.  Run the agent with -Ddemo_module_10 to see
	 * the output of this debugging statement in /var/log/snmpd.log, by
	 * default. Use the -L option to write debugging output to the
	 * screen.
	 */
		DEBUGMSGTL(("demo_module_10", "Initializing\n"));
	/*
	 * Creates a read-only registration handler named longRunScalar,
	 * which calls the get_longRunScalar function to service snmp
	 * requests for the longRunScalar_oid object.  The OID_LENGTH
	 * argument calculates the length of the longRunScalar_oid.
	 */
	myreg = netsnmp_create_handler_registration
		       ("longRunScalar",
			get_longRunScalar,
			longRunScalar_oid,
			OID_LENGTH(longRunScalar_oid),
			HANDLER_CAN_RONLY);
	/*
	 * Register the instance and handler.
	 *
	 */
	netsnmp_register_read_only_instance(myreg);

	/*
	 * Creates a read/write registration handler named getStatus,
	 * which calls the get_status function to service snmp
	 * requests for the status_oid object.  The OID_LENGTH
	 * argument calculates the length of the status_oid.
	 */
	
	myreg = netsnmp_create_handler_registration
		       ("delayed_instance_handler",
			delayed_instance_handler,
			status_oid,
			OID_LENGTH(status_oid),
			HANDLER_CAN_RWRITE);
	/*
	 * Register the instance and handler.
	 *
	 */
	netsnmp_register_instance(myreg);


	/*
	 * Creates a read-only registration handler named getTimestamp,
	 * which calls the get_timestamp function to service snmp
	 * get requests for the timestamp_oid object.  The OID_LENGTH
	 * argument calculates the length of the timestamp_oid.
	 */
	
	myreg = netsnmp_create_handler_registration
		       ("getTimestamp",
			get_timestamp,
			refreshTime_oid,
			OID_LENGTH(refreshTime_oid),
			HANDLER_CAN_RONLY);
	/*
	 * Register the instance and handler.
	 *
	 */
	netsnmp_register_instance(myreg);

}
void
init_demo_module_7(void)
{

	char *filexcon = "fileX";
	char *fileycon = "fileY";


	netsnmp_handler_registration *myreg1;
	int status;

	/*
	Create a read-only registration handler named filesize,
	which calls the get_filesize function to service snmp requests
	for the me1filesize_oid object.  The OID_LENGTH argument
	calculates the length of the me1filesize_oid. */
	DEBUGMSGTL(("demo_module_7", "Initializing\n"));
	myreg1 = netsnmp_create_handler_registration
					("filesize",
					get_filesize,
					me1filesize_oid,
					OID_LENGTH(me1filesize_oid),
					HANDLER_CAN_RONLY);

	myreg1->contextName = filexcon;
	status = netsnmp_register_read_only_instance(myreg1);
	DEBUGMSGTL(("demo_module_7", "init reg1 status %d:\n",  status));


	myreg1 = netsnmp_create_handler_registration
					("filesize",
					get_filesize,
					me1filesize_oid,
					OID_LENGTH(me1filesize_oid),
					HANDLER_CAN_RONLY);

	myreg1->contextName = fileycon;
	status = netsnmp_register_read_only_instance(myreg1);
	DEBUGMSGTL(("demo_module_7", "init reg2 status %d:\n",  status));


	/*
	Create a read-write registration handler named filesize,
	which calls the set_createContext function to service snmp requests
	for the me1createContext_oid object.  The OID_LENGTH argument
	calculates the length of the me1createContext_oid. */
	myreg1 = netsnmp_create_handler_registration
					("filesize",
					set_createContext,
					me1createContext_oid,
					OID_LENGTH(me1createContext_oid),
					HANDLER_CAN_RWRITE);

	status = netsnmp_register_instance(myreg1);
	DEBUGMSGTL(("filesize", "init reg3 status %d:\n",  status));

	/*
	Create a read-write registration handler named filesize,
	which calls the set_removeContext function to service snmp requests
	for the me1removeContext_oid object.  The OID_LENGTH argument
	calculates the length of the me1removeContext_oid. */
	myreg1 = netsnmp_create_handler_registration
					("filesize",
					set_removeContext,
					me1removeContext_oid,
					OID_LENGTH(me1removeContext_oid),
					HANDLER_CAN_RWRITE);

	status = netsnmp_register_instance(myreg1);
	DEBUGMSGTL(("demo_module_7", "init reg4 status %d:\n", status));
}
int
set_createContext(netsnmp_mib_handler *handler,
	netsnmp_handler_registration *reginfo,
	netsnmp_agent_request_info *reqinfo,
	netsnmp_request_info *requests)
{

	netsnmp_handler_registration *myreg;
	char *context_names[256];
	int status;
	DEBUGMSGTL(("demo_module_7", "set_createContext CALLED\n"));
	DEBUGMSGTL(("demo_module_7", "reqinfo->mode = %d\n", reqinfo->mode));
	switch (reqinfo -> mode) {

	case MODE_SET_RESERVE1:
		break;

	case MODE_SET_RESERVE2:
		break;

	case MODE_SET_FREE:
		break;

	case MODE_SET_ACTION:

		DEBUGMSGTL(("demo_module_7", "MODE_SET_ACTION CALLED\n"));
		DEBUGMSGTL(("demo_module_7", "requests->requestvb->val = %s\n",
			(u_char *) requests->requestvb->val.string));

                // You must allocate memory for this variable because
		// the unregister_mib function frees it.
		filename = malloc(requests->requestvb->val_len + 1);
		snprintf(filename, requests->requestvb->val_len + 1, "%s",
		    (u_char *) requests->requestvb->val.string);
	        filename[requests->requestvb->val_len + 1] = '\0';
	
		DEBUGMSGTL(("demo_module_7", "filename = %s\n", filename));

		/*
		Create a registration handler for the me1filesize_oid
		object in the new context name specified by
		the snmp set on the me1createContext OID. */
		myreg = netsnmp_create_handler_registration
			("test", get_test, me1filesize_oid,
			OID_LENGTH(me1filesize_oid),
			HANDLER_CAN_RONLY);
		myreg->contextName = filename;
		status = netsnmp_register_read_only_instance(myreg);
		DEBUGMSGTL(("demo_module_7", "status %d:\n",  status));
		break;

	case MODE_SET_COMMIT:
		break;

	case MODE_SET_UNDO:
		/*
		Not handling the undo case because we don't care about
		multi-phase sets for this example. */
		break;

	case MODE_GET:
		snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
			(u_char *)filename, sizeof (filename));

	default:
		/* we should never get here, so this is a really bad error */
	DEBUGMSGTL(("demo_module_7", "default CALLED\n"));
	}

	return (SNMP_ERR_NOERROR);
}