Hi,
I need to translate the below VB script to Perl
Appreciate your help !!
<?xml version="1.0" standalone="yes" ?>
<package>
<comment><![CDATA[
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File: vnDevList.wsf
Version: See WSH resource ID ATTEASE_VERSION
Synopsis: Extract a list of VitalSuite Net (VitalNet) po
+lled devices,
write out XML file.
Detailed Description 1. This script runs on the VitalNet masters.
+If the present
machine is not a master then exit.
2. Discover the machine's aggrs.
3. For each aggr, run the query to list the de
+vice inventory
as XML.
Command Syntax: See <example> element, below, for all options
Prerequisite: Windows 7 or later, Windows Server 2008 or later
+.
Notes: 1. This WSH file should be well-formed XML. Use
+ ValidateXml.vbs to check.
2. A DTD cannot be embedded in this file. This
+is a limitation of WSH.
3. The WScript.Arguments.ShowUsage() method will
+ display everything
within the <runtime> element. Use /? argumen
+t to invoke this method.
References:
Windows Script Host XML format is on MSDN under
+ Reference (Windows Script Host)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
]]></comment>
<job id="vnDevList">
<runtime>
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^
ADJUST THE <description> AND <example> ELEMENTS FOR YOUR AP
+PLICATION
The description and example will be displayed if the /? swi
+tch
is entered or if the command syntax is invalid
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^ -->
<description><![CDATA[Fetch VitalNet Device List]]></description
+>
<example><![CDATA[ [ /? ] | [ -version ] |
{
[ -config=(a[,b[,c...]]) ]
[ "-customer=customer" ]
[ -distlist=standard|alternate|default ]
[ -ipaddr=vsInstallIP ]
[ -mail=always|never|conditional ]
[ -stats ] [ -traceLevel=n ]
[ -trapError | -noTrapError ]
[ -valcfg | -validateconfiguration ]
}]]>
</example>
</runtime>
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^
ADJUST ALL DIRECTORY PATHS FOR YOUR APPLICATION:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^ -->
<resource id="ATTEASE_APPNAME">vnDevList</resource> <!-- applica
+tion name -->
<resource id="ATTEASE_VERSION">1.0.2</resource> <!-- applica
+tion version -->
<resource id="ATTEASE_HOME">.</resource> <!-- applica
+tion home directory -->
<resource id="ATTEASE_CONF">.</resource> <!-- applica
+tion conf directory -->
<resource id="ATTEASE_LIB">.</resource> <!-- applica
+tion lib directory -->
<!-- Configuration files in format [fileName,rootElementId,versi
+on]: -->
<resource id="ATTEASE_CONFIG_FILES">
[AttConfigGlobal.xml,attConfig,1.00],
[AttConfigVnDevList.xml,attConfig,1.00]
</resource>
<resource id="ATTEASE_CONFIG_TEMPLATE">dummy.xml</resource>
<!-- The following scripts are required by most applications:
+-->
<script language="vbscript" src="AttAdo.vbs" /> <!-- ADO cons
+tants -->
<script language="vbscript" src="AttApp.vbs" /> <!-- applicat
+ion method dispatcher -->
<script language="vbscript" src="AttCore.vbs" /> <!-- core uti
+lities -->
<script language="vbscript" src="AttConfig.vbs" /> <!-- configur
+ation utilities -->
<script language="vbscript" src="AttEmail.vbs" /> <!-- email cl
+ass -->
<script language="vbscript" src="AttFile.vbs" /> <!-- file man
+ipulation -->
<script language="vbscript" src="AttLog.vbs" /> <!-- log clas
+s -->
<script language="vbscript" src="AttNet.vbs" /> <!-- network
+ -->
<script language="vbscript" src="AttSort.vbs" /> <!-- Sort rou
+tine -->
<script language="vbscript" src="AttWmi.vbs" /> <!-- WMI clas
+s -->
<script language="vbscript">
<![CDATA[
Option Explicit
AttCore.requireVersion "AttAdo","1.04"
AttCore.requireVersion "AttApp","1.40"
AttCore.requireVersion "AttCore","1.20"
AttCore.requireVersion "AttConfig","1.20"
AttCore.requireVersion "AttEmail","1.08"
AttCore.requireVersion "AttFile","1.04"
AttCore.requireVersion "AttLog","1.07"
AttCore.requireVersion "AttNet","1.04"
AttCore.requireVersion "AttSort","1.01"
AttCore.requireVersion "AttWmi","1.08"
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
'
' Initialization
'
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
' Instantiate, populate an ATTEASE object.
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
AttCore.InitResources ' load WSH-defined resources into global AT
+TEASE object
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
' Preprocess the command line arguments to get optional custom co
+nfig file names
' specified via the -config=(filename[,filename...]) option
' ^^^^^^^^^h^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^^
Call AttCore.getArgumentsFiltered
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
' Instantiate the configuration object
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
ReDim aConfigFiles(-1)
Dim configFile, aConfigFile
If UBound(AttCore.getConfigFiles()) > -1 Then ' get the config fi
+lenames from the command line
For Each configfile In AttCore.getConfigFiles()
AttCore.push aConfigFiles,Array(configfile,"attConfig","1.
+00")
Next
Else ' take the default from the WSH resource
For Each aConfigfile In AttCore.getConfFiles()
AttCore.push aConfigFiles,aConfigfile
Next
End If
AttCore.setConfig((new AttConfig).Init(aConfigFiles))
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
' Need to know if VitalNet supports new data columns for IPv6.
' This is true if VitalNet version >= 11.
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
Dim bHasIPv6: bHasIPv6=True
Function hasIPv6: hasIPv6=bHasIPv6: End Function
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
' Process the command line arguments, handling nonstandard argume
+nts here
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^
Dim oConfig: Set oConfig=AttCore.getConfig()
Dim oWatchlet: Set oWatchlet=oConfig.watchlet
Dim customer: customer=AttCore.getCustomer ' must be reprocessed
+after config and args are processed
Dim masterIpaddr: masterIpaddr=oWatchlet.vsInstallIp
Dim sCustomArg
For Each sCustomArg In AttCore.getArgumentsFiltered()
Select Case LCase(sCustomArg)
Case Else
If AttCore.strSearch(1,sCustomArg,"^[-/]ipaddr=(\S+)$",
+vbTextCompare)>0 Then
Dim aIpaddr: aIpaddr=Split(sCustomArg,"=")
' WScript.Echo "ipaddr=" & aIpaddr(1)
masterIpaddr=aIpaddr(1)
If Not AttCore.isIpaddr(masterIpaddr) Then
wScript.Echo "vnDevList: invalid argument, " & m
+asterIpaddr & _
", not a valid IP address"
WScript.Quit(2)
End If
AttCore.pushCommandArgument("Ipaddr(" & masterIpaddr
+ & ")")
Else
WScript.Echo("vnDevList: Unknown argument, " & sCust
+omArg)
WScript.Arguments.ShowUsage()
WScript.Quit(2)
End If
End Select
Next
customer=AttCore.getCustomer ' must be reprocessed after config an
+d args are processed
Dim MssqlADODB: Set MssqlADODB=New MssqlADODB_ ' create connection
+ factory for MS SQL Server
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^
' Instantiate the log object
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^
Set ATTEASE.LOG=(New AttLog).Init("vndevlist",True) ' message pref
+ix, echo
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^
' Execute the application's configured methods in sequence
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^
Set ATTEASE.APP=New AttApp
Dim bApplRc: bApplRc=True
bApplRc=ATTEASE.APP.validate() ' validate that each configured met
+hod exists
If bApplRc Then bApplRc = ATTEASE.APP.dispatch()
Set ATTEASE.LOG=Nothing
WScript.Quit(0)
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^
' Add extending functions here.
'
' Message range for extensions begins with 6000.
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^
' Method buildDeviceList
'
' 1. Determine from the registry whether VitalNet is installed. Ch
+eck the VN
' version. If version is < 11 then note that IPv6 is not suppor
+ted.
' 2. Determine from the catalog of databases whether this is a Vita
+lNet master.
' If it is not a master then exit. This logic is a subset of th
+e logic for
' Vitalwatch discovery.
' 3. Discover the machine's aggrs.
' 4. For each aggr, run the query to list the device inventory
' as XML.
'
' Reserved message range: 6000-6199
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^
Function buildDeviceList()
On Error GoTo 0
Dim bReturnCode: bReturnCode=True ' success
Dim rc, sDescr ' return code from called functions as integer an
+d as string
ATTEASE.LOG.writeLine(VbCrLf & "Build VitalSuite NET Device List
+")
If AttCore.getTraceLevel() > 0 Then
ATTEASE.LOG.writeMsg "6000","I","Start buildDeviceList at " &
+ AttCore.formatDate(,,Empty)
End If
Dim config: Set config=AttCore.getConfig()
Dim watchlet: Set watchlet=config.watchlet
If Watchlet Is Nothing Then
getEmailSubject().addIssue("Configuration Error")
ATTEASE.LOG.writeMsg "6002","C","Method buildDeviceList calle
+d but no watchlet defined"
buildDeviceList=False
Exit Function
End If
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^
' IPv6 is supported from VitalNet 11 on. There are new columns
+that support
' IPv6. We must determine that these columns are accessible. Ch
+ecking
' the version of the VN Master (this machine) should be good eno
+ugh.
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^
' Check registry for VitalSuiteCommon\VitalNet. This could be i
+n SOFTWARE
' branch or SOFTWARE\Wow6432Node.
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^
Dim sVitalNetVersion: svitalNetVersion=Null
Dim sKeyPath: sKeyPath="SOFTWARE\VitalSuiteCommon\VitalNet"
Dim sErrDescr ' capture error message from VBScript Err object
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
On Error Resume Next
Dim oLocator: Set oLocator = CreateObject("WbemScripting.SWbe
+mLocator")
Dim oRegSvc: Set oRegSvc = oLocator.ConnectServer(".", "root
+\default")
oRegSvc.Security_.ImpersonationLevel=3
Dim oReg: Set oReg = oRegSvc.Get("StdRegProv")
If Err.Number<>0 Then
sErrDescr=Err.Description
On Error GoTo 0
Err.Raise 11111,"vnDevList","Computer '.' received error conn
+ecting to registry: " & sErrDescr
End If
On Error Goto 0
oReg.GetStringValue HKEY_LOCAL_MACHINE,sKeyPath,"Version",sVital
+NetVersion
If isNull(sVitalNetVersion) Then
sKeyPath="SOFTWARE\Wow6432Node\VitalSuiteCommon\VitalNet"
oReg.GetStringValue HKEY_LOCAL_MACHINE,sKeyPath,"Version",sVi
+talNetVersion
If isNull(sVitalNetVersion) Then
ATTEASE.APP.getEmailSubject().addIssue "VitalSuite Net not
+ installed"
ATTEASE.LOG.write(" ").WriteMsg "6018","E","VitalSuite Ne
+t not found in Windows registry, exiting"
buildDeviceList=False
Exit Function
End If
End If
'sVitalNetVersion="10.9.9.9"
'WScript.Echo(sVitalNetVersion)
bHasIPv6= (AttCore.cmpVersion(sVitalNetVersion,"11") >= 0) ' ver
+sion 11 is required for IPv6 support
'WScript.Echo "HasIPv6=" & hasIPv6()
'WScript.Quit(0)
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^
' Discover VitalSuite features - NET master, aggr, poller, VS rep
+orting
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^
ATTEASE.LOG.write(" ").writeMsg "6020","I","Discovering VitalSui
+te NET features"
Dim mssqlServer: mssqlServer=masterIpaddr
Dim oCon: Set oCon=MssqlADODB.connect(mssqlServer)
If oCon Is Nothing Then
ATTEASE.APP.getEmailSubject().addIssue "ADODB connection open
+ failed"
ATTEASE.LOG.write(" ").WriteMsg "6022","E","ADODB connection
+ open to "& mssqlServer & " failed for reason: " & MSsqlADODB.errstr
buildDeviceList=False
Exit Function
End If
Dim oRst: Set oRst = CreateObject("ADODB.Recordset")
' Database initialization is done.
' Discover the VitalSuite databases on this machine:
' VitalSuite databases found:
Dim bDbVNMaster: bDbVNMaster=False
Dim bDbVNAggr: bDbVNAggr=False
Dim bDbVNPoller: bDbVNPoller=False
Dim bDbVSReports: bDbVSReports=False
' Vital Real-Time
Dim bHasRT: bHasRT=False
' Discover the VitalSuite databases on this machine:
On Error Resume Next
' In VBScript tristate logic, -1 is vbTrue and 0 is vbFalse
oRst.Open "select case when DB_ID(N'VNMaster') is null then 0 els
+e -1 end as hasVNMaster, " & _
"case when DB_ID(N'VNAggr') is null then 0 else
+-1 end as hasVNAggr, " & _
"case when DB_ID(N'VNPoller') is null then 0 els
+e -1 end as hasVNPoller, " & _
"case when DB_ID(N'VSReports') is null then 0 el
+se -1 end as hasVSReports", oCon
If Err.Number <> 0 Then
sErrDescr=Err.Description
On Error GoTo 0
ATTEASE.APP.getEmailSubject().addIssue "Query open for databa
+ses failed"
ATTEASE.LOG.WriteMsg "6030","E","ADODB Query open for discove
+ring databases failed for reason: " & sErrDescr
buildDeviceList=False
Exit Function
End If
On Error Goto 0
bDbVNMaster=oRst("hasVNMaster").Value
bDbVNAggr=oRst("hasVNAggr").Value
bDbVNPoller=oRst("hasVNPoller").Value
bDbVSReports=oRst("hasVSReports").Value
oRst.Close
' Create set of databases discovered on this host:
Dim aDbSet: aDbSet=Array( _
Array("VNMaster",bDbVNMaster), _
Array("VNAggr",bDbVNAggr), _
Array("VNPoller",bDbVNPoller), _
Array("VSReports",bDbVSReports) _
)
' Document the discovered databases;
Dim aDb
ReDim dbList(-1)
For Each aDb In aDbSet
Dim sDB,bHasServerRole: sDb=aDb(0): bHasServerRole=aDb(1)
If bHasServerRole Then AttCore.push dbList,sDb
Next
ATTEASE.LOG.write(" ").writeMsg "6032","I","VitalSuite databas
+es are " & Join(dbList,", ")
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^
' If this machine does not have a VNMASTER database, stop here.
+This is
' not a VitalSuite Net master. Signal success anyway, since this
' is not a script error.
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^
If Not bDbVNMaster Then
ATTEASE.LOG.write(" ").writeMsg "6040","I","This host is no
+t a VitalSuite NET master. " & _
"Device list will not be ge
+nerated."
buildDeviceList=True
Exit Function
End If
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^
' Discover aggrs for this master.
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^
ATTEASE.LOG.write(" ").writeMsg "6050","I","Discovering VitalSui
+te NET Aggrs"
' Track the IP addresses of the peer network devices so that we c
+an eliminate duplicates
' Map address->aggrID
Dim dictAggr: Set dictAggr = CreateObject("Scripting.Dictionary")
Dim oNetDevice,oInterface ' temporary variables
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^
' Find all the aggr machines for this master (including this mach
+ine)
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^
' bDbVNMaster=oRst("hasVNMaster").Value
' bDbVNAggr=oRst("hasVNAggr").Value
' bDbVNPoller=oRst("hasVNPoller").Value
On Error Resume Next
oRst.Open "select AggrID, AggrName, AggrAddress, AggrStatus " &
+_
" from VNMaster.dba.VnAggrTable" & _
" where AggrAddress > ''" & _
" order by AggrID", oCon,adOpenForwardOnly,adLockReadO
+nly,adCmdText
If Err.Number Then
sErrDescr=Err.description
On Error GoTo 0
Err.Clear
buildDeviceList=False
ATTEASE.APP.getEmailSubject().addIssue "Query for aggrs faile
+d"
ATTEASE.LOG.writeMsg "6054","E", _
"ADODB Query open for aggrs failed for r
+eason: " & sErrDescr
Exit Function
End If
On Error GoTo 0
Dim iTotalVitalnetAggrsRead: iTotalVitalnetAggrsRead=0
Do Until oRst.EOF
iTotalVitalnetAggrsRead = iTotalVitalnetAggrsRead + 1
If False Then
WScript.Echo " AggrID=" & oRst("AggrID").Value & _
", AggrName=" & oRst("AggrName").Value & _
", AggrAddress=" & oRst("AggrAddress").Value &
+ _
", AggrStatus=" & oRst("AggrStatus").Value
End If
' net device requires label, active attributes
If dictAggr.Exists(oRst("AggrAddress").Value) Then
' WScript.Echo(" already have IP address " & oRst("AggrAd
+dress").Value)
ElseIf oRst("AggrStatus").Value=0 Then
' WScript.Echo(" IP address " & oRst("AggrAddress").Value
+ & " has AggrStatus of 0, will not be used")
Else
dictAggr.Add oRst("AggrAddress").Value,oRst("AggrID").Value
End If
oRst.MoveNext
Loop
oRst.Close
Set oRst=Nothing
oCon.Close
Set oCon=Nothing
ATTEASE.LOG.Write(" ").writeMsg "6060","I", _
"Aggrs are: " & Join(dictAggr.
+Keys,", ")
Dim outFilename: outFilename="vndevlist_" & masterIpaddr & ".xml
+"
outFilename=config.emailMailbag() & "\" & outFilename
ATTEASE.LOG.write(" ").writeMsg "6100","I","Writing to file " &
+ outFilename & " at " & _
AttCore.formatDate(,,Empty)
On Error Resume Next
Dim oStream
Set oStream=AttFile.AttFileFSO.OpenTextFile(outFilename, _
AttFileOpenForWritin
+g, _
True, _
False)
If Err Then
Dim desc: desc=Err.description
On Error GoTo 0
Err.Raise 11111,"vnDevList.buildDeviceList","File " & outFile
+name & " cannot be opened for output: " & desc
End If
On Error GoTo 0
oStream.WriteLine "<?xml version=""1.0"" standalone=""yes"" ?>"
oStream.Writeline "<vnDevList customer=""" & AttCore.htmlspecial
+chars(customer,ENT_QUOTES) & _
""" masterIpaddr=""" & masterIpaddr & _
""" version=""" & AttCore.getVersion() & _
""" genDate=""" & AttCore.formatDate(,,Empty)
+& _
""" timestamp=""" & AttCore.formatDate(AttCore
+DateTimeUnix,,Empty) & """ >"
' document the aggrs used in this device list:
Dim sAggrAddress
For Each sAggrAddress In dictAggr.Keys
' WScript.Echo " aggr IP address=" & sAggrAddress
oStream.Writeline " <aggr ipAddr=""" & sAggrAddress & _
""" aggrID=""" & dictAggr.Item(sAggrAddres
+s) & """ />"
Next
Dim iTotalDevRead: iTotalDevRead = 0 ' count the monitored devic
+es in inventory
For Each sAggrAddress In dictAggr.Keys
Dim sAggrID: sAggrID=dictAggr.Item(sAggrAddress)
WScript.Echo " aggr IP address=" & sAggrAddress
mssqlServer=sAggrAddress
Set oCon=MssqlADODB.connect(sAggrAddress)
If oCon Is Nothing Then
ATTEASE.APP.getEmailSubject().addIssue "ADODB connection
+ open failed"
ATTEASE.LOG.write(" ").WriteMsg "6110","E","ADODB conne
+ction open to "& sAggrAddress & " failed for reason: " & MSsqlADODB.e
+rrstr
buildDeviceList=False
Exit Function
End If
Dim sDevIPv6Sarg: sDevIPv6Sarg=AttCore.Choose(hasIPv6(),"coal
+esce(b.devIPv6,'')","''")
Set oRst = CreateObject("ADODB.Recordset")
' !!!!!! Note: check devIPv6 - may be wrong. check IPAddress
+String for substitute for both v6 and v4
' !!!!! check address type devAddrType
Dim sSelect
sSelect="select distinct " & _
"rtrim(a.devName) as devName, " & _
"coalesce(b.devipstring,'') as devipstring, " & _
sDevIPv6Sarg & " as devIPv6, " & _
"suspend = case when a.suspend = 0 then 'active' els
+e 'deactivated' end," & _
"convert(varchar(20),a.devLastModified,120) as devLa
+stModified, " & _
"a.devId, " & _
"b.domainId, " & _
"c.domainName, " & _
"'" & sAggrAddress & "' as aggrIpaddr, " & _
"'" & sAggrID & "' as aggrID, " & _
"'" & AttCore.getConfig().Customer & "' as account,
+" & _
"c.parentDomainId " & _
"from VNAggr.dba.devtable a " & _
" inner join VNaggr.dba.resourceview b " & _
" on a.devid = b.devid " & _
" inner join vnaggr.dba.domaintable c " & _
" on b.domainId = c.domainId "
' WScript.Echo sSelect
On Error Resume Next
oRst.Open sSelect,oCon,adOpenForwardOnly,adLockReadOnly,adCmd
+Text
If Err.Number Then
sErrDescr=Err.description
On Error GoTo 0
Err.Clear
buildDeviceList=False
ATTEASE.APP.getEmailSubject().addIssue "Query for aggrs fa
+iled"
ATTEASE.LOG.writeMsg "6130","E", _
"ADODB Query open for device list fai
+led for reason: " & sErrDescr
Exit Function
End If
On Error GoTo 0
Dim iDevRead: iDevRead = 0
Do Until oRst.EOF
iDevRead = iDevRead + 1
iTotalDevRead = iTotalDevRead + 1
If False Then
WScript.Echo " devName=" & oRst("devName").Value & _
", devIpString=" & oRst("devIpString").Value
+& _
", devIPv6=" & oRst("devIPv6").Value & _
", suspend=" & oRst("suspend").Value & _
", devLastModified=" & oRst("devLastModified"
+).Value & _
", devId=" & oRst("devId").Value & _
", domainId=" & oRst("domainId").Value & _
", domainName=" & oRst("domainName").Value &
+_
", aggrIpaddr=" & oRst("aggrIpaddr").Value &
+_
", aggrID=" & oRst("aggrID").Value & _
", account=" & oRst("account").Value & _
", parentDomainId=" & oRst("parentDomainId").
+Value
End If
' DATETIME format 120 is ODBC canonical format: yyyy-mm-dd h
+h:mm:ss
oStream.Writeline " <device deviceName=""" & AttCore.htmlsp
+ecialchars(oRst("devName").Value,ENT_QUOTES) & _
""" deviceIpaddr=""" & oRst("devIpString")
+.Value & _
""" devIPv6=""" & oRst("devIPv6").Value &
+_
""" suspend=""" & oRst("suspend").Value &
+_
""" deviceLastModified=""" & oRst("devLast
+Modified").Value & _
""" deviceId=""" & oRst("devId").Value & _
""" domainId=""" & oRst("domainId").Value
+& _
""" domainName=""" & AttCore.htmlspecialch
+ars(oRst("domainName").Value,ENT_QUOTES) & _
""" aggrIpaddr=""" & oRst("aggrIpaddr").Va
+lue & _
""" aggrID=""" & oRst("aggrID").Value & _
""" account=""" & AttCore.htmlspecialchars
+(oRst("account").Value,ENT_QUOTES) & _
""" parentDomainId=""" & oRst("parentDomai
+nId").Value & _
""" />"
oRst.MoveNext
Loop
oRst.Close
Set oRst=Nothing
oCon.Close
Set oCon=Nothing
ATTEASE.LOG.Write(" ").writeMsg "6140","I", _
"Devices for aggr " & sAggrAddress &
+" processed: " & iDevRead
Next
oStream.Writeline "</vnDevList>"
oStream.Close
ATTEASE.LOG.Write(" ").writeMsg "6150","I", _
"Total devices processed: " & iTotalDe
+vRead
ATTEASE.LOG.writeline ""
If AttCore.getTraceLevel() > 0 Then
ATTEASE.LOG.writeMsg "6199","I","End buildDeviceList at " & At
+tCore.formatDate(,,Empty)
End If
buildDeviceList=bReturnCode
End Function ' buildDeviceList
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^
' End Application logic
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^
' Namespace MssqlADODB and static factory function MssqlADODB.connect
+(server)
' Application must instantiate MssqlADODB as an instance of MssqlADOD
+B_
'
' Call ADODB.Connection to create custom database connection handle f
+or
' MS SQL Server.
'
' Fetch default parameters from configuration. Fetch overrides such
' as IP address from named arguments.
'
' Usage:
'
' Set oCon=MssqlADODB.connect(server)
' If oCon Is Nothing Then
' ATTEASE.LOG.writeMsg "nnnn","E", _
' "Failed connecting to MS SQL Server databa
+se at " & server & _
' MssqlADDB.errstr
' End If
'
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^^^^^
Class MssqlADODB_
Private sErrstr
Public Property Get errstr()
errstr=sErrstr
End Property
Private Property Let errstr(ByVal s)
sErrstr=s
End Property
Public Sub Class_Initialize
errstr=""
End Sub
Function connect(ByVal server)
On Error GoTo 0
errstr=""
Set connect=Nothing
Dim config: Set config=AttCore.getConfig()
Dim watchlet: Set watchlet=config.watchlet
Dim mssqlUserid: mssqlUserid=watchlet.mssqlUserid
Dim mssqlPassword: mssqlPassword=watchlet.mssqlPassword
Dim sErrDescr ' capture error message from VBScript Err object
On Error Resume Next
Dim oCon: Set oCon = CreateObject("ADODB.Connection")
oCon.ConnectionTimeout=watchlet.mssqlConnectionTimeout ' default
+is 15 seconds
oCon.CommandTimeout=watchlet.mssqlCommandTimeout ' default
+is 30 seconds
oCon.IsolationLevel=adXactBrowse ' read unc
+ommitted
oCon.Mode=adModeRead
oCon.Open "Driver={" & AttAdo.getMsSqlServerDriver() & "};Server=
+" & server & ";Database=master;Uid=" & _
mssqlUserid & ";Pwd=" & mssqlPassword
If Err.Number <> 0 Then
sErrDescr=Err.Description
On Error GoTo 0
errstr="Connection open failed for reason: " & sErrDescr
Set connect=Nothing
Exit Function
End If
oCon.Execute "set lock_timeout " & watchlet.mssqlLockTimeout ' de
+nominated in milliseconds
If Err.Number <> 0 Then
sErrDescr=Err.Description
oCon.Close()
On Error GoTo 0
Set connect=Nothing
sErrstr="set lock_timeout failed for reason: " & sErrDescr
Exit Function
End If
On Error Goto 0
Set connect=oCon
End Function ' connect
End Class ' MssqlADODB_
]]>
</script>
</job>
</package>
<!-- end vnDevList.wsf -->
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.