@@ -114,7 +114,7 @@ static int in_snmp_collect(struct flb_input_instance *ins, struct flb_config *co
114114 int ret = 0 ;
115115 struct flb_snmp * ctx = in_context ;
116116
117- netsnmp_session session , * ss ;
117+ netsnmp_session * ss ;
118118 netsnmp_pdu * pdu ;
119119 netsnmp_pdu * response ;
120120
@@ -131,24 +131,7 @@ static int in_snmp_collect(struct flb_input_instance *ins, struct flb_config *co
131131 bool is_walk = false;
132132
133133 char * err ;
134-
135-
136- init_snmp (PLUGIN_NAME );
137134
138- init_snmp (PLUGIN_NAME );
139- snmp_sess_init (& session );
140-
141- session .peername = ctx -> target_host ;
142-
143- if (strcmp (ctx -> version , "1" ) == 0 ) {
144- session .version = SNMP_VERSION_1 ;
145- } else if (strcmp (ctx -> version , "2c" ) == 0 ) {
146- session .version = SNMP_VERSION_2c ;
147- } else {
148- flb_plg_error (ctx -> ins , "Unsupported SNMP version : %s" , ctx -> version );
149- return -1 ;
150- }
151-
152135 if (strcmp (ctx -> oid_type , "get" ) == 0 ) {
153136 is_walk = false;
154137 } else if (strcmp (ctx -> oid_type , "walk" ) == 0 ) {
@@ -158,10 +141,7 @@ static int in_snmp_collect(struct flb_input_instance *ins, struct flb_config *co
158141 return -1 ;
159142 }
160143
161- session .community = (u_char * ) ctx -> community ;
162- session .community_len = strlen (ctx -> community );
163-
164- ss = snmp_open (& session );
144+ ss = snmp_open (& ctx -> session );
165145 if (!ss ) {
166146 snmp_error (ss , NULL , NULL , & err );
167147 flb_plg_error (ctx -> ins , "%s" , err );
@@ -275,7 +255,7 @@ static int in_snmp_collect(struct flb_input_instance *ins, struct flb_config *co
275255 flb_plg_error (ctx -> ins , "Error in packet. Reason: %s" , snmp_errstring (response -> errstat ));
276256 running = 0 ;
277257 } else if (status == STAT_TIMEOUT ) {
278- flb_plg_error (ctx -> ins , "Timeout: No response from %s" , session .peername );
258+ flb_plg_error (ctx -> ins , "Timeout: No response from %s" , ctx -> session .peername );
279259 running = 0 ;
280260 } else {
281261 snmp_error (ss , NULL , NULL , & err );
@@ -367,10 +347,31 @@ static int in_snmp_init(struct flb_input_instance *in,
367347
368348 netsnmp_ds_set_boolean (NETSNMP_DS_LIBRARY_ID , NETSNMP_DS_LIB_NUMERIC_TIMETICKS , 1 );
369349 netsnmp_ds_set_boolean (NETSNMP_DS_LIBRARY_ID , NETSNMP_DS_LIB_QUICK_PRINT , 1 );
350+ netsnmp_ds_set_boolean (NETSNMP_DS_LIBRARY_ID , NETSNMP_DS_LIB_DISABLE_PERSISTENT_LOAD , 1 );
351+ netsnmp_ds_set_boolean (NETSNMP_DS_LIBRARY_ID , NETSNMP_DS_LIB_DISABLE_PERSISTENT_SAVE , 1 );
352+ netsnmp_ds_set_int (NETSNMP_DS_LIBRARY_ID , NETSNMP_DS_LIB_TIMEOUT , ctx -> timeout );
353+ netsnmp_ds_set_int (NETSNMP_DS_LIBRARY_ID , NETSNMP_DS_LIB_RETRIES , ctx -> retries );
370354
371355 SOCK_STARTUP ;
372356 init_snmp (PLUGIN_NAME );
373357
358+ snmp_sess_init (& ctx -> session );
359+
360+ ctx -> session .peername = ctx -> target_host ;
361+
362+ if (strcmp (ctx -> version , "1" ) == 0 ) {
363+ ctx -> session .version = SNMP_VERSION_1 ;
364+ } else if (strcmp (ctx -> version , "2c" ) == 0 ) {
365+ ctx -> session .version = SNMP_VERSION_2c ;
366+ } else {
367+ flb_plg_error (ctx -> ins , "Unsupported SNMP version : %s" , ctx -> version );
368+ flb_free (ctx );
369+ return -1 ;
370+ }
371+
372+ ctx -> session .community = (u_char * ) ctx -> community ;
373+ ctx -> session .community_len = strlen (ctx -> community );
374+
374375 return 0 ;
375376}
376377
@@ -448,11 +449,6 @@ static struct flb_config_map config_map[] = {
448449 0 , FLB_TRUE , offsetof(struct flb_snmp , oid ),
449450 "set the OID of the SNMP request."
450451 },
451- {
452- FLB_CONFIG_MAP_STR , "name" , "" ,
453- 0 , FLB_TRUE , offsetof(struct flb_snmp , name ),
454- "set the name for the variable from SNMP request."
455- },
456452 {0 }
457453};
458454
0 commit comments