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).]