none
关于Windows service监控及Recovery RRS feed

  • 问题

  • 各位高手好

    想实现如下一个功能,就是监控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']$


    2015年5月26日 8:15

答案

  • 您好,

    作为一个 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 .

    2015年5月30日 3:25
    版主

全部回复

  •  我是想知道, 调用action的时候, 怎么把监控得到的service name传人 net start command中, 谢谢!
    2015年5月27日 7:59
  • 您好,

    请参考下面的链接中提到 的使用  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}”


    "

    http://www.server-log.com/blog/2012/9/18/running-powershell-scripts-as-recovery-tasks-in-system-cente.html

    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 .

    2015年5月27日 9:05
    版主
  • 我是想获取到如下alert中的service name "avbackup",然后把这个service name传入action中,这样就可以启动该service了

    不过,我不知道该怎么把alert 中的 这个变量 传到action中

    或者大家有没有什么其他好的方法可以监控windows中启动方式为automatic的service并且可以自动recover这个service,谢谢!

    2015年5月28日 8:09
  • Please see the alert context for details.
    Service Backup Agent(avbackup) change from Running to Stopped on CIS1263VMINSPI.AVNET.COM

    2015年5月28日 8:11
  • 您好,

    作为一个 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 .

    2015年5月30日 3:25
    版主