Folks;
Triggering discovery of SNMPV2 device through JSON API:
Hats off to tdanner for this, I've modified it to suit my needs, and verified that it works.
You will need to make your own modifications as necessary.
Be advised it returns right away, and the only way to tell if the discovery worked is to query for the node some time later (not sure how much later), and if the node does not exist, then clearly discovery did not work. For now, rinse and repeat as necessary with your own iterative process...
Testing:
I have verified this works with a single IP, but I have not tested whether or not it works with a network range.
Perl 5.10 on Redhat 6.5 and 5.18.2 for OSX Yosemite test just fine.
Disclaimer:
No warranty expressed or implied. Use at your own risk. Your mileage may vary. Fasten Seat Belts. Objects in code may be larger than they appear. Use in a well ventilated area of over 1,000 square meters. Should code ignite, treat it as one would burning metals.
--begin code--
sub orion_DiscoverSNMPv2Device() {
my ($self,$ManagementIP,$Region,$snmpCommunityString,$engineID) = @_;
#my $ManagementIP = $self->get_RemedyManagementIP($self->{RemedyDevice});
my @Results = ();
if ( $ipAddress ne "" ) {
my $SWQuery = sprintf("select NodeID, NodeName, IPAddress from Orion.Nodes where NodeName = '%s' OR NodeName like '%s.%%';", $self->{RemedyDevice}->{raw}->{DeviceName},$self->{RemedyDevice}->{raw}->{DeviceName});
my @Results = $self->orion_Query($SWQuery,$self->{engineconfig}->{OrionConfig}->{"$Region"});
my $NodeID = undef;
if ( @Results == 0 ) {
printf("We do not have this node within solar winds... I shall add it for you.\n");
if ( $engineID eq "" ) {
$engineID = 1;
}
if ($snmpCommunityString eq "") {
$snmpCommunityString = $self->{RemedyDevice}->{normalized}->{ROv2SNMPCommunityString};
}
my $discoveryProfileXml = <<"END";
<PluginItems xmlns="http://schemas.datacontract.org/2004/07/SolarWinds.Orion.Core.Models.Discovery">
<knownTypes>
<ArrayOfstring xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<string>SolarWinds.Orion.Core.Models.Discovery.CoreDiscoveryPluginConfiguration,SolarWinds.Orion.Core.Models</string>
</ArrayOfstring>
</knownTypes>
<pluginItem>
<ArrayOfDiscoveryPluginConfigurationBase xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<DiscoveryPluginConfigurationBase i:type="d2p1:CoreDiscoveryPluginConfiguration" xmlns:d2p1="http://schemas.solarwinds.com/2008/Orion">
<d2p1:AddressRange/>
<d2p1:AgentsAddresses xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<d2p1:BulkList xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d3p1:string>$ipAddress</d3p1:string>
</d2p1:BulkList>
<d2p1:Credentials>
<d2p1:credentials>
<knownTypes>
<ArrayOfstring xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<string>SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV2,SolarWinds.Orion.Core.Models</string>
</ArrayOfstring>
</knownTypes>
<pluginItem>
<d2p1:ArrayOfCredential>
<d2p1:Credential i:type="d2p1:SnmpCredentialsV2">
<d2p1:Description i:nil="true"/>
<d2p1:ID i:nil="true"/>
<d2p1:IsBroken>false</d2p1:IsBroken>
<d2p1:Name>mud</d2p1:Name>
<d2p1:Owner i:nil="true"/>
<d2p1:Community>$snmpCommunityString</d2p1:Community>
</d2p1:Credential>
</d2p1:ArrayOfCredential>
</pluginItem>
</d2p1:credentials>
</d2p1:Credentials>
<d2p1:DiscoverAgentNodes>false</d2p1:DiscoverAgentNodes>
<d2p1:SharedCredentials xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<d2p1:SubnetList/>
<d2p1:WmiRetries>1</d2p1:WmiRetries>
<d2p1:WmiRetryInterval>PT10S</d2p1:WmiRetryInterval>
</DiscoveryPluginConfigurationBase>
</ArrayOfDiscoveryPluginConfigurationBase>
</pluginItem>
</PluginItems>
END
my @pluginConfigurationItems = ({ PluginConfigurationItem => "$discoveryProfileXml" });
my %startDiscoveryConfiguration = (
Name => 'json discovery test' ,
EngineID => $engineID,
JobTimeoutSeconds => 3600,
SearchTimeoutMiliseconds => 2000,
SnmpTimeoutMiliseconds => 3000,
SnmpRetries => 1,
RepeatIntervalMiliseconds => 1800,
SnmpPort => 161,
HopCount => 0,
PreferredSnmpVersion => 'SNMP2c',
DisableIcmp => 0,
AllowDuplicateNodes => 0,
IsAutoImport => 1,
IsHidden => 1,
PluginConfigurations => \@pluginConfigurationItems
);
my @verbArguments = (\%startDiscoveryConfiguration);
my $SWServer = $self->{engineconfig}->{OrionConfig}->{"$Region"};
my $swhostname = $SWServer->{OrionServer}; # fill in a hostname
my $swport = $SWServer->{JSONPort};
my $swprotocol = $SWServer->{Protocol};
my $SWCredentials = $self->get_credentials($SWServer->{CredentialSetName});
my $username = $SWCredentials->{username};
my $password = $self->decrypt_password($SWCredentials->{password});
my $uri = "https://$swhostname:$swport/SolarWinds/InformationService/v3/Json/Invoke/Orion.Discovery/StartDiscovery";
my $rest = REST::Client->new();
$rest->getUseragent()->proxy(['https']);
$rest->getUseragent()->ssl_opts(verify_hostname => 0);
my $headers = {
Authorization => 'Basic ' . MIME::Base64::encode_base64($username . ':' . $password),
'Content-Type' => 'application/json'
};
my $json = JSON->new->allow_nonref->utf8;
my $json_text = $json->space_after->encode(\@verbArguments);
#print "$json_text\n";
my $response = $rest->POST($uri, $json_text, $headers);
return($response);
#sleep(1);
}
} else {
return(undef);
}
}
--end code--