class LogStash::Outputs::Application_insights::Utils

Constants

UNESCAPES

Public Class Methods

alphanumeric?( s ) click to toggle source
# File lib/logstash/outputs/application_insights/utils.rb, line 90
def self.alphanumeric? ( s )
  s =~ /\A[a-zA-Z0-9]*\z/
end
base64?( s ) click to toggle source
# 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 ) click to toggle source
# 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 ) click to toggle source
# 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 ) click to toggle source
# File lib/logstash/outputs/application_insights/utils.rb, line 98
def self.ext? ( s )
  s =~ /\A[a-zA-Z0-9\-\_]*\z/
end
guid?( s ) click to toggle source
# 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 ) click to toggle source
# 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 ) click to toggle source
# 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 ) click to toggle source
# File lib/logstash/outputs/application_insights/utils.rb, line 70
def self.integer? ( s )
  s =~ /\A[-+]?[0-9]*\z/
end
ip4_address?( s ) click to toggle source
# 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 ) click to toggle source
# 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 ) click to toggle source
# File lib/logstash/outputs/application_insights/utils.rb, line 74
def self.numeric? ( s )
  s =~ /\A[-+]?[0-9]*\.?[0-9]+\z/
end
os() click to toggle source
# 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) click to toggle source
# 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 ) click to toggle source
# 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 ) click to toggle source
# 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) click to toggle source
# 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 ) click to toggle source
# 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 ) click to toggle source
# 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() click to toggle source
# 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 ) click to toggle source
# 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