Quantcast
Channel: THWACK: Popular Discussions - Orion SDK
Viewing all 3719 articles
Browse latest View live

Problem with a script to suppress alerts on specified nodes

$
0
0

I am having a problem that I cannot seem to figure out what is going on.  I have a set of 4 scripts that run every night in a schedule task as the System account.  These 4 scripts work exactly the same way.  They generate a list of server from a query and turn on Alert Suppression on those nodes for 10 hours.  The problem is the scripts are randomly failing.  The script that runs at 8pm will be successfully, but the one at 9pm, 10pm, and 11pm will fail.  I have error handling set up in the script but the error that is generated during the Alert Suppression task is "one or more errors occurred"  Can someone point me to the log file that SWIS SDK powershell cmdlets use so I can try and see what the one or more errors are to attempt to fix the problem?  I have added the script that I am using.

 

Function Create-EventSource

{

  param(

    [string]$logfileName,

    [string]$sourceName

  )

 

  If([System.Diagnostics.EventLog]::Exists($logfileName))

    {

        write-output "$logFileName Exists"

        If([System.Diagnostics.EventLog]::SourceExists($sourceName))

        {

 

 

        }

        else

        {

            New-EventLog -LogName $logfilename -Source $sourceName

        }

    }

    else

    {

        $event = "Creating $logfilename EventLog"

        New-EventLog -LogName $logfileName -Source $sourceName

        Limit-EventLog -LogName $logFileName -OverflowAction OverwriteAsNeeded -MaximumSize 50MB

        Write-EventLog -LogName Application -Source OVO -EntryType Information -Category 0 -EventId 200 -Message $event

    }

}

 

 

Function Send-Email

{

    param(

        [string]$body

    )

    $subject = "Script Failed to Connect to SolarWinds"

    $smtpTo = "some email address"

    $smtpFrom = "some other address"

    $smtpServer = "smtp server"

   

    Send-MailMessage -From $smtpFrom -To $smtpTo -Body $body -Subject $subject -SmtpServer $smtpServer

}

 

 

Function Validate-MaintenanceMode

{

    Param(

        [string]$nodeName,

        [string]$uri,

        [object]$swisConnection

    )

 

 

    $tmpquery1 = "select entityuri, suppressfrom, suppressuntil from orion.AlertSuppression where entityuri = '$uri'"

    $AlertSuppressionInfo = Get-SwisData -SwisConnection $swisConnection -Query $tmpQuery1

    If(([string]::IsNullOrEmpty($AlertSuppressionInfo.suppressfrom)) -and ([string]::IsNullOrEmpty($AlertSuppressionInfo.suppressuntil)))

    {

        $IsSet = "No"

    }

    elseif([string]::IsNullOrEmpty($AlertSuppressionInfo.suppressuntil))

    {

        $IsSet = "Manual"

    }

    else

    {

        $IsSet = "Yes"

    }

 

 

    $obj = New-Object PSObject -Property @{

                            NodeName = $nodeName

                            MMStartTime = $AlertSuppressionInfo.suppressfrom

                            MMEndTime = $AlertSuppressionInfo.suppressUntil

                            URI = "$uri"

                            isSet = $IsSet

                       }

    return $obj

}

 

 

 

 

######################### Main #############################################################

 

 

$source = "ArgoMaintenanceModeMountain"

$eventLogMessage = ""

$eventLogName = "EventMonitoring"

 

 

Create-EventSource -logfileName $eventLogName -sourceName $source

 

 

#Add the snapin | import the module for SolarWinds API

#Add-PSSnapin SwisSnapin

Import-Module C:\SLW\PSModules\SwisPowerShell\2.3.0.108\SwisPowerShell.psd1

 

 

#create a connection to solarwinds

$hostname = 'orion server ip address'

$username = 'username'

$password = 'password'

 

 

#Set DateTime Parameters

$startTime = get-date

$endtime = $startTime.AddHours(10)

 

 

$eventLogMessage += "Getting the starting time and end time for Alert Suppression for the Argo Servers in Eastern Time Zone`r`n"

$eventLogMessage += "Start Time:  $startTime`r`n"

$eventLogMessage += "End Time: $endTime`r`n"

$eventLogMessage += "Creating Connection to SolarWinds Application`r`n"

 

 

try{

    $swis = Connect-Swis -Hostname $hostname -Usernam $UserName -Password $password -ErrorAction stop

}

catch

{

    $body = "$($MyInvocation.InvocationName) was unable to connect to Production SolarWinds through API.  Please Validate the username and password are correct"

    $eventLogMessage += $body

    Send-Email -body $body

    Write-EventLog -LogName $eventLogName -Source $source -EntryType Error -Category 0 -EventId 3245 -Message $eventLogMessage

    exit

}

 

 

$eventLogMessage += "Generating the List of Argo Servers to be placed into Maintenance Mode`r`n"

 

 

$query = "select caption,uri from orion.nodes where caption like '%azargmtw%'"

 

 

try

{

    $uri = Get-SwisData -SwisConnection $swis -query $query -ErrorAction Stop

}

catch

{

    $body = "$($MyInvocation.InvocationName) hit an exception during the query to get server information.  The Error:`r`n $($error[0])"

    $eventLogMessage += "$body"

    send-email -body $body

    Write-EventLog -LogName $eventLogName -Source $source -EntryType Error -Category 0 -EventId 3245 -Message $eventLogMessage

    Exit

}

 

 

if([string]::IsNullOrEmpty($uri))

{

    $body = "$($MyInvocation.InvocationName): SolarWinds Query did not return any values.  Please Validate Query in the SWQL Studio`r`n The query was '$query'"

    $eventLogMessage += $body

    Send-Email -body $body

}

else

{

    $eventlogMessage += "Found $($uri.count) servers to put into maintenance mode`r`n"

    $eventlogMessage += "Placing Servers into maintenance mode`r`n"

    try

    {

        Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.AlertSuppression -Verb SuppressAlerts -Arguments @([string[]] $uri.uri, $startTime, $endtime) -ErrorAction Stop | Out-Null

    }

    catch

    {

        $body = "$($MyInvocation.InvocationName): Exception when attempting to Set AlertSuppression on the Node.  The Error:`r`n $($error[0])"

        $eventLogMessage += $body

        Send-Email -body $body

    }

 

 

    $eventLogMessage += "Validating Maintenance Mode was Set on the Servers`r`n"

 

 

    foreach($info in $uri)

    {

        $result = Validate-MaintenanceMode -nodeName $info.caption -uri $info.uri -swisConnection $swis

        Switch($result.IsSet)

        {

            {$_ -eq "No"} {$eventLogMessage += "$($result.nodeName): Maintenance Mode was not set`r`n"}

            {$_ -eq "Manual"} {$eventLogMessage += "$($result.nodeName): Maintenance Mode was set at $($result.MMStartTime.ToLocalTime()) but needs to be manually reset`r`n"}

            {$_ -eq "Yes"} {$eventLogMessage += "$($result.nodeName): Maintenance Mode was set at $($result.MMStartTime.ToLocalTime()) to $($result.MMEndTime.ToLocalTime())`r`n"}

        }

    }

}

 

 

$eventLogMessage

Write-EventLog -LogName $eventLogName -Source $source -EntryType Information -Category 0 -EventId 200 -Message $eventLogMessage


Icon for VMAN Datastore Name

$
0
0

Hello SWQL Ninjas!

 

I'm trying to identify where to pull the icon status from for VMware datastores within the VMAN product. For Nodes within Orion core this is found in the [Orion.Nodes].StatusIcon column, however, the same column does not exist within the [Orion.Vim.Datastores] table. 

 

I see the following options under [Orion.Vim.Datastores]:

     StatusDescription (Null values)

     StatusIconHint (Null values)

     StatusLED (Null values)

     Status (Int values)

Obviously, the first three columns are useless.  The "Status" column will require a lookup table and further logic via a case statement matching up the given value with the meaning and then linking that to the appropriate .gif file. I think I found a table that can be used in the Orion core db [Orion.StatusInfo]. 

 

Now for my questions...Is this the only option for pulling in the datastore icons or is there a better way?  If this is the only option, does anyone have the logic already before I dive in? I know Solarwinds is doing this in the backend somehow because when you hover on the datastore name (pulled from DetailsUrl) there is a status icon showing.

 

Related question, is there an ERD available for the Solarwinds Databases (including all products)? I found a thread from around 2014 that didn't look promising, I'm hoping four years has allowed for a better response.

 

Code included below for clarity - I'm just trying to get a view of datastores with low space that I can customize further down the road. Screenshot of query attached, the names are blocked out for obvious reasons.

SELECT d.Name, Type, Accessible as [Available],    CASE        WHEN (d.Capacity/1024/1024/1024/1024) > 1 THEN (TOSTRING(ROUND(d.Capacity/1024/1024/1024/1024,2))+ ' TB')        WHEN (d.Capacity/1024/1024/1024) > 1 THEN (TOSTRING(ROUND(d.Capacity/1024/1024/1024,2))+ ' GB')        WHEN (d.Capacity/1024/1024) > 1 THEN (TOSTRING(ROUND(d.Capacity/1024/1024,2))+ ' MB')    END AS [Datastore Size],    CASE         WHEN (d.FreeSpace/1024/1024/1024/1024) > 1 THEN (tostring(ROUND(d.FreeSpace/1024/1024/1024/1024,2))+ ' TB')        WHEN (d.FreeSpace/1024/1024/1024) > 1 THEN (TOSTRING(ROUND(d.FreeSpace/1024/1024/1024,2))+ ' GB')        WHEN (d.FreeSpace/1024/1024) > 1 THEN (TOSTRING(ROUND(d.FreeSpace/1024/1024,2))+ ' MB')    END AS [Free Space],    ROUND(d.SpaceUtilization,2) as [% Used],    CASE         WHEN (d.ProvisionedSpace/1024/1024/1024/1024) > 1 THEN (tostring(ROUND(d.ProvisionedSpace/1024/1024/1024/1024,2))+ ' TB')        WHEN (d.ProvisionedSpace/1024/1024/1024) > 1 THEN (TOSTRING(ROUND(d.ProvisionedSpace/1024/1024/1024,2))+ ' GB')        WHEN (d.ProvisionedSpace/1024/1024) > 1 THEN (TOSTRING(ROUND(d.ProvisionedSpace/1024/1024,2))+ ' MB')    END AS [Provisioned],    ROUND(d.ProvisionedSpaceAllocation,2) as [% Provisioned],    d.DetailsUrl AS [_linkfor_Name]
FROM Orion.Vim.Datastores AS d
--WHERE d.Name LIKE '%${SEARCH_STRING}%'
ORDER BY [% Used] DESC

 

Thanks in advance!

SWQL -> SplitStringToArray -> ArrayValueAt

$
0
0

Hey guys,

 

first of all, please excuse my bad english

 

i try since two days to create a swql-query that give me with SPLITSTRINGTOARRAY one value from a string that contains two values wich are seperatet by |§|§| as shown in the SDK. But it dont work.

 

Thats the query :

 

SELECT SPLITSTRINGTOARRAY(Arr.Str) as ArrVal, ARRAYVALUEAT(ArrVal,0) as A0, ARRAYVALUEAT(ArrVal,1) as A1

     From (SELECT accp.WertePaar10 as Str

           From orion.AlertConfigurationsCustomProperties accp

           Where accp.Alert.AlertID = 188) as Arr

 

The faild message: Cannot resolve property ArrVal

 

If i execute the query without the "ARRAYVALUEAT" i get the array:

 

SELECT SPLITSTRINGTOARRAY(Arr.Str) as ArrVal

     From (SELECT accp.WertePaar10 as Str

           From orion.AlertConfigurationsCustomProperties accp

           Where accp.Alert.AlertID = 188) as Arr

 

Result:  ArrVal = [Test1, Test2]

 

Ive tried multiple query-variations without an useable result. Only failure-Messages. Can anyone help?

Solarwind API

$
0
0

We required API which can be integrate into the .net framework system.

 

If possible could you please provide us a Example for the same with asp.net integration.

 

No snap-ins have been registered for Windows PS v. 5.0

$
0
0

Hi Thwack,

 

As I was trying to unmanage whole groups at a time I stumbled upon OrionSDK and with that, PowerOrion.

I have installed OrionSDK and copied the PowerOrion directory to C:\Windows\System32\WindowsPowerShell\v1.0\Modules\.

Whenever I try to either Import-Module PowerOrion or Add-PSSnapin SwisSnapin I get this:

 

PS C:\Company> Add-PSSnapin SwisSnapin 

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 5.

At line:1 char:1

+ Add-PSSnapin SwisSnapin

+ ~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (SwisSnapin:String) [Add-PSSnapin], PSArgumentException

    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

 

 

 

PS C:\Company> Import-Module PowerOrion

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 5.

At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PowerOrion\PowerOrion.psm1:5 char:1

+ Add-PSSnapin SwisSnapin

+ ~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (SwisSnapin:String) [Add-PSSnapin], PSArgumentException

    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

 

I've tried running the following without success: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe 'C:\Program Files (x86)\SolarWinds\Orion SDK\SWQL Studio\SwisPowerShell.dll'

 

Any help is greatly appreciated.

 

Glad Regards,

Frederik Bruun

Powershell scripts to automatically unmanage\remanage a node using the Orion SDK

$
0
0

First, I'll share the script. Then, I'll explain why we need it and how it helps us in our environment.

To use the script you must have the Orion SDK installed on the monitored node.

 

Take the text below, paste in Powershell ISE and save it as a PS1.

------------------------------------ Start PS1 -----------------------------------------------------------------

 

# 2014-07-21 Node Unmanage script for SolarWinds SDK Powershell

# by Joe Dissmeyer | Thwack - @JoeDissmeyer | Twitter - @JoeDissmeyer | www.joedissmeyer.com

# This script will unmanage a single node in the Orion database. First, it finds the node number in the Orion database, then it will unmanage it for 99 years.

# This script assumes you are running it LOCALLY from an already managed node AND that the machine has the Orion SDK v1.9 installed on it.

# If the machine is not already managed in SolarWinds this script will fail without warning.

# Replace ORIONSERVERNAME with the appropriate values.

# ORIONSERVERNAME = Your Orion poller instance. (Ex. 'SOLARWINDS01.DOMAIN.LOCAL'). Single quotes are important.

 

# Load the SolarWinds Powershell snapin. Needed in order to execute the script. Requires the Orion SDK 1.9 installed on the machine this script is running from.

Add-PSSnapin SwisSnapin

 

 

# SolarWinds user name and password section. Create an Orion local account that only has node management rights. Enter the user name and password here.

$username = "SWnodemanagement"

$password = "MyP@44w0$d"

 

# This section allows the password to be embedded in this script. Without it the script will not work.

$secstr = New-Object -TypeName System.Security.SecureString

$password .ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}

$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$secstr

 

# The actual job

$ORIONSERVERNAME = 'SWServer1.domain.local'

$nodename = $env:COMPUTERNAME

 

$swis = Connect-Swis -Credential $cred -host $orionservername

$nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$nodename%'"

$now =[DateTime ]:: Now

$later =$now.AddYears(99)

Invoke-SwisVerb $swis Orion.Nodes Unmanage @("N: $nodeid ", $now ,$later , "false")

 

------------------------------------ End PS1 -----------------------------------------------------------------

 

 

 

And now the Remanage script. Again, save as a .PS1 file.

------------------------------------ Start PS1 -----------------------------------------------------------------

 

# 2014-07-21 Node Remanage script for SolarWinds SDK Powershell

# by Joe Dissmeyer | Thwack - @JoeDissmeyer | Twitter - @JoeDissmeyer | www.joedissmeyer.com

# This script will remanage a single node in the Orion database.

# This script assumes you are running it LOCALLY from an already managed node AND that the machine has the Orion SDK v1.9 installed on it.

# If the machine is not already managed in SolarWinds this script will fail without warning.

# Replace ORIONSERVERNAME with the appropriate values.

# ORIONSERVERNAME = Your Orion poller instance. (Ex. 'SOLARWINDS01.DOMAIN.LOCAL'). Single quotes are important.

 

 

# Load the SolarWinds Powershell snapin. Needed in order to execute the script. Requires the Orion SDK 1.9 installed on the machine this script is running from.

Add-PSSnapin SwisSnapin

 

 

# SolarWinds user name and password section. Create an Orion local account that only has node management rights. Enter the user name and password here.

$username = "SWnodemanagement"

$password = "MyP@44w0%d"

 

 

# This section allows the password to be embedded in this script. Without it the script will not work.

$secstr = New-Object -TypeName System.Security.SecureString

$password .ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}

$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$secstr

 

 

# The actual job

$ORIONSERVERNAME = 'SWServer1.domain.local'

$nodename = $env:COMPUTERNAME

 

 

$swis = Connect-Swis -Credential $cred -host $orionservername

$nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$nodename%'"

$now =[DateTime ]:: Now

$later =$now.AddYears(99)

Invoke-SwisVerb $swis Orion.Nodes Remanage @("N: $nodeid ", $now ,$later , "false")

 

------------------------------------ End PS1 -----------------------------------------------------------------

 

Explanation:

My company had a very unique need to monitor our enterprise Windows application that runs not only on standard desktop PCs, but also runs on mobile tablets connected to WiFi access points. These tablets run the standard Windows 7 Professional OS so it makes it easy to set up application monitoring in SolarWinds SAM for these machines. However, the problem comes at the end of the day when these tablets are turned off and placed in their charging docks for the night. As you can imagine, this creates an administrative nightmare (not to mention an email alert flood) in SolarWinds when this happens.

 

SolarWinds Orion NPM and SAM is designed to always keep an eye on a node or application that is entered in it's database. It is not designed to monitor an application or node only "part of the time" --- well, at least it isn't designed for this purpose out of the box. So instead, we have to create a workaround that will suit our needs. What we needed to do was figure out how to automatically "unmanage" these Windows tablet PCs in SolarWinds when they are shut down for the night, but also automatically "re-manage" them once they boot up. This is where the script comes into play.

 

The idea is to take the Unmanage script and apply it as a shut down script in Group Policy, then take the Remanage script and apply it as a boot up script in Group Policy.

Here is why this works for us:

The business is supposed to gracefully shut down the tablet by clicking Start > Shut down. If not, then an email alert triggers that informs us that the application is down on the machine.

If the tablet goes offline in the middle of the day for any reason, we will receive an email alert about that node.

When the machine is shut down properly, the node is automatically unmanaged in SolarWinds.

When the machine boots up and someone logs into the machine, the node is automatically remanaged in SolarWinds.

 

But here is an even better use for these scripts --- Scheduled Server Maintenance! How many times have we, server administrators, had to patch Windows Servers during scheduled maintenance hours? Normally you would have to go into SolarWinds and unmanage the node first BEFORE rebooting as not to trigger an email alert. Well with these scripts you wouldn't have to worry about that as much since this would be automatic.

 

Final notes:

Of course, this is just one way to go about auto-managing nodes in SolarWinds. There are some alternatives to doing this using the Orion SDK and Powershell which is to, instead, use the built-in .NET properties in Powershell 2.0 to access the Orion SQL database directly, find the node ID, and unmanage it in that manner. For those that are interested in how do to this without the Orion SDK, let me know and I'd be happy to elaborate.

Set-SwisObject error when updating IPAM.Subnet

$
0
0

I am executing the following command via powershell and getting an error.  However, despite the error it does update the FriendlyName in the database.  Any thoughts on how to get rid of the error?

 

Command:

 

Set-SwisObject -SwisConnection $swis -Uri 'swis://ORIONSERVER/Orion/IPAM.Subnet/SubnetId=14030,ParentId=7649' -Properties @{FriendlyName="TEST";}

 

Error:

 

Set-SwisObject : SolarWinds.IPAM.Contract.Service.IIpamGroupNodeProxy.Scan failed,

check fault information.

At line:1 char:1

+ Set-SwisObject -SwisConnection $swis -Uri 'swis://ORIONSERVER ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [Set-SwisObject], FaultException`

   1

    + FullyQualifiedErrorId : SwisError,SwisPowerShell.SetSwisObject

How to enable API in Solarwinds to integrate with other tools?

$
0
0

Hi,

 

We are trying to create a “Central Dashboard for Capacity” related reports for my customer so that whenever needed one can login to this Tool and generate a report.

 

To generate those reports in our Tool, our Tool needs to further integrated with Solarwinds to get the Capacity and Performance related data. And API (Web services) is the only protocol that our Tool support.

 

We need your help to understand whether Solarwinds support API so that we can explore further to get the Capacity and Performance related data from Solarwinds.

 

Also, how we can enable API Integration.


Can any one supply a REST example of how to define a Node in Solarwinds

$
0
0

I am developing an integration agent for SolarWindws and would like to use the REST API to add nodes to SolarWindws and change the system name

Powershell scripts to automatically unmanage\remanage a node using the Orion SDK

$
0
0

First, I'll share the script. Then, I'll explain why we need it and how it helps us in our environment.

To use the script you must have the Orion SDK installed on the monitored node.

 

Take the text below, paste in Powershell ISE and save it as a PS1.

------------------------------------ Start PS1 -----------------------------------------------------------------

 

# 2014-07-21 Node Unmanage script for SolarWinds SDK Powershell

# by Joe Dissmeyer | Thwack - @JoeDissmeyer | Twitter - @JoeDissmeyer | www.joedissmeyer.com

# This script will unmanage a single node in the Orion database. First, it finds the node number in the Orion database, then it will unmanage it for 99 years.

# This script assumes you are running it LOCALLY from an already managed node AND that the machine has the Orion SDK v1.9 installed on it.

# If the machine is not already managed in SolarWinds this script will fail without warning.

# Replace ORIONSERVERNAME with the appropriate values.

# ORIONSERVERNAME = Your Orion poller instance. (Ex. 'SOLARWINDS01.DOMAIN.LOCAL'). Single quotes are important.

 

# Load the SolarWinds Powershell snapin. Needed in order to execute the script. Requires the Orion SDK 1.9 installed on the machine this script is running from.

Add-PSSnapin SwisSnapin

 

 

# SolarWinds user name and password section. Create an Orion local account that only has node management rights. Enter the user name and password here.

$username = "SWnodemanagement"

$password = "MyP@44w0$d"

 

# This section allows the password to be embedded in this script. Without it the script will not work.

$secstr = New-Object -TypeName System.Security.SecureString

$password .ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}

$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$secstr

 

# The actual job

$ORIONSERVERNAME = 'SWServer1.domain.local'

$nodename = $env:COMPUTERNAME

 

$swis = Connect-Swis -Credential $cred -host $orionservername

$nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$nodename%'"

$now =[DateTime ]:: Now

$later =$now.AddYears(99)

Invoke-SwisVerb $swis Orion.Nodes Unmanage @("N: $nodeid ", $now ,$later , "false")

 

------------------------------------ End PS1 -----------------------------------------------------------------

 

 

 

And now the Remanage script. Again, save as a .PS1 file.

------------------------------------ Start PS1 -----------------------------------------------------------------

 

# 2014-07-21 Node Remanage script for SolarWinds SDK Powershell

# by Joe Dissmeyer | Thwack - @JoeDissmeyer | Twitter - @JoeDissmeyer | www.joedissmeyer.com

# This script will remanage a single node in the Orion database.

# This script assumes you are running it LOCALLY from an already managed node AND that the machine has the Orion SDK v1.9 installed on it.

# If the machine is not already managed in SolarWinds this script will fail without warning.

# Replace ORIONSERVERNAME with the appropriate values.

# ORIONSERVERNAME = Your Orion poller instance. (Ex. 'SOLARWINDS01.DOMAIN.LOCAL'). Single quotes are important.

 

 

# Load the SolarWinds Powershell snapin. Needed in order to execute the script. Requires the Orion SDK 1.9 installed on the machine this script is running from.

Add-PSSnapin SwisSnapin

 

 

# SolarWinds user name and password section. Create an Orion local account that only has node management rights. Enter the user name and password here.

$username = "SWnodemanagement"

$password = "MyP@44w0%d"

 

 

# This section allows the password to be embedded in this script. Without it the script will not work.

$secstr = New-Object -TypeName System.Security.SecureString

$password .ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}

$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$secstr

 

 

# The actual job

$ORIONSERVERNAME = 'SWServer1.domain.local'

$nodename = $env:COMPUTERNAME

 

 

$swis = Connect-Swis -Credential $cred -host $orionservername

$nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$nodename%'"

$now =[DateTime ]:: Now

$later =$now.AddYears(99)

Invoke-SwisVerb $swis Orion.Nodes Remanage @("N: $nodeid ", $now ,$later , "false")

 

------------------------------------ End PS1 -----------------------------------------------------------------

 

Explanation:

My company had a very unique need to monitor our enterprise Windows application that runs not only on standard desktop PCs, but also runs on mobile tablets connected to WiFi access points. These tablets run the standard Windows 7 Professional OS so it makes it easy to set up application monitoring in SolarWinds SAM for these machines. However, the problem comes at the end of the day when these tablets are turned off and placed in their charging docks for the night. As you can imagine, this creates an administrative nightmare (not to mention an email alert flood) in SolarWinds when this happens.

 

SolarWinds Orion NPM and SAM is designed to always keep an eye on a node or application that is entered in it's database. It is not designed to monitor an application or node only "part of the time" --- well, at least it isn't designed for this purpose out of the box. So instead, we have to create a workaround that will suit our needs. What we needed to do was figure out how to automatically "unmanage" these Windows tablet PCs in SolarWinds when they are shut down for the night, but also automatically "re-manage" them once they boot up. This is where the script comes into play.

 

The idea is to take the Unmanage script and apply it as a shut down script in Group Policy, then take the Remanage script and apply it as a boot up script in Group Policy.

Here is why this works for us:

The business is supposed to gracefully shut down the tablet by clicking Start > Shut down. If not, then an email alert triggers that informs us that the application is down on the machine.

If the tablet goes offline in the middle of the day for any reason, we will receive an email alert about that node.

When the machine is shut down properly, the node is automatically unmanaged in SolarWinds.

When the machine boots up and someone logs into the machine, the node is automatically remanaged in SolarWinds.

 

But here is an even better use for these scripts --- Scheduled Server Maintenance! How many times have we, server administrators, had to patch Windows Servers during scheduled maintenance hours? Normally you would have to go into SolarWinds and unmanage the node first BEFORE rebooting as not to trigger an email alert. Well with these scripts you wouldn't have to worry about that as much since this would be automatic.

 

Final notes:

Of course, this is just one way to go about auto-managing nodes in SolarWinds. There are some alternatives to doing this using the Orion SDK and Powershell which is to, instead, use the built-in .NET properties in Powershell 2.0 to access the Orion SQL database directly, find the node ID, and unmanage it in that manner. For those that are interested in how do to this without the Orion SDK, let me know and I'd be happy to elaborate.

No snap-ins have been registered for Windows PS v. 5.0

$
0
0

Hi Thwack,

 

As I was trying to unmanage whole groups at a time I stumbled upon OrionSDK and with that, PowerOrion.

I have installed OrionSDK and copied the PowerOrion directory to C:\Windows\System32\WindowsPowerShell\v1.0\Modules\.

Whenever I try to either Import-Module PowerOrion or Add-PSSnapin SwisSnapin I get this:

 

PS C:\Company> Add-PSSnapin SwisSnapin 

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 5.

At line:1 char:1

+ Add-PSSnapin SwisSnapin

+ ~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (SwisSnapin:String) [Add-PSSnapin], PSArgumentException

    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

 

 

 

PS C:\Company> Import-Module PowerOrion

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 5.

At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PowerOrion\PowerOrion.psm1:5 char:1

+ Add-PSSnapin SwisSnapin

+ ~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (SwisSnapin:String) [Add-PSSnapin], PSArgumentException

    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

 

I've tried running the following without success: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe 'C:\Program Files (x86)\SolarWinds\Orion SDK\SWQL Studio\SwisPowerShell.dll'

 

Any help is greatly appreciated.

 

Glad Regards,

Frederik Bruun

How to Create a Discovery Profile using Orion API in PHP

$
0
0

Hi Everyone,

 

I've been trying to get a PHP page I've been writing to start a Discovery Profile, but it seems to be getting hung up on getting the XML Context into JSON format so that I can send it it the REST API via cURL.

 

Has anyone been able to do this before, and if not, does anyone have any ideas?

 

I am relatively new to PHP and curl, so I'm sure I've missed some obvious things.

 

I've set the following XML equal to the variable $core_plugin which I later try to pass into an Invoke call.

<CorePluginConfigurationContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>        <BulkList>                <IpAddress>                        <Address>                        </Address>                </IpAddress>        </BulkList>        <Credentials>                <SharedCredentialInfo>                        <CredentialID>1</CredentialID>                        <Order>1</Order>                </SharedCredentialInfo>        </Credentials>        <WmiRetriesCount>0</WmiRetriesCount>        <WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds></CorePluginConfigurationContext>

 

which I then do this is PHP

// Construct the Core Plugin XML Document, then Have Solarwinds Build the Plugin
$info = simplexml_load_string($core_plugin);
$info->BulkList->IpAddress->Address = "10.10.10.10";
$updated_core_plugin = $info->asXML();
$core_plugin_url = "https://solarwindsServer.com:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Discovery/CreateCorePluginConfiguration";
$core_plugin_data = array('context' => "$updated_core_plugin");
$json_core_plugin = json_encode($core_plugin_data);
$finished_core_plugin = CallAPI($core_plugin_url, $json_core_plugin);

function CallAPI($url, $data = false) {
   $ch = curl_init();    // Authentication:  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  curl_setopt($ch, CURLOPT_USERPWD, "username:password");  curl_setopt($ch, CURLOPT_URL, $url);  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  curl_setopt($ch, CURLOPT_VERBOSE, true);  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                        'Content-type: application/json',                                        'Content-length: ' . strlen($data)                                      ));  $result = curl_exec($ch);  $response = curl_getinfo($ch, CURLINFO_HTTP_CODE);  $error = curl_error($ch);  $info = curl_getinfo($ch);  curl_close($ch);    if ($result == false) {  echo "Response: " . $response . "
";  echo "Error: " . $error . "
";  echo "Info: " . print_r($info);  die();  }  return $result;
}

 

 

If you need anything else from me, please let me know.

 

Just FYI, the curl section was from another user on Thwack.

 

Thanks,

 

Jordan

Problem with a script to suppress alerts on specified nodes

$
0
0

I am having a problem that I cannot seem to figure out what is going on.  I have a set of 4 scripts that run every night in a schedule task as the System account.  These 4 scripts work exactly the same way.  They generate a list of server from a query and turn on Alert Suppression on those nodes for 10 hours.  The problem is the scripts are randomly failing.  The script that runs at 8pm will be successfully, but the one at 9pm, 10pm, and 11pm will fail.  I have error handling set up in the script but the error that is generated during the Alert Suppression task is "one or more errors occurred"  Can someone point me to the log file that SWIS SDK powershell cmdlets use so I can try and see what the one or more errors are to attempt to fix the problem?  I have added the script that I am using.

 

Function Create-EventSource

{

  param(

    [string]$logfileName,

    [string]$sourceName

  )

 

  If([System.Diagnostics.EventLog]::Exists($logfileName))

    {

        write-output "$logFileName Exists"

        If([System.Diagnostics.EventLog]::SourceExists($sourceName))

        {

 

 

        }

        else

        {

            New-EventLog -LogName $logfilename -Source $sourceName

        }

    }

    else

    {

        $event = "Creating $logfilename EventLog"

        New-EventLog -LogName $logfileName -Source $sourceName

        Limit-EventLog -LogName $logFileName -OverflowAction OverwriteAsNeeded -MaximumSize 50MB

        Write-EventLog -LogName Application -Source OVO -EntryType Information -Category 0 -EventId 200 -Message $event

    }

}

 

 

Function Send-Email

{

    param(

        [string]$body

    )

    $subject = "Script Failed to Connect to SolarWinds"

    $smtpTo = "some email address"

    $smtpFrom = "some other address"

    $smtpServer = "smtp server"

   

    Send-MailMessage -From $smtpFrom -To $smtpTo -Body $body -Subject $subject -SmtpServer $smtpServer

}

 

 

Function Validate-MaintenanceMode

{

    Param(

        [string]$nodeName,

        [string]$uri,

        [object]$swisConnection

    )

 

 

    $tmpquery1 = "select entityuri, suppressfrom, suppressuntil from orion.AlertSuppression where entityuri = '$uri'"

    $AlertSuppressionInfo = Get-SwisData -SwisConnection $swisConnection -Query $tmpQuery1

    If(([string]::IsNullOrEmpty($AlertSuppressionInfo.suppressfrom)) -and ([string]::IsNullOrEmpty($AlertSuppressionInfo.suppressuntil)))

    {

        $IsSet = "No"

    }

    elseif([string]::IsNullOrEmpty($AlertSuppressionInfo.suppressuntil))

    {

        $IsSet = "Manual"

    }

    else

    {

        $IsSet = "Yes"

    }

 

 

    $obj = New-Object PSObject -Property @{

                            NodeName = $nodeName

                            MMStartTime = $AlertSuppressionInfo.suppressfrom

                            MMEndTime = $AlertSuppressionInfo.suppressUntil

                            URI = "$uri"

                            isSet = $IsSet

                       }

    return $obj

}

 

 

 

 

######################### Main #############################################################

 

 

$source = "ArgoMaintenanceModeMountain"

$eventLogMessage = ""

$eventLogName = "EventMonitoring"

 

 

Create-EventSource -logfileName $eventLogName -sourceName $source

 

 

#Add the snapin | import the module for SolarWinds API

#Add-PSSnapin SwisSnapin

Import-Module C:\SLW\PSModules\SwisPowerShell\2.3.0.108\SwisPowerShell.psd1

 

 

#create a connection to solarwinds

$hostname = 'orion server ip address'

$username = 'username'

$password = 'password'

 

 

#Set DateTime Parameters

$startTime = get-date

$endtime = $startTime.AddHours(10)

 

 

$eventLogMessage += "Getting the starting time and end time for Alert Suppression for the Argo Servers in Eastern Time Zone`r`n"

$eventLogMessage += "Start Time:  $startTime`r`n"

$eventLogMessage += "End Time: $endTime`r`n"

$eventLogMessage += "Creating Connection to SolarWinds Application`r`n"

 

 

try{

    $swis = Connect-Swis -Hostname $hostname -Usernam $UserName -Password $password -ErrorAction stop

}

catch

{

    $body = "$($MyInvocation.InvocationName) was unable to connect to Production SolarWinds through API.  Please Validate the username and password are correct"

    $eventLogMessage += $body

    Send-Email -body $body

    Write-EventLog -LogName $eventLogName -Source $source -EntryType Error -Category 0 -EventId 3245 -Message $eventLogMessage

    exit

}

 

 

$eventLogMessage += "Generating the List of Argo Servers to be placed into Maintenance Mode`r`n"

 

 

$query = "select caption,uri from orion.nodes where caption like '%azargmtw%'"

 

 

try

{

    $uri = Get-SwisData -SwisConnection $swis -query $query -ErrorAction Stop

}

catch

{

    $body = "$($MyInvocation.InvocationName) hit an exception during the query to get server information.  The Error:`r`n $($error[0])"

    $eventLogMessage += "$body"

    send-email -body $body

    Write-EventLog -LogName $eventLogName -Source $source -EntryType Error -Category 0 -EventId 3245 -Message $eventLogMessage

    Exit

}

 

 

if([string]::IsNullOrEmpty($uri))

{

    $body = "$($MyInvocation.InvocationName): SolarWinds Query did not return any values.  Please Validate Query in the SWQL Studio`r`n The query was '$query'"

    $eventLogMessage += $body

    Send-Email -body $body

}

else

{

    $eventlogMessage += "Found $($uri.count) servers to put into maintenance mode`r`n"

    $eventlogMessage += "Placing Servers into maintenance mode`r`n"

    try

    {

        Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.AlertSuppression -Verb SuppressAlerts -Arguments @([string[]] $uri.uri, $startTime, $endtime) -ErrorAction Stop | Out-Null

    }

    catch

    {

        $body = "$($MyInvocation.InvocationName): Exception when attempting to Set AlertSuppression on the Node.  The Error:`r`n $($error[0])"

        $eventLogMessage += $body

        Send-Email -body $body

    }

 

 

    $eventLogMessage += "Validating Maintenance Mode was Set on the Servers`r`n"

 

 

    foreach($info in $uri)

    {

        $result = Validate-MaintenanceMode -nodeName $info.caption -uri $info.uri -swisConnection $swis

        Switch($result.IsSet)

        {

            {$_ -eq "No"} {$eventLogMessage += "$($result.nodeName): Maintenance Mode was not set`r`n"}

            {$_ -eq "Manual"} {$eventLogMessage += "$($result.nodeName): Maintenance Mode was set at $($result.MMStartTime.ToLocalTime()) but needs to be manually reset`r`n"}

            {$_ -eq "Yes"} {$eventLogMessage += "$($result.nodeName): Maintenance Mode was set at $($result.MMStartTime.ToLocalTime()) to $($result.MMEndTime.ToLocalTime())`r`n"}

        }

    }

}

 

 

$eventLogMessage

Write-EventLog -LogName $eventLogName -Source $source -EntryType Information -Category 0 -EventId 200 -Message $eventLogMessage

Receiving 403 Forbidden When Using REST API In C#

$
0
0

Receiving 403 Forbidden When Using REST API In C#

 

I was referred to the following C# example of using REST APIs Sample code: OrionSDK/Program.cs at master · solarwinds/OrionSDK · GitHub

 

This looked very promising and I have attempted to implement it for my process. However, all requests are failing with a 403 Forbidden error.

 

I have verified if I used invalid credentials I get a 401 unauthorized error so it appears to be authenticating my request, but I can't get results for a simple query operation.

 

I am basically using the code from the example but I am only calling the query action with the following simple query string and no arguments:

conststring query = @"SELECT nodeid, caption FROM Orion.Nodes";

 

I have output the JSON string created before it is passed to the request and it looks like this:

{"parameters":null,"query":"SELECT nodeid, caption FROM Orion.Nodes"}

 

Is there something wrong with the JSON or my query request?

Creating custom IPNode properties using REST api

$
0
0

Hello,

I've been working on automation recently and it's been going well until recently when I encounter a new problem.

We have some custom fields in the IPNode entity that I usually update with the REST api, I noticed when there is no custom fields set at all, the api returns "null" (which is normal) but the data does not update.

 

This is the request that I have been using:

 

POST https://myserver:17778/SolarWinds/InformationService/v3/Json/swis://myserver/Orion/IPAM.IPNode/IpNodeId=22222/Custom

JSON body:

 

{

    "Server_Name": "Test"

}

 

The field "Server_Name" is the custom field that I'm trying to update.

I tried to figure out what's wrong using SWQL studio and I found that if there is no rows representing IpNodeId in IPAM.IPNodeAttr table I won't be able to update the custom field.

 

Seems to me like I hate to create the entity first somehow. I tried to google this issue but unfortunately I could not find the answer.

I would really appreciate any help.

 

Thanks.


Query nodes based on custom property

$
0
0

Hello,

 

Is there any way to query the Orion nodes with all the custom properties?

 

Thanks.

CluM09

Solarwind API

$
0
0

We required API which can be integrate into the .net framework system.

 

If possible could you please provide us a Example for the same with asp.net integration.

 

Definition of "Status" field in "Orion.Nodes" table

$
0
0


Dear Sir or Madam -

 

Would you please document the possible values that may appear in the  "Status"  field of the  "Orion.Nodes"  table ?

 

I know that value "1"  means "up"  and value  "2"  means  "down".   What other values may appear and what do they mean ?

 

Thank you.

 

James Troy

Query nodes based on custom property

$
0
0

Hello,

 

Is there any way to query the Orion nodes with all the custom properties?

 

Thanks.

CluM09

Receiving 403 Forbidden When Using REST API In C#

$
0
0

Receiving 403 Forbidden When Using REST API In C#

 

I was referred to the following C# example of using REST APIs Sample code: OrionSDK/Program.cs at master · solarwinds/OrionSDK · GitHub

 

This looked very promising and I have attempted to implement it for my process. However, all requests are failing with a 403 Forbidden error.

 

I have verified if I used invalid credentials I get a 401 unauthorized error so it appears to be authenticating my request, but I can't get results for a simple query operation.

 

I am basically using the code from the example but I am only calling the query action with the following simple query string and no arguments:

conststring query = @"SELECT nodeid, caption FROM Orion.Nodes";

 

I have output the JSON string created before it is passed to the request and it looks like this:

{"parameters":null,"query":"SELECT nodeid, caption FROM Orion.Nodes"}

 

Is there something wrong with the JSON or my query request?

Viewing all 3719 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>