I'm using PS and the API to add nodes from a CSV, and set custom properties. Here is the content of the CSV:
Code, Hostname, IpAddr, Department, Env, TimeOffset
C1, DAG01, 10.0.0.1, Win DBA, Testing, 0
C2, DAG02, 10.0.0.2, Server Operations, Production, 0
The nodes get created, the custom properties get set, but they are never polled and the NodeID is not inserted into the Pollers table. The IP (changed for this thread) is pingable. When I use the GUI "Add Node" and the same IP it gets into the poller table and comes up right away.
What am I missing?
Here is the code:
#requires -version 2
<#
.SYNOPSIS
This script is used to add a new node using CRUD operations from a CSV file
It adds the node in Alert_Muted_Node = TRUE state
Other customproperties can be set
The script progresses in several steps:
1. Create the node based on caption and IP
1a. Optionally set a trailing caption qualifier
2. Assign ICMP pollers
3. Set custom properties
.DESCRIPTION
Run via SWIS.
.OUTPUTS
None.
.NOTES
Version: 1.0
Author: Michael Landman <Michael.Landman@FirstCitizens.com>
Creation Date: MAR. 01, 2017
Purpose/Change: Initial script development.
#>
#---------------------------------------------------------[Initializations]--------------------------------------------------------
# set error action to silently continue
$ErrorActionPreference = "SilentlyContinue"
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# script version
$scriptVersion = "1.0"
#-------------------------------------------------------------[Init]---------------------------------------------------------------
$hostname = "REDACTED";
$Nodename = @();
$IPAddr = @();
$Dept = @();
$Environ = @();
$TimeO = @();
$customProps = @();
$CaptionQualifier = "";
$PathToFile = "D:\temp\TestClustersIP.csv";
$msg="";
$now = (get-date -Format s);
$outFile = ("d:\temp\$now.AddIcmpNodeSWISlog.txt").Replace(":",".");
#-----------------------------------------------------------[Functions]------------------------------------------------------------
#-----------------------------------------------------------[Execution]------------------------------------------------------------
if (-not (Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {
Add-PSSnapin "SwisSnapin"
}
# Connect to SWIS
$cred = Get-Credential
$swis = Connect-Swis -host $hostname -cred $cred
Import-Csv $PathToFile |ForEach-Object {
$Nodename += $_."Hostname";
$IPAddr += $_."IpAddr";
$Dept += $_."Department";
$Environ += $_."Env";
$TimeO += $_."TimeOffset";
}
#$ip = "10.0.0.1"
# add a node
for ($i=0; $i -lt $Nodename.length; $i++)
{
If($Nodename[$i] -match "sd")
{
$CaptionQualifier = "_SqlCluster";
}
else
{
$CaptionQualifier = "_Cluster";
}
$newNodeProps = @{
IPAddress = $IPAddr[$i];
EngineID = 1;
ObjectSubType = "ICMP";
Caption = $Nodename[$i] + $CaptionQualifier;
# SNMP v2 specific
#ObjectSubType = "SNMP";
#SNMPVersion = 2;
# === 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
# 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
# set Alert_muted_Node to True and other custom properties
# prepare a custom property value. These MUST be present or no properties will be set
$customProps = @{
Alert_Muted_Node=1;
Department = $Dept[$i];
Environment = $Environ[$i];
TimeOffset=$TimeO[$i];
}
# build the node URI
$uri = "swis://$hostname/Orion/Orion.Nodes/NodeID=$($nodeProps["NodeID"])/CustomProperties";
# set the custom property
Set-SwisObject $swis -Uri $uri -Properties $customProps
}