SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Sending email on perfmon alert


Sending email on perfmon alert

Author
Message
bendhill
bendhill
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 57
Hi,

I would like to use perfmon counter alerts to trigger an email to let developement DBAs know when their machine is running out of memory.

I got an idea from this article: http://www.db-staff.com/index.php/microsoft-sql-server/89-sql-server-monitoring-tool

I have set up an alert and created a small batch file that generates an email:

set mailbody=%1
set mailbody=%mailbody:~1,-1%
sqlcmd -S MyMachine -E -Q "declare @subject sysname; set @subject = 'Performance alert on ' + @@SERVERNAME; EXEC msdb.dbo.sp_send_dbmail @recipients='MyEmail',@subject = @subject , @body = '%mailbody%', @body_format = 'TEXT' ;"



This sends an email using sqlcmd to run a SQL stored procedure. It works when I run it.
When Perfmon tries to run the batch file I see the following error in the event log:

Unable to execute command '' for the MyFirstAlert alert. The alert will continue as scheduled. The error code returned is in the data.

I think I must be doing something wrong with the command line arguments (How exactly do I pass them into the batch file?) or perhaps a permissions issue (I've allowed read and excute to everyone on the .bat. Also allowed cmd.exe to [BATCH].

Thanks in advance.

Ben.
sqlbuddy123
sqlbuddy123
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2334 Visits: 2243
Hi

Try this. It worked for me everytime.

http://www.sqlservercentral.com/articles/Administration/smtpsqlserverperformancealerts/2005/

Thank You,

Best regards,
SQLBuddy
Hawkeye_DBA
Hawkeye_DBA
Old Hand
Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)Old Hand (374 reputation)

Group: General Forum Members
Points: 374 Visits: 566
Depending on the version of SQL Server you could have your DBAs configure an Alert on their server to send them an email. You have to have a mail profile set up on the database server first, then you can go to the SQL Server Agent tree in SQL Management Studio > Alert and create a new alert.

Use the Alert type of SQL Performance Condition or WMI event alert and specify the counter info.

Here's a link to show you how this is done for SQL Server 2008, it is very similiar in 2005: http://msdn.microsoft.com/en-us/library/ms187827.aspx

Great job getting alerts on performance no matter how you do it that's very proactive!

Cheers -

Hawkeye DBA
bendhill
bendhill
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 57
Thanks SQLBuddy,

It's a very similar method. I can get the script to run fine. But when I ask Perfmon to run it I get the same error!

Unable to execute command '' for the MyFirstAlert alert. The alert will continue as scheduled. The error code returned is in the data.

Do you change any permissions when you set this up?

Thanks,
Ben.
bendhill
bendhill
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 57
bendhill (7/19/2010)
Thanks SQLBuddy,

It's a very similar method. I can get the script to run fine. But when I ask Perfmon to run it I get the same error!

Unable to execute command '' for the MyFirstAlert alert. The alert will continue as scheduled. The error code returned is in the data.

Do you change any permissions when you set this up?

Thanks,
Ben.


Doh. Just had to change the "Run as" property on the general tab!
bendhill
bendhill
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 57
Thanks Hawkeye DBA. Maybe one day I will find the time to learn enough WMI script to use this method! Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search