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 sc...

Slowloris POC and breaking down

I will go very basic from step by step. As you are already known, Slowloris is a hacking tool that sends http request slowly to web server like Apache which shall get down the resource that should be available to serve for more connection. I think you guy are used a lot of tool those are created base on the slow HTTP request's theory. But do you really understand what Slowloris and like-Slowloris tools is working? What is HTTP request's detail that browser send to web server? And how the tools send slowly Header HTTP request to web server? I always keep in my mind, tool is not your skill. It is really difference. Use tool only without understanding principle of how it works, you just a scripting kid. Nothing more! That why today i will do a Proof Of Concept (POC) using Python, just to dig into it to understand principle of slow HTTP request. At first of all, let's talk about environment. For anything you haven't done it before, we will need an environment to...