IIS状态监测(如果状态错误则重启IIS)

步骤:

1:建立健康监测文件。文件内容随意,这里以healthcheck.aspx命名,内容是<span>hellow word</span>

2:利用vbs语言执行IIS重启

文件名称:AppPoolRecycle.vbs

注意:自行修改进程池的名称这里是“DefaultAppPool”

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
        & strComputer & "\root\microsoftiisv2")
'回收名为DefaultAppPool的应用程序池
Set colItems = objWMIService.ExecQuery _
    ("Select * From IIsApplicationPool Where Name = " & _
        "'W3SVC/AppPools/DefaultAppPool'")
For Each objItem in colItems
    objItem.Recycle
Next

2:利用VBS调用curl进行探测,利用grep对探测结果进行筛选

文件名称:IISchk.vbs

注意:

A:文件路径中不能有空格,自行修改探测的文件地址这里是http://localhost/healthcheck.aspx

B:本代码位置是C:\healthcheck

C:附件清单(文件夹curl里面有32位64位两个版本外部的curl.exe是32位;grep文件夹里是该软件的安装程序;AppPoolRecycle.vbs 重启脚本;IISchk.vbs检查脚本;curl.txtcurl结果文件;grep.txt grep结果文件;)

d:C:\ProgramFiles\GnuWin32\bin\grep.exe 这个是我的grep安装目录,路径不能有空格

E:建立计划任务周期执行IISchk.vbs脚本就可以了

Set objShell = CreateObject("Wscript.Shell")
'利用curl获取目标网页的http头信息
strcmd1 = "%comspec% /c C:\healthcheck\curl -I http://localhost/healthcheck.aspx -o c:\healthcheck\curl.txt"
'利用grep筛选出curl获取的关键行HTTP/1.1
strcmd2 = "%comspec% /c C:\ProgramFiles\GnuWin32\bin\grep.exe -i HTTP/1.1 c:\healthcheck\curl.txt > c:\healthcheck\grep.txt"
objShell.Run(strcmd1)
'等待500毫秒让strcmd1的文件写完,因为strcmd2需要这个文件
WScript.Sleep 500
objShell.Run(strcmd2)
'打开经过筛选后的grep.txt文本
Const ForReading=1
Dim strLine,strnewline
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\healthcheck\grep.txt", ForReading)
strLine = objTextFile.ReadLine
'去掉头尾的空格
strnewline  = Trim(strLine)
'判断行是否等于HTTP/1.1 200 OK,如果不等于则运行c:\healthcheck\AppPoolRecycle.vbs
If not strnewline = "HTTP/1.1 200 OK" then
objShell.Run("c:\healthcheck\AppPoolRecycle.vbs")
End if

F:用到的文件

转载于:https://www.cnblogs.com/tommyli/p/3156448.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值