Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

Azure runbook 실행 시 "Errors", "All Logs"에 오류 메시지가 출력되는 경우

얼마 전에, Facebook Azure Korea 그룹에 다음과 같은 질문이 게시되었습니다.

https://www.facebook.com/groups/krazure/permalink/1999097503465742/

안녕하세요. 질문이 있습니다.
VM에 listening하는 포트를 테스트하고 싶은데요.
원하는 그림은 scheduler -> runbook -> port test -> fail시 alert 발생 입니다.

powershell의 Test-NetConnection을 runbook에서 실행하려니 아래와 같이 에러가 발생하네요. 모듈이 안깔려 있는것 같은데 방법이 있을까요?

Find-NetIPsecRule : Cannot connect to CIM server. The specified service does not exist as an installed service. 
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NetTCPIP\Test-NetConnection.psm1:340 char:63
+ ... PsecRules = Find-NetIPsecRule -RemoteAddress $TestNetConnectionResult ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (MSFT_NetConSecRule:String) [Find-NetIPsecRule], CimJobException
+ FullyQualifiedErrorId : CimJob_BrokenCimSession,Find-NetIPsecRule

실제로 Azure에서 runbook을 만들어,

Azure - Runbook 기능 소개
; https://www.sysnet.pe.kr/2/0/11511

다음과 같은 스크립트로 실행하면,

Test-NetConnection -ComputerName "23.12.224.153" -Port 80 -InformationLevel "Detailed"

이렇게 오류가 발생하고,

azure_runbook_error_1.png

오류 내용은 질문자의 것과 동일합니다.




Azure runbook의 PowerShell 스크립트에 대한 오류 처리는 기본적으로 "Continue" 모드로 다음과 같이 테스트 해볼 수 있습니다.

Write-Output "Mode: $ErrorActionPreference"

# 출력 결과
# "Mode: Continue"

일례로 다음과 같이 스크립트를 수정하고 실행하면,

$result = Test-NetConnection -ComputerName "23.12.224.153" -Port 80 -InformationLevel "Detailed"
$result.ComputerName

이번에도 "Errors"에 1개의 오류가 있다고 나오지만 "Output"을 보면 "23.12.224.153"이 찍혀 있는 것을 확인할 수 있습니다. 즉, 전체 스크립트 실행은 완료된 것입니다. 따라서, 스크립트 내의 코드가 예외 발생 시 멈추도록 만들려면 다음과 같이 Stop 모드로 바꿔야 합니다.

$ErrorActionPreference = "Stop"

$result = Test-NetConnection -ComputerName "23.12.224.153" -Port 80 -InformationLevel "Detailed"
$result.ComputerName

위의 경우, Test-NetConnection에서 예외가 발생한 후 실행이 멈추고 $result.ComputerName 출력이 나오지 않습니다. 게다가 스크립트의 실행에 대한 STATUS 값이 "Failed(실패)"로 나옵니다. 즉, $ErrorActionPreference 값을 바꾸지 않는 한 Runbook의 실행 결과는 항상 "Completed(완료됨)"로 끝납니다.



그나저나 Test-NetConnection의 오류 원인을 좀 더 밝혀 볼까요? ^^

Test-NetConnection의 오류에 Find-NetIPsecRule 문자열이 있는 것으로 보아, 아마도 저 명령어는 여러 개의 PowerShell 스크립트 명령어를 조합한 것으로 보입니다. 재현을 위해 Azure runbook에서 다음과 같이 실행해 볼 수도 있습니다.

Find-NetIPsecRule -RemoteAddress "127.0.0.1"
Write-Output "TEST IS GOOD"

위의 결과는 Test-NetConnection을 사용했을 때와 동일한 오류 로그를 보입니다. 즉, Test-NetConnection 내부에서 Find-NetIPsecRule을 실행하다 예외가 발생한 것이고, $ErrorActionPreference 값이 Continue이므로 Test-NetConnection 내부에서도 Find-NetIPsecRule 이후의 명령어는 정상적으로 실행되어 $result.ComputerName에 값이 제대로 나오게 된 것입니다.
참고로, 로컬 PC에서 Winmgmt(Windows Management Instrumentation) 서비스를 Disabled/Stopped 시켜놓고 Find-NetIPsecRule을 실행하면 다음과 같은 오류 메시지가 나옵니다.

PS C:\WINDOWS\system32> Find-NetIPsecRule -RemoteAddress "127.0.0.1"
Find-NetIPsecRule : Cannot connect to CIM server. The service cannot be started, either because it is disabled or because it has no enabled devices associated with it. 
At line:1 char:1
+ Find-NetIPsecRule -RemoteAddress "127.0.0.1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (MSFT_NetConSecRule:String) [Find-NetIPsecRule], CimJobException
    + FullyQualifiedErrorId : CimJob_BrokenCimSession,Find-NetIPsecRule

이런 것으로 보아, Azure runbook이 실행되는 VM은 WMI 서비스는 정상적으로 실행 중이지만, 아마도 Find-NetIPsecRule에서 사용하는 CIM Namespace 관련 정보를 제공하는 서비스가 중지된 것이 아닌가... 예상해봅니다.




마지막으로! Azure runbook의 "Output(출력)", "All logs(모든 로그)"에 데이터를 출력하고 싶다면 Write-Output을 사용해야 합니다. 따라서 다음과 같이 출력한 경우,

Write-Output "TEST IS GOOD0"
Write-Debug "TEST IS GOOD1"
Write-Host "TEST IS GOOD2"

"출력"이나 "모든 로그"에는 "TEST IS GOOD0" 문자열만 보이고, 그 외의 Write-Debug, Write-Host로 출력한 문자열은 보이지 않습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 5/4/2018]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13485정성태12/15/20232101오류 유형: 883. dotnet build/restore - error : Root element is missing
13484정성태12/14/20232179개발 환경 구성: 694. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법
13483정성태12/14/20232321닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
13482정성태12/13/20232922닷넷: 2183. C# - eFriend Expert OCX 예제를 .NET Core/5+ Console App에서 사용하는 방법 [2]파일 다운로드1
13481정성태12/13/20232297개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법파일 다운로드1
13480정성태12/12/20232678개발 환경 구성: 692. Windows WSL 2 + Chrome 웹 브라우저 설치
13479정성태12/11/20232356개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232554닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232278닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
13475정성태12/7/20232352닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
13474정성태12/6/20232203개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/20232419닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/20232222C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/20232298Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/20232613닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입파일 다운로드1
13469정성태12/1/20232329닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/20232276닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/20232367오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/20232554닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232309개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232434닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232379오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
13462정성태11/27/20232394오류 유형: 880. Visual Studio - error CS0246: The type or namespace name '...' could not be found
13461정성태11/26/20232421닷넷: 2173. .NET Core 3/5+ 기반의 COM Server를 registry 등록 없이 사용하는 방법파일 다운로드1
13460정성태11/26/20232367닷넷: 2172. .NET 6+ 기반의 COM Server 내에 Type Library를 내장하는 방법파일 다운로드1
13459정성태11/26/20232343닷넷: 2171. .NET Core 3/5+ 기반의 COM Server를 기존의 regasm처럼 등록하는 방법파일 다운로드1
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...