##########################################################################################
# <copyright file="NewJEEAppServer.ps1" company="Microsoft">
# Copyright (c) Microsoft Corporation. All rights reserved.
# </copyright>
# <summary>Powershell script to perform a first stage discovery of a Java JEE
# application server. The output is a discovered OM
# "Microsoft.JEE.Universal.ApplicationServer" object. </summary>
##########################################################################################
begin
{
Set-PSDebug -Strict
. .\JEEAppServerLibrary.ps1
##########################################################################################
#
# Processes one app server.
# The input URL is parsed for correctness and the hostname and port are extracted.
# The application server type and version are either obtained from the command
# line arguments or queried from the application server if not specified on the command line.
#
# If all the requirements are met a new Operations Manager Discovery data item
# is created using these attributes.
#
# Parameter jeeAppServer - the URL to the application server.
#
##########################################################################################
function ProcessJEEAppServer($jeeAppServer)
{
#
# Validate that the input URL is correctly formed, the protocol, port and hostname are
# extracted from the URL
#
$appServerProp = ParseURL $jeeAppServer
if ($appServerProp -eq $null)
{
Write-Host -foregroundcolor Red "`nFailed to Parse the URL `: $jeeAppServer `n"
return;
}
$appServerHost = $appServerProp["appServerHost"]
$appServerPort = $appServerProp["appServerPort"]
$appServerProtocol = $appServerProp["protocol"]
#
# Get the Discovery class
#
$jeeAppServerClass = GetMonitoringClass $managementGroup "Microsoft.JEE.Universal.ApplicationServer"
if( $jeeAppServerClass -eq $null )
{
#the Microsoft.JEE.Universal.ApplicationServer MP has not been loaded
Write-Host -foregroundcolor Red "`nFailed to load class (Microsoft.JEE.Universal.ApplicationServer) from the imported MP's,"
Write-Host -foregroundcolor Red "please ensure MP's JEE MP's are imported.`n"
return;
}
$jeeAppServerObject = new-object Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObject($jeeAppServerClass)
if ($monitoredProp -eq $null)
{
Write-Host -foregroundcolor Red "Unable to determine the application server type and version `: $jeeAppServer `n"
return
}
$appServerType = $monitoredProp["appServerType"]
$appServerVersion = $monitoredProp["appServerVersion"]
# Print help text.
if ($Help)
{
$helpstr = "`n`nNew-JEEAppServer.ps1`n" +
"`n" +
"Discovers JEE App Servers into Operations Manager. BeanSpy should be deployed to each application server to be discovered.`n" +
"`n" +
"Input:`n" +
" The script accepts a number of JEE App Servers on the input pipe.`n" +
" Each JEE App Server is represented as a fully qualified URL, for example, http://www.contoso.com:8080.`n" +
"`n" +
"Output:`n" +
" The script displays an error message for each app server it fails to discover.`n" +
"`n" +
"Parameters:`n" +
" ManagementServer - Name of OpsMgr server to use. Use current computer if not specified`n" +
" JEEAppServerType - Supported types are JBoss, Tomcat, WebSphere, and WebLogic.`n" +
" Will query each application server if not specified.`n" +
" JEEAppServerVersion - Supported versions are JBoss 4, 5, 6, Tomcat 5, 6, 7, WebSphere 6, 7, and WebLogic 10, 11.`n" +
" Will query each application server if not specified.`n" +
" UserName - User name to access the App Server URL. If provided, the script will prompt for password`n" +
" Target - Additional JEE App Server to discover`n" +
" (done before any JEE App Server piped into the script)`n" +
" help - Prints this help`n" +
"`n" +
"Examples:`n" +
" New-JEEAppServer.ps1 -Target http://www.contoso.com:8080`n" +
" type c:\MyAppServers.txt | New-JEEAppServer.ps1 -JEEAppServerType WebLogic -JEEAppServerVersion 11 `n" +
" type c:\MyAppServers.txt | New-JEEAppServer.ps1 -UserName mymonitor`n"
"`n"
Write-Host $helpstr
exit
}
#
# Load the assemblies required by this script
#
if( Load-Assemblies -eq $true )
{
# If we have one target as command line input we process it first.
if ($Target -ne "")
{
ProcessJEEAppServer $Target
}
}
}
process
{
# Process any targets in pipe.
if ($_)
{
ProcessJEEAppServer $_
}
}