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)
13585정성태3/26/20241502Windows: 262. PerformanceCounter의 InstanceName에 pid를 추가한 "Process V2"
13584정성태3/26/20241462개발 환경 구성: 708. Unity3D - C# Windows Forms / WPF Application에 통합하는 방법파일 다운로드1
13583정성태3/25/20241496Windows: 261. CPU Utilization이 100% 넘는 경우를 성능 카운터로 확인하는 방법
13582정성태3/19/20241608Windows: 260. CPU 사용률을 나타내는 2가지 수치 - 사용량(Usage)과 활용률(Utilization)파일 다운로드1
13581정성태3/18/20241769개발 환경 구성: 707. 빌드한 Unity3D 프로그램을 C++ Windows Application에 통합하는 방법
13580정성태3/15/20241304닷넷: 2231. C# - ReceiveTimeout, SendTimeout이 적용되지 않는 Socket await 비동기 호출파일 다운로드1
13579정성태3/13/20241513오류 유형: 899. HTTP Error 500.32 - ANCM Failed to Load dll
13578정성태3/11/20241668닷넷: 2230. C# - 덮어쓰기 가능한 환형 큐 (Circular queue)파일 다운로드1
13577정성태3/9/20241922닷넷: 2229. C# - 닷넷을 위한 난독화 도구 소개 (예: ConfuserEx)
13576정성태3/8/20241598닷넷: 2228. .NET Profiler - IMetaDataEmit2::DefineMethodSpec 사용법
13575정성태3/7/20241703닷넷: 2227. 최신 C# 문법을 .NET Framework 프로젝트에 쓸 수 있을까요?
13574정성태3/6/20241573닷넷: 2226. C# - "Docker Desktop for Windows" Container 환경에서의 IPv6 DualMode 소켓
13573정성태3/5/20241579닷넷: 2225. Windbg - dumasync로 분석하는 async/await 호출
13572정성태3/4/20241667닷넷: 2224. C# - WPF의 Dispatcher Queue로 알아보는 await 호출의 hang 현상파일 다운로드1
13571정성태3/1/20241644닷넷: 2223. C# - await 호출과 WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13570정성태2/29/20241650닷넷: 2222. C# - WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13569정성태2/28/20241554닷넷: 2221. C# - LoadContext, LoadFromContext 그리고 GAC파일 다운로드1
13568정성태2/27/20241798닷넷: 2220. C# - .NET Framework 프로세스의 LoaderOptimization 설정을 확인하는 방법파일 다운로드1
13567정성태2/27/20241806오류 유형: 898. .NET Framework 3.5 이하에서 mscoree.tlb 참조 시 System.BadImageFormatException파일 다운로드1
13566정성태2/27/20241822오류 유형: 897. Windows 7 SDK 설치 시 ".NET Development" 옵션이 비활성으로 선택이 안 되는 경우
13565정성태2/23/20241686닷넷: 2219. .NET CLR2 보안 모델에서의 개별 System.Security.Permissions 제어
13564정성태2/22/20241912Windows: 259. Hyper-V Generation 1 유형의 VM을 Generation 2 유형으로 바꾸는 방법
13563정성태2/21/20241951디버깅 기술: 196. windbg - async/await 비동기인 경우 메모리 덤프 분석의 어려움
13562정성태2/21/20241975오류 유형: 896. ASP.NET - .NET Framework 기본 예제에서 System.Web에 대한 System.IO.FileNotFoundException 예외 발생
13561정성태2/20/20242048닷넷: 2218. C# - (예를 들어, Socket) 비동기 I/O에 대한 await 호출 시 CancellationToken을 이용한 취소파일 다운로드1
13560정성태2/19/20242082디버깅 기술: 195. windbg 분석 사례 - Semaphore 잠금으로 인한 Hang 현상 (닷넷)
1  [2]  3  4  5  6  7  8  9  10  11  12  13  14  15  ...