I don't like the default polling rates so I have the script below in its simplest form which will set polling and stat collection based on the interface type. The one I actually use has more logic which is based on the device role which I have not included.
[CmdLetBinding()]
param
(
[Parameter(Mandatory =$true, Position =0)]
[string]$OrionApiServer
)
CLS
# Normally this is in a common library, moving to here for readability
functionImport-CustomModule
{
[CmdletBinding()]
param
(
[Parameter(Mandatory =$true, Position =0)]
[string]$ModuleName,
[Parameter(Mandatory =$true, Position =1)]
[string]$ModulePath
)
if(!(Test-Path-Path$ModulePath))
{
Throw("Module path does not exist: {0}"-f$ModulePath)
}
$ModuleInfo=Get-Module-Name$ModuleName
if(!$moduleInfo)
{
Import-Module$ModulePath
}
}
functionProcess-Hostname
{
[CmdletBinding()]
param
(
[Parameter(Mandatory =$true, Position =0)]
[string]$Hostname
)
if($Hostname-match"\.")
{
write-host"Trimming off domain name."
$split=$node.Caption.Split(".")
$hostname=$split[0].ToUpper()
}
if($Hostname-cnotmatch$Hostname.ToUpper())
{
write-host"Making upper case."
$Hostname=$Hostname.ToUpper()
}
return$Hostname
}
if($debug){
$DebugPreference="Continue"
write-host"Debugging enabled"
}
$credential=Get-Credential
$swis=Connect-Swis-Credential$credential-Hostname $OrionApiServer
[string]$nodeQuery="SELECT N.NodeId, N.Caption, N.Uri FROM Orion.Nodes AS N"
$nodes=Get-SwisData-SwisConnection$swis-Query$nodeQuery
# Set ping times based on (InterfaceTypeId, TimeInSeconds)
$pollTimes=New-ObjectSystem.Collections.Specialized.ListDictionary
$pollTimes.Add(6,30) # Physical
$pollTimes.Add(150,30) # MPLS Tunnel
$pollTimes.Add(24,300) # Loopback
$pollTimes.Add(1,3600) # Other
$pollTimes.Add(131,3600) # Encapsulated
$pollTimes.Add(161,30) # Link Agg
$pollTimes.Add(135,3600) # Dot1Q
$pollTimes.Add(53,3600) # Prop Virtual
# Set stat collection time based on (InterfaceTyoeId, TimeInMinutes)
$statTimes=New-ObjectSystem.Collections.Specialized.ListDictionary
$statTimes.Add(6,1) # Physical
$statTimes.Add(150,1) # MPLS Tunnel
$statTimes.Add(24,60) # Loopback
$statTimes.Add(1,1440) # Other
$statTimes.Add(131,1440) # Encapsulated
$statTimes.Add(161,1) # Link Agg
$statTimes.Add(135,1440) # Dot1Q
$statTimes.Add(53,1440) # Prop Virtual
foreach($nodein$nodes)
{
write-host("Processing node: {0}"-f$node.Caption)
# I like the Hostname to use the short name in upper case
[string]$hostname=Process-Hostname-Hostname$node.Caption
# Bydefualt we ping all devices every 30 seconds and collect device stats every minute.
$properties=@{
Caption =$hostname;
PollInterval=30;
StatCollection=1;
}
$setNode=Set-SwisObject-Uri$node.Uri-SwisConnection$swis-Properties$properties
[string]$ifQuery= ("SELECT I.NodeID, I.InterfaceID, I.InterfaceName, I.InterfaceType, I.IfName, I.UnPluggable, I.Uri FROM Orion.NPM.InterfacesAS I WHERE I.NodeId = {0}"-f$node.NodeId)
write-host("Setting Interface: {0}, {1} to Poll={2}, Stat={3}, IfaceID={4}"-f$node.Caption,$interface.IfName,$ifProperties.Item("PollInterval"),$ifProperties.Item("StatCollection"),$interface.InterfaceType)
$interfaces=Get-SwisData-SwisConnection$swis-Query$ifQuery
foreach($interfacein$interfaces)
{
$poll=$pollTimes.Item($interface.InterfaceType)
$stat=$statTimes.Item($interface.InterfaceType)
$ifProperties=@{
PollInterval=$poll;
StatCollection=$stat;
}
Write-Host("Setting Interface: {0}, {1} to Poll={2}, Stat={3}, IfaceID={4}"-f$node.Caption,$interface.IfName,$ifProperties.Item("PollInterval"),$ifProperties.Item("StatCollection"),$interface.InterfaceType)
$setIf=Set-SwisObject-SwisConnection$swis-Uri$interface.Uri-Properties$ifProperties
}
Write-Host""
}