Rev 5506 | Rev 6873 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<%@LANGUAGE="VBSCRIPT"%><%'=====================================================' splunk_build_test_results.asp'' This page is designed to be used by 'splunk'' It is a very simple REST style interface' It simple produces Build and Unit tests metrics'' The output is pure JSON' There are two sections' info : {} - Internal data about the process' data : {} - Build and Test results'' The data section is organised by:' Project and then Release' Within each release there is:' BuildsCompleted' BuildsInError' Within each of these there is:' Count - Total packages' UnitTests - Total Unit Tests' NewVersions - Subset of Count' Ripples - Subset of Count' Other - Subset of Count' The data is for all time' [May need to rethink that if processing time blows out]'' Get Requests' ?day=n - Limit result set n days ago' 0 == Results since midnight' 1 == yesterday''=====================================================%><%Option explicit' Essential to get UTF through all the hoops. ie: VÄSTTRAFIK (VTK)Response.ContentType = "text/html"Response.AddHeader "Content-Type", "text/html;charset=UTF-8"Response.CodePage = 65001Response.CharSet = "UTF-8"%><!--#include file="common/conf.asp"--><!--#include file="common/globals.asp"--><!--#include file="common/qstr.asp"--><!--#include file="common/common_subs.asp"--><SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT><%'------------ Variable Definition -------------Dim result : result = -1Dim SqlQryDim rsQry' Init the output JSON class' Default data will be added at the endDim oJSON : Set oJSON = New aspJSONDim infoSet : Set infoSet = newDataSet("info", oJSON.data)'' Perform the bulk of the work within a sub' Done so that errors propergate up' Using the On Error Resume Next, any error within the routine' will cause the routine to exitOn Error Resume NextCall DoWork'' SQL error detection and reportingIf objEH.LastOraFailed TheninfoSet("error") = 1result = -2infoSet("emsgSummary") = objEH.MessageSummaryinfoSet("emsgDetails") = objEH.MessageDetailsinfoSet("SqlQry") = SqlQry'' Detect program errorsElseIf Err.number <> 0 Thenresult = -3infoSet("error") = 2infoSet("errnum") = Err.numberinfoSet("errtxt") = Err.descriptioninfoSet("errsrc") = Err.sourceEnd IfinfoSet("result") = result'Return the objectResponse.Write oJSON.JSONoutput()Set oJSON = NothingCall Destroy_All_Objects' --- End of Mainline'------------------------------------------------------------------------------'' Create a new collection and add it to an existing colelction' sname - Name of the new collection (Key Name)' pset - Parent collection. The collection to add it to' Returns a Collection ( Scripting Dictionary)Function newDataSet(sname, pset)Set newDataSet = oJSON.Collection()Set pset(sname) = newDataSetEnd Function'------------------------------------------------------------------------------'' Perform the body of the query' Done in a Sub so that errors can be better captured and reportedSub DoWork' Create a collection to contain the returned data'Dim dataSet : Set dataSet = newDataSet("data", oJSON.data)'' Support time limited query'Dim repday : repday = NiceInt( Request("day"), -1 )Dim limit : limit = ""If repday >= 0 TheninfoSet("day") = repdaylimit = " AND bi.TIMESTAMP > TRUNC(SYSDATE - "& repday &")"limit = limit & " AND bi.TIMESTAMP < TRUNC(SYSDATE - "& repday - 1 &")"End If' The query'SqlQry = _"SELECT proj_name," &_" rtag_name," &_" state," &_" reason, " &_" COUNT(reason) AS rc," &_" SUM(test_count) AS tc" &_" FROM" &_" (SELECT pj.PROJ_NAME," &_" RTAG_NAME," &_" DECODE(bi.reason, 'N', 'NewVersion', 'R', 'Ripple', 'T', 'Test', 'P', 'Restored', 'Unknown') as REASON," &_" DECODE(bi.state, 'B', 'Buiding', 'C', 'Complete', 'E', 'Error', 'S', 'SysErr', 'Unknown') as STATE," &_" (SELECT COUNT(*) FROM TEST_RUN tr WHERE tr.build_id = bi.build_id ) AS test_count" &_" FROM BUILD_INSTANCES bi," &_" projects pj," &_" RELEASE_TAGS rt" &_" WHERE bi.RTAG_ID = rt.RTAG_ID" &_" AND rt.proj_id = pj.proj_id" & limit &_" ) group by proj_name, rtag_name, state, reason" &_" ORDER BY PROJ_NAME, rtag_name, state, reason"On Error Resume NextobjEH.ErrorRedirect = FALSEobjEH.TryORA ( OraSession )Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )objEH.CatchORA ( OraSession )' Process each row and return required fields to the userIf objEH.Finally ThenOn Error goto 0Dim lastProjectName, proj : lastProjectName = ""Dim lastReleaseName, rel : lastReleaseName = ""Dim dataOk, dataErrorWhile (NOT rsQry.BOF) AND (NOT rsQry.EOF)' Attempt to speed up access tot he data' Extract all fields for the row' Access fields by indexDim fieldsSet fields = rsQry.FieldsDim pname : pname = fields(0)Dim rname : rname = fields(1)Dim state : state = fields(2)Dim reason : reason = fields(3)Dim rc : rc = CInt(fields(4))Dim tc : tc = CInt(fields(5))Set fields = nothing' Create new Items as required'If pname <> lastProjectName ThenlastProjectName = pnameSet proj = newDataSet(pname,dataSet )End IfIf rname <> lastReleaseName ThenSet rel = newDataSet(rname, proj)lastReleaseName = rnameSet dataOk = newDataSet("BuildsCompleted", rel)dataOk("Count") = 0Set dataError = newDataSet("BuildsInError", rel)dataError("Count") = 0End If' Accumulate data'If state = "Complete" ThendataOk(reason) = dataOk(reason) + rcdataOk("Count") = dataOk("Count") + rcdataOk("UnitTests") = dataOk("UnitTests") + tcElsedataError(reason) = dataError(reason) + rcdataError("Count") = dataError("Count") + rcdataError("UnitTests") = dataError("UnitTests") + tcEnd IfrsQry.MoveNextWendEnd IFrsQry.CloseSet rsQry = Nothingresult = 0End Sub%>