Export multiple monitor definitions

Topics: Developer Forum, News & Releases, Project Management Forum, User Forum
Jul 9, 2008 at 7:13 AM
I have to monitor loads of perf counters for a very large numbers of servers.

After defining all the monitors for 1 server is there a way i can export the setting so as to configure the other servers without having to clone each monitor definition for each counter for each server and edit settings
Developer
Jul 9, 2008 at 4:29 PM
Edited Jul 9, 2008 at 5:25 PM


ed300900 wrote:
I have to monitor loads of perf counters for a very large numbers of servers.

After defining all the monitors for 1 server is there a way i can export the setting so as to configure the other servers without having to clone each monitor definition for each counter for each server and edit settings

--UPDATE - the <Host> and </Host> tags need the H to be capitalized.. I updated the example below

You could use the PowerShell Cmdlets for PolyMon.  If you are just changing the name and host information for your monitors (and leaving the other things the same), you could do something like --

$NameOfMonitorToCopy = 'Name of Monitor To Copy'
$NewServers = Import-CSV c:\servers.csv

foreach ($Server in $NewServers)
{
    $MonitorToCopy = Get-Monitor $NameOfMonitorToCopy
    $MonitorToCopy.MonitorXMLString = $MonitorToCopy.MonitorXMLString -replace '<host>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+</host>', ("<Host>$Server.IPAddress</Host>")
    New-Monitor -Monitor $MonitorToCopy -NewName $Server.MonitorName | out-null
}

You might get a warning, but the monitor was created correctly.  I'm reviewing the cmdlet code though..

This script would load the CSV file and create a number of new custom objects with the new monitor names and IP addresses for those targeted machines.  The script then loads the information from the first created monitor to use as a template.

The first line in the foreach uses a regular expression to replace the current value for the host field in the monitor set up with the IP address assigned in the CSV file.  The second line creates a new monitor object (and writes it to the database) using the template provided and using the Monitor Name from the CSV file.

This script relys on a CSV file set up like below, with the Monitor Name and the new IP Address.  The line preceded by the '#' allows PowerShell to see that as a custom object to import.
#TYPE System.Management.Automation.PSCustomObject
MonitorName, IPAddress
NewMonitor1, 172.27.27.1
NewMonitor2, 172.27.27.2

If any of this is not clear, please let me know, I'd be happy to work with you on it.

Steve