从安之源动环系统中提取数据发送邮件

这篇文章原文发布在”运维日志”博客于 2019年05月06日

针对动环系统暂时发不出报警短信的问题,写程序提取动环系统中我们当前主要关心的机房温度传感值,并每天定时发送EMail到工作人员邮箱。

基本流程如下图。

 

具体的实现:

  1. 分析动环系统中当前采集的值在什么地方存储。

通过对上述几张表进行分析,得出:

系统每天生成一张以日期命名的日志表,表中最新的一条记录就是当前的环境参数值(前提是动环系统本身的采集功能正常!)。

这样,就能使用查询语句查询出机房温度传感器的当前值了。

测试查询语句如下图:

可以看出当前最后一条记录是23:48分的,传感值为18.90。

 

  1. 邮件如何发送。

使用.Net编写程序。

上网找到一个商用的邮件发送库,而且对多种语言都支持,参考文档很详细。

下载试用版进行测试。

https://www.emailarchitect.net/easendmail/kb/vbnet.aspx?cat=0

该链接提供了详细的说明。

基本程序如下:

Imports EASendMail ‘ Add EASendMail namespace
Module Module1
Sub Main()
Dim oMail As New SmtpMail(”TryIt”)
Dim oSmtp As New SmtpClient()
‘ Set sender email address, please change it to yours
oMail.From = “[email protected]”
‘ Set recipient email address, please change it to yours
oMail.To = “[email protected]”
‘ Set email subject
oMail.Subject = “test email from VB.NET project”
‘ Set email body
oMail.TextBody = “this is a test email sent from VB.NET project, do not reply”
‘ Your SMTP server address
Dim oServer As New SmtpServer(”smtp.emailarchitect.net”)
‘ User and password for ESMTP authentication, if your server doesn’t require
‘ User authentication, please remove the following codes.
oServer.User = “[email protected]”
oServer.Password = “testpassword”
‘ If your smtp server requires SSL connection, please add this line
‘ oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
Try
Console.WriteLine(”start to send email …”)
oSmtp.SendMail(oServer, oMail)
Console.WriteLine(”email was sent successfully!”)
Catch ep As Exception
Console.WriteLine(”failed to send email with the following error:”)
Console.WriteLine(ep.Message)
End Try
End Sub
End Module

测试没问题,就开始下一步。

  1. 编写控制台程序(不用界面,只要能采集并发送邮件即可),实现功能。


程序存放在动环系统服务器的E盘。

QQ截图20201215224348.png

  1. 使用Windows定时任务,让程序每天定时执行。

控制面板—管理工具—计划任务程序。

注意:这个程序只采集温度参数。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章