From 7339a3dd4610777253762a5d1b3bec9baa4d3922 Mon Sep 17 00:00:00 2001 From: Rashmi Chandrashekar Date: Fri, 28 Jan 2022 10:45:44 -0800 Subject: [PATCH 1/3] fixing tel bug for placeholder name --- kubernetes/windows/main.ps1 | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/kubernetes/windows/main.ps1 b/kubernetes/windows/main.ps1 index 733ddb408..f5fab4edd 100644 --- a/kubernetes/windows/main.ps1 +++ b/kubernetes/windows/main.ps1 @@ -52,23 +52,29 @@ function Set-EnvironmentVariables { if ($domain -eq "opinsights.azure.com") { $cloud_environment = "azurepubliccloud" $mcs_endpoint = "monitor.azure.com" - } elseif ($domain -eq "opinsights.azure.cn") { + } + elseif ($domain -eq "opinsights.azure.cn") { $cloud_environment = "azurechinacloud" $mcs_endpoint = "monitor.azure.cn" - } elseif ($domain -eq "opinsights.azure.us") { + } + elseif ($domain -eq "opinsights.azure.us") { $cloud_environment = "azureusgovernmentcloud" $mcs_endpoint = "monitor.azure.us" - } elseif ($domain -eq "opinsights.azure.eaglex.ic.gov") { + } + elseif ($domain -eq "opinsights.azure.eaglex.ic.gov") { $cloud_environment = "usnat" $mcs_endpoint = "monitor.azure.eaglex.ic.gov" - } elseif ($domain -eq "opinsights.azure.microsoft.scloud") { + } + elseif ($domain -eq "opinsights.azure.microsoft.scloud") { $cloud_environment = "ussec" $mcs_endpoint = "monitor.azure.microsoft.scloud" - } else { + } + else { Write-Host "Invalid or Unsupported domain name $($domain). EXITING....." exit 1 } - } else { + } + else { Write-Host "Domain name either null or empty. EXITING....." exit 1 } @@ -490,6 +496,11 @@ function Start-Telegraf { Write-Host "Failed to set environment variable NODE_IP for target 'machine' since it is either null or empty" } + $hostName = [System.Environment]::GetEnvironmentVariable("HOSTNAME", "process") + Write-Host "nodename: $($hostName)" + Write-Host "replacing nodename in telegraf config" + (Get-Content "C:\etc\telegraf\telegraf.conf").replace('placeholder_hostname', $hostName) | Set-Content "C:\etc\telegraf\telegraf.conf" + Write-Host "Installing telegraf service" C:\opt\telegraf\telegraf.exe --service install --config "C:\etc\telegraf\telegraf.conf" @@ -589,14 +600,16 @@ if (![string]::IsNullOrEmpty($requiresCertBootstrap) -and ` $isAADMSIAuth = [System.Environment]::GetEnvironmentVariable("USING_AAD_MSI_AUTH") if (![string]::IsNullOrEmpty($isAADMSIAuth) -and $isAADMSIAuth.ToLower() -eq 'true') { Write-Host "skipping agent onboarding via cert since AAD MSI Auth configured" -} else { +} +else { Generate-Certificates Test-CertificatePath } + Start-Fluent-Telegraf # List all powershell processes running. This should have main.ps1 and filesystemwatcher.ps1 Get-WmiObject Win32_process | Where-Object { $_.Name -match 'powershell' } | Format-Table -Property Name, CommandLine, ProcessId #check if fluentd service is running -Get-Service fluentdwinaks +Get-Service fluentdwinaks \ No newline at end of file From 30d4af95a9fa3397475fb94d0587b91e76c14f68 Mon Sep 17 00:00:00 2001 From: Rashmi Chandrashekar Date: Fri, 28 Jan 2022 12:49:03 -0800 Subject: [PATCH 2/3] removing placeholdername --- build/windows/installer/conf/telegraf.conf | 2 +- kubernetes/windows/main.ps1 | 29 ++++++---------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/build/windows/installer/conf/telegraf.conf b/build/windows/installer/conf/telegraf.conf index 5f4d2364e..9d49d0857 100644 --- a/build/windows/installer/conf/telegraf.conf +++ b/build/windows/installer/conf/telegraf.conf @@ -16,7 +16,7 @@ # Global tags can be specified here in key="value" format. [global_tags] - hostName = "placeholder_hostname" + # hostName = "placeholder_hostname" # Configuration for telegraf agent diff --git a/kubernetes/windows/main.ps1 b/kubernetes/windows/main.ps1 index f5fab4edd..733ddb408 100644 --- a/kubernetes/windows/main.ps1 +++ b/kubernetes/windows/main.ps1 @@ -52,29 +52,23 @@ function Set-EnvironmentVariables { if ($domain -eq "opinsights.azure.com") { $cloud_environment = "azurepubliccloud" $mcs_endpoint = "monitor.azure.com" - } - elseif ($domain -eq "opinsights.azure.cn") { + } elseif ($domain -eq "opinsights.azure.cn") { $cloud_environment = "azurechinacloud" $mcs_endpoint = "monitor.azure.cn" - } - elseif ($domain -eq "opinsights.azure.us") { + } elseif ($domain -eq "opinsights.azure.us") { $cloud_environment = "azureusgovernmentcloud" $mcs_endpoint = "monitor.azure.us" - } - elseif ($domain -eq "opinsights.azure.eaglex.ic.gov") { + } elseif ($domain -eq "opinsights.azure.eaglex.ic.gov") { $cloud_environment = "usnat" $mcs_endpoint = "monitor.azure.eaglex.ic.gov" - } - elseif ($domain -eq "opinsights.azure.microsoft.scloud") { + } elseif ($domain -eq "opinsights.azure.microsoft.scloud") { $cloud_environment = "ussec" $mcs_endpoint = "monitor.azure.microsoft.scloud" - } - else { + } else { Write-Host "Invalid or Unsupported domain name $($domain). EXITING....." exit 1 } - } - else { + } else { Write-Host "Domain name either null or empty. EXITING....." exit 1 } @@ -496,11 +490,6 @@ function Start-Telegraf { Write-Host "Failed to set environment variable NODE_IP for target 'machine' since it is either null or empty" } - $hostName = [System.Environment]::GetEnvironmentVariable("HOSTNAME", "process") - Write-Host "nodename: $($hostName)" - Write-Host "replacing nodename in telegraf config" - (Get-Content "C:\etc\telegraf\telegraf.conf").replace('placeholder_hostname', $hostName) | Set-Content "C:\etc\telegraf\telegraf.conf" - Write-Host "Installing telegraf service" C:\opt\telegraf\telegraf.exe --service install --config "C:\etc\telegraf\telegraf.conf" @@ -600,16 +589,14 @@ if (![string]::IsNullOrEmpty($requiresCertBootstrap) -and ` $isAADMSIAuth = [System.Environment]::GetEnvironmentVariable("USING_AAD_MSI_AUTH") if (![string]::IsNullOrEmpty($isAADMSIAuth) -and $isAADMSIAuth.ToLower() -eq 'true') { Write-Host "skipping agent onboarding via cert since AAD MSI Auth configured" -} -else { +} else { Generate-Certificates Test-CertificatePath } - Start-Fluent-Telegraf # List all powershell processes running. This should have main.ps1 and filesystemwatcher.ps1 Get-WmiObject Win32_process | Where-Object { $_.Name -match 'powershell' } | Format-Table -Property Name, CommandLine, ProcessId #check if fluentd service is running -Get-Service fluentdwinaks \ No newline at end of file +Get-Service fluentdwinaks From 7e55e0c147b26edc985642527cbd31c2e858e6d7 Mon Sep 17 00:00:00 2001 From: Rashmi Chandrashekar Date: Fri, 28 Jan 2022 13:06:27 -0800 Subject: [PATCH 3/3] reverting changes --- build/windows/installer/conf/telegraf.conf | 2 +- kubernetes/windows/main.ps1 | 29 ++++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/build/windows/installer/conf/telegraf.conf b/build/windows/installer/conf/telegraf.conf index 9d49d0857..5f4d2364e 100644 --- a/build/windows/installer/conf/telegraf.conf +++ b/build/windows/installer/conf/telegraf.conf @@ -16,7 +16,7 @@ # Global tags can be specified here in key="value" format. [global_tags] - # hostName = "placeholder_hostname" + hostName = "placeholder_hostname" # Configuration for telegraf agent diff --git a/kubernetes/windows/main.ps1 b/kubernetes/windows/main.ps1 index 733ddb408..f5fab4edd 100644 --- a/kubernetes/windows/main.ps1 +++ b/kubernetes/windows/main.ps1 @@ -52,23 +52,29 @@ function Set-EnvironmentVariables { if ($domain -eq "opinsights.azure.com") { $cloud_environment = "azurepubliccloud" $mcs_endpoint = "monitor.azure.com" - } elseif ($domain -eq "opinsights.azure.cn") { + } + elseif ($domain -eq "opinsights.azure.cn") { $cloud_environment = "azurechinacloud" $mcs_endpoint = "monitor.azure.cn" - } elseif ($domain -eq "opinsights.azure.us") { + } + elseif ($domain -eq "opinsights.azure.us") { $cloud_environment = "azureusgovernmentcloud" $mcs_endpoint = "monitor.azure.us" - } elseif ($domain -eq "opinsights.azure.eaglex.ic.gov") { + } + elseif ($domain -eq "opinsights.azure.eaglex.ic.gov") { $cloud_environment = "usnat" $mcs_endpoint = "monitor.azure.eaglex.ic.gov" - } elseif ($domain -eq "opinsights.azure.microsoft.scloud") { + } + elseif ($domain -eq "opinsights.azure.microsoft.scloud") { $cloud_environment = "ussec" $mcs_endpoint = "monitor.azure.microsoft.scloud" - } else { + } + else { Write-Host "Invalid or Unsupported domain name $($domain). EXITING....." exit 1 } - } else { + } + else { Write-Host "Domain name either null or empty. EXITING....." exit 1 } @@ -490,6 +496,11 @@ function Start-Telegraf { Write-Host "Failed to set environment variable NODE_IP for target 'machine' since it is either null or empty" } + $hostName = [System.Environment]::GetEnvironmentVariable("HOSTNAME", "process") + Write-Host "nodename: $($hostName)" + Write-Host "replacing nodename in telegraf config" + (Get-Content "C:\etc\telegraf\telegraf.conf").replace('placeholder_hostname', $hostName) | Set-Content "C:\etc\telegraf\telegraf.conf" + Write-Host "Installing telegraf service" C:\opt\telegraf\telegraf.exe --service install --config "C:\etc\telegraf\telegraf.conf" @@ -589,14 +600,16 @@ if (![string]::IsNullOrEmpty($requiresCertBootstrap) -and ` $isAADMSIAuth = [System.Environment]::GetEnvironmentVariable("USING_AAD_MSI_AUTH") if (![string]::IsNullOrEmpty($isAADMSIAuth) -and $isAADMSIAuth.ToLower() -eq 'true') { Write-Host "skipping agent onboarding via cert since AAD MSI Auth configured" -} else { +} +else { Generate-Certificates Test-CertificatePath } + Start-Fluent-Telegraf # List all powershell processes running. This should have main.ps1 and filesystemwatcher.ps1 Get-WmiObject Win32_process | Where-Object { $_.Name -match 'powershell' } | Format-Table -Property Name, CommandLine, ProcessId #check if fluentd service is running -Get-Service fluentdwinaks +Get-Service fluentdwinaks \ No newline at end of file