Friday, December 01, 2006

Uptime Tool

Uptime Tool

Description: Analyzes lists of servers, and produces report output of the uptime of these servers.  

Reasoning: One time a tool was being used which randomly rebooted hundreds of servers, in order to quickly identify those afflicted, I wrote this tool.

FileName: Uptime.cmd

rem -------------------------------rem Uptime Tool V1.0rem -------------------------------rem Description: Reads a file containing a list of servers and rem dynamically creates a web page that displays the uptime of each serverrem Script could be adjusted to display much more information on each serverrem Author: Nigel Glenwood October 26, 2006remrem *****************************************************************************rem technical desc:rem 1 display the web page, inside web page refresh every 5 secondsrem read server file, and run system information, parse out up timerem pipe this into dynamic web pagerem *****************************************************************************
clsecho off
rem create web page startup
copy /y clock2.gif clock
rem set thedir=c:\dat\*.*
rem echo directory set to %thedir%
rem use template to startcopy /y template.htm thepage.html
echo Analysis Start Time: %DATE% %TIME% >> thepage.html
sleep 2
rem open up the IE startup page, which displays # server uptime informationstart /b c:\progra~1\intern~1\iexplore.exe C:\dat\thepage.html
rem :looprem echo looping...
rem read the a server, and create web pagerem %%z passes into create, we pick it up as %1
for /F %%z in (servers.txt) do call create.cmd %%z
echo Analysis Complete >> thepage.htmlecho ^ >> thepage.htmlecho Uptime tool v1.0 by Nigel Glenwood >> thepage.htmlrem change the image on the page to finished.copy /y finish.jpg clockecho ^<^/i^> >> thepage.html
rem sleep 5
rem goto loop


==========================================================
filename: Create.cmd


echo ^Server: %1 ^<^/B^> >> thepage.html
srvinfo -nf \\%1 find "Up Time" >> thepage.html


DAT (Directory Analysis Tool) By: Nigel Glenwood


DAT (Directory Analysis Tool) By: Nigel Glenwood

filename: file.cmd
rem -------------------------------
rem Directory Alert Tool (DAT)
rem -------------------------------
rem Description: Monitors number of files in a directory, original developed
rem to monitor biz talk, but it could be utilized to monitor directories and
rem ensure there are not more than 25,000 files, or to monitor smtp mail
rem
rem Author: Nigel Glenwood
rem
rem *****************************************************************************
rem technical desc:
rem -q = quite mode, so we do not get headings, andstatistical data in our result
rem -Recurse, 0 do not go through sub-dirs, if -1, goes through all, if 2 would
rem go to 2 iterations, etc...
rem place result into my output file out.txt, to be placed into variable later
rem -i:FS, means we are hitting the FS, not an IIS log, or Event Log etc..
rem *****************************************************************************
rem How does it freakin work?
rem first we have a dynamic web page, intially we copy the start.gif
rem overlaying my.gif, just for startup
rem then we display the webpage, while we are running the background
rem the web page refreshed itself every 5 seconds, in header tag
rem on subsequent loads, my.gif is generated with the latest data
rem when the threshold is reached, a warning gif is displayed
rem when the threshold goes back down, it replaces it back with the my.gif
rem *****************************************************************************


cls
echo off

rem create web page startup
rem overwrite in case warning message present.

copy /y start.gif my.gif

set thedir=c:\dat\*.*

echo directory set to %thedir%
rem open up the IE startup page, which displays # of files
start /b c:\progra~1\intern~1\iexplore.exe C:\dat\warning.htm


:loop
echo looping...

rem chart types: Column3d

rem create the graph
logparser "SELECT count(name) as [Number of Files] into my.gif FROM %%thedir%% where attributes like '%%A%%' " -i:FS -Recurse:0 -q:on -o:CHART -values:on -chartType:Column3d -chartTitle:"Files" -groupSize:600x480

rem place count into out.txt, read later on
logparser "SELECT count(name) as [ ] FROM %%thedir%% where attributes like '%%A%%' " -i:FS -rtp:-1 -Recurse:0 -q:on > out.txt

logparser "SELECT attributes, COUNT(*) AS files INTO graph.jpg FROM %%thedir%% where attributes like '%%A%%' GROUP BY attributes ORDER BY attributes ASC" -i:FS -o:CHART -values:on -chartType:pieexploded3d -chartTitle:"%1" -groupSize:1400x800

rem logparser "SELECT * FROM %%thedir%% " -i:FS -q:on >> theoutput.txt


pause

rem file creator, to check application/test
rem this keeps creating files in the directory, turn off after Testing
echo creating file
echo %random% > %random%.txt


rem read the count we placed into out.txt pass it as a variable
rem in display.cmd we will pick up %%Z as %1 and perform processing

for /F %%z in (out.txt) do call display.cmd %%z




sleep 5

goto loop


=============================================================================
Filename: display.cmd
rem -------------------------------
rem Directory Alert Tool (DAT)
rem -------------------------------
rem By: Nigel G.

cls
echo off
echo you sent me %1


rem convert to arithmitic, so it knows it is a number, how ya like dem apples

set /a thefiles=%1
set /a threshold=70
set /a thresholdb=%threshold%+1

echo the files now is %thefiles%

rem perform ifs to determine if value is greater than threshold
rem if %thefiles% GTR %threshold% start c:\progra~1\intern~1\iexplore.exe C:\dat\warning2.htm
if %thefiles% GTR %threshold% copy /Y one.GIF my.gif
if %thefiles% GTR %threshold% echo Threshold Reached Warning displayed sleeping now...
if %thefiles% GTR %threshold% sleep 1


if %thefiles% LSS %thresholdb% echo Files currently within contraints



=============================================================================
Filename: Warning.html (This dynamically refreshed itself ever 5 secs)

*html*
*head**meta http-equiv="Content-Language" content="en-us"**meta http-equiv="Content-Type" content="text/html; charset=windows-1252"**meta http-equiv="refresh" content="5" * *title*Warning*/title**/head*
*body**p align="center"**img border="0" src="triangle.gif" width="95" height="82"**p align="center"**font face="Trebuchet MS" color="#FF0000"*Monitoring Files...*/font**/p*
*p align="center"**img border="0" src="my.gif" width="600" height="480"**/p*
*/body*
*/html*



***END***