Page 1 of 1 1
Topic Options
#53098 - 2001-01-10 11:30 AM Centralized Reporting
Anonymous
Unregistered


Hey Gang,

I've been working on a script that collects and reports data in a central database. And then using a html gui you can check the data. I would like to get some feedback and suggestions to the script/code, or just crazy ideas and additions to the script.

Well here goes:

This is the kix script which checks space on a number of servers and puts it in a database:

freedb.kix:

code:

;Setconsole ("HIDE")

$engine = "dao.dbengine.36"
$database = "db1.mdb"

$dbe = olecreateobject ( "$engine" )
$dbs = val ( "&" + olecallfunc ( $dbe, "opendatabase", "s", "$database" ))

$Space = GetDiskSpace("\\Server1\c$")
$Server = "Server 1"
$Drive = "C"
Gosub "Calculate"
Gosub "WriteToFile"

$Space = GetDiskSpace("\\Server1\d$")
$Server = "Server 1"
$Drive = "D"
Gosub "Calculate"
Gosub "WriteToFile"

$Space = GetDiskSpace("\\Server2\c$")
$Server = "Server 2"
$Drive = "C"
Gosub "Calculate"
Gosub "WriteToFile"

$Space = GetDiskSpace("\\Server2\d$")
$Server = "Server 2"
$Drive = "D"
Gosub "Calculate"
Gosub "WriteToFile"


Goto "End"

:WriteToFile
;$X = Writeline (1, "Free Space On $Server $Drive Drive: " + "$ErrMsg" + Chr(013) + Chr(010))
$rs = olecallfunc ( $dbs, "execute", "s","INSERT INTO TABLE3 (Dato,Server,Drive,Space) VALUES ('@Date','$Server','$Drive','$ErrMsg');")

if @error goto End endif

Return

:Calculate
Select
Case $Space < 1024 ;** Kilobytes
$Space = $Space * 100
$Units = " Kilobytes"
Case $Space => 1024 and $Space < 1048576 ;** Megabytes
$Space = ($Space * 100) / 1024
$Units = " Megabytes"
Case $Space => 1048576 ;** Gigabytes
$Space = $Space / 10486
$Units = " Gigabytes"
ENDSELECT
;** Convert the $Space value to a string by adding a space to the beginning
$Space = " " + $Space
$Length = LEN($Space)


;** Add the decimal point 2 spaces from the end.
$Space = SUBSTR($Space, 1, $Length - 2) + "." + SUBSTR($Space,$Length - 1, 2)
$ErrMsg = LTRIM($Space)
Return

:End

if $dbe
$rs= olereleaseobject ( $dbe )
endif

if $dbs
$rs= olereleaseobject ( $dbs )
endif


Here is the index.asp file which you can use to filter the data collected, it then passes the selections you make to a file called data.asp

index.asp:

code:

<HTML>
<HEAD>
<TITLE>Query the free space on servers database</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF"><FONT FACE="ARIAL,HELVETICA">
<H2><center>Query the free space on servers database</H2>

<FORM METHOD="GET" ACTION="data.asp">
<p><center> Please type data to filter:
<p><center> (leave fields blank for all data)
<center>
<p align="center">Date (YYYY/MM/DD) <center><INPUT TYPE="text" NAME="date">
<p align="center">Server <center><INPUT TYPE="text" NAME="server">
<p align="center">Drive <center><select size="1" name="Drive">
<option>C</option>
<option>D</option>
<option selected></option>
</select>
<p align="center">Space <center><INPUT TYPE="text" NAME="space">
</center>

<p><center><INPUT TYPE="submit" VALUE="Continue">
</FORM>

</FONT>
</center></center></center>
</BODY>
</HTML>


And the results page data.asp

data.asp:

code:

<HTML>
<BODY>
<Center>
<p align="center"><font face="Arial" size="6">Free Space On Servers</font></p>
<%

Dim objConn, objRS, objDate, objServer, objDrive, objSpace

'Create Database Connection
Set objConn = Server.CreateObject("ADODB.Connection")

'Create Recordset Connection
Set objRS = Server.CreateObject("ADODB.Recordset")

'Open Connection to db1.mdb
objConn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=" & Server.MapPath("db1.mdb")

'Get the values passed from HTML FORM
objDate = Request.QueryString("date")
objServer = Request.QueryString("server")
objDrive = Request.QueryString("drive")
objSpace = Request.QueryString("space")

'Format the result to fit the query
If objDate = "" then objDate = "DATO IS NOT NULL" else objDate = "DATO='" & objDate & "'"

If objServer = "" then objServer = "SERVER IS NOT NULL" else objServer ="Server='" & objServer & "'"

If objDrive = "" then objDrive = "DRIVE IS NOT NULL" else objDrive ="Drive='" & objDrive & "'"

If objSpace = "" then objSpace = "SPACE IS NOT NULL" else objSpace = "SPACE='" & objSpace & "'"

'Refit the query
strSQL = "SELECT * FROM Table3 WHERE "& objDATE & " AND " & objServer & " AND " & objDrive & " AND " & objSpace

'Run the query
objRS.Open strSQL, objConn
'Go to first result
objRS.Movefirst

'Create the table
Response.Write "<center><table border=1>"
Response.Write "<td> <center> Date </td>"
Response.Write "<td> <center> Server </td>"
Response.Write "<td> <center> Drive </td>"
Response.Write "<td> <center> Space </td>"
'Loop thrugh the results
Do while NOT objRS.EOF
Response.Write "<tr>"
Response.Write "<td> <center>" & objRS("Dato") & "</td>"
Response.Write "<td> <center>" & objRS("Server") & "</td>"
Response.Write "<td> <center>" & objRS("Drive") & "</td>"
Response.Write "<td> <center>" & objRS("Space") & " GB</td>"
Response.Write "</tr>"
objRS.MoveNext
Loop

Response.Write "</table>"
'Close the database connection
objConn.Close
%>

</BODY>
</HTML>


You then need the database, the database needs to have a table called: Table3. Then add the folowing coloums to the table (all coloums has to be text coloums): Dato, Server, Drive and Space. And then you are good to go.

Have fun, and please post suggestions/improvements

------------------
Cheers....

David

[This message has been edited by Hallas (edited 10 January 2001).]

Top
#53099 - 2001-01-10 03:57 PM Re: Centralized Reporting
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
David:

Question:

How do you run your script - did you set it up as an AT job on your web server ?

Feedback:

Excellent work!

Suggestion:

1. Might want to put your server & drive info into a text file or INI type file and loop through it in your script. Would make for easier maintenance.

CrazyIdea:

Any way (or need to) include a feature that would email someone if the disk space exceeds certain thresholds ?

Shawn.

Top
#53100 - 2001-01-10 04:09 PM Re: Centralized Reporting
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Shawn, my man! you are back! I hope you had a nice vacation!

As for your idea about disk space exceeding set levels.... I finally finished that diruse.kix script.
http://kix.isorg.net/other_scripts/AdminScripts/NT_Admin/DirUse.kix

Bryce

Top
#53101 - 2001-01-10 05:16 PM Re: Centralized Reporting
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Bryce:

Man - you write bitch'n script !

My holiday was very nice - thanks for asking - but it's good to back though (with two kids out of school and a wife, I can take only so much "quality time" at home)

Shawn.

Top
#53102 - 2001-02-08 05:37 AM Re: Centralized Reporting
brewdude6 Offline
Hey THIS is FUN

Registered: 2000-10-21
Posts: 280
Loc: Nashville, TN
Hallas, I've implemented your handy work...thanks a million. I've got one problem, and I'm not quite sure how to fix it. At this part of the script:

code:

:Calculate
Select
Case $Space < 1024 ;** Kilobytes
$Space = $Space * 100
$Units = " Kilobytes"
Case $Space => 1024 and $Space < 1048576 ;** Megabytes
$Space = ($Space * 100) / 1024
$Units = " Megabytes"
Case $Space => 1048576 ;** Gigabytes
$Space = $Space / 10486
$Units = " Gigabytes"
ENDSELECT
;** Convert the $Space value to a string by adding a space to the beginning
$Space = " " + $Space
$Length = LEN($Space)


;** Add the decimal point 2 spaces from the end.
$Space = SUBSTR($Space, 1, $Length - 2) + "." + SUBSTR($Space,$Length - 1, 2)
$ErrMsg = LTRIM($Space)
Return


It's very hard to distinguish between gigabytes, megabytes, and kilobytes in the returned data though the webpage.
I suspect that when disk space gets to a level that is very low it would be hard to distinguish between the three. Is there a way to add the appropriate identifier to a number before it is written to the database ie. gb, mb, or kb. If anyone could suggest something it would be appreciated.

Thanks

[This message has been edited by brewdude6 (edited 08 February 2001).]

[This message has been edited by brewdude6 (edited 08 February 2001).]

[This message has been edited by brewdude6 (edited 08 February 2001).]

_________________________
I could have made a neat retort but didn't, for I was flurried and didn't think of it till I was downstairs.
-Mark Twain

Top
#53103 - 2001-04-02 01:27 AM Re: Centralized Reporting
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

See inventory.kix for ideas.
Greetings.

see site: http://home.wanadoo.nl/scripting
related topic: http://kixtart.org/board/Forum2/HTML/001430.html

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 988 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.158 seconds in which 0.095 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org