Alert Notification 설정

아래자료를 참고하여 테스트하고 작성 하였습니다.

How to Configure Command Notification in SCOM 2012 with PowerShell script.

출처: <https://blogs.technet.com/b/fesiro/archive/2012/11/26/how-to-configure-command-notification-in-scom-2012-with-powershell-script.aspx>

 

 

임의의 Alert를 생성하고 이를 Notification을 이용해 e-mail 또는 SMS, Log 를 만들고자 할 때 다음 작업을 참조 하여 구성 합니다. 가이드에서는 Log 파일에 Alert Event를 기록 하는 방법을 설명 합니다.

 

1. 응용 프로그램 이벤트 로그에 오류가 발생할 때마다 임의의 Alert를 발생하기 위한 Event 정의

1). Operations console에서 Authoring을 선택 합니다.

 

2). Authoring pane에서 Management Pack Objects > Rules를 선택 오른쪽 버튼을 클릭 Create a new rule...를 선택 합니다.

 

3). Create Rule Wizard 창이 나타납니다.

 

4). Alert Generating Rules > Event Based 를 확장하고 NT Event Log (Alert)를 선택합니다.

 

5). Select destination management pack에서 관리 팩을 리스트에서 선택 할 수 있으나 기존 관리팩을 사용 할 경우 충돌 문제가 발생 할 수 있기 때문에 New 버튼을 클릭하여 새로운 관리 팩을 만들어 사용 합니다.

 

6). Create a Management Pack 창이 활성화 됩니다. General Properties 페이지에서 Name에 임의의 이름을 입력하고, Description에는 적당 한 내용을 입력합니다. 그리고 Next 선택합니다.

 

 7). Knowledge Article 페이지에서는 아무 작업도 하지 마시고 Create 선택합니다.

 

 8). Create Rule Wizard로 돌아오면 방금 만든 관리 팩이 선택되어 있습니다. Next를 선택합니다.

 

9). General 페이지에서 Rule Name에 Application Event Log Error 입력, Description은 적당한 내용 입력, Rule Category 는 Alert을 선택 확인 합니다. Rule target에서 Select…를 클릭합니다.

 

 10). Select Item to Target 창에서 Windows Computer 를 선택하고 OK를 클릭합니다.

 

11). Rule is enabled 체크 합니다. Next 를 선택 합니다.

 

 12). Event Log Type 페이지에서 Log name에 Application 입력, Next 클릭합니다.

 

 13). Build Event Expression 페이지에서 Event ID에 Operator은 Equals로 입력하고, Value는 Alert을 발생 할 때 사용할 임의의 값을 입력 합니다(0~1000사이 임의 값). Event Source에 Operator은 Equals로 입력하고, Value는EventCreate룰 입력합니다. Next를 클릭합니다.

 

 14). Configure Alerts 페이지에서 Alert description에 아래 내용을 입력 합니다.

 

Source: $Data/EventSourceName$ Event ID: $Data/EventDisplayNumber$ Event Category: $Data/EventCategory$ User: $Data/UserName$ Computer: $Data/LoggingComputer$ Event Description: $Data/EventDescription$

 

 

15). Severity 는 Warning을 선택합니다. Alert suppression… 버튼을 클릭합니다.

 

16). Alert suppression에서 Event ID, Event Source, Logging Computer, Event Category, User, Description를 체크 합니다. OK 버튼을 클릭합니다.

 

17). Create 버튼을 클릭합니다.

 

18). Rule 리스트에서 방금 만든 Rule을 확인 합니다.

 

2. Alert Log 생성

Alert이 발생 할 때마다 Log 파일에 기록하기 위하여 아래 작업을 진행 합니다.

1). LogAlerts.sp1 스크립터 만들기

PowerShell 또는 메모장을 이용하여 아래와 같이 작성 후 .sp1 확장자로 저장 합니다.

Param ([String]$AlertName,[String]$SubscriptionID)

$Logstring = $AlertName + " " + $SubscriptionID

$Logfile = "c:\temp\LogAlerts.log"

$DateTime = Get-Date -Uformat "%y-%m-%d %H:%M:%S"

$Logstring = $DateTime + " " + $Logstring

Add-content $Logfile -value $Logstring

2) 만들어진 스크립트 파일이 정상적으로 동작하는지 bat 파일을 만들어 확인합니다.

메모장을 이용하여 아래와 같이 작성 후 run.bat 로 저장 합니다.

c:\windows\system32\windowspowershell\v1.0\powershell.exe

"c:\temp\LogAlerts.ps1" 'ALert Name' 'Subscription ID's

3). run.bat를 더블 클릭하여 실행합니다. 아래와 같이 Log 파일이 생성되고 기록 되면 정상적으로 동작하는 것입니다.

 

 

 

3. Notification 생성

Alert에 대한 Log를 파일로 기록하기 위하여 Notification를 아래와 같이 작업합니다.

1). Create Channel

(1). Administration > Notifications > Channel를 선택합니다. 가운데 목록영역에서 마우스 오른 클릭 후 New > Command… 를 클릭합니다.

 

(2). Command Notification Channel 창이 활성화 됩니다.

 

(3). Description 페이지에서 Channel name을 입력합니다. Next를 클릭합니다.

(예 : Alert Test PowerShell Command Notification Channel)

 

 (4). Settings 페이지에서 아래와 같이 입력 합니다. PowerShell 위치 및 사용 할 스크립트 파일의 파라메터 등을 지정합니다.

분류 입력내용

Full path of the command file

c:\windows\system32\windowspowershell\v1.0\powershell.exe

Command line parameters

"c:\temp\LogAlerts.ps1" '$Data/Context/DataItem/AlertName$'

'$MPElement$'

Startup folder for the command line

c:\windows\system32\windowspowershell\v1.0\

 

(5). Finish 버튼을 클릭합니다. Channel saved successfully 를 확인하고 Close 버튼을 클릭합니다.

 

(6). 생성된 Channel을 목록에서 확인 합니다.

 

2). Create Subscribers

(1). Administration > Notifications > Subscribers 를 선택합니다. 가운데 목록영역에서 마우스 오른 클릭 후 New 를 클릭합니다.

 

(2). Notification Subscriber Wizard, Description 페이지에서 Subscriber Name에 적당한 이름을 입력합니다. (예 : Alert Test PowerShell Command Line Subscriber) Next를 클릭합니다.

 

(3). Schedule 페이지에서 Always send notifications 선택을 확인 하고, Next 버튼 클릭합니다.

 

(4). Addresses 페이지에서 Subscriber address에 Add… 클릭하여 추가합니다.

 

(5). Subscriber Address 창이 활성화 됩니다. General 페이지에서 Address name을 입력 합니다. Next 버튼을 클릭합니다. (예 : Alert Test PowerShell Command Address)

 

(6). Channel 페이지에서 Channel Type 을 Command로 선택합니다.

 

(7). Channel페이지에서 Command Channel은 앞에서 만들어둔 Channel를 선택합니다. Next 버튼을 클릭합니다. (예 : Alert Test PowerShell Command Notification Channel)

 

(8). Schedule 페이지에서 Always send notifications 성택을 확인 하고 Finish 버튼을 클릭합니다.

 

(9). Notification Subscriber Wizard로 돌아 오면 Subscriber address에 방금 만든 Address를 확인 할 수 있습니다. Finish 버튼을 클릭합니다.

 

(10). Subscriber saved successfully 를 확인하고 Close 버튼을 클릭합니다.

 

(11). 생성된 Subscriber 를 목록에서 확인 합니다.

 

3). Create Subscription

(1). Administration > Notifications > Subscription 를 선택합니다. 가운데 목록영역에서 마우스 오른 클릭 후 New 를클릭합니다.

 

(2). Notification Subscription Wizard 가 활성화 됩니다. Description 페이지에서 Subscription name를 입력합니다(예 : Alert Test Powershell Command Line Subscription). Next 버튼을 클릭합니다.

 

(3). Criteria 페이지 에서는 Notify on all alerts 확인 후 Next 버튼을 클릭합니다.

 

(4). Subscribers 페이지에서 Selected subscribers 추가를 위해 Add… 클릭합니다.

 

(5). Subscriber Search 창이 나타나면 Filter by에 powershell 입력하고 Search 버튼을 클릭한다. Available subscribers에 확인된 subscriber를 선택하고 Add 버튼을 클릭해서 Selected subscribers 에 추가합니다. OK 버튼을 클릭합니다.

 

(6). Notification Subscription Wizard로 돌아오며, Selected subscribers 리스트에 추가 된 것을 확인 할 수 있습니다. Next 버튼을 클릭합니다.

 

(7). Channels 페이지에서 Channels 에 Add… 클릭합니다.

 

(8). Channel Search 창이 화성화 됩니다. Filter by에 powershell 를 입력하고 Search 버튼을 클릭합니다. Available channels에 확인된 channel를 선택하고 Add 버튼을 클릭해서 Selected channels 에 추가합니다. OK 버튼을 클릭합니다.

 

(9). Notification Subscription Wizard로 돌아오며, Channels 리스트에 추가 된 것을 확인 할 수 있습니다. Next 버튼을클릭합니다.

 

(10). 설정 내용을 혹안하고, Enable the notification subscription 체크하고 Finish 버튼을 클릭합니다.

 

(11). Subscription saved successfully를 확인 후 Close 버튼을 클릭합니다.

 

(12). 생성된 Subscriptions를 목록에서 확인 합니다.

 

 4. Alert 생성 및 확인

CMD를 이용해 지금까지 만든 이벤트를 생성해보고 Log 파일에 기록이 잘 되고, OM Console > Active Alert에도 정상적으로 나타나는지 확인 합니다.

1). CMD.exe 를 실행 합니다.

2). LogAlert.sp1. 파일이 있는 곳으로 이동 합니다.

3). 아래와 같이 입력 합니다.

C:\Temp>eventcreate /t error /id 100 /l application /d "Alert Test"

여기에서 /id 에는 앞에서 임의로 만든 Event ID 를 입력 합니다.

4). 입력 후 실행 하면 아래 와 같이 SUCCESS 메시지가 나타납니다.

 

5) SCOM Console 의 Active Alert 에 Event가 발생 된다.

 

6). Log 파일에도 아래와 같이 기록 되는 것을 확인 할 수 있습니다.