Device Server-Side Inbound Kb Powershell Probe

AP.F5.Probe.Device.ServerSideInboundKb.Powershell (ProbeActionModuleType)

Gets Device Server-Side Inbound Kb as Property Bags

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
PSScript ProbeAction Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Debugbool$Config/Debug$DebugDebug Flag, if true then additional info is posted to event log.

Source Code:

<ProbeActionModuleType ID="AP.F5.Probe.Device.ServerSideInboundKb.Powershell" Accessibility="Public" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Debug" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DeviceAddress" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DevicePort" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DeviceCommunity" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Debug" Selector="$Config/Debug$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PSScript" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>Get-DeviceServerSideInboundKb.ps1</ScriptName>
<ScriptBody><Script>#==================================================================================
# Script: Get-DeviceServerSideInboundKb.ps1
# Date: 11/10/18
# Author: Andi Patrick
# Purpose: Gets Device ServerSide Inbound Kb via SNMP returns as Property Bag
#==================================================================================

# Get the named parameters
param($Debug,$DeviceAddress,$DevicePort,$DeviceCommunity,$SharpSnmpLocation)

# Get Start Time For Script
$StartTime = (GET-DATE)

#Constants used for event logging
$SCRIPT_NAME = 'Get-DeviceServerSideInboundKb.ps1'
$EVENT_LEVEL_ERROR = 1
$VENT_LEVEL_WARNING = 2
$EVENT_LEVEL_INFO = 4

$SCRIPT_STARTED = 4601
$SCRIPT_PROPERTYBAG_CREATED = 4602
$SCRIPT_EVENT = 4603
$SCRIPT_ENDED = 4604
$SCRIPT_ERROR = 4605

#==================================================================================
# Sub: LogDebugEvent
# Purpose: Logs an informational event to the Operations Manager event log
# only if Debug argument is true
#==================================================================================
function Log-DebugEvent
{
param($eventNo,$message)

$message = "`n" + $message
if ($Debug -eq $true)
{
$api.LogScriptEvent($SCRIPT_NAME,$eventNo,$EVENT_LEVEL_INFO,$message)
}
}

#Start by setting up API object.
$api = New-Object -comObject 'MOM.ScriptAPI'

# Log Startup Message
Log-DebugEvent $SCRIPT_STARTED "Script Started."

# Load SharpSNMPLib
[reflection.assembly]::LoadFrom( (Resolve-Path $SharpSnmpLocation) )

# Use SNMP v2
$ver = [Lextm.SharpSnmpLib.VersionCode]::V2

# Set Walk Mode to WithinSubtree
$walkMode = [Lextm.SharpSnmpLib.Messaging.WalkMode]::WithinSubtree

# OIDs used
# bigipTrafficMgmt.bigipSystem.sysGlobals.sysGlobalStats.sysGlobalStat.sysStatServerBytesIn5m
[string]$sysStatServerBytesIn5m = ".1.3.6.1.4.1.3375.2.1.1.2.1.95.0"

Try
{

# Create endpoint for SNMP server
$ip = [System.Net.IPAddress]::Parse($DeviceAddress)
$svr = New-Object System.Net.IpEndPoint ($ip, $DevicePort)

# Create List for SNMP Get
$vList = New-Object 'System.Collections.Generic.List[Lextm.SharpSnmpLib.Variable]'
$oidClient = New-Object Lextm.SharpSnmpLib.ObjectIdentifier ($sysStatServerBytesIn5m)
$vList.Add($oidClient)

Try {
# Get SNMP Results
$results = [Lextm.SharpSnmpLib.Messaging.Messenger]::Get($ver, $svr, $DeviceCommunity, $vList, 3000)
# As Long as we have one result we can continue
if ($Results.Count -gt 0) {
[int]$NetworkBytes = $results[0].Data.ToString()
[int]$NetworkKb = $NetworkBytes / 1024
# Create a property bag.
$bag = $api.CreatePropertyBag()
$bag.AddValue("NetworkKb", [int]$NetworkKb)
[string] $message = "Created Property bag for $DeviceAddress`r`n" + "Server-Side Inbound (Kb): " + $NetworkKb + "`r`n"
Log-DebugEvent $SCRIPT_PROPERTYBAG_CREATED $message
#$api.Return($bag)
$bag
}
} Catch {
$message = "SNMP Server : $DeviceAddress" + "`r`nSNMP Port : " + $DevicePort + "`r`nSNMP Community : " + $DeviceCommunity + "`r`nSharpSnmp Location : " + $SharpSnmpLocation + "`r`nError : $_"
Log-DebugEvent $SCRIPT_ERROR $message
}

}
Catch
{
$message = "SNMP Server : $DeviceAddress" + "`r`nSNMP Port : " + $DevicePort + "`r`nSNMP Community : " + $DeviceCommunity + "`r`nSharpSnmp Location : " + $SharpSnmpLocation + "`r`nError : $_"
Log-DebugEvent $SCRIPT_ERROR $message
}

# Get End Time For Script
$EndTime = (GET-DATE)
$TimeTaken = NEW-TIMESPAN -Start $StartTime -End $EndTime
$Seconds = [math]::Round($TimeTaken.TotalSeconds, 2)
# Log Finished Message
Log-DebugEvent $SCRIPT_ENDED "Script Finished. Took $Seconds Seconds to Complete!"</Script></ScriptBody>
<SnapIns/>
<Parameters>
<Parameter>
<Name>DeviceAddress</Name>
<Value>$Config/DeviceAddress$</Value>
</Parameter>
<Parameter>
<Name>DevicePort</Name>
<Value>$Config/DevicePort$</Value>
</Parameter>
<Parameter>
<Name>DeviceCommunity</Name>
<Value>$Config/DeviceCommunity$</Value>
</Parameter>
<Parameter>
<Name>debug</Name>
<Value>$Config/Debug$</Value>
</Parameter>
<Parameter>
<Name>SharpSnmpLocation</Name>
<Value>$FileResource[Name="AP.F5.SharpSnmpLib"]/Path$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>60</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PSScript"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>