Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <package>
- <job id="WebSiteMonitor">
- <script language="jscript">
- function getCurrentTime() {
- var dsDateObj = new Date();
- return(dsDateObj.getTime());
- }
- function getTimeDiff(t1,t2) {
- return(t2-t1);
- }
- </script>
- <script language="vbscript">
- option explicit
- 'on error resume next
- '********************************************************************************
- ' This routine agressively checks a file every 5 minutes and restarts the server
- ' if that file is not found. The idea is to keep the DreamHost VPS servers running
- '********************************************************************************
- ' Installation:
- ' 1. Create a text file that contains just the string "123$SiteMonitorPSText!!~end"
- ' with no CRLF at the end. Upload that to the root of a website on the VPS.
- ' 2. Place this .wsf file on a Windows server or workstation.
- ' 3. Fill in the values that follow these instructions.
- ' 4. Uncomment out the 4 lines near the end if you reaaly want it to reboot your VPS.
- ' 5. Schedule it to run every 5 minutes (or however often you want to check)
- dim sitestocheck,logfilename,mailto,mailfrom,mailrelay,mailport
- ' sitestocheck contains an array of arrays that describe each site to check.
- ' The fields are: description, test-file-url, value-in-test-file, reserved, API key, VPS name
- sitestocheck = Array( _
- Array("example.com", _
- "http://example.com/SiteMonitorPS.txt", _
- Array("123$SiteMonitorPSText!!~end"), _
- "","API-KEY-HERE", _
- "ps99999") _
- )
- logfilename = "SiteMonitorPS.log"
- mailto = "webmaster@example.com"
- mailfrom = "postmaster@example.com"
- mailrelay = "mail.example.com"
- mailport = 25
- '********************************************************************************
- dim xmlhttp,stime,etime,rtime,statuscode,pagebody,pagelines,pageline
- dim x,fso,myfile,myfilename,pageok,pagesok,msg,logfile
- dim sitenum,sitetocheck,sitepageval, badsitelist(), badsites, badsite
- dim waitfile,rebootlist(),reboots,msgsubj
- Set fso = CreateObject("Scripting.FileSystemObject")
- set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
- call xmlhttp.setTimeouts(45000, 45000, 45000, 45000)
- 'call xmlhttp.setProxy(2,"10.4.1.2:3128")
- set logfile = fso.OpenTextFile(logfilename,8,TRUE)
- sitenum=0
- badsites=0
- reboots=0
- for each sitetocheck in sitestocheck
- sitenum=sitenum+1
- waitfile = "-PS-" & cstr(sitenum) & "-reboot-wait.txt"
- 'First, load the login page so that variables are created and cookies set.
- stime = getCurrentTime()
- wscript.echo "Checking site " & sitetocheck(0)
- xmlhttp.open "GET",sitetocheck(1),true
- xmlhttp.send
- for x = 1 to 30*1000/100
- wscript.sleep 100
- if xmlhttp.readyState = 4 then exit for
- next
- if xmlhttp.readyState = 4 then
- statuscode = xmlhttp.status
- pagebody = xmlhttp.responseText
- else
- statuscode = "-1"
- pagebody = ""
- end if
- etime = getCurrentTime()
- rtime = cint((getTimeDiff(stime,etime)+5)/10)/100
- logline sitetocheck(0) & ": Took " & rtime & " seconds to retrieve page, status=" & statuscode
- 'logline xmlhttp.getAllResponseHeaders
- pageok = false
- if statuscode = 200 then
- myfilename = "-PS-" & cstr(sitenum) & "-pagebody.htm"
- set myfile = fso.OpenTextFile(myfilename,2,TRUE)
- pagelines = split(pagebody,chr(10))
- for each pageline in pagelines
- for each sitepageval in sitetocheck(2)
- if instr(pageline,sitepageval) > 0 then pageok = true
- next
- 'wscript.echo pageline
- myfile.writeline pageline
- next
- myfile.close
- end if
- if pageok then
- logline sitetocheck(0) & ": Page validated OK."
- logfile.writeline now() & " " & sitetocheck(0) & ": site is functioning, response time = " & rtime & " seconds"
- if fso.fileExists(waitfile) then fso.deleteFile(waitfile)
- else
- redim preserve badsitelist(badsites)
- badsitelist(badsites)=sitetocheck(0)
- badsites=badsites+1
- logfile.writeline now() & " " & sitetocheck(0) & ": site is NOT functioning, response time = " & rtime & " seconds, status code=" & statuscode
- Call rebootsite(sitetocheck(4),sitetocheck(5))
- end if
- next
- Set xmlhttp = nothing
- logfile.close
- set logfile = nothing
- if badsites > 0 then
- set msg = CreateObject("CDO.Message")
- msg.From = mailfrom
- msg.To = mailto
- msg.Subject = "**Downtime**"
- for each badsite in badsitelist
- msg.TextBody = msg.TextBody & "The " & badsite & " site is NOT currently functioning." & chr(10)
- msg.Subject = msg.Subject & " " & badsite
- next
- for each badsite in rebootlist
- msg.TextBody = msg.TextBody & "The " & badsite & " server was rebooted." & chr(10)
- next
- msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
- msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailrelay
- msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = mailport
- msg.Configuration.Fields.Update
- msg.Send
- Set msg = Nothing
- end if
- function logline(myline)
- wscript.echo myline
- end function
- function rebootsite(myauth,myserver)
- dim TypeLib,NewGUID,l,myfile,myfilename
- if fso.fileExists(waitfile) then 'It takes twice down to issue a reboot command
- Call fso.deleteFile(waitfile) 'Make sure we clean it up so we don't repeatedly reboot
- wscript.echo "Trying to reboot: " & myserver
- redim preserve rebootlist(reboots)
- rebootlist(reboots)=myserver
- reboots=reboots+1
- Set TypeLib = CreateObject("Scriptlet.TypeLib")
- NewGUID = Trim(TypeLib.Guid)
- l = Len(NewGUID)
- 'wscript.echo l & " - " & NewGUID
- NewGUID = mid(NewGUID,2,l-3)
- 'wscript.echo l & " - " & NewGUID
- Set TypeLib = Nothing
- xmlhttp.open "POST","https://panel.dreamhost.com/api/",false
- xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- xmlhttp.send "key="&myauth&"&cmd=dreamhost_ps-reboot&unique_id="&newGUID&"&ps="&myserver
- statuscode = xmlhttp.status
- wscript.echo xmlhttp.responseText
- myfilename = "-PS-" & cstr(sitenum) & "-reboot.txt"
- set myfile = fso.OpenTextFile(myfilename,2,TRUE)
- myfile.writeline "Status="&statuscode
- myfile.write xmlhttp.responseText
- myfile.close
- set myfile=nothing
- else
- 'comment out to disable rebooting-- comment 4 lines below to stop reboot feature
- 'set myfile = fso.OpenTextFile(waitfile,2,TRUE)
- 'myfile.writeline now() & " - waiting until next check to reboot " & myserver
- 'myfile.close
- 'set myfile=nothing
- end if
- end function
- </script>
- </job>
- </package>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement