Home Database Mysql Tutorial 6. SQL Server数据库监控

6. SQL Server数据库监控

Jun 07, 2016 pm 04:48 PM
Alarm database monitor Short message mail

常用的告警方式大致有:短信、邮件、应用程序(beep提示,图标提示,升窗提示等),可是不能一直坐在电脑前看着应用程序,或者用脚本部署监控,根本没有程序界面,

常用的告警方式大致有:短信、邮件、应用程序 (beep提示,图标提示,升窗提示等),可是不能一直坐在电脑前看着应用程序,或者用脚本部署监控,根本没有程序界面,所以通常用短信、邮件两种方式告警。

一. 告警方式

1. 短信

用程序发短信的方式一般有这两种:

(1) 硬件

需要1张SIM卡,1个SIM卡读卡设备 (比如:短信猫),然后把设备连接到电脑,应用程序根据设备的软件接口,传参并发送短信。记得把SIM卡设备放在信号好,无干扰的地方;

如果有大量短信要发,1张SIM卡是不够用的,而且发送过度频繁,可能被运营商视为恶意短信,把SIM卡号加入黑名单,那么就需要多张SIM卡甚至多个读卡设备。

显示号码为当前SIM卡号码,大多供应商都支持DLL、HTTP等多种接口,当然也可以基于接口二次开发。

DLL接口方法参考:SmsManager.sendTextMessage(…)

 

(2) 第三方短信接口

有多种接口形式提供,比如:Web Service形式,HTTP形式,还有邮件接口:往1380013900@xxx.com发个短小的邮件,这个邮件会以短信的形式转发到手机上,等等。只要往接口传参数,告诉它发给谁,发什么内容,就可以了。

显示号码为某个SIM卡号码,或者为固定号码 (如:106开头的),这取决于短信平台和运营商的实现方式,因为运营商发短信是不要卡的,直接可以发给目标号码,而且可以显示为固定的某个号码。

Web Service接口地址参考:?wsdl

Http接口地址参考:

 

2. 邮件

凡是实现了SMTP协议的组件,都可以发送邮件。

在Windows环境下,有系统自带的组件CDO (Collaboration Data Objects,以前叫OLE Messaging 或者Active Messaging),是MAPI库的COM封装。不管是自己开发程序,使用VBS,还是SQL Server的SQL Mail/Database Mail,通常都是调用的这个组件。

SMTP协议要求的参数大致如下:

SMTP Hostname: SMTP服务器名,如mail.test.com或者IP

SMTP Port: SMTP服务端口,25

SMTP Username: 通过SMTP发送邮件用来验证的用户名, 如果不要求身份验证,留空

SMTP Password: 通过SMTP发送邮件用来验证的密码, 如果不要求身份验证,留空

 

二. 选择告警方式并配置

1. 短信

不管是选择硬件,还是第三方接口,都需要一个程序来调用,可以是监控工具、脚本、甚至数据库。

(1)  监控工具/应用程序中,通常都留有短信接口的配置,配置接口地址即可;

(2) 在脚本中配置,Windows环境通常要借助OLE Automation;

OLE Automation后来改名叫Automation,是Windows上基于COM,用于脚本语言实现进程间通讯的机制,脚本如:VBS, SQL, Powershell,不包括BAT(BAT可以调用VBS)。

SQL Server中使用OLE Automation调用Web Service短信接口如下:

exec sp_configure'show advanced options', 1; RECONFIGURE; exec sp_configure'Ole Automation Procedures', 1; RECONFIGURE;   declare @text_message nvarchar(180)        ,@phone_numbernvarchar(15)        ,@soap_object  int        ,@status       int        ,@output       nvarchar(255)   set @text_message = N'Testing Mail' set @phone_number = N'138000139000'   --Create MSSOAP.SoapClient object exec @status=sp_OACreate'MSSOAP.SoapClient',@soap_object out   --SmsManager is Web Service name exec @status =sp_OAMethod@object, 'mssoapinit', null, 'http://123.456.789.000/SmsManager.asmx?wsdl', 'SmsManager'   --SendTextMessage is webservice method exec @status =sp_OAMethod@object, 'SendTextMessage', @output OUT, @phone_number,@text_message   if @status 0 begin    exec sp_OAGetErrorInfo@soap_object       select@soap_object end else begin    select@output end   --Destroy MSSOAP.SoapClient object exec @status =sp_OADestroy@soap_object GO

对于HTTP, DLL接口,和SOAP接口类似,用OLE Automation也都可以调用,主要区别就是在CreateObject() 时。

以VBS为例,调用HTTP, DLL时CreateObject()如下:

Dim http Set http =CreateObject("Msxml2.XMLHTTP")   Dim dll Set dll = CreateObject("工程名.类名")

 

2. 邮件

(1)  监控工具/应用程序中,通常都留有SMTP配置项,配置SMTP参数即可;

(2) 在脚本中配置,Windows环境通常要借助OLE Automation;

VBS发送邮件如下:

Dim ns ns ="http://schemas.microsoft.com/cdo/configuration/"   Dim title, content title = "db_maint_alert" content = "" content = content&"Hi All," content = content&chr(13)&chr(10) content = content&" " content = content&chr(13)&chr(10) content = content&"----testmail----" Msgbox('~1~')   Set cm =CreateObject("CDO.Message") cm.from ="from_user_name@abc.com" cm.to = "to_user_name@abc.com" cm.cc = "cc_user_name@abc.com" cm.subject = title cm.textbody = content 'cm.AddAttachment "" Msgbox('~2~')   'sendusing: 1 = pickup, 2 = port 'smtpauthenticate: 0 = anonymous,1 =common,2 = NTLM 'smtpusessl: 0 = no,1 = yes With cm.configuration.fields          .item(ns& "sendusing") = 2          .item(ns& "smtpserver") = "xxx.xxx.xxx.xxx"          .item(ns& "smtpserverport") = 25          .item(ns& "smtpauthenticate") = 1          .item(ns& "sendusername") = "user_name@abc.com"          .item(ns& "sendpassword") = "*****************"          .item(ns& "smtpconnectiontimeout") = 10          .item(ns& "smtpusessl") = 0          .update End With Msgbox('~3~')   cm.send Set cm = nothing Msgbox('~success~')


SQL Server 2000发送邮件如下:

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Apple's iOS 18 mail app gets AI wings: enhanced search, smart writing/reply, classification and summarization, etc. Apple's iOS 18 mail app gets AI wings: enhanced search, smart writing/reply, classification and summarization, etc. Jun 11, 2024 pm 09:34 PM

According to news on June 7, technology media AppleInsider published a blog post yesterday, revealing that Apple is developing Project BlackPearl internally, which mainly enhances the email application in iOS18 and macOS15 systems, allowing AI to help users compose and reply to emails. The relevant content is summarized as follows: Enhanced Search Project BlackPearl first enhances email search results, which will display more information from address books, locations and locally stored documents. Smart Replies In addition, the new "Smart Replies" function in the email application will provide appropriate reply content based on the locally running large language model (LLM) Ajax and combined with the context of the email. compose mail

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

Tips and practices for handling Chinese garbled characters in databases with PHP Tips and practices for handling Chinese garbled characters in databases with PHP Mar 27, 2024 pm 05:21 PM

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.

See all articles