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.

Automating custom attributes

Hello all,

I have a script that add nodes to Orion but I would like to populate Make, Model, and serial.  I removed all the important stuff, I would like $Serial to populate the custom array. Here is my code

#This sample script demonstrates how to add a new node using CRUD operations.

#

# Please update the hostname and credential setup to match your configuration, and

# information about the node you would like to add for monitoring.

# Connect to SWIS

$hostname = ""

$username = ""

$password = Read-Host "Enter Password" -AsSecureString

$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

$swis = Connect-Swis -host $hostname -cred $cred

$ip = Read-Host "Enter the IP Address of Node"

# add a node

$newNodeProps = @{

    IPAddress = $ip;

    EngineID = 1;

 

    # SNMP v2 specific

    ObjectSubType = "SNMP";

    SNMPVersion = 2;

    Community = ""

    # === default values ===

    # EntityType = 'Orion.Nodes'

    # Caption = ''

    # DynamicIP = false

    # PollInterval = 120

    # RediscoveryInterval = 30

    # StatCollection = 10 

}

$newNodeUri = New-SwisObject $swis -EntityType "Orion.Nodes" -Properties $newNodeProps

$nodeProps = Get-SwisObject $swis -Uri $newNodeUri

$id =$nodeProps.NodeID

$serial = Get-SwisData $swis "SELECT ServiceTag FROM Orion.HardwareHealth.HardwareInfo WHERE NODEID= `'$id'"

# register specific pollers for the node

$poller = @{

    NetObject="N:"+$nodeProps["NodeID"];

    NetObjectType="N";

    NetObjectID=$nodeProps["NodeID"];

}

# Status

$poller["PollerType"]="N.Status.ICMP.Native";

$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

# Response time

$poller["PollerType"]="N.ResponseTime.ICMP.Native";

$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

# Details

$poller["PollerType"]="N.Details.SNMP.Generic";

$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

# Uptime

$poller["PollerType"]="N.Uptime.SNMP.Generic";

$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

# CPU

$poller["PollerType"]="N.Cpu.SNMP.CiscoGen3";

$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

# Memory

$poller["PollerType"]="N.Memory.SNMP.CiscoGen3";

$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

$CustomProperties= @{

  AppEnvironment="Production";

  AppName="ESXi";

  AppRole="Management";

  Comments= "VSAN HOST D"

  ConsoleAllowed="False";

  enVision="False";

  Make="Cisco Systems";

  Model="UCSC-C240-M4Sx";

  Rack="";

  SerialNumber= ${serial};

  Type="Server";

  Site="MTXH";

  }

# set the custom property

Set-SwisObject $swis -Uri  ($newNodeUri + '/CustomProperties') -Properties $CustomProperties

  • You may have reasons for scripting it but have you tried simply using network discovery in combination with alerts? You can pull anything you like from the DB and use alerts to react and set custom fields however you like. I have several network discovery scans pointing to different AD OU's that pull in new nodes each night. I then have a selection of alerts for auto populating custom fields that run 4 times a day. For example I wrote an alert using SWQL to populate a 'machine type' field. If the node has a virtualmachine ID of anything other than null and the custom field is anything other than virtual machine it sets it to be this (I created this as I am never informed when machines are P2V'd and I have different application monitors auto apply to VM's and physical machines!). You could do the same so if your 'serial' field is null, populate it with ServiceTag FROM Orion.HardwareHealth.HardwareInfo.