cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 9

How to modify a discovered device properties like snmpv3 credentials using REST API

Jump to solution

Hi,

Can anyone advised how to modify a network device snmpv3 credentials to assign it to a new profile using REST API?

 

Thanks,

Jinqiang

0 Kudos
2 Solutions
Level 14

Hi Jinqaing,

Have a look at the examples scripts provided on the Orion SDK GitHub repository, as they just what you are looking for.

Here is the Powershell version, but other language examples are also provided:

https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/ChangeSNMPVersion.ps1 

 

You first "get" the device's details, then update the required fields and post the back to the API.

This script could easily be adapted to extract a list of devices and a ForEach loop through them.

 

I hope it helps!

yaquaholic

View solution in original post

I used this script before to make the change by running a discovery with my snmpv3 creds against all my nodes that i needed to change, that way I could confirm that my creds were good before i cut anything over.  For anything that had a v3 match it switched it over

 

# load the snappin if it's not already loaded (step 1)
if (!(Get-PSSnapin | Where-Object { $_.Name -eq "SwisSnapin" })) {
    Add-PSSnapin "SwisSnapin"
}

#####-----------------------------------------------------------------------------------------#####  
  
#region Functions  
  
# Create a function to connect to the SolarWinds Information Service (SWIS)  
Function Set-SwisConnection {  
      
    Param(  
        [ Parameter( Mandatory = $true, HelpMessage = "What SolarWinds server are you connecting to (Hostname or IP)?" ) ] [ string ] $SolarWindsServer,  
        [ Parameter( Mandatory = $true, HelpMessage = "Do you want to use the credentials from PowerShell (Trusted), or a new login (Explicit)?" ) ] [ ValidateSet( 'Trusted', 'Explicit' ) ] [ string ] $ConnectionType  
    )  
    # Connect to SWIS  
    IF ( $ConnectionType -eq 'Trusted'  ) {  
        $swis = Connect-Swis -Trusted -Hostname $SolarWindsServer  
    }  
    ELSE {  
        $creds = Get-Credential -Message "Please provide a Domain or Local Login for SolarWinds"  
        $swis = Connect-Swis -Credential $creds -Hostname $SolarWindsServer  
    }  
RETURN $swis  
}  

#endregion Functions  
  
#####-----------------------------------------------------------------------------------------#####  

#region Variables  
  
# Connect to SWIS  
$hostname = Read-Host -Prompt "Hostname or IP Address of your SolarWinds server"  
$swis = Set-SwisConnection -SolarWindsServer $hostname -ConnectionType Explicit  


#endregion Variables  
  
#####-----------------------------------------------------------------------------------------#####  

#region Execution  

"Updating SNMPv2 nodes to use SNMPv3"

Invoke-SwisVerb $swis 'Orion.Reporting' 'ExecuteSQL' @"
update n set n.snmpversion = disc.newversion
--select n.caption, n.snmpversion, disc.newversion
from nodes n
join
(select n.nodeid, n.caption, n.ip_address, n.objectsubtype, n.snmpversion, n.engineid, dn.profileid, dn.snmpversion as newversion, dn.subtype, dn.credentialid  
from nodes n
join discoverednodes dn on dn.ipaddress=n.ip_address
where n.objectsubtype != 'WMI'
and dn.snmpversion = 3
) disc on n.nodeid=disc.nodeid
;
insert into nodesettings (nodeid, settingname, settingvalue)
select n.nodeid, 'ROSNMPCredentialID', dn.credentialid
from nodes n
join discoverednodes dn on dn.ipaddress=n.ip_address
where n.objectsubtype != 'WMI'
and n.snmpversion = 2 and dn.snmpversion = 3
"@@
- Marc Netterfield, Github

View solution in original post

3 Replies

I used this script before to make the change by running a discovery with my snmpv3 creds against all my nodes that i needed to change, that way I could confirm that my creds were good before i cut anything over.  For anything that had a v3 match it switched it over

 

# load the snappin if it's not already loaded (step 1)
if (!(Get-PSSnapin | Where-Object { $_.Name -eq "SwisSnapin" })) {
    Add-PSSnapin "SwisSnapin"
}

#####-----------------------------------------------------------------------------------------#####  
  
#region Functions  
  
# Create a function to connect to the SolarWinds Information Service (SWIS)  
Function Set-SwisConnection {  
      
    Param(  
        [ Parameter( Mandatory = $true, HelpMessage = "What SolarWinds server are you connecting to (Hostname or IP)?" ) ] [ string ] $SolarWindsServer,  
        [ Parameter( Mandatory = $true, HelpMessage = "Do you want to use the credentials from PowerShell (Trusted), or a new login (Explicit)?" ) ] [ ValidateSet( 'Trusted', 'Explicit' ) ] [ string ] $ConnectionType  
    )  
    # Connect to SWIS  
    IF ( $ConnectionType -eq 'Trusted'  ) {  
        $swis = Connect-Swis -Trusted -Hostname $SolarWindsServer  
    }  
    ELSE {  
        $creds = Get-Credential -Message "Please provide a Domain or Local Login for SolarWinds"  
        $swis = Connect-Swis -Credential $creds -Hostname $SolarWindsServer  
    }  
RETURN $swis  
}  

#endregion Functions  
  
#####-----------------------------------------------------------------------------------------#####  

#region Variables  
  
# Connect to SWIS  
$hostname = Read-Host -Prompt "Hostname or IP Address of your SolarWinds server"  
$swis = Set-SwisConnection -SolarWindsServer $hostname -ConnectionType Explicit  


#endregion Variables  
  
#####-----------------------------------------------------------------------------------------#####  

#region Execution  

"Updating SNMPv2 nodes to use SNMPv3"

Invoke-SwisVerb $swis 'Orion.Reporting' 'ExecuteSQL' @"
update n set n.snmpversion = disc.newversion
--select n.caption, n.snmpversion, disc.newversion
from nodes n
join
(select n.nodeid, n.caption, n.ip_address, n.objectsubtype, n.snmpversion, n.engineid, dn.profileid, dn.snmpversion as newversion, dn.subtype, dn.credentialid  
from nodes n
join discoverednodes dn on dn.ipaddress=n.ip_address
where n.objectsubtype != 'WMI'
and dn.snmpversion = 3
) disc on n.nodeid=disc.nodeid
;
insert into nodesettings (nodeid, settingname, settingvalue)
select n.nodeid, 'ROSNMPCredentialID', dn.credentialid
from nodes n
join discoverednodes dn on dn.ipaddress=n.ip_address
where n.objectsubtype != 'WMI'
and n.snmpversion = 2 and dn.snmpversion = 3
"@@
- Marc Netterfield, Github

View solution in original post

Level 14

Hi Jinqaing,

Have a look at the examples scripts provided on the Orion SDK GitHub repository, as they just what you are looking for.

Here is the Powershell version, but other language examples are also provided:

https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/ChangeSNMPVersion.ps1 

 

You first "get" the device's details, then update the required fields and post the back to the API.

This script could easily be adapted to extract a list of devices and a ForEach loop through them.

 

I hope it helps!

yaquaholic

View solution in original post

MVP
MVP

You update the NCM node's ConnectionProfileID but as I write that I don't know where that list of connection profiles comes from. I'm asking Ana who wrote this example for SolarWinds' repository. In the meantime, here it is:

https://github.com/solarwinds/OrionSDK/blob/master/Samples/Go/NCMProfile/main.go