Can we add node (snmp v3 ) using java ?
I added discovery to the java sample: https://github.com/solarwinds/OrionSDK/commit/e370abdf84c46c74457e69ae18cfd0ab48b0475b
Don't be intimidated by the size of the diff - most of it is just model classes for various discovery configuration objects. The actual logic involved is small.
This is a port of the powershell sample for the same task: https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/DiscoverSnmpV3Node.ps1
Thank you for your kind help..!!
Using Power shell (Link above you share)
Error :
Import-Module : The specified module 'SwisPowerShell' was not loaded because no valid module file was found in any module directory.
+ Import-Module SwisPowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (SwisPowerShell:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Connect-Swis : The term 'Connect-Swis' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At C:\MSCI\Inventory_Sources\NodeAddition_Linux.ps1:21 char:10
+ $swis = Connect-Swis $OrionServer -UserName $Username -Password $Password
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-Swis:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Kind regards,
Aftab
See this page for background on how to work with SWIS from PowerShell: PowerShell · solarwinds/OrionSDK Wiki · GitHub
In short, you need to run Install-Module -Name SwisPowerShell to get that script to work.
Hi tdanner,
Everything is working as expected.... Thanks !!
One error we are getting that is :
SwisPowerShell was not loaded because no valid module file was found ?
Can you please help ? if mssing how to downaload and from where to download ?
Thank you for help.
Hi,
One more help please.
We are planning to add bulk device best possible way to this ? Preferred viascripting.
Please guide as we are new to Powershell.
This page has instructions for setting up Install-Module on various versions of PowerShell: https://docs.microsoft.com/en-us/powershell/gallery/installing-psget
Finally its woirking....!!
Thank you sir.
This script is working well. One further question.
Is it possible to set some filters for volumes and interfaces?
I'm not sure if there are some XML-Tags for that.
Greetings
Domi
Best way to learn and understand the XML is to build a discovery with the settings you want in the GUI, and then look at the database table called discoveryprofile and there is a configuration column there with all the XML that defines the discovery. Make changes in the GUI then observe how those changes affect the settings in the DB so you can make those same edits with your scripts.
When doing a discovery via API, you can definitely use filters for interfaces (not sure about volumes though). We do this with Python, and here is an example (look for interfacesPluginContext, where you'll see various interface filters (AutoImportExpressionFilter). We found that basically anything you can do on that screen (Status, Port Mode, Hardware, Advanced filters) can all be accomplished inside the interfacesPluginContext.
Python example (look for my post on Nov 16, 2017): Re: Node Resource Discovery Via JSON API
This link documents how the Interfaces Plugin Configuration works specifically when using PowerShell for API discovery: Discovery · solarwinds/OrionSDK Wiki · GitHub
Thanks, I'll try.
I searched with SWQL Studio for the attribute but it looks like there is no xml stored. Instead I found some columns e.g. in Orion.DiscoveryProfiles which contains the data I searched for.
So I have still the problem that i dont know which attributes are valid for the xml
I should have been more specific, you have to check the actual sql database, for some reason the discovery config doesn't show up in swql.
I was able to find my example discover in the database. The information matches also with the python script from clarv02 (Re: Node Resource Discovery Via JSON API ).
But I'm still not sure about the syntax.
Web GUI:
Database Output of Web GUI Discover:
...
<DiscoveryPluginConfigurationBase xmlns:d2p1="http://schemas.solarwinds.com/2008/Interfaces" i:type="d2p1:InterfacesDiscoveryPluginConfiguration">
<d2p1:AutoImportExpressionFilter xmlns:d3p1="http://schemas.datacontract.org/2004/07/">
<d3p1:InterfaceFiltering.Expression>
<d3p1:Op>regex</d3p1:Op>
<d3p1:Prop>name</d3p1:Prop>
<d3p1:Val>%28%5Eeth%29%7C%28%5Eens%29%7C%28%5Eeno%29</d3p1:Val>
</d3p1:InterfaceFiltering.Expression>
</d2p1:AutoImportExpressionFilter>
<d2p1:AutoImportStatus xmlns:d3p1="http://schemas.datacontract.org/2004/07/SolarWinds.Interfaces.Common.Enums">
<d3p1:IfAutoImportStatus>Up</d3p1:IfAutoImportStatus>
</d2p1:AutoImportStatus>
<d2p1:AutoImportVirtualTypes xmlns:d3p1="http://schemas.datacontract.org/2004/07/System">
<d3p1:boolean>false</d3p1:boolean>
<d3p1:boolean>true</d3p1:boolean>
<d3p1:boolean i:nil="true" />
</d2p1:AutoImportVirtualTypes>
<d2p1:AutoImportVlanPortTypes xmlns:d3p1="http://schemas.datacontract.org/2004/07/SolarWinds.Orion.Core.Models.Enums">
<d3p1:VlanPortType>Trunk</d3p1:VlanPortType>
<d3p1:VlanPortType>Access</d3p1:VlanPortType>
</d2p1:AutoImportVlanPortTypes>
<d2p1:DiscoverVLANs>false</d2p1:DiscoverVLANs>
</DiscoveryPluginConfigurationBase>
Do I have to change the XML tags?
<d3p1:Op>regex</d3p1:Op> --> <Op>regex</Op>
And Do I have to change the Value for regax back '(^eth)|(^ens)|(^eno)'?
I tested this format but it ignores the interface filter and import all interfaces:
$InterfacesPluginConfigurationContext = ([xml]"
<InterfacesDiscoveryPluginContext xmlns='http://schemas.solarwinds.com/2008/Interfaces'
xmlns:a='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>
<AutoImportExpressionFilter xmlns='http://schemas.datacontract.org/2004/07/'>
<InterfaceFiltering.Expression>
<Op>regex</Op>
<Prop>name</Prop>
<Val>'^ens'</Val>
</InterfaceFiltering.Expression>
</AutoImportExpressionFilter>
<AutoImportStatus>
<a:string>Up</a:string>
<a:string>Down</a:string>
<a:string>Shutdown</a:string>
</AutoImportStatus>
Do I have to change the XML tags?<d3p1:Op>regex</d3p1:Op> --> <Op>regex</Op>
Those d3p1 prefixes are XML Namespaces. I don't think you'll need to keep those.
The regular expression looks like it has been encoded with URL encoding rules (HTML URL Encoding Reference). For example, the initial left parenthesis character has been replaced with %28. It's not immediately clear to me whether you need to preserve that encoding or whether that is something that happens just when it's being stored in the database.
Working with this in Python using JSON structures removes some of the complexities of dealing with XML formatting: Python AutoImportExpressionFilter
If you can post a full PowerShell script with what you are trying to do, that might help with troubleshooting it.
Hi, I need a script which adds a device automatically.
These devices are all linux vms with same snmpV3 credentials.
I want to add them and auto import:
Therefore I got this script, which import a device but ignores the filters (search for XML-tags 'AutoImportExpressionFilter' and 'AutoImportVoulemeType') for interfaces and volumes. So the node is added with all volumes and interfaces.
For testing purposes the filter for interface name is just 'eth', later I would change the regex value.
Param( [Parameter(Mandatory=$true)][string]$IP, [Parameter(Mandatory=$true)][string]$SNMPCredentialSet, [Parameter(Mandatory=$true)][string]$Poller)function Write-Log{ Param( [Parameter(Mandatory=$false)][ValidateSet("INFO", "WARN", "ERROR")][string]$Level = "INFO", [Parameter(Mandatory=$true)][string]$Message ) Write "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") [$Level] : $Message"}$ErrorActionPreference = "Stop"#Import SWIS moduletry{ Import-Module SWISPowerShell}catch{throw "SWISPowershell module could not be loaded successfully."}#Establish SWIS connectiontry{ $OrionServer = "<orion_url>" $Username = "<orion_user>" $Password = ConvertTo-SecureString -AsPlainText -Force -String '<orion_password>' $Credential = New-Object -typename System.Management.Automation.PSCredential -argumentlist $Username, $Password $SwisConnection = Connect-Swis $OrionServer -Credential $Credential Write-Log -Level INFO -Message "SWIS connection to $OrionServer established."}catch{ throw "SWIS connection to $OrionServer could not be established."}#Get stored snmp credentialsettry{ $SNMPCredentialID = Get-SwisData $SwisConnection "SELECT ID FROM Orion.Credential WHERE Name=@name" @{name = $SNMPCredentialSet} Write-Log -Level INFO -Message "SNMP credential ID: $SNMPCredentialID"}catch{ throw "Could not find credentialset '$SNMPCredentialSet'."}#Get EngineIDtry{ $EngineID = Get-SwisData $SwisConnection "SELECT EngineID FROM Orion.Engines WHERE ServerName=@servername" @{servername = $Poller} Write-Log -Level INFO -Message "EngineID of '$Poller': $EngineID"}catch{ throw "Could not find EngineID of '$Poller'"}$DeleteProfileAfterDiscoveryCompletes = "true"#Define CorePluginConfiguration$CorePluginConfigurationContext = ([xml]"<CorePluginConfigurationContext xmlns='schemas.solarwinds.com/.../Core' xmlns:i='www.w3.org/.../XMLSchema-instance'> <AutoImportVolumeTypes xmlns:d3p1='schemas.datacontract.org/.../SolarWinds.Common.Snmp'><VolumeType>FixedDisk</VolumeType><VolumeType>MountPoint</VolumeType></AutoImportVolumeTypes> <BulkList> <IpAddress> <Address>$IP</Address> </IpAddress> </BulkList> <Credentials> <SharedCredentialInfo> <CredentialID>$SNMPCredentialID</CredentialID> <Order>1</Order> </SharedCredentialInfo> </Credentials> <WmiRetriesCount>1</WmiRetriesCount> <WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds></CorePluginConfigurationContext>").DocumentElement$CorePluginConfiguration = Invoke-SwisVerb $SwisConnection Orion.Discovery CreateCorePluginConfiguration @($CorePluginConfigurationContext)#Define InterfacePluginConfiguration$InterfacesPluginConfigurationContext = ([xml]"<InterfacesDiscoveryPluginContext xmlns='schemas.solarwinds.com/.../Interfaces' xmlns:a='schemas.microsoft.com/.../Arrays'> <AutoImportExpressionFilter xmlns='schemas.datacontract.org/.../'> <InterfaceFiltering.Expression><Op>regex</Op><Prop>name</Prop><Val>%5Eeth</Val></InterfaceFiltering.Expression>cvbcdfg</AutoImportExpressionFilter> <AutoImportStatus> <a:string>Up</a:string> <a:string>Down</a:string> <a:string>Shutdown</a:string> </AutoImportStatus> <AutoImportVirtualTypes> <a:string>Virtual</a:string> <a:string>Physical</a:string> </AutoImportVirtualTypes> <AutoImportVlanPortTypes> <a:string>Trunk</a:string> <a:string>Access</a:string> <a:string>Unknown</a:string> </AutoImportVlanPortTypes> <UseDefaults>false</UseDefaults></InterfacesDiscoveryPluginContext>").DocumentElement$InterfacesPluginConfiguration = Invoke-SwisVerb $SwisConnection Orion.NPM.Interfaces CreateInterfacesPluginConfiguration @($InterfacesPluginConfigurationContext)#>#Build Discovery$StartDiscoveryContext = ([xml]"<StartDiscoveryContext xmlns='schemas.solarwinds.com/.../Core' xmlns:i='www.w3.org/.../XMLSchema-instance'> <Name>Linux Script Discovery for '$IP' at $([DateTime]::Now)</Name> <EngineId>$EngineID</EngineId> <JobTimeoutSeconds>3600</JobTimeoutSeconds> <SearchTimeoutMiliseconds>2000</SearchTimeoutMiliseconds> <SnmpTimeoutMiliseconds>2000</SnmpTimeoutMiliseconds> <SnmpRetries>1</SnmpRetries> <RepeatIntervalMiliseconds>1500</RepeatIntervalMiliseconds> <SnmpPort>161</SnmpPort> <HopCount>0</HopCount> <PreferredSnmpVersion>SNMP2c</PreferredSnmpVersion> <DisableIcmp>true</DisableIcmp> <AllowDuplicateNodes>false</AllowDuplicateNodes> <IsAutoImport>true</IsAutoImport> <IsHidden>$DeleteProfileAfterDiscoveryCompletes</IsHidden> <PluginConfigurations> <PluginConfiguration> <PluginConfigurationItem>$($CorePluginConfiguration.InnerXml)</PluginConfigurationItem> <PluginConfigurationItem>$($InterfacesPluginConfiguration.InnerXml)</PluginConfigurationItem> </PluginConfiguration> </PluginConfigurations></StartDiscoveryContext>").DocumentElement#Start Discovery$DiscoveryProfileID = (Invoke-SwisVerb $SwisConnection Orion.Discovery StartDiscovery @($StartDiscoveryContext)).InnerText# Wait until the discovery completesdo { Write-Host -NoNewline "." Start-Sleep -Seconds 1 $Status = Get-SwisData $SwisConnection "SELECT Status FROM Orion.DiscoveryProfiles WHERE ProfileID = @profileId" @{profileId = $DiscoveryProfileID}} while ($Status -eq 1)# If $DeleteProfileAfterDiscoveryCompletes is true, then the profile will be gone at this point, but we can still get the result from Orion.DiscoveryLogs$Result = Get-SwisData $SwisConnection "SELECT Result, ResultDescription, ErrorMessage, BatchID FROM Orion.DiscoveryLogs WHERE ProfileID = @profileId" @{profileId = $DiscoveryProfileID}# Print the outcomeswitch ($Result.Result) { 0 {"Unknown"} 1 {"InProgress"} 2 {"Finished"} 3 {"Error"} 4 {"NotScheduled"} 5 {"Scheduled"} 6 {"NotCompleted"} 7 {"Canceling"} 8 {"ReadyForImport"}}$Result.ResultDescription$Result.ErrorMessageif ($Result.Result -eq 2) { # if discovery completed successfully # Find out what objects were discovered $Discovered = Get-SwisData $SwisConnection "SELECT EntityType, DisplayName, NetObjectID FROM Orion.DiscoveryLogItems WHERE BatchID = @batchId" @{batchId = $Result.BatchID} "$($Discovered.Count) items imported." $Discovered}
other option would be I create a 'discover template' where I just change the list of IPs. But i couldnt find a change discovery profile methode in SWIS.