trying to send alert in application log

  • alen teplitsky

    SSC-Dedicated

    Points: 30014

    looking to catch the dreaded 14151 errors on replication and below code is not sending an alert.

    in production i'm obviously going to change the -eq to -gt 1. and increase the timeout a bit

    $date = get-date

    wait-event -timeout 30

    $result = (get-eventlog -logname application -after $date -source mssqlserver | where-object { $_.eventid -eq 14151 }).count

    if ($result -eq 0)

    {send-mailmessage -to "dba@domain.com","1111111111@txt.att.net","1111111111@messaging.sprintpcs.com","1111111112@messaging.sprintpcs.com" -from "dba@domain.com" -subject "Check SQLREPL" -body "Errors on SQLREPL" -smtpserver smtp.domain.com}

  • Keith Langmead

    Ten Centuries

    Points: 1018

    Well to me at least the send-mailmessage statement looks fine. Have you checked that from that server you are able to send e-mail via that smtp server without logging in or anything?

    Easiest way to check is to send a mail via a telnet connection, which should then give you a like for like setup. If you don't know how to do it there's a good guide here http://www.yuki-onna.co.uk/email/smtp.html

  • alen teplitsky

    SSC-Dedicated

    Points: 30014

    got it figured out with help from the MSDN forums

    if there are no events it's not a 0, but a null or some other kind of value. i've had this running where the conditions are gt 0 and it works pretty good

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply