xml.vbs - vbscript script by ActiveXperts Software
xml.vbs performs a query on an XML source.
Use xml.vbs directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select xml.vbs. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
xml.vbs script code
' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor - VBScript based checks
' // For more information about ActiveXperts Network Monitor and VBScript, visit
' // http://www.activexperts.com/support/network-monitor/online/vbscript/
' ///////////////////////////////////////////////////////////////////////////////
Option Explicit
' Declaration of global variables
Dim SYSDATA, SYSEXPLANATION ' SYSDATA is displayed in the 'Data' column in the Manager; SYSEXPLANATION in the 'LastResponse' column
' Constants - return values
Const retvalUnknown = 1 ' ActiveXperts Network Monitor functions should always return True (-1, Success), False (0, Error) or retvalUnknown (1, Uncertain)
' // To test a function outside Network Monitor (e.g. using CSCRIPT from the
' // command line), remove the comment character (') in the following lines:
' Dim bResult
' bResult = QueryXml()
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
Function QueryXml( strXmlPath )
' Description:
' This function queries cdcatalog.xml for CDs that have more than 12 songs
' If there is more than one record, the function is successfull.
' Parameters:
' 1) strXmlPath - Path to the Xml file. Can be either a URL, or a filesystem path
' Usage:
' QueryXml( "<URL to XML file | XML on Filesystem>" )
' Sample:
' QueryXml( "http://www.activexperts.com/network-monitor/demopage/cdcatalog.xml" )
On Error Resume Next
Dim xmlDoc, x, colNodes, strCDs, strProducts
QueryXml = retvalUnknown ' Default return value
SYSDATA = "" ' Not used by this function
SYSEXPLANATION = "" ' Set initial value
strProducts = ""
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = "false"
xmlDoc.load( strXmlPath )
Set colNodes = xmlDoc.selectNodes("/catalog/cd")
For Each x in colNodes
If( strCDs <> "" ) Then
strCDs = strCDs & ", "
End If
strCDs = strCDs & x.SelectSingleNode("artist").text & "-" & x.SelectSingleNode("title").text
Next
If( strCDs <> "" ) Then
SYSEXPLANATION = "Following CDs were found: [" & strCDs & "]"
QueryXml = True
Else
SYSEXPLANATION = "No CDs found"
QueryXml = False
End If
End Function
