Skip to main content

Check MSSQL data and send email alert through Gmail

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:
-------------------------------------------------------------------------------------------------------------------------
@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

Popular posts from this blog

Install Python and SqlMap on Windows 7

Download and install python Since sqlmap is written in python, the first thing you need is the python interpreter. Download the python interpreter from  python.org . Download and install Python version 2.7.x.  Sqlmap have to run with version 2.7.x on Windows 7 (tested). At last you need to append some strings like C:\Python to PATH variable in Environment Variables Setting follow these steps below: 1. Open the Start Menu and right click on Computer. Select Properties. 2. Select Advanced system settings. 3. In the Advanced tab, select Environment Variables 4. Edit PATH variable, append path to your Python installation folder (ex: C:\Python27) 5. Just save it and open cmd and type python, if it works it will show you the screen like this: Download and install sqlmap Next download the sqlmap zip file from  sqlmap.org . Extract the zip files in any directory. Launch the dos prompt and navigate to the directory of sqlmap. Now run the sqlmap.py script with the

SQL Injection

  I got an sql injection tutorial, it's quite useful for you guy want to know about it. So if you are interested with SQL Injection ( a part of hacking and penetration ) just take a look below. SQL Injection Tutorial created by ande for www.evilzone.org In this tutorial 1.0 What is SQL? 1.1 Types of SQL or SQL engines 1.2 Understanding the SQL structure 1.3 Finding vulnerabilities 1.4 Exploiting vulnerabilities 1.5 Securing vulnerabilities 1.0 What is SQL? SQL stands for Structured Query Language. It is a way to store, modify and update data secure, fast and reliable. SQL is mostly used for web sites but can however be used for almost any application and or service which is in need of storing, editing and or updating data in a good and structured way. In this tutorial I will be using PHP as script language for examples. PHP is a web script engine. Its the most widely used one, its the best one and its the one you are most likely to encounter in real life s