forked from Mesverrum/MyPublicWork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscoveryByCSV
118 lines (100 loc) · 4.6 KB
/
DiscoveryByCSV
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<#------------- CONNECT TO SWIS -------------#>
# load the snappin if it's not already loaded (step 1)
if (!(Get-PSSnapin | Where-Object { $_.Name -eq "SwisSnapin" })) {
Add-PSSnapin "SwisSnapin"
}
#define target host and credentials
$hostname = 'localhost'
$user = "user"
$password = "password"
# create a connection to the SolarWinds API
$swis = connect-swis -host $hostname -username $user -password $password -ignoresslerrors
#$swis = Connect-Swis -Hostname $hostname -Trusted
<#------------- ACTUAL SCRIPT -------------#>
# Query to get list of creds in use currently, need to figure out how to automatically embed this directly in the XML
# Import addresses from csv files
$pathtocsv = "D:\Scripts\Discovery\SampleImport.csv"
#$addresses = Get-Content $pathtocsv
# Alternate filters and data checking
# filtered to exclude lines with CIDR notation (/24)
#$addresses = Get-Content $pathtocsv | Select-String '^[^/]*$' | ConvertFrom-Csv -Header Addresses
# subnets includes only lines with / character
#$subnets = Get-Content $pathtocsv | Select-String '^[\s|\S]+[/]+\d+' | ConvertFrom-Csv -Header Addresses
$discoveryName = 'Scripted Discovery'
$autoImport = 'true'
$query = @"
SELECT id
FROM Orion.Credential
where credentialowner='Orion' and credentialtype = 'SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3'
"@
$creds = Get-SwisData $swis $query
# Might need to change this for your environment
$EngineID = 1
$DeleteProfileAfterDiscoveryCompletes = "false"
# build the raw XML first
$header = "<CorePluginConfigurationContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>"
$bulklist = "<BulkList>"
foreach ($address in $addresses) {
$bulklist += "<IpAddress><Address>$($address)</Address></IpAddress>"
}
$bulklist += "</BulkList>"
$order = 0
$credentials = "<Credentials>"
foreach ($row in $creds) {
$order ++
$credentials += "<SharedCredentialInfo><CredentialID>$($row)</CredentialID><Order>$order</Order></SharedCredentialInfo>"
}
$credentials += "</Credentials>"
$footer = @"
<WmiRetriesCount>1</WmiRetriesCount>
<WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds>
</CorePluginConfigurationContext>
"@
$CorePluginConfigurationContext = ([xml]($header + $bulklist + $credentials + $footer)).DocumentElement
$CorePluginConfiguration = Invoke-SwisVerb $swis Orion.Discovery CreateCorePluginConfiguration @($CorePluginConfigurationContext)
$InterfacesPluginConfigurationContext = ([xml]"
<InterfacesDiscoveryPluginContext xmlns='http://schemas.solarwinds.com/2008/Interfaces'
xmlns:a='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>
<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>true</UseDefaults>
</InterfacesDiscoveryPluginContext>
").DocumentElement
$InterfacesPluginConfiguration = Invoke-SwisVerb $swis Orion.NPM.Interfaces CreateInterfacesPluginConfiguration @($InterfacesPluginConfigurationContext)
$StartDiscoveryContext = ([xml]"
<StartDiscoveryContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<Name>$discoveryName $([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>false</DisableIcmp>
<AllowDuplicateNodes>false</AllowDuplicateNodes>
<IsAutoImport>$autoImport</IsAutoImport>
<IsHidden>$DeleteProfileAfterDiscoveryCompletes</IsHidden>
<PluginConfigurations>
<PluginConfiguration>
<PluginConfigurationItem>$($CorePluginConfiguration.InnerXml)</PluginConfigurationItem>
<PluginConfigurationItem>$($InterfacesPluginConfiguration.InnerXml)</PluginConfigurationItem>
</PluginConfiguration>
</PluginConfigurations>
</StartDiscoveryContext>
").DocumentElement
$DiscoveryProfileID = (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($StartDiscoveryContext)).InnerText