当特定服务的特定严重性事件触发Windows服务器事件日志时,是否有一种简单的方法来发送电子邮件? 这是在Windows Server 2003上,如果它有所作为。
NB我们在工作场所对生产服务器有适当的监控和警报,但是我们只是需要快速的解决scheme来开发这个服务。
你可以用OSSEC这个多平台的开源软件来做到这一点:
OSSEC是一个完整的平台来监视和控制你的系统。 它将HIDS(基于主机的入侵检测),日志监控和SIM / SIEM的所有方面组合在一起,形成一个简单,强大且开源的解决scheme。
对于日志监视/警报:
实时和可configuration的警报
OSSEC允许客户configuration要提醒的事件,让他们专注于提高任何系统上的常规噪声的关键事件的优先级。 通过与smtp,sms和syslog集成,客户可以通过将这些信息发送到电子邮件和手持设备(如手机和传呼机)来提醒用户。
[…]
networking上的每个操作系统,应用程序和设备都会生成日志(事件),以便让您知道发生了什么事情。 OSSEC收集,分析和关联这些日志,让您知道是否有错误发生(攻击,误用,错误等)。
这里有一篇关于OSSEC 360°安全的文章 。
专门的商业替代scheme: EventTracker (Prism Microssystems):
EventTracker是一个完整的安全信息和事件pipe理(SIEM)解决scheme,它将实时日志pipe理与function强大的configuration和变更pipe理结合在一个交钥匙软件包中。
这里有另外一个从我这里用另外几个脚本拼凑的VBScript创build。
Option Explicit ' Main Dim objShell, objWMIService, objEventSink, dictEventsToMonitor, eventToMonitor ' =====================( Configuration )===================== ' Set to 0 to disable event log reporting of bans / unbans Const USE_EVENTLOG = 1 Const EVENTLOG_SOURCE = "SimpleEventMonitor" ' SMTP configuration Const EMAIL_SENDER = "[email protected]" Const EMAIL_RECIPIENT = "[email protected]" Const EMAIL_SMTP_SERVER = "smtp-server" Const EMAIL_SMTP_PORT = 25 Const EMAIL_TIMEOUT = 20 Set dictEventsToMonitor = CreateObject("Scripting.Dictionary") ' Define events that should be monitored. Matches are based on exact matches of all non-NULL fields ' Monitor our own startup and alert based on starting PushEventToMonitor "100", "Application", EVENTLOG_SOURCE, NULL, NULL, NULL, NULL PushEventToMonitor "7036", "System", "Service Control Manager", NULL, NULL, NULL, "Telnet service.*(running|stopped).*state" ' ===================( End Configuration )=================== Set objShell = CreateObject("WScript.Shell") ' Create event sink to catchevents Set objWMIService = GetObject("winmgmts:{(security)}!root/cimv2") Set objEventSink = WScript.CreateObject("WbemScripting.SWbemSink", "eventSink_") objWMIService.ExecNotificationQueryAsync objEventSink, "SELECT * FROM __InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent'" ' Loop sleeping for one week, logging an event each week to say we're still alive While (True) LogEvent 100, "INFORMATION", "Simple Event Log Monitor started" WScript.Sleep(7 * 24 * 60 * 60 * 1000) Wend ' Fires each time new events are generated Sub eventSink_OnObjectReady(objEvent, objWbemAsyncContext) Dim evt, field, boolAlert, regexpMessage For Each evt In dictEventsToMonitor.Keys boolAlert = True For Each field In dictEventsToMonitor.Item(evt).Keys If UCase(Field) = "MESSAGE" Then Set regexpMessage = new Regexp regexpMessage.Pattern = dictEventsToMonitor.Item(evt).Item(Field) regexpMessage.IgnoreCase = True If NOT regexpMessage.Test(objEvent.TargetInstance.Properties_(Field)) then boolAlert = False Else If UCase(objEvent.TargetInstance.Properties_(Field)) <> UCase(dictEventsToMonitor.Item(evt).Item(field)) Then boolAlert = False End If Next ' field if boolAlert = True Then SendMessage "Simple Event Log Monitor notification from " & objEvent.TargetInstance.ComputerName, _ "Event ID: " & objEvent.TargetInstance.EventCode & VbCrLf _ & "Date/Time: " & Mid(objEvent.TargetInstance.TimeGenerated, 5, 2) & "/" & Mid(objEvent.TargetInstance.TimeGenerated, 7, 2) & "/" & Mid(objEvent.TargetInstance.TimeGenerated, 1, 4) & " " & Mid(objEvent.TargetInstance.TimeGenerated, 9, 2) & ":" & Mid(objEvent.TargetInstance.TimeGenerated, 11, 2) & ":" & Mid(objEvent.TargetInstance.TimeGenerated, 13, 2) & VbCrLf _ & "Computer: " & objEvent.TargetInstance.ComputerName & vbCrLf _ & "Event Log: " & objEvent.TargetInstance.LogFile & vbCrLf _ & "Event Source: " & objEvent.TargetInstance.SourceName & vbCrLf _ & "Event Category: " & objEvent.TargetInstance.CategoryString & vbCrLf _ & "Event Type: " & objEvent.TargetInstance.Type & vbCrLf _ & "User Name: " & objEvent.TargetInstance.User & vbCrLf _ & "Message:" & vbCrLf & vbCrLF _ & objEvent.TargetInstance.Message Exit Sub End If Next ' evt End Sub Sub LogEvent(ID, EventType, Message) ' Log an event to the Windows event log If USE_EVENTLOG Then objShell.Exec "EVENTCREATE /L APPLICATION /SO " & EVENTLOG_SOURCE & " /ID " & ID & " /T " & EventType & " /D """ & Message & """" End Sub Sub SendMessage(strSubject, strBody) Dim objCDOMessage Set objCDOMessage = CreateObject("CDO.Message") objCDOMessage.From = EMAIL_SENDER objCDOMessage.To = EMAIL_RECIPIENT objCDOMessage.Subject = strSubject objCDOMessage.Textbody = strBody objCDOMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = EMAIL_SMTP_SERVER objCDOMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = EMAIL_SMTP_PORT objCDOMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = EMAIL_TIMEOUT objCDOMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objCDOMessage.Configuration.Fields.Update objCDOMessage.send End Sub Sub PushEventToMonitor(strID, strLog, strSource, strCategory, strType, strUser, strMessagePattern) Dim x x = dictEventsToMonitor.Count Set dictEventsToMonitor.Item(x) = CreateObject("Scripting.Dictionary") If NOT IsNull(strID) Then dictEventsToMonitor.Item(x).Add "EventCode", strID If NOT IsNull(strLog) Then dictEventsToMonitor.Item(x).Add "LogFile", strLog If NOT IsNull(strSource) Then dictEventsToMonitor.Item(x).Add "SourceName", strSource If NOT IsNull(strCategory) Then dictEventsToMonitor.Item(x).Add "CategoryString", strCategory If NOT IsNull(strType) Then dictEventsToMonitor.Item(x).Add "Type", strType If NOT IsNull(strType) Then dictEventsToMonitor.Item(x).Add "User", strUser If NOT IsNull(strMessagePattern) Then dictEventsToMonitor.Item(x).Add "Message", strMessagePattern End Sub
如果您使用类似Non-Sucking Service Manager或SRVANY来安装它,则可以将其作为Windows服务运行。 使用NSSM,comamnd行将是:
nssm install SimpleEventLogMonitor %SystemRoot%\System32\cscript.exe "\"Pull_path_and_filename_of_script\""
请务必replace您的电子邮件收件人,发件人和SMTP服务器名称。
您使用“PushEventToMonitor”调用来定义要提醒的事件。 这些参数是:事件ID,事件日志名称,源,类别,types,用户以及可以与日志消息匹配的正则expression式。 我在那里有一个与TELNET服务的启动/停止相匹配的例子,以及与脚本本身的启动(将事件logging到应用程序日志)相匹配的例子。
这是第一份草案,因为我为客户写的实际上是“正在生产”的那个是写在他们的硬币上的,属于他们的。 因此,我已经重新编码了这个(实际上与客户所使用的实际上是完全不同的),并且可能有潜伏的愚蠢的错误。 我今天晚上在我的一些系统上运行了一段时间,我没有看到问题。
也许我最终会做得更好一点。 如果将其configuration从registry中删除(因此可以使用组策略进行控制),并将其打包为MSI,以便轻松部署到服务器组,则会很好。 好吧。
你可以用Windows任务来做到这一点
看到这里http://www.vistax64.com/tutorials/67961-event-viewer-email-notification.html
活着的服务器可以为你做这个。 该产品是免费的最多10个事件来监测。
NT事件日志监视器是一个在这里免费插件。 非常容易使用和设置。
GFI的集中式事件日志pipe理工具( GFI EventsManager )可以做到这一点,虽然不是FOSS。
实时警报,SNMPv2陷阱警报包括
GFI EventsManager™的最新版本已经提高了在networking上检测到的关键事件或入侵的警报级别。 GFI EventsManager允许您触发诸如脚本之类的操作,或者通过电子邮件,networking消息,通过电子邮件发送到SMS网关或服务发送的SMS通知向一个或多个人发送警报,并且现在包括SNMPv2陷阱。 SNMP警报的生成还将允许pipe理员将GFI EventsManager与预先存在的或通用的监视机制进行集成。
有关基于自定义事件filter发送电子邮件的方法,请参阅https://serverfault.com/a/517457/75770
在Server 2008上进行testing,甚至需要SMTPauthentication。