33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
# File 'lib/logstash/outputs/application_insights/config.rb', line 33
def self.validate_and_adjust_configuration ( configuration )
configuration.each_pair { |config_name, config_value|
raise ConfigurationError, "#{config_name.to_s} must be defined" unless config_value || BOOLEAN_PROPERTIES.include?( config_name )
case config_name
when :logger_level
logger_level = validate_and_adjust( config_name, config_value, String )
raise ConfigurationError, "#{config_name.to_s} can be set to only one of the valid log levels" unless LOGGER_LEVEL_MAP[logger_level.upcase.to_sym]
configuration[config_name] = LOGGER_LEVEL_MAP[logger_level.upcase.to_sym]
when :logger_files
config_value = [ config_value ] if config_value.is_a?( String )
logger_files = validate_and_adjust( config_name, config_value, Array )
i = 0
logger_files.map! do |file_name|
file_name = validate_and_adjust( "#{config_name.to_s}[#{i}]", file_name, String )
i += 1
if "stdout" == file_name.downcase
file_name = :stdout
file = STDOUT
elsif "stderr" == file_name.downcase
file_name = :stderr
file = STDERR
else
file = ::File.open( file_name, "a+" )
end
[ file_name, file ]
end
configuration[config_name] = logger_files
when :logger_progname
configuration[config_name] = validate_and_adjust( config_name, config_value, String )
when :logger_shift_size
configuration[config_name] = validate_and_adjust_integer( config_name, config_value, MIN_LOGGER_SHIFT_SIZE, MAX_LOGGER_SHIFT_SIZE )
when :logger_shift_age
if config_value.is_a?( String )
config_value = validate_and_adjust( config_name, config_value, String ).downcase
raise ConfigurationError, "#{config_name.to_s} if string, can be set to only one of the following values: #{VALID_LOGGER_SHIFT_AGES}" unless VALID_LOGGER_SHIFT_AGES. include?( config_value )
elsif config_value.is_a?( Integer )
config_value = validate_and_adjust_integer( config_name, config_value, MIN_LOGGER_SHIFT_AGE, MAX_LOGGER_SHIFT_AGE )
else
raise ConfigurationError, "#{config_name.to_s} must be either a string or integer"
end
configuration[config_name] = config_value
when :azure_storage_container_prefix
azure_storage_container_prefix = validate_and_adjust( config_name, config_value, String )
unless azure_storage_container_prefix.empty?
len = 63 - "-#{AZURE_STORAGE_CONTAINER_LOGSTASH_PREFIX}-yyyy-mm-dd".length
validate_max( "azure_storage_container_prefix length", azure_storage_container_prefix.length, len )
azure_storage_container_prefix += "-"
end
azure_storage_container_prefix = azure_storage_container_prefix.downcase
container_name = "#{azure_storage_container_prefix}#{AZURE_STORAGE_CONTAINER_LOGSTASH_PREFIX}-yyyy-mm-dd"
raise ConfigurationError, "#{config_name.to_s} must have only alphanumeric and dash characters, cannot start or end with a dash, and a dash cannot follow a dash" unless Utils.valid_container_name?( container_name )
configuration[config_name] = azure_storage_container_prefix + AZURE_STORAGE_CONTAINER_LOGSTASH_PREFIX
when :azure_storage_azure_storage_table_prefix
azure_storage_table_prefix = validate_and_adjust( config_name, config_value, String )
unless azure_storage_table_prefix.empty?
len = 63 - "-#{AZURE_STORAGE_TABLE_LOGSTASH_PREFIX}yyyymmdd".length
validate_max( "azure_storage_table_prefix length", azure_storage_table_prefix.length, len )
end
table_name = "#{azure_storage_table_prefix}#{AZURE_STORAGE_TABLE_LOGSTASH_PREFIX}yyyymmdd"
raise ConfigurationError, "#{config_name} must have only alphanumeric" unless Utils.valid_table_name?( table_name )
configuration[config_name] = azure_storage_table_prefix + AZURE_STORAGE_TABLE_LOGSTASH_PREFIX
when :ca_file
config_value = validate_and_adjust( config_name, config_value, String )
unless config_value.empty?
raise ConfigurationError, "#{config_name} must have a valid path name" unless Utils.valid_file_path?( config_value )
end
configuration[config_name] = validate_and_adjust( config_name, config_value, String )
when :azure_storage_blob_prefix
azure_storage_blob_prefix = validate_and_adjust( config_name, config_value, String )
unless azure_storage_blob_prefix.empty?
len = 1024 - "-#{AZURE_STORAGE_BLOB_LOGSTASH_PREFIX}_ikey-#{INSTRUMENTATION_KEY_TEMPLATE}_table-#{TABLE_ID_TEMPLATE}_yyyy-mm-dd-HH-MM-SS-LLL".length
validate_max( "azure_storage_blob_prefix length", azure_storage_blob_prefix.length, len )
azure_storage_blob_prefix += "-"
end
azure_storage_blob_prefix += AZURE_STORAGE_BLOB_LOGSTASH_PREFIX
raise ConfigurationError, "#{config_name.to_s} doesn't meet url format" unless Utils.url?( "http://storage/container/#{azure_storage_blob_prefix}_ikey-#{INSTRUMENTATION_KEY_TEMPLATE}_table-#{TABLE_ID_TEMPLATE}.json" )
configuration[config_name] = azure_storage_blob_prefix
when :table_id
configuration[config_name] = validate_and_adjust_guid( config_name, config_value )
when :blob_max_bytesize
configuration[config_name] = validate_and_adjust_integer( config_name, config_value, MIN_BLOB_MAX_BYTESIZE, MAX_BLOB_MAX_BYTESIZE )
when :blob_max_events
configuration[config_name] = validate_and_adjust_integer( config_name, config_value, MIN_BLOB_MAX_EVENTS, MAX_BLOB_MAX_EVENTS )
when :blob_retention_time
configuration[config_name] = validate_and_adjust_number( config_name, config_value, MIN_BLOB_RETENTION_TIME, MAX_BLOB_RETENTION_TIME )
when :blob_access_expiry_time
configuration[config_name] = validate_and_adjust_number( config_name, config_value, MIN_BLOB_ACCESS_EXPIRY_TIME, MAX_BLOB_ACCESS_EXPIRY_TIME )
when :resurrect_delay
configuration[config_name] = validate_and_adjust_number( config_name, config_value, MIN_STORAGE_RESURRECT_DELAY, MAX_STORAGE_RESURRECT_DELAY )
when :flow_control_suspend_bytes
configuration[config_name] = validate_and_adjust_number( config_name, config_value, MIN_FLOW_CONTROL_SUSPEND_BYTES, MAX_FLOW_CONTROL_SUSPEND_BYTES )
when :flow_control_resume_bytes
configuration[config_name] = validate_and_adjust_number( config_name, config_value, MIN_FLOW_CONTROL_RESUME_BYTES, MAX_FLOW_CONTROL_RESUME_BYTES )
when :flow_control_delay
configuration[config_name] = validate_and_adjust_number( config_name, config_value, MIN_FLOW_CONTROL_DELAY, MAX_FLOW_CONTROL_DELAY )
when :io_retry_delay
configuration[config_name] = validate_and_adjust_number( config_name, config_value, MIN_IO_RETRY_DELAY, MAX_IO_RETRY_DELAY )
when :io_max_retries
configuration[config_name] = validate_and_adjust_integer( config_name, config_value, MIN_IO_MAX_RETRIES, MAX_IO_MAX_RETRIES )
when :storage_account_name_key
config_value = validate_and_adjust( config_name, config_value, Array )
if config_value.empty?
raise ConfigurationError, "#{config_name.to_s} is empty, at least one storage account name should be defined" unless ENV['AZURE_STORAGE_ACCOUNT']
raise ConfigurationError, "#{config_name.to_s} is empty, at least one storage account access key should be defined" unless ENV['AZURE_STORAGE_ACCESS_KEY']
config_value = [ ENV['AZURE_STORAGE_ACCOUNT'], ENV['AZURE_STORAGE_ACCESS_KEY'] ]
end
storage_account_name_key = validate_and_adjust( config_name, config_value, Array, :disallow_empty )
unless storage_account_name_key[0].is_a?( Array )
raise ConfigurationError, "#{config_name.to_s} property is empty, should contain at least one pair: account_name, key" unless 2 == storage_account_name_key.length
storage_account_name_key = [ [ storage_account_name_key[0], storage_account_name_key[1] ]]
end
index = 0
storage_account_name_key.map! { |pair|
pair = validate_and_adjust( "#{config_name.to_s}[#{index}]", pair, Array, :disallow_empty )
raise ConfigurationError, "#{config_name.to_s}[#{index}] must have two items" unless 2 == pair.length
( name, keys ) = pair
name = validate_and_adjust( "#{config_name.to_s}[#{index}]:name", name, String, :disallow_empty )
raise ConfigurationError, "#{config_name.to_s}[#{index}]:name must between 3 to 24 characters" unless (name.length >= 3) && (name.length <= 24)
raise ConfigurationError, "##{config_name.to_s}[#{index}]:name bad format, must have only alphanumeric characters" unless Utils.alphanumeric?( name )
keys = [ keys ] if keys.is_a?( String )
keys = validate_and_adjust( "#{config_name}[#{index}]:keys", keys, Array, :disallow_empty )
keys.each_index do |i|
key = validate_and_adjust( "#{config_name}[#{index}:keys[#{i}]", keys[i], String, :disallow_empty )
raise ConfigurationError, "#{config_name}[#{index}:keys[#{i}] must have only valid base64 characters" unless Utils.base64?( key )
end
index += 1
[ name.downcase, keys ]
}
configuration[config_name] = storage_account_name_key
when :tables
tables = validate_and_adjust( config_name, config_value, Hash )
tables.each_pair { |table_id, properties|
table_id = validate_and_adjust_guid( "#{config_name}:table_id", table_id )
info = "#{config_name}[#{table_id}]"
properties = validate_and_adjust( info, properties, Hash )
properties = Utils.symbolize_hash_keys( properties )
validate_and_adjust_table_properties!( properties, configuration, info )
configuration[config_name][table_id] = properties
}
end
}
validate_and_adjust_table_properties!( configuration, configuration )
@@configuration = configuration
end
|