@@ -74,18 +74,23 @@ def register
74
74
retries = host [ "retries" ] || 2
75
75
timeout = host [ "timeout" ] || 1000
76
76
77
+ # TODO: move these validations in a custom validator so it happens before the register method is called.
77
78
host_details = host_name . match ( HOST_REGEX )
78
79
raise ( LogStash ::ConfigurationError , "invalid format for host option '#{ host_name } '" ) unless host_details
79
- raise ( LogStash ::ConfigurationError , "only the udp protocol is supported for now" ) unless host_details [ :host_protocol ] . to_s =~ /udp/i
80
+ raise ( LogStash ::ConfigurationError , "only udp & tcp protocols are supported for host option '#{ host_name } '" ) unless host_details [ :host_protocol ] . to_s =~ /^(?:udp|tcp)$/i
81
+
82
+ protocol = host_details [ :host_protocol ]
83
+ address = host_details [ :host_address ]
84
+ port = host_details [ :host_port ]
80
85
81
86
definition = {
82
- :client => LogStash ::SnmpClient . new ( host_name , community , version , retries , timeout , mib ) ,
87
+ :client => LogStash ::SnmpClient . new ( protocol , address , port , community , version , retries , timeout , mib ) ,
83
88
:get => Array ( get ) ,
84
89
:walk => Array ( walk ) ,
85
90
86
- :host_protocol => host_details [ :host_protocol ] ,
87
- :host_address => host_details [ :host_address ] ,
88
- :host_port => host_details [ :host_port ] ,
91
+ :host_protocol => protocol ,
92
+ :host_address => address ,
93
+ :host_port => port ,
89
94
:host_community => community ,
90
95
}
91
96
@client_definitions << definition
0 commit comments