Dell.DRAC.SNMPPing.Probe (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData
OutputTypeMicrosoft.Windows.SerializedObjectData

Member Modules:

ID Module Type TypeId RunAs 
PA ProbeAction Microsoft.Windows.PowerShellProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
CheckIntervalint$Config/CheckInterval$Node Interface Check Delay(Minutes)Interval for the reachability check execution
TimePeriodToCheckint$Config/TimePeriodToCheck$Task Run Period(Minutes)Time Out for the DSMT script execution
LogEnabledbool$Config/LogEnabled$Log EnabledEnable/Disable the log generation

Source Code:

<ProbeActionModuleType ID="Dell.DRAC.SNMPPing.Probe" Accessibility="Public">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IP" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimePeriodToCheck" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CheckInterval" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CommunityString" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="LogEnabled" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="CheckInterval" Selector="$Config/CheckInterval$" ParameterType="int"/>
<OverrideableParameter ID="TimePeriodToCheck" Selector="$Config/TimePeriodToCheck$" ParameterType="int"/>
<OverrideableParameter ID="LogEnabled" Selector="$Config/LogEnabled$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PA" TypeID="Windows!Microsoft.Windows.PowerShellProbe">
<ScriptName>WSMAN-SNMP-DRAC-Ping.ps1</ScriptName>
<ScriptBody><Script>
param($IP, [int]$TimePeriodToCheck, [int]$CheckInterval, $CommunityString, $LogEnabled)
import-module OperationsManager

if (![Reflection.Assembly]::LoadWithPartialName("SharpSnmpLib"))
{
Write-Error "Missing Lextm.SharpSnmpLib Assembly; is it installed?"
return
}

$logDirectory = "DellDeviceReachability_Logs"
$TempFolder = $env:SystemRoot + "\Temp"
$LogLocation = $TempFolder + "\" + $logDirectory + "\"
$scriptname = "WSMAN-SNMP-DRAC-Interface-Check"
$TimeOut = 3000
[int]$Success= 0
[int]$Failure= 0
[int]$SNMPsuccess=0
[int]$SNMPfailure=0
$OID = ".1.3.6.1.2.1.1.2.0"
[string]$loop = "true"

$SNMPDevices = get-scomclass -Displayname "Network Device" | get-scomclassinstance
$SNMPDeviceList = $SNMPDevices | select DisplayName,@{Label="SNMPAddress";Expression={$_.'[System.NetworkManagement.Node].SNMPAddress'}},@{Label="SNMPPORT";Expression={$_.'[System.NetworkManagement.Node].PortNumber'}},@{Label="SNMPVersion";Expression={$_.'[System.NetworkManagement.Node].SNMPVersion'}}
$SNMPDevice = $SNMPDeviceList | Where-Object {$_.SNMPAddress.Value -eq $IP}
$SNMPVersion = $SNMPDevice.SNMPVersion.Value
$SNMPPortNumber = $SNMPDevice.SNMPPORT.Value


if($LogEnabled -eq "True")
{
If(!(Test-Path -path($TempFolder)))
{
# create the directory if not present
$obj = New-Item $TempFolder -type directory
}

If(!(Test-Path -path($LogLocation)))
{
# create the directory if not present
$obj = New-Item $LogLocation -type directory
}

$Global:LogFileLocation = $LogLocation + $scriptname + ".log"
If(!(Test-Path -path($LogFileLocation)))
{
# create the file if it does not exist
$obj = New-Item $LogFileLocation -type file
}

Else
{
$logFileSize = Get-ChildItem $LogFileLocation | ForEach-Object {($_.Length/1KB)}

If ($logFileSize -gt 512)
{
# existingLogFile is greater than 512 KB
$archiveTime = Get-Date -f "yyyy-MM-dd_HH.mm"
Rename-Item $LogFileLocation ("ArchivedLog_" + $scriptname + "_" + $archiveTime + ".log")
$obj = New-Item $LogFileLocation -type file
}
}
}


Function psDebugLog
{
param($message)
if($LogEnabled -eq "True")
{
$currentTime = Get-Date -f "yyyy-MM-dd_HH.mm.ss"
Out-File -FilePath $LogFileLocation -InputObject ($currentTime + " Machine IpAddress " + $IP + " :: " + $message) -Append
}
}

Function Invoke-SNMPget ($IP, $OID, [string]$CommunityString, [int]$SNMPPortNumber, [string]$SNMPVersion, [int]$TimeOut=3000)
{
# $OIDs can be a single OID string, or an array of OID strings
# $TimeOut is in msec, 0 or -1 for infinite
# $vList = New-GenericObject System.Collections.Generic.List Lextm.SharpSnmpLib.Variable # PowerShell v1 and v2

$vList = New-Object System.Collections.Generic.List[Lextm.SharpSnmpLib.Variable] # PowerShell v3

$oid = New-Object Lextm.SharpSnmpLib.ObjectIdentifier ($OID)
$vList.Add($oid)

# Create endpoint for SNMP server
$ip = [System.Net.IPAddress]::Parse($IP)

$svr = New-Object System.Net.IpEndPoint ($ip, $SNMPPortNumber)

# Use SNMP v1 or v2
if($SNMPVersion -eq "1")
{
$ver = [Lextm.SharpSnmpLib.VersionCode]::V1
psDebugLog -message " ----SNMP V1 version";
}

ElseIf ($SNMPVersion -eq "2")
{
$ver = [Lextm.SharpSnmpLib.VersionCode]::V2
psDebugLog -message " ----SNMP V2 version";
}



# Perform SNMP Get
try {

$msg = [Lextm.SharpSnmpLib.Messaging.Messenger]::Get($ver, $svr, $CommunityString, $vList, $TimeOut)

}

catch {
$ErrorMessage = $_.Exception.Message
psDebugLog -message ("SNMP Get error in interface check task ---- " + " Exception-Message:" + $ErrorMessage)
Return $null
}

$msg | select Data
}
[int]$delay = ([int]$CheckInterval * 60)
[int]$TimePeriodCheck = ([int]$TimePeriodToCheck * 60)
$script:StopWatch = [System.diagnostics.stopwatch]::StartNew()
[int]$Attempt = 0

try
{
while ($script:StopWatch.Elapsed.TotalSeconds -le $TimePeriodCheck)
{


$Attempt++
psDebugLog -message "---- Testing connection with device ----- Attempt number: $Attempt -----";
$PingResult = Test-Connection $IP -count 1 -quiet


if($PingResult)
{

$Success++
psDebugLog -message "---- Device connection successfull ----- Success attempt number: $Success -----";
psDebugLog -message " ----SNMP command execution starting.";
$SNMPReply=$null

$SNMPReply = Invoke-SNMPget $IP $OID $CommunityString $SNMPPortNumber $SNMPVersion $TimeOut
# psDebugLog -message " ----SNMP command Executed. IP $IP OID $OID CommunityString $CommunityString SNMPPortNumber $SNMPPortNumber "
psDebugLog -message " ----SNMP command Executed.";
if(!$CommunityString) {
psDebugLog -message "SNMP interface check failed as Run As Configuration Profiles 'SNMP Monitoring Account' is not associated with 'Run As Account'."
}

if($SNMPReply -ne $null)
{
$SNMPsuccess++
psDebugLog -message " ----SNMP positive response received ----- Success attempt number: $SNMPsuccess -----"
}

else
{
$SNMPfailure++
psDebugLog -message " ----SNMP positive response not received. ----- Failure attempt number: $SNMPfailure -----"
}
}

else
{
$Failure++
psDebugLog -message " ----Test connection failure occured with device."
}

psDebugLog -message " ----Going on wait for $delay seconds."
Start-Sleep -Seconds $delay

[int]$Elaspedtime = [int]$StopWatch.Elapsed.TotalSeconds
psDebugLog -message " ---Total elapsed time is $Elaspedtime seconds"
psDebugLog -message " ----------------------------------------Waiting time over for $delay seconds, starting for next cycle of interface connection check ---------------------------------------"

}
}

catch
{
$failure++
$ErrorMessage = $_.Exception.Message
psDebugLog -message ("Exception in interface check task ---- " + " Exception-Message:" + $ErrorMessage)
}
psDebugLog -message ("Node interface check completed publishing results on Task Output.")
Write-Host "Reachability Check: Attempted "$Attempt" times, Success "$Success" times, Failure "$Failure" times"
Write-Host "SNMP Interface Check: Attempted "$Success" times, Success "$SNMPsuccess" times, Failure "$SNMPfailure" times"
if(!$CommunityString) {
Write-Host "SNMP interface check failed as Run As Configuration Profiles 'SNMP Monitoring Account' is not associated with Run As Account."
}
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>IP</Name>
<Value>$Config/IP$</Value>
</Parameter>
<Parameter>
<Name>TimeoutSeconds</Name>
<Value>$Config/TimeoutSeconds$</Value>
</Parameter>
<Parameter>
<Name>TimePeriodToCheck</Name>
<Value>$Config/TimePeriodToCheck$</Value>
</Parameter>
<Parameter>
<Name>CheckInterval</Name>
<Value>$Config/CheckInterval$</Value>
</Parameter>
<Parameter>
<Name>CommunityString</Name>
<Value>$Config/CommunityString$</Value>
</Parameter>
<Parameter>
<Name>LogEnabled</Name>
<Value>$Config/LogEnabled$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PA"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Windows!Microsoft.Windows.SerializedObjectData</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>