<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JJClements.co.uk &#187; uptime</title>
	<atom:link href="http://www.jjclements.co.uk/tag/uptime/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jjclements.co.uk</link>
	<description>Clem&#039;s Technical Blog</description>
	<lastBuildDate>Tue, 15 Nov 2011 00:16:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>KiXtart script to generate and email uptime report</title>
		<link>http://www.jjclements.co.uk/2009/03/10/kixtart-script-to-generate-and-email-uptime-report/</link>
		<comments>http://www.jjclements.co.uk/2009/03/10/kixtart-script-to-generate-and-email-uptime-report/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 11:05:26 +0000</pubDate>
		<dc:creator>James Clements</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows Server 2003]]></category>
		<category><![CDATA[uptime]]></category>

		<guid isPermaLink="false">http://www.jjclements.co.uk/?p=178</guid>
		<description><![CDATA[As part of my Service Level Agreement at work I have to produce a monthly uptime report for each server. Rather than generate individual reports for each server I decided to write a KiXtart script that would generate a report for all servers and email it to me each month. The following script uses two [...]]]></description>
			<content:encoded><![CDATA[<p>As part of my Service Level Agreement at work I have to produce a monthly uptime report for each server. Rather than generate individual reports for each server I decided to write a <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> script that would generate a report for all servers and email it to me each month.</p>
<p><span id="more-178"></span></p>
<p>The following script uses two other applications:</p>
<p><a href="http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm" target="_blank" rel="nofollow">BMail</a> - A command line SMTP mailing tool<br />
<a href="http://support.microsoft.com/kb/232243" target="_blank" rel="nofollow">Uptime</a> - Allows you to estimate Server availability</p>
<p>Full credit to Craig Peacock for BMail.</p>
<p>Here is the script:</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Clear Existing Uptime Report<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>IF EXIST ("Report")<br />
DEL "Report\*.txt"<br />
ENDIF</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Produce Uptime Report<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>;Convert YYYY/MM/DD to DD-MM-YYYY<br />
$temp = @DATE<br />
$todaysdate = SUBSTR($temp, 9, 2)<br />
$todaysdate = $todaysdate + "-" + SUBSTR($temp, 6, 2)<br />
$todaysdate = $todaysdate + "-" + SUBSTR($temp, 1, 4)</p>
<p>;Array containing server names<br />
Dim $ComputerNames[5]<br />
$ComputerNames[0] = "Server01"<br />
$ComputerNames[1] = "Server02"<br />
$ComputerNames[2] = "Server03"<br />
$ComputerNames[3] = "Server04"<br />
$ComputerNames[4] = "Server05"</p>
<p>;If Report directory doesn't exist then create it<br />
IF NOT EXIST ("Report")<br />
MD "Report"<br />
ENDIF</p>
<p>;Output uptime report for all computers in the array<br />
For Each $Element In $ComputerNames</p>
<p>IF $Element = ""<br />
GoTo "Email"<br />
ENDIF</p>
<p>shell "%comspec% /c " + chr(34) + "Uptime.exe" + " " + $Element + " " + chr(34) + " /s /p:31 >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo. >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo. >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo ******************************************************************************** >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo ******************************************************************************** >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo ******************************************************************************** >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo. >> Report\$todaysdate-UptimeReport.txt"<br />
shell "%comspec% /c echo. >> Report\$todaysdate-UptimeReport.txt"</p>
<p>Next</p>
<p>:Email<br />
;===============================================<br />
;===============================================<br />
;<br />
;         Email Uptime Report<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$emailserver = "someemailserver"<br />
$toaddress = "james" + chr(64) + "somedomain.com"<br />
$fromaddress = "uptime" + chr(64) + "somedomain.com"<br />
$subject = "Uptime Report For all London Servers"</p>
<p>;Form email command<br />
$emailcommand = "bmail -s " + $emailserver + " -t " + $toaddress + " -f " + $fromaddress + " -h -a " + chr(34) + $subject + chr(34) + " -m " + "Report\" + $todaysdate + "-UptimeReport.txt" + " -c"</p>
<p>RUN ($emailcommand)</p>
<p>;===============================================</p>
<p>The script works by generating a file that contains the results of uptime.exe for each server specified. The contents of the file are then emailed using bmail.</p>
<p>This script obviously requires a few variables to be modified to get it to work in another environment. The following will need to be altered:</p>
<p>Dim $ComputerNames[5] - you will need to change the numeric value to the number of servers you want to generate a report for</p>
<p>NOTE: the example above is for 5 servers. If you wanted to monitor 4 servers then you will need to modify the array to change the number of elements to 4. So your array would look like (the last line has been removed):</p>
<p>$ComputerNames[0] = "Server01"<br />
$ComputerNames[1] = "Server02"<br />
$ComputerNames[2] = "Server03"<br />
$ComputerNames[3] = "Server04"</p>
<p>$ComputerNames[0] = "Server01" - you need to change Server01 to the server you want to generate a report for<br />
$emailserver - the name of your email server (the server running this script must be allowed to relay through it)<br />
$toaddress - the address you want the email alert to go to<br />
$fromaddress - the (spoof) address you want the email to appear to come from<br />
$subject - the subject line of the email</p>
<p>I use a scheduled task on a Windows Server 2003 to run this script once a month. It generates a report for the last 31 days of uptime for each server in the array and then emails me the report.</p>
<p>NOTE: you can change 31 day period that the script gathers uptime information for by modifying /p:31 on the following line:</p>
<p>(31 represents the number of days in the past to gather uptime statistics for)</p>
<p>shell "%comspec% /c " + chr(34) + "Uptime.exe" + " " + $Element + " " + chr(34) + " /s /p:31 >> Report\$todaysdate-UptimeReport.txt"</p>
<p>To use this:</p>
<p>1) Save the above script as kixtart.kix in a directory containing the kixtart application<br />
2) Save bmail.exe and uptime.exe (available from the links above) in the same directory<br />
3) Modify variables as appropriate<br />
4) Make sure that the server running the script can relay email through your email server<br />
5) Test by running the script manually and/or create the scheduled task</p>
<p>Alternatively, download the above script and necessary files - <a href="http://www.jjclements.co.uk/wp-content/uploads/2009/03/uptime-report.zip" target="_blank" rel="nofollow">HERE</a></p>
<p>The end result is an email with a breakdown of uptime availability for each server including any dates and times where necessary.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jjclements.co.uk/2009/03/10/kixtart-script-to-generate-and-email-uptime-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KiXtart script to check for website availability</title>
		<link>http://www.jjclements.co.uk/2009/02/19/kixtart-script-to-check-for-website-availability/</link>
		<comments>http://www.jjclements.co.uk/2009/02/19/kixtart-script-to-check-for-website-availability/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 12:06:42 +0000</pubDate>
		<dc:creator>James Clements</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows Server 2003]]></category>
		<category><![CDATA[SLA]]></category>
		<category><![CDATA[uptime]]></category>

		<guid isPermaLink="false">http://www.jjclements.co.uk/?p=130</guid>
		<description><![CDATA[At work there is an old web application that is managed offsite by a hosting company. It runs on Oracle 9iAS. Apparently there is an issue with Oracle 9i and the web service will frequently crash (due to a known caching problem) taking the application offline. Rather than spending money on the software and licensing [...]]]></description>
			<content:encoded><![CDATA[<p>At work there is an old web application that is managed offsite by a hosting company. It runs on Oracle 9iAS. Apparently there is an issue with Oracle 9i and the web service will frequently crash (due to a known caching problem) taking the application offline.</p>
<p><span id="more-130"></span></p>
<p>Rather than spending money on the software and licensing required to upgrade both Oracle and the Operating System (as it's being replaced anyway) the company made a decision to live with the issue for the time being. I decided to write a <a href="http://www.kixtart.org" target="_blank" rel="nofollow">KiXtart</a> script to monitor the website and let me know of any issues it may incur.</p>
<p>The following script uses two other applications:</p>
<p><a href="http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm" target="_blank" rel="nofollow">BMail</a> - A command line SMTP mailing tool<br />
<a href="http://johnmu.com/web-toolbox-1/" target="_blank" rel="nofollow">WebResult</a> - A command line URL result code tool</p>
<p>Full credit to Craig Peacock for BMail and John Mueller for WebResult.</p>
<p>Here is the script:</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Remove temp files<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>IF EXIST ("result.txt")<br />
DEL ("result.txt")<br />
ENDIF</p>
<p>IF EXIST ("status.txt")<br />
DEL ("status.txt")<br />
ENDIF</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Check/record http status in result.txt<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$website = "http://www.jjclements.co.uk"</p>
<p>SHELL "%comspec% /c " + chr(34) + "webresult.exe " + $website + chr(34) + " >> result.txt"</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Open result.txt and read into variable<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>getfilecontents("result.txt")</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Explode variable into array<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$myarray = SPLIT ($result, "	", -1)</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Declare global variable to store desc<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$errordesc = ""</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Check each array element against codes<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$element = $myarray[1]<br />
 SELECT</p>
<p>  CASE $element = "0"<br />
  $errordesc = "The current status is: Error " + $element + " - Website Unavailable"</p>
<p>  CASE $element = "400"<br />
  $errordesc = "The current status is: Error " + $element + " - Bad Request"</p>
<p>  CASE $element = "403"<br />
  $errordesc = "The current status is: Error " + $element + " - Forbidden"</p>
<p>  CASE $element = "404"<br />
  $errordesc = "The current status is: Error " + $element + " - Not Found"</p>
<p>  CASE $element = "405"<br />
  $errordesc = "The current status is: Error " + $element + " - Method Not Allowed"</p>
<p>  CASE $element = "406"<br />
  $errordesc = "The current status is: Error " + $element + " - Not Acceptable"</p>
<p>  CASE $element = "408"<br />
  $errordesc = "The current status is: Error " + $element + " - Request Timeout"</p>
<p>  CASE $element = "409"<br />
  $errordesc = "The current status is: Error " + $element + " - Conflict"</p>
<p>  CASE $element = "410"<br />
  $errordesc = "The current status is: Error " + $element + " - Gone"</p>
<p>  CASE $element = "500"<br />
  $errordesc = "The current status is: Error " + $element + " - Internal Server Error"</p>
<p>  CASE $element = "501"<br />
  $errordesc = "The current status is: Error " + $element + " - Not Implemented"</p>
<p>  CASE $element = "502"<br />
  $errordesc = "The current status is: Error " + $element + " - Bad Gateway"</p>
<p>  CASE $element = "503"<br />
  $errordesc = "The current status is: Error " + $element + " - Internal Server Error"</p>
<p>  CASE $element = "504"<br />
  $errordesc = "The current status is: Error " + $element + " - Gateway Timeout"</p>
<p>  CASE $element = "505"<br />
  $errordesc = "The current status is: Error " + $element + " - HTTP Version not supported"</p>
<p>  CASE 1<br />
  EXIT</p>
<p> ENDSELECT</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Threshold - Times to retry + interval<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$numberofretries = "2"<br />
$latencyseconds = "10"</p>
<p>IF $numberofretries > "0"</p>
<p>DO</p>
<p>SLEEP $latencyseconds</p>
<p>IF EXIST ("result.txt")<br />
DEL ("result.txt")<br />
ENDIF</p>
<p>SHELL "%comspec% /c " + chr(34) + "webresult.exe " + $website + chr(34) + " >> result.txt"</p>
<p>getfilecontents("result.txt")</p>
<p>$mytemparray = SPLIT ($result, "	", -1)</p>
<p>$tempelement = $mytemparray[1]</p>
<p>IF NOT $element = $tempelement<br />
EXIT<br />
ENDIF</p>
<p>$currentretry = $currentretry + 1</p>
<p>UNTIL $numberofretries = $currentretry</p>
<p>ENDIF</p>
<p>;===============================================<br />
;===============================================<br />
;<br />
;         Email Server Status<br />
;<br />
;===============================================<br />
;===============================================</p>
<p>$emailserver = "someemailserver"<br />
$toaddress = "james" + chr(64) + "somedomain.com"<br />
$fromaddress = "serverfailure" + chr(64) + "somedomain.com"<br />
$subject = "Server Issue"</p>
<p>;Form email body<br />
shell "%comspec% /c echo. >> status.txt"<br />
shell "%comspec% /c echo. >> status.txt"<br />
shell "%comspec% /c echo WebServer is currently offline >> status.txt"<br />
shell "%comspec% /c echo. >> status.txt"<br />
shell "%comspec% /c echo " + $errordesc + " >> status.txt"<br />
shell "%comspec% /c echo. >> status.txt"<br />
shell "%comspec% /c echo Please restart the WebServer application to ensure SLAs are adhered to! >> status.txt"</p>
<p>;Form email command<br />
$emailcommand = "bmail -s " + $emailserver + " -t " + $toaddress + " -f " + $fromaddress + " -h -a " + chr(34) + $subject + chr(34) + " -m " + "status.txt" + " -c"</p>
<p>SHELL ($emailcommand)</p>
<p>;=======================================<br />
;	Get File Contents<br />
;=======================================</p>
<p>Function getfilecontents($filesource)</p>
<p>OPEN (1, "$filesource")<br />
$result = READLINE (1)<br />
CLOSE (1)</p>
<p>EndFunction</p>
<p>;=======================================</p>
<p>This script obviously requires a few variables to be modified to get it to work in another environment. The following will need to be altered:</p>
<p>$website - you will need to enter your own website you want to monitor here (you must use http://)<br />
$numberofretries - the number of times the script will test the website before emailing an error<br />
$latencyseconds - the time in seconds before each retry (if $numberofretries is NOT set to 0)<br />
$emailserver - the name of your email server (the server running this script must be allowed to relay through it)<br />
$toaddress - the address you want the email alert to go to<br />
$fromaddress - the (spoof) address you want the email to appear to come from<br />
$subject - the subject line of the email</p>
<p>The only other thing you may want to change is the message contained within the email (underneath ';Form email body'). I have a few instances of this script monitoring different servers so I have customised the email body for each server to inform me of the server name and IP address etc.</p>
<p>As mentioned the script makes use of a threshold although it isn't used if you set $numberofretries = "0". The threshold sets the number of times to try the website before sending an email. You can also set the delay between each retry (in seconds) by setting a value for $latencyseconds.</p>
<p>I use a scheduled task on a Windows Server 2003 to run this script every 5 minutes. When there is a problem with the web application I am alerted to it and can respond as necessary. One thing to be aware of, if you set your scheduled task to run every 5 minutes but you set the script to retry say 3 times with a latency of 120 seconds (total 360 seconds - 6 minutes) then the scheduled task will try to run again before the script has finished causing problems.</p>
<p>To use this: </p>
<p>1) Save the above script as kixtart.kix in a directory containing the kixtart application<br />
2) Save webresult.exe and bmail.exe (available from the links above) in the same directory<br />
3) Modify variables as appropriate<br />
4) Make sure that the server running the script can relay email through your email server<br />
5) Test by running the script manually and/or create the scheduled task</p>
<p>Alternatively, download the above script and necessary files - <a href="http://www.jjclements.co.uk/wp-content/uploads/2009/02/website-availability-script.zip" target="_blank" rel="nofollow">HERE</a></p>
<p>The end result is an email that tells you the exact http error code and description when your web application becomes unavailable and meets any threshold that may be set.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jjclements.co.uk/2009/02/19/kixtart-script-to-check-for-website-availability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

