Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

13
Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba www.shellyourexperience.wordpress.com http://www.simple-talk.com/author/laerte-juni or / http://sqlpsx.codeplex.com /

Transcript of Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

Page 1: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

Hey PowerShell Eventing, Can You Notify Me ?

Laerte Junior @laertesqldbawww.shellyourexperience.wordpress.com

http://www.simple-talk.com/author/laerte-junior/http://sqlpsx.codeplex.com/

Page 2: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

Brazil

Page 3: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

My Skills

• I Know a Bit of PowerShell (3 years)

• I DO like to play with SQL Server (12 years)

• BETTER COFFE MAKER FROM BRAZIL (30 years)

Page 4: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

Notification System

• Your Bank send a SMS about a transaction

• Your car warning you when something wrong happens

• Your body alerts you when something is not right

Page 5: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

DARKNESS

Page 6: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

WMI

• WMI is an acronym for Windows Management Instrumentation– Registry, File and Disk systems, Services and

processes, Printers ,Networking, IIS, Performance Counters

• WMI Provider For Server Events– The WMI Provider for Server Events lets you

use the Windows Management Instrumentation (WMI) to monitor events in SQL Server.

Page 7: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

Windows Management Instrumentation Query Language

• SQL ANSI with WMI-Specific Extensions• SELECT { event_property [ ,...n ] | * } FROM event_type WHERE where_condition

EVENT QUERY LANGUAGE

SELECT <Propertie-List> FROM <Event-Class Name> <WITHIN Seconds> WHERE <Instace-State> ISA '<Wmi-Class Name>'

"select * from __InstanceModificationEvent within 5 where TargetInstance ISA 'Win32_Service' and TargetInstance.Name='MSSQLSERVER' and TargetInstance.State='Stopped‘”

Page 8: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

THE BEAUTY OF WQL

• WQL for WMI/WMI SQL

• WQL For Event Query

Page 9: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

DEMO

Page 10: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

WMI/WQL – EVENT QUERY• Show a Balloon tip (SQL Server Stops)• Alert CPU Threshold • Alert SQL Server Process CPU Threshold • Alert Free Disk Space

WMI/WQL – Server Events• Monitoring Database Mirroring• Monitoring Database Suspect Pages• Mointoring Database Options (eventlog)

Page 11: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

What is The Ideia ?

Monitoring Server

Server 1

Server 2

Register The Event

Write in EventLog

Trigger The Event

Trigger The Event

Register The Event

Write in EventLog

Send Email

Trigger The Event

Page 12: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba
Page 13: Hey PowerShell Eventing, Can You Notify Me ? Laerte Junior @laertesqldba

Coming up…

#SQLBITS

Speaker Title Room

Stephan Stoltze Writeback-Here Comes the Sun Aintree

James Boother POSH Clustering Lancaster

Kasper de Jonge Building Great Models for Crescent Pearce

Andy Leonard Designing an SSIS Framework Boardroom

Milos Radivojevic TSQL Performance Recommendations Empire

Christina E. Leo Working with Server Side Traces Derby