Class: LogStash::Outputs::Application_insights::Utils
- Inherits:
-
Object
- Object
- LogStash::Outputs::Application_insights::Utils
- Defined in:
- lib/logstash/outputs/application_insights/utils.rb
Constant Summary collapse
- UNESCAPES =
{ 'a' => "\x07", 'b' => "\x08", 't' => "\x09", 'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c", 'r' => "\x0d", 'e' => "\x1b", "\\\\" => "\x5c", "\"" => "\x22", "'" => "\x27" }
Class Method Summary collapse
- .alphanumeric?(s) ⇒ Boolean
- .base64?(s) ⇒ Boolean
- .dns_address?(s) ⇒ Boolean
- .downcase_hash_keys(hash) ⇒ Object
- .ext?(s) ⇒ Boolean
- .guid?(s) ⇒ Boolean
- .hostname?(s) ⇒ Boolean
- .hosts_address?(s) ⇒ Boolean
- .integer?(s) ⇒ Boolean
- .ip4_address?(s) ⇒ Boolean
- .ip6_address?(s) ⇒ Boolean
- .numeric?(s) ⇒ Boolean
- .os ⇒ Object
- .string_to_hex_string(str, readable = true) ⇒ Object
- .symbolize_hash_keys(hash) ⇒ Object
- .to_storage_name(s) ⇒ Object
- .unescape(str) ⇒ Object
- .url?(s) ⇒ Boolean
- .valid_container_name?(s) ⇒ Boolean
- .valid_file_path ⇒ Object
- .valid_table_name?(s) ⇒ Boolean
Class Method Details
.alphanumeric?(s) ⇒ Boolean
90 91 92 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 90 def self.alphanumeric? ( s ) s =~ /\A[a-zA-Z0-9]*\z/ end |
.base64?(s) ⇒ Boolean
102 103 104 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 102 def self.base64? ( s ) s =~ /\A(?:[A-Za-z0-9\+\/]{4})*(?:[A-Za-z0-9\+\/]{2}==|[A-Za-z0-9\+\/]{3}\=)?\z/ end |
.dns_address?(s) ⇒ Boolean
122 123 124 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 122 def self.dns_address? ( s ) s =~ /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ end |
.downcase_hash_keys(hash) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 144 def self.downcase_hash_keys ( hash ) # to_h not supported in Ruby 2.0 and below # hash.map {|k, v| [k.downcase, v] }.to_h new_hash = {} hash.each_pair do |k, v| new_hash[k.downcase] = v end new_hash end |
.ext?(s) ⇒ Boolean
98 99 100 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 98 def self.ext? ( s ) s =~ /\A[a-zA-Z0-9\-\_]*\z/ end |
.guid?(s) ⇒ Boolean
78 79 80 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 78 def self.guid? ( s ) s =~ /\A[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i end |
.hostname?(s) ⇒ Boolean
110 111 112 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 110 def self.hostname? ( s ) s =~ /\A(?<hostname>([A-Za-z0-9\.\-]+)|\[[0-9A-Fa-f\:]+\])(:(?<port>\d+))?\z/ end |
.hosts_address?(s) ⇒ Boolean
126 127 128 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 126 def self.hosts_address? ( s ) ip4_address?( s ) || ip6_address?( s ) || dns_address?( s ) end |
.integer?(s) ⇒ Boolean
70 71 72 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 70 def self.integer? ( s ) s =~ /\A[-+]?[0-9]*\z/ end |
.ip4_address?(s) ⇒ Boolean
114 115 116 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 114 def self.ip4_address? ( s ) s =~ /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/ end |
.ip6_address?(s) ⇒ Boolean
118 119 120 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 118 def self.ip6_address? ( s ) s =~ /\A(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\z/ end |
.numeric?(s) ⇒ Boolean
74 75 76 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 74 def self.numeric? ( s ) s =~ /\A[-+]?[0-9]*\.?[0-9]+\z/ end |
.os ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 40 def self.os host_os = RbConfig::CONFIG['host_os'] case host_os when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ "Windows #{host_os}" when /darwin|mac os/ "MacOS #{host_os}" when /linux/ "Linux #{host_os}" when /solaris|bsd/ "Unix #{host_os}" else "Unknown #{host_os}" end end |
.string_to_hex_string(str, readable = true) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 25 def self.string_to_hex_string(str, readable = true) unpacked = str.unpack('H*').first if readable unpacked.gsub(/(..)/,'\1 ').rstrip else unpacked end end |
.symbolize_hash_keys(hash) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 134 def self.symbolize_hash_keys ( hash ) # to_h not supported in Ruby 2.0 and below # hash.map {|k, v| [k.to_sym, v] }.to_h new_hash = {} hash.each_pair do |k, v| new_hash[k.to_sym] = v end new_hash end |
.to_storage_name(s) ⇒ Object
130 131 132 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 130 def self.to_storage_name ( s ) s.nil? ? nil : s.downcase.gsub(/[^0-9a-z]/i, '') end |
.unescape(str) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 57 def self.unescape(str) # Escape all the things str.gsub(/\\(?:([#{UNESCAPES.keys.join}])|u([\da-fA-F]{4}))|\\0?x([\da-fA-F]{2})/) { if $1 if $1 == '\\' then '\\' else UNESCAPES[$1] end elsif $2 # escape \u0000 unicode ["#$2".hex].pack('U*') elsif $3 # escape \0xff or \xff [$3].pack('H2') end } end |
.url?(s) ⇒ Boolean
106 107 108 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 106 def self.url? ( s ) s =~ /\A#{URI::regexp(['http', 'https'])}\z/ end |
.valid_container_name?(s) ⇒ Boolean
82 83 84 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 82 def self.valid_container_name? ( s ) s =~ /\A[a-z0-9](?:[a-z0-9]|(\-(?!\-))){1,61}[a-z0-9]\z/ end |
.valid_file_path ⇒ Object
94 95 96 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 94 def self.valid_file_path s =~ /\A(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+\z/ end |
.valid_table_name?(s) ⇒ Boolean
86 87 88 |
# File 'lib/logstash/outputs/application_insights/utils.rb', line 86 def self.valid_table_name? ( s ) s =~ /\A[a-zA-Z][a-zA-Z0-9]{2,62}\z/ end |