forked from Mesverrum/MyPublicWork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscoveryByScript
105 lines (88 loc) · 4.35 KB
/
DiscoveryByScript
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
# Connect to SWIS
$hostname = "localhost"
$swis = $swis = Connect-Swis -Trusted -Hostname $hostname
$credquery = @"
SELECT id
FROM Orion.Credential
where credentialowner='Orion'
--and credentialtype='SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3'
--Credential Types available
--SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV2
--SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV3
--SolarWinds.Orion.Core.SharedCredentials.Credentials.UsernamePasswordCredential --this is WMI
"@
$DeleteProfileAfterDiscoveryCompletes = "false"
$nodes = get-swisdata $swis "select ip_address, engineid from orion.nodes n where n.vendor = 'Cisco'"
$engines = $nodes.engineid | sort-object | Get-Unique
foreach ($engine in $engines) {
$addresses = $nodes | Where-Object {$_.engineid -eq $engine}
# 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.ip_address)</Address></IpAddress>"
}
$bulklist += "</BulkList>"
$creds = Get-SwisData $swis $credquery
$order = 1
$credentials = "<Credentials>"
foreach ($row in $creds) {
$credentials += "<SharedCredentialInfo><CredentialID>$($row)</CredentialID><Order>$order</Order></SharedCredentialInfo>"
$order ++
}
$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>Scripted Discovery for Engine $engine - $([DateTime]::Now)</Name>
<EngineId>$Engine</EngineId>
<JobTimeoutSeconds>36000</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
$DiscoveryProfileID = (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($StartDiscoveryContext)).InnerText
"Created Scripted Discovery for Engine $engine - $([DateTime]::Now)"
}