This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Force a custom property to auto set to a default level

Background: We have an interface priority custom property to allow differing types of interface or based on clients whims, to alert into our ITSM at the assigned level.

The Issue:  we need to find a way to automate interfaces being added as a P4, whether it's a brand new piece of kit or just an extra interface on a single device being enabled.

The problem: I don't know how best to automate this.

  • I can easily set up a report to send me any interfaces that aren't assigned to P2, P3 or P4 but that's manual and reactive, and relies on me being in.

Ideally I'd like to have a job (?I guess?) run that finds any interface that doesn't have a priority assigned and change it to P4. This job would run daily in the small hours, as it is rare an interface added today will be in support the same day or even less likely that it will alert.

But I have no idea where to start building a script that would do this for me, or even if a job is the right approach. An alert might be a better approach and it 'fixes' the issue within minutes - but it is still the issue of how to do the fix that I don't have a clue about.

Suggestions? 
Anybody already done this on another CP that I can edit to our needs?

Parents
  • Yes, we do a fair amount of this. I didn't have any on the interfaces, so I modified a script I had for servers. That means I didn't test it, so please do that, and shout at me if you get stuck making it work. Update the parts for your server and your property name, and I hope its close to what you need.  

    $SwisServer = 'orion.yourdomain.com'
    $CustomPropertyName = 'Severity'
    Try {
    	Import-Module SwisPowerShell
    } Catch {
    	Write-Host "Message: $($Error[0])";
    	Exit 1;
    }
    Try {
    	$swis = Connect-Swis -Certificate
    } Catch {
    	$Creds = Get-Credential
    	$Swis = Connect-Swis $SwisServer -Credential $Creds
    }
    
    $queryInterfacesWithNoSysID = "SELECT ICP.$CustomPropertyName,  ICP.Uri FROM Orion.NPM.InterfacesCustomProperties ICP Where ICP.$CustomPropertyName is Null or ICP.$CustomPropertyName not like 'P2' or ICP.$CustomPropertyName not like 'P3' or ICP.$CustomPropertyName not like 'P4'"
    $InterfacesWithNoProperty = Get-SwisData $swis -query $queryInterfacesWithNoSysID
    
    ForEach ($Interface In $InterfacesWithNoProperty) {
    	$uri = $Interface.uri
    	$CustomProps = @{
    		$CustomPropertyName = 'P4';
    	}
    	Set-SwisObject $swis -Uri $uri -Properties $CustomProps
    }

  • So I admit  that I am NOT a programmer or scripter in any shape or form. 36yrs ago when I stared in IT the most I needed for my job was to hack at BATch files - which I can still do. But here I am 36yrs later having to learn SQL/SWQL and Powershell to use this product.

    Anyway, here's my edit on your start.  It appears to run and finds/does nothing (other than echo the script back to the screen).. I've REM'd out most of the stuff at the start as I have no idea what that is doing.. Slight smile - I get the credentials bit, and when in working script form this will have those in for access 24*7.

    $SwisServer = 'my_orion_server'
    $CustomPropertyName = 'Interface_Priority'
    #Try {
    #	Import-Module SwisPowerShell
    #} Catch {
    #	Write-Host "Message: $($Error[0])";
    #	Exit 1;
    #}
    #Try {
    #	$swis = Connect-Swis -Certificate
    #} Catch {
    #	$Creds = Get-Credential
    #	$Swis = Connect-Swis $SwisServer -Credential $Creds
    #}
    
    $queryInterfacesWithNoPriority = "
    SELECT ICP.$CustomPropertyName,  
    ICP.Uri FROM Orion.NPM.InterfacesCustomProperties ICP Where ICP.$CustomPropertyName is Null"
    $InterfacesWithNoProperty = Get-SwisData $swis -query $queryInterfacesWithNoPriority
    
    ForEach ($Interface In $InterfacesWithNoProperty) {
    	$uri = $Interface.uri
    	$CustomProps = @{
    		$CustomPropertyName = 'PRIORITY_4';
    	}
    	##Set-SwisObject $swis -Uri $uri -Properties $CustomProps
    }

    I definitely don't understand the use of the ICP.uri or $uri bits

  • The latest iteration of this I have, which now runs without any results or doing anything is:

    $SwisServer = '163.164.101.60'
    $CustomPropertyName = 'Interface_Priority'
    
    $queryInterfacesWithNoPriority = "
    SELECT ICP.$CustomPropertyName,  ICP.InterfaceID,
    ICP.Uri FROM Orion.NPM.InterfacesCustomProperties ICP Where ICP.$CustomPropertyName is Null"
    $InterfacesWithNoProperty = Get-SwisData $swis -query $queryInterfacesWithNoPriority
    
    ForEach ($Interface In $queryInterfacesWithNoProperty) 
    {
    	$uri = $Interface.uri
    	$CustomProps = @{
    		$CustomPropertyName = 'PRIORITY_4';
        }
    	#Set-SwisObject $swis -Uri $uri -Properties $CustomProps
    }

    So why do I know it does nothing...

    First I edit an interface priority to deliberately make it a NULL result. I then run the basic SWQL query in SWQL studio and it returns 1 interface as NULL. I verify the InterfaceID matches the one in question.

    If I then run the full script, it runs and returns no output. If I now re-run my SWQL query, I still get the 1 interface.

  • trying changing your query to below, it's likely not a NULL in the DB and is now "whitespace"

    $queryInterfacesWithNoPriority = "
    SELECT ICP.$CustomPropertyName,  ICP.InterfaceID,
    ICP.Uri FROM Orion.NPM.InterfacesCustomProperties ICP Where ICP.$CustomPropertyName is Null or ICP.$CustomPropertyName  = ''"

  • I think  is right. 

    And we can simplify the script to. If we don't use the variable to populate the custom property name you can try to run it in SWQL studio if you want.  Or just paste into the value of $queryInterfacesWithNoPriority in the powershell. 

    SELECT ICP.Interface_Priority,  ICP.InterfaceID, ICP.Uri 
    FROM Orion.NPM.InterfacesCustomProperties ICP 
    Where ICP.Interface_Priority not like 'PRIORITY_1'
        and ICP.Interface_Priority not like 'PRIORITY_2'
        and ICP.Interface_Priority not like 'PRIORITY_3'
        and ICP.Interface_Priority not like 'PRIORITY_4'

    I also hard coded the values of priority that I think you have you may need to alter it. 

  • also I noticed that you have the actual task to update commented out, if this is in fact the version you are running you'll need to uncomment Set-SwisObject $swis -Uri $uri -Properties $CustomProps by removing the "#" in front of it.

  • Good spot/shout. I'd done that to prove that actual select process was working as expected. Of which, NULL does work, but I will also add in the option to look for empty values.

  • Take a look at the [String]::IsNullOrWhiteSpace() method for powershell. Takes care of both null, empty and if it just contains white space.

    There's also functionality to set the default of a custom property. The only way to set the default of the custom property (globally) or alter it is by the API or direct database. I have toyed with that a bit but haven't had time to fully understand its abilities  yet but I do know that when I created a new custom property manually via the API and set a default, it got auto-populated as such when adding a node manually... surely more testing could be done.

    https://github.com/solarwinds/OrionSDK/wiki/Managing-Custom-Properties

    thwack.solarwinds.com/.../tc18-creating-and-updating-orion-custom-properties-with-powershell

Reply Children
No Data