Today, I got a task about checking data in MSSQL and send alert email if there is something wrong with it. Of course you can do it with nagios plugin but i just don't want to implement with nagios. No why :) This what i did to finish this little task.
-------------------------------------------------------------------------------------------------------------------------
A Batch script:
-------------------------------------------------------------------------------------------------------------------------
A SQL script:
-------------------------------------------------------------------------------------------------------------------------
2 VBS scripts to send mail through gmail server, i just give you 1 because it is the same, just differ about content to send
-------------------------------------------------------------------------------------------------------------------------
OK done, not much. Hope this will help someone to release the brain for other harder task.
Regards,
-------------------------------------------------------------------------------------------------------------------------
A Batch script:
-------------------------------------------------------------------------------------------------------------------------
@echo off
@setlocal enableextensions enabledelayedexpansion
del result.txt
cd C:\Program Files\Microsoft SQL Server\100\Tools\Binn
SQLCMD.EXE -U username -P password -S ipaddress -i D:\Scripts\check_match_active.sql -o result.txt
findstr /m "1 rows affected" result.txt
if %errorlevel%==0 (
cscript "sendemail_ok.vbs"
) else (
cscript "sendemail_fail.vbs"
)
-------------------------------------------------------------------------------------------------------------------------
A SQL script:
-------------------------------------------------------------------------------------------------------------------------
use Databasename:-------------------------------------------------------------------------------------------------------------------------
select count(*) from Match where cast(PlayDate as date)=CAST(GETDATE() AS DATE) and StatusID=1;
2 VBS scripts to send mail through gmail server, i just give you 1 because it is the same, just differ about content to send
-------------------------------------------------------------------------------------------------------------------------
Dim emailObj, emailConfig
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "alert@gmail.com"
emailObj.To = "me@domain"
emailObj.Subject = "Put your Subject"
emailObj.TextBody = "Put your content"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
emailConfig.Fields.Update
emailObj.Send
Set emailObj = nothing
Set emailConfig = nothing
OK done, not much. Hope this will help someone to release the brain for other harder task.
Regards,
Comments
Post a Comment