PSMetrics Part 3: A simple ASP ingestor
Welcome to part 3 in the PSMetrics series. In this part, I'll be building a simple ingestor to receive and process data from the collectors, and send the data on to the database.
For the code on this, I'll be using classic ASP. Why? Because that is what I know. If you are more of a .Net person, or even a PHP connoisseur, this basic chunk of code can be translated very easily. The five things that are happening in this script are:
- Create database connectivity
- Set defaults
- Retrieve inbound values from collector
- Process/validate inbound values
- Send to database
This code will be running on an IIS 10 webserver, on Windows 2016. If you are using this code directly, you'll need to enable classic ASP on your IIS server before using these snippets. Also, be sure to watch for line wrap on these snippets. Some of them are a little long!
The first section of the script will set up our database connectivity. In this example, I am reusing a MS SQL server in my lab, but you can just as easily use MySQL, with some minor twiddling of the SQL string.
CFG_Conn="Driver={SQL Server};Server=sqllab01.psmetricslab.local;Database=PostMet;Uid=PostMet;Pwd=P@$$Word;"
Set objConn = server.CreateObject("ADODB.Connection")
objConn.ConnectionString=CFG_Conn
ErrorOccurred=0
Tree=trim(request.querystring("tree"))
SubTree=trim(request.querystring("subtree"))
Metric=trim(request.querystring("metric"))
CValue=trim(request.querystring("cvalue"))
TimeStamp=trim(request.querystring("ts"))
TimeStamp=Replace(TimeStamp,"%20","")
if Len(Tree)=0 or Len(SubTree)=0 or Len(Metric)=0 or Len(CValue)=0 or len(timestamp)=0 then
ErrorOccurred=1
end if
If ErrorOccurred=0 then
dblValue=cdbl(CValue)
strSQL="insert into tblmain (tree,subtree,metric,cvalue,datestamp) values('" & Tree & "','" & SubTree & "','" & Metric & "'," & CValue & ",'" & TimeStamp & "')"
objConn.Open
objConn.Execute(strSQL)
objConn.close
response.write "success"
else
response.write "error - check IIS logs for complete error information"
end if
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.