For multiple reasons we are using server initiated communication for our agent deployments. As you may aware the Solarwinds API does not support creating nodes as server initiated communication and manipulating the database tables directly does not produce the desired result. The only method supported is through the browser where it appears the javascript on the Solarwinds web page controls portions of the node creation that can't be skipped. Obviously this is a major hindrance if we are going to try to fully automate our environment.
To work around this we created a script that leverages Selenium to automate the node creation. Here is a code snippet that will automate a Chrome browser to log in and manipulate the GUI to add an agent in server initiated communication:
add-type -path "c:\scripts\lib\webdriver.dll"
add-type -path "c:\scripts\lib\WebDriver.Support.dll"
$env:PATH += ";c:\scripts\lib"
$Browser = New-Object "OpenQA.Selenium.Chrome.ChromeDriver"
$seleniumWait = New-Object -TypeName OpenQA.Selenium.Support.UI.WebDriverWait($browser, (New-TimeSpan -seconds 30) )
$browser.navigate().GoToUrl( "http://$SWIShostname)/orion" )
$browser.FindElementById("ctl00_BodyContent_Username").SendKeys($SWISusername)
$browser.FindElementById("ctl00_BodyContent_Password").SendKeys($SWISpassword)
$browser.FindElementByClassName("sw-btn").Click();
$browser.navigate().GoToUrl("http://$SWIShostname)/Orion/AgentManagement/Admin/EditAgent.aspx")
$browser.FindElementById("ctl00_ctl00_ctl00_ctl00_BodyContent_ContentPlaceHolder1_adminContentPlaceholder_adminContentPlaceholder_passiveRadio").click()
$browser.FindElementById("ctl00_ctl00_ctl00_ctl00_BodyContent_ContentPlaceHolder1_adminContentPlaceholder_adminContentPlaceholder_nameBox").SendKeys($nodename)
$browser.FindElementById("ctl00_ctl00_ctl00_ctl00_BodyContent_ContentPlaceHolder1_adminContentPlaceholder_adminContentPlaceholder_passiveAgentHostnameBox").SendKeys($IP)
$Browser.FindElementByClassName("sw-btn-t").click()
start-sleep -seconds 5
if ( $browser.url -like "*EditAgent*") {
#If we're still on the EditAgent page something went wrong and return false
$browser.Quit()
return $false
}
$browser.quit()
return $true
We also encountered similar issues when managing volumes on our nodes. The API does not support discovery of volumes or provide any method of making sure all the volumes under 'List Resources' are selected automatically during node creation. This previously required a manual process for someone to click through the GUI to select these volumes. However we were also able to automate that function as well:
add-type -path "c:\scripts\lib\webdriver.dll"
add-type -path "c:\scripts\lib\WebDriver.Support.dll"
$env:PATH += ";c:\scripts\lib"
$Browser = New-Object "OpenQA.Selenium.Chrome.ChromeDriver"
$seleniumWait = New-Object -TypeName OpenQA.Selenium.Support.UI.WebDriverWait($browser, (New-TimeSpan -seconds 300) )
$browser.navigate().GoToUrl( "http://$SWIShostname)/orion" )
$browser.FindElementById("ctl00_BodyContent_Username").SendKeys($SWISusername)
$browser.FindElementById("ctl00_BodyContent_Password").SendKeys($SWISpassword)
$browser.FindElementByClassName("sw-btn").Click();
start-sleep -seconds 2
$browser.navigate().GoToUrl("http://$SWIShostname)/Orion/Nodes/ListResources.aspx?Nodes=$NodeId")
start-sleep -seconds 5
$browser.navigate().GoToUrl("http://$SWIShostname)/Orion/Nodes/ListResources.aspx?Nodes=$NodeId")
#It takes a while for volumes to be discovered. Wait until the checkbox is visible.
$seleniumWait.Until([OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementIsVisible([OpenQA.Selenium.By]::Xpath("//input[@objecttype='DiscoveredVolumesGroup']")))
$browser.FindElementByXPath("//input[@objecttype='DiscoveredVolumesGroup']").click()
start-sleep -seconds 1
#TODO: Add try/catch if timeout is exceeded
$btn = $browser.FindElementsByClassName("sw-btn") | ?{$_.text -eq "SUBMIT"}
$btn.click()
start-sleep -seconds 5
$browser.quit()
Selenium is an open source browser automation tool that can support multiple browsers and environments. This snippet requires webdriver.dll, webdriver.support.dll, chromedriver.exe and Chrome installed on the machine running the script.
Hopefully this helps with your automation workflow.