load_configuration

in source/code/plugins/oms_configuration.rb [239:369]


      def load_configuration(conf_path, cert_path, key_path)
        return true if @@ConfigurationLoaded
        return false if !test_onboard_file(conf_path) or !test_onboard_file(cert_path) or !test_onboard_file(key_path)

        @@ProxyConfig = get_proxy_config(@@ProxyConfigFilePath)

        endpoint_lines = IO.readlines(conf_path).select{ |line| line.start_with?("OMS_ENDPOINT")}
        if endpoint_lines.size == 0
          OMS::Log.error_once("Could not find OMS_ENDPOINT setting in #{conf_path}")
          return false
        elsif endpoint_lines.size > 1
          OMS::Log.warn_once("Found more than one OMS_ENDPOINT setting in #{conf_path}, will use the first one.")
        end

        begin
          endpoint_url = endpoint_lines[0].split("=")[1].strip
          @@ODSEndpoint = URI.parse( endpoint_url )
          @@GetBlobODSEndpoint = @@ODSEndpoint.clone
          @@GetBlobODSEndpoint.path = '/ContainerService.svc/GetBlobUploadUri'
          @@NotifyBlobODSEndpoint = @@ODSEndpoint.clone
          @@NotifyBlobODSEndpoint.path = '/ContainerService.svc/PostBlobUploadNotification'
        rescue => e
          OMS::Log.error_once("Error parsing endpoint url. #{e}")
          return false
        end

        begin
          diagnostic_endpoint_lines = IO.readlines(conf_path).select{ |line| line.start_with?("DIAGNOSTIC_ENDPOINT=")}
          if diagnostic_endpoint_lines.size == 0
            
            @@DiagnosticEndpoint = @@ODSEndpoint.clone
            @@DiagnosticEndpoint.path = '/DiagnosticsDataService.svc/PostJsonDataItems'
          else
            if diagnostic_endpoint_lines.size > 1
              OMS::Log.warn_once("Found more than one DIAGNOSTIC_ENDPOINT setting in #{conf_path}, will use the first one.")
            end
            diagnostic_endpoint_url = diagnostic_endpoint_lines[0].split("=")[1].strip
            @@DiagnosticEndpoint = URI.parse( diagnostic_endpoint_url )
          end
        rescue => e
          OMS::Log.error_once("Error obtaining diagnostic endpoint url. #{e}")
          return false
        end

        agentid_lines = IO.readlines(conf_path).select{ |line| line.start_with?("AGENT_GUID")}
        if agentid_lines.size == 0
          OMS::Log.error_once("Could not find AGENT_GUID setting in #{conf_path}")
          return false
        elsif agentid_lines.size > 1
          OMS::Log.warn_once("Found more than one AGENT_GUID setting in #{conf_path}, will use the first one.")
        end

        begin
          @@AgentId = agentid_lines[0].split("=")[1].strip
        rescue => e
          OMS::Log.error_once("Error parsing agent id. #{e}")
          return false
        end

        File.open(conf_path).each_line do |line|
          if line =~ /^WORKSPACE_ID/
            @@WorkspaceId = line.sub("WORKSPACE_ID=","").strip
          end
          if line =~ /AZURE_RESOURCE_ID/
            
            
            
            @@AzureResourceId = ENV['customResourceId']
            
            
            if @@AzureResourceId.nil? || @@AzureResourceId.empty?              
              @@AzureResourceId = line.sub("AZURE_RESOURCE_ID=","").strip
              if @@AzureResourceId.include? "Microsoft.ContainerService"
                OMS::Log.info_once("Azure resource id in configuration file is for AKS. It will be used")                  
              else
                Thread.new(&method(:update_azure_resource_id)) if @@AzureResIDThreadLock.try_lock
              end            
            else
              OMS::Log.info_once("There is non empty value set for overriden-resourceId environment variable. It will be used")
            end
          end
          if line =~ /OMSCLOUD_ID/
            @@OmsCloudId = line.sub("OMSCLOUD_ID=","").strip
          end
          if line =~ /^AGENT_GUID/
            @@AgentGUID = line.sub("AGENT_GUID=","").strip
          end
          if line =~ /^URL_TLD/
            @@URLTLD = line.sub("URL_TLD=","").strip
          end
          if line =~ /^LOG_FACILITY/
            @@LogFacility = line.sub("LOG_FACILITY=","").strip
          end
          if line =~ /UUID/
            uuid_str = line.sub("UUID=","").strip
            uuid_regex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/
            if uuid_str =~ uuid_regex
              @@UUID = uuid_str
            else
              @@UUID = "00000000-0000-0000-0000-000000000000" 
            end          
          end
        end

        begin
          raw = File.read cert_path
          @@Cert = OpenSSL::X509::Certificate.new raw
          raw = File.read key_path
          @@Key  = OpenSSL::PKey::RSA.new raw
        rescue => e
          OMS::Log.error_once("Error loading certs: #{e}")
          return false
        end
    
        @@AzureRegion = get_azure_region_from_imds()
        if @@AzureRegion.nil? || @@AzureRegion.empty?
          OMS::Log.warn_once("Azure region value is not set. This must be onpremise machine")
          @@AzureRegion = "OnPremise"
        end
        
        @@ConfigurationLoaded = true
        return true
      end 

      def set_request_intervals(topology_interval, telemetry_interval)
        @@TopologyInterval = topology_interval
        @@TelemetryInterval = telemetry_interval
        OMS::Log.info_once("OMS agent management service topology request interval now #{@@TopologyInterval}")
        OMS::Log.info_once("OMS agent management service telemetry request interval now #{@@TelemetryInterval}")
      end