這篇文章原文發佈在”運維日誌”博客於 2019年05月06日
針對動環系統暫時發不出報警短信的問題,寫程序提取動環系統中我們當前主要關心的機房溫度傳感值,並每天定時發送EMail到工作人員郵箱。
基本流程如下圖。
具體的實現:
- 分析動環系統中當前採集的值在什麼地方存儲。
通過對上述幾張表進行分析,得出:
系統每天生成一張以日期命名的日誌表,表中最新的一條記錄就是當前的環境參數值(前提是動環系統本身的採集功能正常!)。
這樣,就能使用查詢語句查詢出機房溫度傳感器的當前值了。
測試查詢語句如下圖:
可以看出當前最後一條記錄是23:48分的,傳感值爲18.90。
- 郵件如何發送。
使用.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
測試沒問題,就開始下一步。
- 編寫控制檯程序(不用界面,只要能採集併發送郵件即可),實現功能。
程序存放在動環系統服務器的E盤。
- 使用Windows定時任務,讓程序每天定時執行。
控制面板—管理工具—計劃任務程序。
注意:這個程序只採集溫度參數。