积极答复者
关于Windows service监控及Recovery

问题
-
各位高手好
想实现如下一个功能,就是监控Windows server上启动方式为automatic的service状态,如果发现service stop了,产生alert并且实现自动调用action 启动这个service.
由于WMI Event Rule 产生alert之后无法调用action,所以打算创建WMI Event Monitor来实现该功能,WQL 如下:
SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_Service' AND TargetInstance.StartMode = 'Auto'
monitor创建好了之后,单个service 状态从Running变为Stopped, 会有相应的alert生成,但是如果同时又多个service 状态从Running变为Stopped之后,由于health没有reset, 好像只会有一个alert生成, 如果health reset之后, 才会有新的alert生成。
另外,在recover action中,本来计划用 net start xxx来启动service,不过尝试了几次好像都没成功,不知道,使用如下命令来启动service是否正确,谢谢!
命令:c:\windows\system32\net.exe
参数:start $Collection[@Name='TargetInstance']/Property[@Name='Name']$或者
命令:c:\windows\system32\net.exe
参数:$Data/EventData/DataItem/Collection['TargetInstance']/Property[@Name='Name']$
答案
-
您好,
作为一个 workaround 我觉得 您可以 尝试用下面这个 powershell 命令 当 reover action 被 触发 :
gwmi win32_service | ?{$_.startmode -eq "auto" -and $_.state -eq "stopped"} | start-service
触发这命令会检查 所有 自动启 动 但是 已经停止的服务 并 启动 停掉的服务。
谢谢
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com .
- 已建议为答案 Elton_JiModerator 2015年6月8日 7:11
- 已标记为答案 Daniel JiSunModerator 2015年6月10日 6:36
全部回复
-
您好,
请参考下面的链接中提到 的使用 powershell.exe 去执行 recover action :
"
Full path to file is the powershell.exe:
C:\windows\system32\windowspowershell\v1.0\powershell.exe
In the parameter field are the PowerShell cmdlets separated by semi-colon in the following way:
-Command “& {cmdlet ; cmdlet ; cmdlet}”
"Best Regards,
Elton Ji
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com .
-
您好,
作为一个 workaround 我觉得 您可以 尝试用下面这个 powershell 命令 当 reover action 被 触发 :
gwmi win32_service | ?{$_.startmode -eq "auto" -and $_.state -eq "stopped"} | start-service
触发这命令会检查 所有 自动启 动 但是 已经停止的服务 并 启动 停掉的服务。
谢谢
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com .
- 已建议为答案 Elton_JiModerator 2015年6月8日 7:11
- 已标记为答案 Daniel JiSunModerator 2015年6月10日 6:36