Citrix.NetScaler Device DiscoveryProvider

Citrix.NetScaler.NetscalerDevice.DiscoveryProvider (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Intervalint$Config/Interval$Interval

Source Code:

<DataSourceModuleType ID="Citrix.NetScaler.NetscalerDevice.DiscoveryProvider" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Interval" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DeviceKey" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IPAddress" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="CommunityString" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Interval" Selector="$Config/Interval$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/Interval$</IntervalSeconds>
<SyncTime/>
<ScriptName>Citrix.NetScaler.Discovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Config/DeviceKey$ $Config/IPAddress$ $Config/CommunityString$</Arguments>
<ScriptBody><Script>Option Explicit

Main

Sub Main

Dim oArgs, oAPI, oDisc, oInst, oSNMP
Set oArgs = WScript.Arguments
Dim SourceID, ManagedEntityId, TargetComputer, haStateNum, haStateString, DeviceKey
Dim hostNameString, haPeerIPString, CommunityString, BuildversionString, lReturnCode
Dim EvtErrorMsg

SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
DeviceKey = oArgs(2)
TargetComputer = oArgs(3)
CommunityString = oArgs(4)

'Const haPeerState= "1.3.6.1.4.1.5951.4.1.1.23.3.0"
'This represents the state of the failover peer NetScaler whether 'Primary or Secondary (0-&gt;standlone, 1-&gt;secondary, 2-&gt;primary).
'Const haPeerIPAddress= "1.3.6.1.4.1.5951.4.1.1.23.2.0"
'Const buildVersion= "1.3.6.1.4.1.5951.4.1.1.1.0"

Const haStateOID = "1.3.6.1.4.1.5951.4.1.1.23.3.0"
Const haPeerOID = "1.3.6.1.4.1.5951.4.1.1.23.2.0"
Const buildVersionOID = "1.3.6.1.4.1.5951.4.1.1.1.0"

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oSNMP = CreateObject("SScripting.SNMPManager")
if IsNull (oSNMP) then
'Log event
Call oAPI.LogScriptEvent("Citrix.NetScaler.Discovery.vbs", 9001, 1, "SScripting.SNMPManager object creation failed.")
Set oSNMP = Nothing
Set oAPI = Nothing
Exit Sub
end if

oSNMP.Agent = TargetComputer

oSNMP.Community = CommunityString

oSNMP.Variables.Add(haStateOID)
oSNMP.Variables.Add(haPeerOID)
oSNMP.Variables.Add(buildVersionOID)

lReturnCode = oSNMP.Get()

if lReturnCode &lt;&gt; 0 then
Dim temp
temp = "Encoded CommunityString: " &amp; CommunityString &amp; "decoded: " &amp; oSNMP.Community
EvtErrorMsg = ErrorMessage(TargetComputer, temp , lReturnCode)
Call oAPI.LogScriptEvent("Citrix.NetScaler.Discovery.vbs", 9001, 1, EvtErrorMsg)
Set oSNMP = Nothing
Set oAPI = Nothing
Exit Sub
end if

'haPeerState numeric (0-&gt;standlone, 1-&gt;primary, 2-&gt;secondary)
'haState numeric (0-&gt;standlone, 1-&gt;secondary, 2-&gt;primary)

haStateNum = oSNMP.Variables.Item(1).Value

if haStateNum = "0" then
haStateString = "Standalone"
elseif haStateNum = "1" then
haStateString = "Secondary"
elseif haStateNum = "2" then
haStateString = "Primary"
else
haStateString = "Unknown"
end if

'HOST NAME POPULATION
hostNameString = HostName(TargetComputer)

'HAPEERIP POPULATION
haPeerIPString = oSNMP.Variables.Item(2).Value
If haPeerIPString = "0.0.0.0" then
haPeerIPString = "-"
end If


'BUILD VERSION
BuildversionString = oSNMP.Variables.Item(3).Value

set oDisc = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
oDisc.IsSnapshot = True
set oInst = oDisc.CreateClassInstance("$MPElement[Name='Citrix.NetScaler.NetscalerDevice']$")

call oInst.AddProperty("$MPElement[Name='NetworkLibrary!System.NetworkManagement.Node']/DeviceKey$",DeviceKey)

call oInst.AddProperty("$MPElement[Name='NetworkLibrary!System.NetworkManagement.Node']/SNMPAddress$",TargetComputer)

call oInst.AddProperty("$MPElement[Name='Citrix.NetScaler.NetscalerDevice']/haState$", haStateString)

call oInst.AddProperty("$MPElement[Name='Citrix.NetScaler.NetscalerDevice']/sysHardwareVersionId$", BuildversionString)
call oInst.AddProperty("$MPElement[Name='Citrix.NetScaler.NetscalerDevice']/hostName$", hostNameString)
call oInst.AddProperty("$MPElement[Name='Citrix.NetScaler.NetscalerDevice']/haPeerIP$", haPeerIPString)

call oDisc.AddInstance(oInst)
call oAPI.Return(oDisc)

Set oSNMP = Nothing
Set oAPI = Nothing

End Sub

Function HostName(ByVal vIPAddress)
Dim oIPNetwork, hostNameString

Set oIPNetwork = CreateObject("SScripting.IPNetwork")
hostNameString = oIPNetwork.DNSLookup( vIPAddress )

If Trim(hostNameString) = "" then
hostNameString = "-"
End If

Set oIPNetwork = Nothing
HostName = hostNameString
End Function

Function Base64ToBSTR(strBase64)
Dim Byte1, Byte2, Byte3, Byte4, Data, iterator

Const CharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

For iterator = 0 To Len(strBase64) - 1 Step 4
Byte1 = InStr(CharMap, Mid(strBase64, iterator + 1, 1)) - 1
Byte2 = InStr(CharMap, Mid(strBase64, iterator + 2, 1)) - 1
Byte3 = InStr(CharMap, Mid(strBase64, iterator + 3, 1)) - 1
Byte4 = InStr(CharMap, Mid(strBase64, iterator + 4, 1)) - 1

Data = Data &amp; ChrB(Byte1 * 4 + Byte2 \ 16)

If Byte3 &gt;= 0 Then
Data = Data &amp; ChrB((Byte2 And 15) * 16 + Byte3 \ 4)
Else
Data = Data &amp; ChrB((iterator * 3 \ 4 + 1) = (Byte2 And 15) * 16)
End If

If Byte4 &gt;= 0 Then
Data = Data &amp; ChrB((Byte3 And 3) * 64 + Byte4)
End If
Next

Base64ToBSTR = Data
End Function

Function ErrorMessage(ByVal vTargetComputer, ByVal vCounters, ByVal vErrorCode)

Dim ErrorString
Dim ErrorStringHeader
Dim SNMPError(6)
ErrorStringHeader = "SNMP GET for Device:" &amp; vTargetComputer &amp; ":Counters :" &amp; vCounters
SNMPError(0) = ErrorStringHeader &amp; ": SNMP Get / GetNext Successfull"
SNMPError(1) = ErrorStringHeader &amp; ": Err-10:SNMP Variable OID Invalid"
SNMPError(2) = ErrorStringHeader &amp; ": Err-40:Data Too Big to fit in Single SNMP message"
SNMPError(3) = ErrorStringHeader &amp; ": Err-50:SNMP Request Timed-out"
SNMPError(4) = ErrorStringHeader &amp; ": Err-60:SNMP Unspecified Error"
SNMPError(5) = ErrorStringHeader &amp; ": Err-70:SNMP Variable List Empty"
SNMPError(6) = ErrorStringHeader &amp; ": Err-80:SNMP Support Not Available"

ErrorString = "Not Specified"
Select Case vErrorCode
Case 0
ErrorString = SNMPError(0)
Case 10
ErrorString = SNMPError(1)
Case 40
ErrorString = SNMPError(2)
Case 50
ErrorString = SNMPError(3)
Case 60
ErrorString = SNMPError(4)
Case 70
ErrorString = SNMPError(5)
Case 80
ErrorString = SNMPError(6)
End Select

ErrorMessage = ErrorString
End Function</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>