Script to send email notification when sql server stops..

Hi,
I am looking for a script through which I can monitor sql server service status and if it down for any reason, I want to send email to Dba team.  How to achieve this? Did anyone has already done similar kind of monitoring?
Again, I am not looking for any 3rd party monitoring system like SCOM etc.. I looking for a batch file or script outside sql which can solve this.
Any help would be greatly appreciated.
Thank you.

There are two ways to do it:
1). There is a job option wherein you can put the alert message and then in schedule option, select to alert you only when Sql Agent Services get restarted. So this way you will come to know when Sql Agent Services got restarted.
2). From any centralize\third server apart from your database server\host, you can put a job to execute almost around every 5 minutes to check service status and then call a batch file which will call OSQL code to execute sql code for sending alert
based on the message content you want to like below:
Scripts below, even you can tweak more on this as per your environment requirement and even you can merge some scripts to make one out of two or similar, however keeping each separate one helps to track scripts.
First Batch File with Name: ServiceStatusCheck.bat
with below content
Echo "Checking Service Status"
:Query
FOR /F "tokens=4 delims= " %%A IN ('SC QUERY "XXXXXXXXServiceNametobeCheckedPutHere" ^| FIND "STATE"') DO SET status=%%A
IF "%status%"=="STOPPED" GOTO Shootout
:Shootout
'email for success in first attempt
'Put path of batch file
"D:\Script\Successemail.bat"
Exit
Second Batch file with below content which will call Sql file to send alert: File Name: Successemail.bat
ECHO "Send Email Alert"
OSQL -E -S XXXXXXXXX -i "D:\Script\Successemail.sql"
ECHO "Done"
Exit
Third Sql File to send email: File Name: Successemail.sql
Declare @bodyT varchar(200)
Set @bodyT  =
'Service was found in stopped status and Date & Time::'
 +replace(convert(varchar(20),GETDATE(), 102),'.','/')
 +'::'
 +convert(varchar(20),GETDATE(), 108)
EXEC msdb.dbo.sp_send_dbmail
    @profile_name='Profilename',
    @recipients = '[email protected]',
    @body  = @bodyT,
    @subject = 'Service was found in stopped status, Check Details!!'
GO
Santosh Singh

Similar Messages

  • Send email notification when my question is answered by friends

    Send email notification when my question is answered by friends

    babowa wrote:
    This is not FaceBook.
    Thank goodness.....
    Could be worse. It could be Twitter

  • Send email notification when a concurrent request completes with Error

    {color:#0000ff}I need to setup the system such that when a concurrent request completes with the status "Error", generate/send email notification to an application user. Please advice if you know how to configure the system to accomplish this.
    Note: If the concurrent request completes with status "Normal" or "Warning", do not send/generate email notification to the application user.
    Thanks.
    {color}

    We do what amOx does. I made a concurrent program that calls a sql script, and emails me of errored jobs. It is more convenient than logging in each day. I ran this twice daily, and the sql checks for the previous 12 hour time slice (ie - twice a day run).
    ..colin

  • Send email notification when the baseline and actual values are different in project

    Hi
    I am working with MS Project 2013 and Project Server 2013.
    I need to the send email notification to the program manager (or to a user) whenever the project manager changes the task finish date for a task. Comparison should happen with the baseline finish and the difference needs to be updated to the Program Manager
    over mail.
    How to configure/customize email notification for changes in MPP.
    Please suggest.
    Regards,
    Sudhir

    If you are not having developer skills it will be complicated for you.
    You need to create event handler by code, as in the below link:
    http://msdn.microsoft.com/en-us/library/office/gg615466%28v=office.14%29.aspx
    Then compare your values and finally send email by code.
    Twitter : @MShoubaki | http://jo.linkedin.com/in/mshoubaki

  • Send email/notification when server shutting down?

    Is it possible to send out a notification via e-mail (or maybe even text) to all the users listed in the user accounts when the server is shutting down? We have been experiencing some severe weather here and I need to shut the server down on occasion when the power starts to gray out/black out. I would like to automatically initiate an emails alert to the users when OS X Server gets a shutdown commend. Can this be done?

    Consider acquiring and configuring a less-interruptible power supply, and configure that to communicate with OS X Server via USB; options that will work include the APC SmartUPS supplies I've tried.  (OS X Server doesn't generally "appreciate" having the power yanked, and if the grid is already greying out, it's a little late; I don't know that I'd trust the shutdown to complete.)
    If you're shutting down the system via ssh session or equivalent (and not the GUI), you could write a shell script that does what you need prior to issuing the shutdown command.
    If you're shutting down via UPS, there's a script that can be used but it's kinda far along and unlikely that mail or SMS will be read before the server is offline.

  • Send Email Notification when comment blog in Sharepoint 2010

    Hi,
    Anyone can help me, when i comment on the blog, then send email directly ?. According to this link http://www.sitefinity.com/devnet/forums/sitefinity-3-x/general-discussions/blog-comment-notification.aspx 
    Its make some development or modifications, beside that is there any other way to do that without making modifications? probably just setting up in sharepoint admin?
    Please advice,
    Regards

    Hi
    I just found out that the the blog comments are stored in a list
    htp://yoursite/Blog/Lists/Comments/AllComments.aspx
    So you can write a workflow to send an email when a new item is created in this list.

  • Need Help of Sending Email Notification when new task assigned

    Hi all,
    How can we send a email alert notification for existing lead or new lead, when a new Task is assigned to particular person. Here in my requirement daily n number of tasks assigned to executives. So how can i send the same.
    Thanks in advance.
    Regards,
    Ratan

    Hi Ratan,
    It is not clear from your question whether you are trying to trigger the email notification for the task or the lead, but it doesn't matter. You'll need to write a WF for the Lead/Task and trigger it when a new record is created and then in actions select the email notification.
    Best of luck

  • Script to send Email notification depending on return value

    When I run this I get a report of users who's accounts is about to expire, a scheduled task that run, say every week. Only problem it that this will send an email report even if there is nothing to report. What I would like is: if any return value is given
    it sends the mail. If no return value is given it dosen't send any mail. I'm trying to get an if solution where if ($bodyoutstring return value -eq true) {send mailmessage} else {do nothing} But not sure this is possible since $bodyoutsring is a
    variable? Input in this matter is appriciated.
    ###Change these according to your own setup
    $smtpServer="smtpServer.com" #mailserver
    $from = "Scheduled task, <[email protected]>" #mail from
    $Recipient = [email protected] #mail to
    # Script start - Get Users From AD who have AccountExpirationdate: 32 days left
    Import-Module ActiveDirectory
    # Email Subject Set Here
        $subject="AD Accounts is about to expire."
    #Variabel collect info and out-string it into html
    $bodyoutstring = get-aduser -filter * -Properties * |Where-Object{$_.AccountExpirationdate -ne $null}| Select-Object Name, Description, SamAccountName,@{Name='DaysTilExpiration';Expression={($_.AccountExpirationdate - (get-date)).Days}}  | Where-Object
    {$_.DaysTilExpiration -le 32} | ConvertTo-Html| Out-String
    # Send Email Message
    Send-Mailmessage -smtpServer $smtpServer -from $from -to $Recipient -subject $subject -body $bodyoutstring -bodyasHTML -priority Normal
    # End Send Message

    Hi,
    You can do something like this:
    If ($bodyoutstring) {
    Send-MailMessage ...
    This way if no results are returned no email is sent.
    EDIT: Wait, I'm wrong. Since you're piping through ConvertTo-Html, you'll always get a result... Hold please.
    EDIT2: This version checks the users first, then does the test and converts only if it needs to:
    $userList = Get-ADUser -Filter * -Properties Description,AccountExpirationDate |
    Where-Object { $_.AccountExpirationdate -ne $null }|
    Select-Object Name, Description, SamAccountName,@{Name='DaysTilExpiration';Expression={($_.AccountExpirationdate - (get-date)).Days}} |
    Where-Object {$_.DaysTilExpiration -le 32}
    If ($userList) {
    $bodyOutString = $userList | ConvertTo-Html | Out-String
    SendMailMessage ...
    I've also changed your -Properties parameter to return only the properties you need. Using * will slow your query down.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Using Alert Framework to send email notifications when Process Chain fails

    Hi Everyone,
    I've configured ALRTCATDEF in Solution Manager, selected the alerting option for Process Chains in - RSPC > Attributes > Alerting, but it looks like whenever any process chain fails, an email notification will be sent to the same recipients.
    Is there anyway to have an ALRCATDEF - alert category for different process chains, so that different recipients receive notifications for different Process Chains.
    Thanks,
    Ken

    Interesting....I was actually hoping for different recipients for different process chains.
    E.g. for our
    CRM process chain - Support Team 1
    FI process chain - Support Team 2
    and so on and so on.
    I think the only way may be creating a custom process type and implementing a class for this process type that calls function SALRT_CREATE_API. Then adding this process type to the process chain, with a different variant for each.
    However if anyone knows a way to do this in a SAP standard way using the Alert Framework, that would be great.
    Cheers,
    Ken

  • BPM Alerts not sending email notifications

    Hello Experts,
    I've successfully configured BPM within SolMan and alerts are being generated but I'm not receiving any email notifications. In the setup of Business Process Monitoring, "Contacts" have been maintained within the Solution Directory as well as the notifications section of the monitoring type with a sender and a valid recipient address . Both yellow and red alerts are being generated but no email notifications are being sent. Thresholds have also been maintained.
    Researching other threads regarding this same issue points to tcode RZ20->SAP CCMS Technical Expert Monitors ->All Monitoring Contexts->BPM->Activate Maintanance Function-> and assiging Central auto reaction methods to MTE Class BPMRoot Context and the other BPM_APPMON_* MTE classes. Is there something that I am missing in order to have these alerts send email notifications when the alert threshold is reached?
    I also defined the new Central Auto Reaction method and maintained the parameters properly which calls FM DSWP_BPM_SEND_ALERT. Please assist as I have exhausted all options. Please provide a step by step guide to setup alert notifications if possible.
    Thanks
    Mike

    These notes might help you
    [https://websmp130.sap-ag.de/sap%28bD1lbiZjPTAwMQ==%29/bc/bsp/spn/sapnotes/index2.htm?numm=543414]
    [https://websmp130.sap-ag.de/sap%28bD1lbiZjPTAwMQ==%29/bc/bsp/spn/sapnotes/index2.htm?numm=546981]
    check the timezone settings also [https://websmp130.sap-ag.de/sap%28bD1lbiZjPTAwMQ==%29/bc/bsp/spn/sapnotes/index2.htm?numm=572608]
    regards
    Naveen

  • Unable to send Email Notification for Oracle Identity Manager 11g for users

    Hi All,
    Can anyone please share a workaround to send email notifications when user is created through trusted recon in OIM 11G.Please Help Me out.
    \oim_user

    Hi
    Do you just create the user in OIM and not anywhere else?
    I have cofigured notification on the the target resources that i automatically assign to users as soon as they are created via trusted recon. Let say a user gets AD rersource. Ill notify whoever i want from there.
    Another way i did it was using the post eventHandler code. I call an email service to notify admins on the status of the recon and post recon eventhandlers. snippet below..
    tcEmailNotificationUtil emailNotificationUtil = new tcEmailNotificationUtil(dbReference);
    emailNotificationUtil.constructEmail(emailTemp);
    emailNotificationUtil.setBody(buildMailBody(message));
    emailNotificationUtil.sendEmail(toAddress);
    Let me know if this gives you an idea.

  • Is it possible to send email notifications in UCM without workflow/java?

    Is it possible to send email notifications in UCM without workflow/java?
    I need to send email notifications when an item is checked-in ,without workflow and without java code.
    Thanks,
    Chely

    Yes. You need subscriptions - see here http://docs.oracle.com/cd/E23943_01/doc.1111/e10797/c04_working_with_files.htm#CSUSG899

  • Sharepoint Server 2013 not sending Email notification

    I have a Sharepoint 2013 farm that is not sending any kind of email notifications. I also have a Sharepoint 2010 farm whit the same Outgoing Email settings and it is sending emails notifications normaly.
    The SMTP service (the role) is in the same member servers of the 2013 farm, so it is reachable. The timer service is running well in both member servers of the 2013 farm. We don't have an On-premise Exchange enviroment because we use Office 365 (I cannot
    set the sharepoint servers as allowed to relay in Exchange). The 2010 farm and the 2013 farm have the same Outgoing Email settings, I don´t know why the 2013 does not send emails. It is driving me crazy!.
    How can I solve this?
    Melvintt
    MCTS, Windows Server 2008 R2: Network Infrastructure
    MCTS, Windows Server 2008 R2: Active Directory, Configuring

    What about Relay and Authentication?
    Trevor Seward, MCC
    Follow or contact me at...
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.
    Look.
    I think this is the correct configuration because it sends emails normaly with SharePoint 2010.
    If I configure my own email account in Outbound Security, Sharepoint 2013 sends emails but just when I login to Sharepoint, if other users login it doesn't send emails.
    Melvintt
    MCTS, Windows Server 2008 R2: Network Infrastructure
    MCTS, Windows Server 2008 R2: Active Directory, Configuring

  • Configuring SMTP Email Notification on WSUS server When using Outlook 365

    We have a SMTP relay set up on a different server. I have tried to set up email notifications from WSUS server. I get the following error when trying to test. We are using Outlook 365. I've tried using ports 25 and 587 respectively. Any ides? Thanks in advance!
    System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
       at Microsoft.UpdateServices.Internal.BaseApi.SoapExceptionProcessor.DeserializeAndThrow(SoapException soapException)
       at Microsoft.UpdateServices.Internal.DatabaseAccess.AdminDataAccessProxy.SendTestEmail(String emailLanguage, String smtpUserName, String senderEmailAddress, String smtpHostName, Int32 smtpPort, String recipients)
       at Microsoft.UpdateServices.Internal.BaseApi.EmailNotificationConfiguration.SendTestEmail()
       at Microsoft.UpdateServices.UI.SnapIn.Dialogs.EmailNotificationSettingsDialog.backgroundWorker_DoWork(Object sender, DoWorkEventArgs e)

    We have a SMTP relay set up on a different server. I have tried to set up email notifications from WSUS server. I get the following error when trying to test. We are using Outlook 365. I've tried using ports 25 and 587 respectively. Any ides? Thanks in advance!
    System.Net.Mail.SmtpException: The SMTP server requires a secure connection
    You cannot email from a WSUS server direct to an O365 SMTP server, because the O365 SMTP Server *requires* a TLS-authenticated/encrypted connection and WSUS does not support TLS sessions. You'll need to have WSUS sent to an unencrypted onsite SMTP relay that
    has the ability to initiate a TLS relay connection to O365.
    Lawrence Garvin, M.S., MCSA, MCITP:EA, MCDBA
    SolarWinds Head Geek
    Microsoft MVP - Software Packaging, Deployment & Servicing (2005-2014)
    My MVP Profile: http://mvp.microsoft.com/en-us/mvp/Lawrence%20R%20Garvin-32101
    http://www.solarwinds.com/gotmicrosoft
    The views expressed on this post are mine and do not necessarily reflect the views of SolarWinds.

  • Sending Email notifications in FCS withOUT being on Server OSX

    I'd like to send email notifications from FCS but I am NOT running the Server version of Snow Leopard. Anyone know how to serve SMTP without upgrading to the server OS?
    Thanks,
    Hans
    Hans Damkoehler
    VideoBloom, Inc.
    Senior Video Editor/Producer

    All you need to do is be able to send email to an SMTP server that doesn't require authentication. You configure the SMTP address of this server from within the Basic or Advanced Administration pane of Final Cut Server.

Maybe you are looking for

  • Stored Procedure for Zero Price in GRPO

    Hi all,    Can anybody let me know the required stored procedure for restricting zero price in the GRPO transaction . Thanks in advance , Aditya

  • Isolate OMBPlus environment

    Hello, I was wondering if there was any way of isolating the OMBplus environment from the total installation package of Warehouse Builder (9.2). I'm asking this because I've written a TCL script to deploy objects from the design repository saved thro

  • Can't print to printer in list

    I'm running Mountain Lion on my MacBook Pro, and I have added my printer to the print&fax list from system settings, but when I try to print to it from an application, the printer does not show up in the list. Other printers at my school work fine. A

  • Help! Toning in bridge and once we make corrections to images it does not stay

    Good afternoon everyone - We are currently processing a wedding in CS5 and Bridge. Once my assistant tones the images it does not retain the information and reverts to a random horrid color setting. We have never seen this before - in 100 of weddings

  • Latest JDBC-ODBC-Bridge

    HI, we are using JDK1.2 and dont want to change. We are extensively using jdbc:odbc - but it seems it is not really stable. Where can I find the latest jdbc-odbc-Bridge as a separate package? Can it be used with jdk1.2? Tino