For a while now we have had automation scripts in place for adding in nodes that we monitor via SNMP, namely linux server. The automation scripts work well and add in the server, add in the interfaces and the volumes. These scripts save our teams a great deal of time as when they start the automated build process, they get a report out at the end of it that shows the server has been added into solarwinds, the network interface is added and all of the standard file system - brilliant, our work here is Done!
Except, this doesn't work for Windows servers! There also is nothing in the samples for doing all of this with WMI and windows. SO after a lot of digging and trial and error I have come up with the following script that does add an interface to a windows server using WMI!
So a lot of head scratching went on as we were trying to use the discovery script for SNMP - bad move we then started looking at the the add SNMP interfaces, which gave us a better starting point. We eventually came up this the following script:
############################################################################
# Pass variable in on the command line using the named switches
# eg c:\addinterface.ps1 -ip 127.0.0.1
#
# currently the IP address of the node is hard coded for testing.
# By commenting out the line starting $ip and uncomment param we can then pass the IP in as shown above
#param ($ip)
$ip= "<IP address of the node to add interface to>"
write-host $ip
if (!(Get-PSSnapin | where {$_.name -eq "swisSnapin"})) {
Add-PSSnapin swissnapin
}
# Connect to SWIS
$swis = connect-swis -hostname localhost -Trusted
# Script Variables loaded from param
$ipaddress = $ip
# Fetch Node Details
# Check that Node exists
$NodeID = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE IPAddress=@ipadd" @{ipadd=$ipaddress}
if (!$NodeId) {
Write-Host "ERROR: Can't find Node with IP Address '$ipaddress'"
exit 1
}
write-host "NodeID: "$NodeID
$GetNodeUri = Get-swisdata $swis "SELECT uri FROM Orion.Nodes WHERE IPAddress=@ipadd" @{ipadd=$ipaddress}
$nodeProps = Get-SwisObject $swis -Uri $GetNodeUri
write-host $nodeProps
$NodeID = $nodeProps["NodeID"]
write-host $NodeID
# add an interface, please fill in the correct values you need
# these seem to be the minimum values needed to get the interface to add correctly
$newIfaceProps = @{
NodeID = $NodeID;
InterfaceIndex=3;
InterfaceName='vmxnet3 Ethernet Adapter';
IfName="ethernet_32772";
# Interface Index may need to be passed in from vco or altered to match build details
Caption="vmxnet3 Ethernet Adapter · Ethernet0";
ObjectSubType="WMI";
#Status=0;
RediscoveryInterval=5;
PollInterval=10;
StatCollection=1;
NextRediscovery=[DateTime]::UtcNow;
InterfaceIcon="6.gif";
Interfacetypename="ethernetCsmacd";
nextpoll=[DateTime]::UtcNow;
InterfacetypeDescription="Ethernet";
Interfacesubtype=3;
InterfaceType=6;
InterfaceAlias="Ethernet0";
Counter64="Y";
}
add-content WMI.txt $newIfaceProps
Write-host "Debug: New interface properties : $newIfaceProps"
$newIfaceUri = New-SwisObject $swis –EntityType "Orion.NPM.Interfaces" –Properties $newIfaceProps
Write-Host "Debug: New interface uri : $newIfaceUri"
$ifaceProps = Get-SwisObject $swis -Uri $newIfaceUri
Write-Host "Debug: New interface properties $ifaceProps"
# register specific pollers for the node
# for WMI nodes you need to use WI instead of I
$poller = @{
NetObject="IW:"+$ifaceProps["InterfaceID"];
NetObjectType="IW";
NetObjectID=$ifaceProps["InterfaceID"];
}
$IntID = $ifaceProps["InterfaceID"]
Write-host "Echo - Interface ID is $IntID"
# Below are the pollers needed for WMI - these werre pulled from the poller table in the DB
#
# Status
$poller["PollerType"]="IW.Status.WMI.WinV62";
$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
# Interface Traffic
$poller["PollerType"]="IW.StatisticsTraffic.WMI.WinV62";
$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
# Interface Errors
$poller["PollerType"]="IW.StatisticsErrors.WMI.WinV62";
$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
# Rediscovery
$poller["PollerType"]="IW.Rediscovery.WMI.WinV62";
$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
# Trigger a PollNow on the node to cause other properties and stats to be filled in
Invoke-SwisVerb $swis Orion.Nodes PollNow @("N:" + $nodeProps["NodeID"])
##########################################################################################
Please feel free to try this out.
Things you'll need to change are:
Caption, IfName, interfacename & interfacealias. if you are unsure what these are then using SWQL studio on your environment run
select Caption, IfName, interfacename, interfacealias from orion.npm.interfaces
where objectsubtype='WMI'
this will then give you those 4 values to set within your script.
This script runs using the localhost and trusted so save the script to your main server and run it from there - little more secure that hard coding a username and password into the script. If you want to use a username and password and not hard code them, then you can edit the $swis and add a few lines before. This basically gets you to enter your login creds securely and passes them into the connection string:
$creds= get-credential -Message "Please enter your login details to access the SWIS functions" #pops up a windows box
$hostname= '<maninpollername>'
# Connect to SWIS
$swis = connect-Swis -host $hostname -credential $creds
I hope this helps someone out there as for a good while we have automated the build and addition of our Linux nodes into NPM, but now with this we will be able to automate our windows build and addition to monitoring
@aparna.valsala @deekshitha.krishnappa @dc4networks @KMSigma.SWI