v8 Soap ASP

(imported topic written by cstoneba)

I was using the attached .ASP page to show BES license usage as a page on our web server. Since our v8 upgrade, it no longer runs. Does anyone know if any v8 changes could be the reason? thanks

(imported comment written by MattBoyd)

It’s probably something that idiot Matt Boyd did when writing the code :wink:

I’ll take a look and see if it works for me and, if not, update it since we use it internally as a sample script.

Could you give me the error that you’re getting?

(imported comment written by cstoneba)

thanks Boyd. I modified this script though, so what you see was not the original.

I’m not getting an error, I just don’t see any data. When the page renders, I don’t get any output.

(imported comment written by MattBoyd)

Well, the error that I received with the original script was this:

XML parsing error: The node is neither valid nor invalid because no DTD/Schema declaration was found.

I went to page 67 of the Web Reports documentation (http://support.bigfix.com/product/documents/BigFix_Web_Reports_80_100810.pdf) and sure enough, I was specifying a different soap namespace. After fixing that, it works.

Note:

Is there anyone with Web Reports 7.2 that could verify the script below still works for that version as well?

Here’s version 1.2 of the my VBscript:

'===================================================================== 
'      BigFix Web Reports SOAP API Example 
' Author:         Matthew Boyd (mdb305) 
'       Created:        10/20/2009 
'  Modified:       11/16/2010 
'  Version: 1.2 
' 
'    This is  an example of how to use the Web Reports SOAP  
'     API to retrieve information about clients in BigFix. It is  
' written in VBScript. It should be called from a command 
'     line prompt using the syntax in the line below.   
' 
'       Usage:  cscript.exe WebReportsSoapExample.vbs  
' 
'  Note: You must set the username and password values  
'        to an actual Web Reports username and password in order  
'    for the script to successfully complete. The script was  
'    tested and worked with Web Reports version 8.0.627.0. 
'=====================================================================   Dim SoapRequest, username, password, relevance, url, objHTTP, result, i, objXML, NodeList   url = 
"https://web reports server:52312/webreports" 
'The URL of the BigFix Web Reports site username = 
"webreportsuser" 
' The web reports username that is used for authentication. password = 
"password" 
' The password of the Web Reports account 
''
' This is where the relevance string is set. You can set it to any relevance you'd like. Remember, quotes in the relevance clause must be escaped by using two quotes (see below near: name of it starts with 
"CB") relevance = 
"(names of it, ip addresses of it, (last report time of it) as universal string) of bes computers whose (name of it starts with "
"CB"
")"   
''
'This  section builds the Soap Request Body  that will be sent to the Web Reports web server SoapRequest = 
"<?xml version="
"1.0"
" encoding="
"utf-8"
"?>" SoapRequest = SoapRequest & 
"<env:Envelope xmlns:xsi="
"http://www.w3.org/2001/XMLSchema-instance"
" xmlns:xsd="
"http://www.w3.org/2001/XMLSchema"
" xmlns:env="
"http://schemas.xmlsoap.org/soap/envelope/"
"> " SoapRequest = SoapRequest & 
"<env:Body>"   
''
'This section contains the actual call to the GetRelevanceResult method. SoapRequest = SoapRequest & 
"<GetRelevanceResult xmlns="
"https://schemas.bigfix.com/Relevance"
">" SoapRequest = SoapRequest & 
"<relevanceExpr><![CDATA["& relevance & 
"]]></relevanceExpr>" 
'This is the relevance parameter. The relevance expression must be enclosed in <relevanceExpr></relevanceExpr> brackets. SoapRequest = SoapRequest & 
"<username>"& username & 
"</username>" 
'This is the username parameter in the Soap Request. Notice the credentials are part of the SOAP request. This is why all Web Reports SOAP request (or any authentication to Web Reports) should be done over HTTPS! Otherwise, they are passed in clear text. SoapRequest = SoapRequest & 
"<password>"& password & 
"</password>" 
'This is the password parameter in the Soap Request. SoapRequest = SoapRequest & 
"</GetRelevanceResult>"   
''
'This section cloases the Soap Request Body SoapRequest = SoapRequest & 
"</env:Body>" SoapRequest = SoapRequest & 
"</env:Envelope>"   
''
'Now that we've built the Soap request, we need to send it over HTTP. This section handles that. Set objHTTP = CreateObject(
"Msxml2.XMLHTTP") 
'Create an HTTP object to send the SOAP Request to the BigFix Server objHTTP.open 
"POST", URL, 

false 
'Configure the HTTP object to use POST, point it to the Web Reports URL. objHTTP.setRequestHeader 
"Content-Type", 
"text/xml" objHTTP.setRequestHeader 
"SOAPAction", url & 
"GetRelevanceResultResponse" objHTTP.send SoapRequest 
'Sendthe Soap Request to the Web Reports Server, collect the result.   result = objHTTP.responseText  
'At this point we have the result of the relevance query. However, it's in XML format, with each result record between <a></a> tags.  We can extract 

this information using a DOMDocument object (see below)   
''
'This section extracts the text data from the result, which is in XML format. We do this by loading the result string into an MSxml2.DOMDocument object and then using SelectNodes with an XPATH statement to select all nodes enclodsed in <a></a> tags. Set objXML = CreateObject (
"Msxml2.DOMDocument") objXML.LoadXml result 
'Load the result from the SOAP Request     If not objXML.SelectSinglenode (
"//faultstring") is nothing then 
'If a faultstring node exists in the XML, GetRelevanceResult returned an error. Raise an exception with the source and description. Err.Raise 1,  
"GetRelevanceResult:" & objXML.SelectSingleNode(
"//faultcode").text, Trim(objXML.SelectSingleNode(
"//faultstring").text) End If   Set NodeList = objXML.SelectNodes(
"//a") 
'Select the nodes enclosed in <a></a> from the XML. Load into NodeList object. wscript.echo NodeList.length For i = 0 to NodeList.length - 1 
'Iterate through each node in the NodeList object, write the text contents to the console. wscript.echo NodeList.Item(i).text Next

(imported comment written by cstoneba)

i see you were using it as a .vbs. I was using it as a .asp and made some tweaks so that I could make it display with some defnined text, etc. Would that make a difference?

(imported comment written by MattBoyd)

I wouldn’t think so, but life’s full of surprises.

The only lines you should have to change are these:

''
'This  section builds the Soap Request Body  that will be sent to the Web Reports web server SoapRequest = 
"<?xml version="
"1.0"
" encoding="
"utf-8"
"?>" SoapRequest = SoapRequest & 
"<soap12:Envelope xmlns:xsi="
"http://www.w3.org/2001/XMLSchema-instance"
" xmlns:xsd="
"http://www.w3.org/2001/XMLSchema"
" xmlns:soap12="
"http://www.w3.org/2003/05/soap-envelope"
"> " SoapRequest = SoapRequest & 
"<soap12:Body>"   ...   
''
'This section cloases the Soap Request Body SoapRequest = SoapRequest & 
"</soap12:Body>" SoapRequest = SoapRequest & 
"</soap12:Envelope>"

To these

''
'This  section builds the Soap Request Body  that will be sent to the Web Reports web server SoapRequest = 
"<?xml version="
"1.0"
" encoding="
"utf-8"
"?>" SoapRequest = SoapRequest & 
"<env:Envelope xmlns:xsi="
"http://www.w3.org/2001/XMLSchema-instance"
" xmlns:xsd="
"http://www.w3.org/2001/XMLSchema"
" xmlns:env="
"http://schemas.xmlsoap.org/soap/envelope/"
"> " SoapRequest = SoapRequest & 
"<env:Body>"   ...   
''
'This section cloases the Soap Request Body SoapRequest = SoapRequest & 
"</env:Body>" SoapRequest = SoapRequest & 
"</env:Envelope>"

(imported comment written by cstoneba)

no go. I get an http 500 error. I will keep troubleshooting…

(imported comment written by MattBoyd)

What happens if you use my VBScript instead?

(imported comment written by cstoneba)

it reports back the computers that start with “CB”, so it works. How would you have those results be displayed on a webpage? For example:

“Number of computers within our environment that beging with CB”: abc123, abc12345

(imported comment written by cstoneba)

I’m seeing issues with all my SOAP stuff now, since the v8 upgrade. Can you see what happens when you try the attachment? I get ‘Access Denied’, even though this user worked with your vbs test.

(imported comment written by MattBoyd)

cstoneba

I’m seeing issues with all my SOAP stuff now, since the v8 upgrade. Can you see what happens when you try the attachment? I get ‘Access Denied’, even though this user worked with your vbs test.

Hmm, that looks like Javascript, and I don’t think that will work due to XSS issues (see: http://forum.bigfix.com/viewtopic.php?pid=25415#p25415)

I tested your ASP script (after modifying those 4 lines of code), and produced a result successfully. Are you sure you don’t have a typo somewhere in the ASP script?

(imported comment written by cstoneba)

So you took my .ASP, modified those 4 lines like you suggested, and it worked for you?

(imported comment written by MattBoyd)

Correct.

(imported comment written by cstoneba)

I’ve done that, but maybe I messed up. Can you attach yours?

(imported comment written by MattBoyd)

Sure, here it is.

(imported comment written by cstoneba)

Well i’m baffled. Yours worked, I made your 2 changes to mine, and mine worked. Even though I tried that before! Oh well. Everything is working now, and these queries seem to run faster with v8. Thanks for your help boyd.

(imported comment written by MattBoyd)

No problem, glad to hear it’s working :slight_smile:

(imported comment written by nberger91)

Boyd, this is great thread…

Would you happen to have a vbs that works with 8.1 ?

I have session relevance that i need to automate and pipe the results out to a csv, looks like youve done something similar before…

(item 0 of it as string & " | " & item 1 of it as string ) of ((if (exists Scripts of Actions of it) then ( concatenations " | " of (unique values of matches (regex"http:/\S+") of Scripts of Actions of it as string)) else ("")), (if (exists Name of it) then (concatenations " | " of (Name of it as string)) else ("")), (if (exists Source Severity of it) then (concatenations " | " of (Source Severity of it as string)) else (""))) of bes fixlets whose ((name of site of it = “Enterprise Security” ))

thanks in advance

(imported comment written by MattBoyd)

Sure, this should work with 8.1:

'===================================================================== 
'  BigFix Web Reports SOAP API Example 
' Author:         Matthew Boyd (mdb305) 
'       Created:        10/20/2009 
'  Modified:       11/16/2010 
'  Version: 1.2 
' 
'    This is  an example of how to use the Web Reports SOAP  
'     API to retrieve information about clients in BigFix. It is  
' written in VBScript. It should be called from a command 
'     line prompt using the syntax in the line below.   
' 
'       Usage:  cscript.exe WebReportsSoapExample.vbs  
' 
'  Note: You must set the username and password values  
'        to an actual Web Reports username and password in order  
'    for the script to successfully complete. The script was  
'    tested and worked with Web Reports version 8.0.627.0. 
'=====================================================================   Dim SoapRequest, username, password, relevance, url, objHTTP, result, i, objXML, NodeList   url = 
"https://web reports server:52312/webreports" 
'The URL of the BigFix Web Reports site username = 
"webreportsuser" 
' The web reports username that is used for authentication. password = 
"password" 
' The password of the Web Reports account 
''
' This is where the relevance string is set. You can set it to any relevance you'd like. Remember, quotes in the relevance clause must be escaped by using two quotes (see below near: name of it starts with 
"CB") relevance = 
"(names of it, ip addresses of it, (last report time of it) as universal string) of bes computers whose (name of it starts with "
"CB"
")"   
''
'This  section builds the Soap Request Body  that will be sent to the Web Reports web server SoapRequest = 
"<?xml version="
"1.0"
" encoding="
"utf-8"
"?>" SoapRequest = SoapRequest & 
"<env:Envelope xmlns:xsi="
"http://www.w3.org/2001/XMLSchema-instance"
" xmlns:xsd="
"http://www.w3.org/2001/XMLSchema"
" xmlns:env="
"http://schemas.xmlsoap.org/soap/envelope/"
"> " SoapRequest = SoapRequest & 
"<env:Body>"   
''
'This section contains the actual call to the GetRelevanceResult method. SoapRequest = SoapRequest & 
"<GetRelevanceResult xmlns="
"https://schemas.bigfix.com/Relevance"
">" SoapRequest = SoapRequest & 
"<relevanceExpr><![CDATA["& relevance & 
"]]></relevanceExpr>" 
'This is the relevance parameter. The relevance expression must be enclosed in <relevanceExpr></relevanceExpr> brackets. SoapRequest = SoapRequest & 
"<username>"& username & 
"</username>" 
'This is the username parameter in the Soap Request. Notice the credentials are part of the SOAP request. This is why all Web Reports SOAP request (or any authentication to Web Reports) should be done over HTTPS! Otherwise, they are passed in clear text. SoapRequest = SoapRequest & 
"<password>"& password & 
"</password>" 
'This is the password parameter in the Soap Request. SoapRequest = SoapRequest & 
"</GetRelevanceResult>"   
''
'This section cloases the Soap Request Body SoapRequest = SoapRequest & 
"</env:Body>" SoapRequest = SoapRequest & 
"</env:Envelope>"   
''
'Now that we've built the Soap request, we need to send it over HTTP. This section handles that. Set objHTTP = CreateObject(
"Msxml2.XMLHTTP") 
'Create an HTTP object to send the SOAP Request to the BigFix Server objHTTP.open 
"POST", URL, 

false 
'Configure the HTTP object to use POST, point it to the Web Reports URL. objHTTP.setRequestHeader 
"Content-Type", 
"text/xml" objHTTP.setRequestHeader 
"SOAPAction", url & 
"GetRelevanceResultResponse" objHTTP.send SoapRequest 
'Sendthe Soap Request to the Web Reports Server, collect the result.   result = objHTTP.responseText  
'At this point we have the result of the relevance query. However, it's in XML format, with each result record between <a></a> tags.  We can extract 

this information using a DOMDocument object (see below)   
''
'This section extracts the text data from the result, which is in XML format. We do this by loading the result string into an MSxml2.DOMDocument object and then using SelectNodes with an XPATH statement to select all nodes enclodsed in <a></a> tags. Set objXML = CreateObject (
"Msxml2.DOMDocument") objXML.LoadXml result 
'Load the result from the SOAP Request     If not objXML.SelectSinglenode (
"//faultstring") is nothing then 
'If a faultstring node exists in the XML, GetRelevanceResult returned an error. Raise an exception with the source and description. Err.Raise 1,  
"GetRelevanceResult:" & objXML.SelectSingleNode(
"//faultcode").text, Trim(objXML.SelectSingleNode(
"//faultstring").text) End If   Set NodeList = objXML.SelectNodes(
"//a") 
'Select the nodes enclosed in <a></a> from the XML. Load into NodeList object. wscript.echo NodeList.length For i = 0 to NodeList.length - 1 
'Iterate through each node in the NodeList object, write the text contents to the console. wscript.echo NodeList.Item(i).text Next

(imported comment written by nberger91)

awesome, works great. thanks …