본문 바로가기
IT/Azure

ADH(Azure dedicated host) 남아있는 유지관리 기간 확인 cli

by rapker 2023. 4. 25.
반응형
728x90

기본적으로 ADH(Azure Dedicated Host)의 유지보수 기간을 확인하는 방법은 다음과 같습니다.

  1. Azure Portal에 로그인합니다.
  2. 검색 상자에서 "Dedicated Hosts"를 입력하고, "Dedicated Hosts" 페이지를 엽니다.
  3. 확인하려는 Dedicated Host를 선택합니다.
  4. "설정" 탭에서 "관리" 섹션으로 이동합니다.
  5. "유지관리" 섹션에서, "유지관리 상태"를 확인할 수 있습니다.
  6. "유지관리 상태"가 "계획된" 경우, "계획된 유지보수" 항목에서 유지보수 일정을 확인할 수 있습니다.

위 단계를 따라 진행하면 해당 Dedicated Host의 유지보수 상태를 확인할 수 있습니다.

 

 

하지만 언제나 그렇듯 자동화 해두면 몸과 마음이 편해지기 때문에 Azure Portal에서 직접 확인하지 않고

Powershell script를 만들어 확인이 가능하며 해당 내용을 기록해 둡니다.

 

 

 



결과 미리보기

 


스크립트

최종본으로 다운로드 받아서 곧 바로 사용할 수 있습니다.

 

dh-show-cmw-remain-day.ps1
0.00MB

 

반응형

 

사용방법

해당 스크립트는 리소스 그룹 내의 모든 ADH들을 찾아서 검색하기 때문에

검색할 리소스 그룹을 지정해 주기만 하면 됩니다.


검사할 리소스 그룹을 스크립트 하단의 $ResourceGroupList.Add()로 추가 후 실행


powershell 7.1

#https://docs.microsoft.com/ko-kr/powershell/module/microsoft.powershell.utility/add-type?view=powershell-7.1#example-1--add-a--net-type-to-a-session
Add-Type @"
namespace Custom
{
  public class HostInfo
  {
      public string cmwName;
      public string rgName;
      public string hostName;
      public string groupName;
  }
}
"@
function ShowHost {
  param(
      [Parameter(mandatory=$true)]
      [AllowNull ()]
      [string]
      $ResourceGroupList         
  )
  $HostList = New-Object 'system.collections.generic.List[Custom.HostInfo]'
   
  $ResourceGroupList | ForEach-Object -Parallel {
      $HostList = $using:HostList
      #https://docs.microsoft.com/ko-kr/cli/azure/vm/host/group?view=azure-cli-latest#az_vm_host_group_list
      $groupNames = az vm host group list -g $_ --query '[].name' | ConvertFrom-Json
   
      foreach ($groupName in $groupNames) {
   
        #https://docs.microsoft.com/ko-kr/cli/azure/vm/host?view=azure-cli-latest#az_vm_host_list
        $hostListTmp = az vm host list `
                        -g $_ `
                        --host-group $groupName `
                        --query '[].{name:name, rg:resourceGroup}' | ConvertFrom-Json
     
        foreach ($hostTmp in $hostListTmp) {
         
            #https://docs.microsoft.com/ko-kr/cli/azure/maintenance/assignment?view=azure-cli-latest#az_maintenance_assignment_list_parent
            $cmwId = @(az maintenance assignment list-parent `
                    --resource-group $hostTmp.rg `
                    --provider-name "Microsoft.Compute" `
                    --resource-name $hostTmp.name `
                    --resource-type "hosts" `
                    --resource-parent-name $groupName `
                    --resource-parent-type "hostGroups" `
                    --query '[].maintenanceConfigurationId' | ConvertFrom-Json)[0]
            $cmwName = @($cmwId -split "/")[8]
     
            $obj = New-Object Custom.HostInfo
            $obj.cmwName = $cmwName
            $obj.rgName = $hostTmp.rg
            $obj.hostName = $hostTmp.name
            $obj.groupName = $groupName
         
            $HostList.Add($obj)
        }
      }
  } -ThrottleLimit 20
   
   
  if ($HostList.Count -gt 0) {
   
      Write-Host ("=============== 체크시작 =========== ")
      $HostList | ForEach-Object -Parallel {
   
        #https://docs.microsoft.com/ko-kr/cli/azure/maintenance/applyupdate?view=azure-cli-latest#az_maintenance_applyupdate_get_parent-examples
        $get = @(az maintenance applyupdate get-parent `
              --name $_.cmwName `
              --provider-name Microsoft.Compute `
              --resource-group $_.rgName `
              --resource-name $_.hostName `
              --resource-parent-name $_.groupName `
              --resource-parent-type hostGroups `
              --resource-type hosts | ConvertFrom-Json)
   
        #$get
        $hostname = @($get.resourceId -split "/")[10]
   
   
        ##https://docs.microsoft.com/ko-kr/azure/virtual-machines/maintenance-control-cli#check-for-pending-updates
        $maintenanceInfo = @(az maintenance update list-parent `
                    --resource-group $_.rgName `
                    --resource-name $_.hostName `
                    --resource-type hosts `
                    --provider-name Microsoft.Compute `
                    --resource-parent-name $_.groupName `
                    --resource-parent-type hostGroups | ConvertFrom-Json)[0]
         
        $nextTimeDesc = ""
   
        if ($maintenanceInfo.notBefore.Length -gt 0){
   
            $next = Get-Date($maintenanceInfo.notBefore) -Format "yyyy/MM/dd HH:mm:ss"
            $now = Get-Date -Format "yyyy/MM/dd HH:mm:ss"
   
            $ts = New-TimeSpan -Start $now -End $next
           
            $nextTimeDesc = "(" + $ts.Days + " 일 남음)"
        }
   
        $impactDesc = " ( impactType: " + $maintenanceInfo.impactType + ", impactDurationInSec: " + $maintenanceInfo.impactDurationInSec + " )"
   
        #status value : Completed, InProgress, Pending
        Write-Host "[" $hostname " => " $get.status "] lastUpdateTime:" $get.lastUpdateTime ", nextUpdateTime:" $maintenanceInfo.notBefore $nextTimeDesc $impactDesc
   
      } -ThrottleLimit 20
   
      Write-Host ("=============== 체크종료 =========== ")
  }
}
$ResourceGroupList = New-Object 'system.collections.generic.List[string]'
$ResourceGroupList.Add("")
ShowHost $ResourceGroupList

 

 

 

반응형
LIST