<ProbeActionModuleType ID="Fujitsu.Servers.PRIMERGY.OutOfBand.PerfMon.PerformanceMonitor.Probe" Accessibility="Internal" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false" PassThrough="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="StrictErrorHandling" type="xsd:boolean"/>
<!-- Fixed Parameters -->
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="UserName" type="NonNullString"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Password" type="NonNullString"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SkipCACheck" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SkipCNCheck" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ManagementUrl" type="NonNullString"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>PerfMonMonitor.ps1</ScriptName>
<ScriptBody><Script>
##################################################################################
# #
# NOTICE #
# #
# COPYRIGHT 2014 - 2016 Fujitsu Technology Solutions #
# ALL RIGHTS RESERVED #
# #
# This computer program is CONFIDENTIAL and contains TRADE SECRETS of #
# Fujitsu Technology Solutions. The receipt or possession of this program does #
# not convey any rights to reproduce or disclose its contents, or to #
# manufacture, use, or sell anything that it may describe, in whole or #
# in part, without the specific written consent of Fujitsu Technology Solutions. #
# Any reproduction of this program without the express written consent #
# of Fujitsu Technology Solutions is a violation of the copyright laws and may #
# subject you to civil liability and criminal prosecution. #
# #
##################################################################################
# This script collects all Performance Sensors information from the iRMC system report
# For cookdown the component status identifier and a mapped HealthStatus
# property bag are returned and filtered afterwards for the specific component status
# set CONSTANT variables (can not be changed):
set-variable -name PoShScriptName -value $ScriptName -option constant
[int]$SCRIPT_EVENT_NUMBER = 8209 # a prime
# Note: Keep in sync with discovery
[int]$ERROR_NO_SDR_INFORMATION = 8231 # a prime
[int]$ERROR_NO_TEMP_INFORMATION = 8233 # a prime
[int]$ERROR_NO_POWERCONSUMPTION_INFORMATION = 8237 # a prime
[bool]$propertyBagReturned = $False
# SCCI Temperature Status Value definition
[int]$CMV_SENSSTAT_NOTAVAIL = 0
[int]$CMV_SENSSTAT_OK = 1
[int]$CMV_SENSSTAT_FAIL = 3
[int]$CMV_SENSSTAT_TEMPWARN = 4
[int]$CMV_SENSSTAT_TEMPCRIT = 5
[int]$CMV_SENSSTAT_TEMPOK = 6
[int]$CMV_SENSSTAT_TEMPPREWARN = 7
$hostURL = $ManagementUrl
# Extract the IP from the ManagementUrl
$IP = $ManagementUrl.Substring(0, $ManagementUrl.LastIndexOf(":")).ToUpper().TrimStart("HTTPS://")
# we need to make multiple authenticated HTTP requests...
[System.Net.NetworkCredential]$NetworkCredential = New-Object System.Net.NetworkCredential ($UserName, $Password)
[System.Net.ServicePointManager]::DefaultConnectionLimit = 1000
# Strip any potential garbage at the and of the XML string
Function Clean-XmlString ([string]$xmlString, [string]$endTag) {
if ($xmlString.contains( $endTag )) {
$xmlString.TrimEnd( $xmlString.Substring( ($xmlString.IndexOf($endTag) +$endTag.Length) ))
} else {
$xmlString
}
}
# something went wrong
Function EarlyExit
{
if ($propertyBagReturned -eq $False) {
# Return empty property bag if something went wrong
$propertyBag = $ScriptApi.CreatePropertyBag()
$propertyBag
}
Exit
}
# We monitor only a subset of available Temperature Sensors as Performance Monitors
if (($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_INLET_AIR_TEMP) -or ($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_SYSTEM_BOARD) -or ($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_POWER_SUPPLY) -or ($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_PROCESSOR) -or ($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_MEMORY_DEVICE)){
$SensorUnits = $SensorNumber = $SensorType = $EntityId = $EntityInstance = 'N/A'
if ($sdr.Data.Decoded.Sensor.BaseUnitName -ne $Null) {
$SensorUnits = $sdr.Data.Decoded.Sensor.BaseUnitName
}
if ($sdr.Data.Decoded.Sensor.TypeName -ne $Null) {
$SensorType = $sdr.Data.Decoded.Sensor.TypeName
}
if ($sdr.Data.Decoded.Key.SensorNumber -ne $Null) {
$SensorNumber = $sdr.Data.Decoded.Key.SensorNumber
}
if ($sdr.Data.Decoded.Entity.ID -ne $Null) {
$EntityId = IPMI-GetEntityId ([int]$sdr.Data.Decoded.Entity.ID)
}
if ($sdr.Data.Decoded.Entity.Instance -ne $Null) {
$EntityInstance = $sdr.Data.Decoded.Entity.Instance
}
$propertyBag = $ScriptApi.CreatePropertyBag()
# Map numeric SCCI Temperature Status to health status
switch ($StatusVal) {
$CMV_SENSSTAT_OK {$HealthStatus = 'OK' } # digital discrete
$CMV_SENSSTAT_FAIL {$HealthStatus = 'Error' } # digital discrete
$CMV_SENSSTAT_TEMPWARN {$HealthStatus = 'Warning'} # Threshold
$CMV_SENSSTAT_TEMPCRIT {$HealthStatus = 'Error' } # Threshold
$CMV_SENSSTAT_TEMPOK {$HealthStatus = 'OK' } # Threshold
$CMV_SENSSTAT_TEMPPREWARN {$HealthStatus = 'Warning'} # Unused
default {$HealthStatus = 'Unknown'}
}
# The Out-Of-Band Server this Temperature Monitor is hosted
$propertyBag.AddValue('IP' , $IP)
# Properties to identify this Temperature Monitor Instance
$propertyBag.AddValue('ID' , $SensorName)
$propertyBag.AddValue('SensorType' , $SensorType)
$propertyBag.AddValue('SensorNumber' , $SensorNumber)
$propertyBag.AddValue('EntityId' , $EntityId)
$propertyBag.AddValue('EntityInstance', $EntityInstance)
$propertyBag.AddValue('HealthStatus' , $HealthStatus)
$propertyBag.AddValue('CurrentValue' , $elem.CurrValue) # Actual Performance Monitor Value ...
DebugOut "$IP - Temperature '$($SensorName)' SensorNumber=$($SensorNumber) SensorType='$($SensorType)' Entity ID='$($EntityId)' Entity Instance='$($EntityInstance)' Status='$($elem.Status.Description)' HealthStatus='$($HealthStatus)' Current Value: $($elem.CurrValue) $SensorUnits"
# Return each property bag as we create and populate it.
$propertyBag
$propertyBagReturned = $True
}
}
} else {
DebugErr $ERROR_NO_TEMP_INFORMATION "$IP - Temperature System Report not available"
}
}
} catch {
DebugErr $ERROR_NO_TEMP_INFORMATION "$IP - Could not process iRMC Temperature System Report Information. Exception=$_"
}
} else {
# No response or garbage ...
LogScriptEventWithEventSource -EventSource $IP -EventLevel $WARNING_LEVEL -EventNumber $ERROR_NO_TEMP_INFORMATION -Message ("iRMC System Report Information not available")
DebugErr $ERROR_NO_TEMP_INFORMATION "$IP - iRMC Temperature System Report Information not available"
}
if ($powerInst -ne $Null ) {
DebugOut "$IP - Processing Power Consumption Information"
foreach ($elem in $powerInst.Sensors.Sensor) {
$SensorName = $elem.Name
$Status = $elem.Status.GetAttribute("Description")
if ($Status -eq 'Not Present') {
DebugOut "$IP -`t`tSkipping Not Present Power Consumption Sensor '$($SensorName)' ..."
continue
}
if ($Status -eq 'N/A') {
DebugOut "$IP -`t`tSkipping N/A Power Consumption Sensor '$($SensorName)' ..."
continue
}
# Find matching SDR
$sdr = @($powerSdr | where { $_.Data.Decoded.Entity.Name -eq $SensorName } )
if ($sdr.count -eq 0 ) {
DebugOut "$IP -`t`tSkipping Power Consumption Sensor '$($sensorName)' due to not found SDR ..."
continue
}
if ($sdr.count -gt 1) {
DebugOut "$IP -`t`tSkipping Multi Instance / Build To Order Power Consumption Sensor '$($SensorName)' ..."
continue
}
# We monitor only a subset of available Power Consumption as Performance Monitors
if (($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_OEM_E0) -or ($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_POWER_SUPPLY) -or ($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_PROCESSOR) -or ($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_SYSTEM_CHASSIS)){
# Note: Entity Instance 0: primary (external) Power Consumption (power plug)
# Entity Instance 1: secondary (internal) Power Consumption (after the PSU internal losses)
# Typical names are: 'Total Power' / 'Total Power Out'
# Skip the 'Total Power Out' instance (also applies to System Chassis for Multi Node Systems)
if ($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_OEM_E0 -and $sdr.Data.Decoded.Entity.Instance -ne 0) {
continue
}
if ($sdr.Data.Decoded.Entity.ID -eq $SDR_ENTITY_ID_SYSTEM_CHASSIS -and $sdr.Data.Decoded.Entity.Instance -ne 0) {
continue
}
if ($sdr.Data.Decoded.Sensor.BaseUnitName -ne $Null) {
$SensorUnits = $sdr.Data.Decoded.Sensor.BaseUnitName
}
if ($sdr.Data.Decoded.Sensor.TypeName -ne $Null) {
$SensorType = $sdr.Data.Decoded.Sensor.TypeName
}
if ($sdr.Data.Decoded.Key.SensorNumber -ne $Null) {
$SensorNumber = $sdr.Data.Decoded.Key.SensorNumber
}
if ($sdr.Data.Decoded.Entity.ID -ne $Null) {
$EntityId = IPMI-GetEntityId ([int]$sdr.Data.Decoded.Entity.ID)
}
if ($sdr.Data.Decoded.Entity.Instance -ne $Null) {
$EntityInstance = $sdr.Data.Decoded.Entity.Instance
}
$propertyBag = $ScriptApi.CreatePropertyBag()
# Map Status to health status
switch ($Status) {
'OK' {$HealthStatus = 'OK' }
'Critical' {$HealthStatus = 'Error' }
'Warning' {$HealthStatus = 'Warning'}
default {$HealthStatus = 'Unknown'}
}
# The Out-Of-Band Server this Performance Monitor is hosted
$propertyBag.AddValue('IP' , $IP)
# Properties to identify this Performance Monitor Instance
$propertyBag.AddValue('ID' , $SensorName)
$propertyBag.AddValue('SensorType' , $SensorType)
$propertyBag.AddValue('SensorNumber' , $SensorNumber)
$propertyBag.AddValue('EntityId' , $EntityId)
$propertyBag.AddValue('EntityInstance', $EntityInstance)
$propertyBag.AddValue('HealthStatus' , $HealthStatus)
$propertyBag.AddValue('CurrentValue' , $elem.CurrentValue) # Note: Actual Performance Monitor Value ...
DebugOut "$IP - PowerConsumption '$($SensorName)' SensorNumber=$($SensorNumber) SensorType='$($SensorType)' Entity ID='$($EntityId)' Entity Instance='$($EntityInstance)' Status='$($elem.Status.Description)' HealthStatus='$($HealthStatus)' Current Value: $($elem.CurrentValue) $SensorUnits"
# Return each property bag as we create and populate it.
$propertyBag
$propertyBagReturned = $True
}
}
} else {
# Power Consumption is optional
DebugOut "$IP - Power Consumption System Report not available"
}
}
} catch {
DebugErr $ERROR_NO_POWERCONSUMPTION_INFORMATION "$IP - Could not process iRMC Power Consumption System Report Information. Exception=$_"
}
} else {
# No response or garbage ...
LogScriptEventWithEventSource -EventSource $IP -EventLevel $WARNING_LEVEL -EventNumber $ERROR_NO_POWERCONSUMPTION_INFORMATION -Message ("iRMC Power Consumption System Report Information not available")
DebugErr $ERROR_NO_POWERCONSUMPTION_INFORMATION "$IP - iRMC Power Consumption System Report Information not available"
}
if ($propertyBagReturned -eq $False) {
# Return empty property bag if something went wrong
$propertyBag = $ScriptApi.CreatePropertyBag()
$propertyBag
}
DebugOut "$IP - Performance Monitoring for Fujitsu Out-Of-Band Server - finished"
}
# This script part contains some IPMI helper functions
# and is embedded into the final script via Visual Studio Authoring Extensions
# This script part contains helper functions to perform web based requests
# and is embedded into the final script via Visual Studio Authoring Extensions
[int]$ERROR_SSL_CA_ERROR = 8399 # is not a prime
[int]$ERROR_SSL_CN_ERROR = 8499 # is not a prime
[int]$ERROR_BMC_NO_RESPONSE = 8599 # is a prime
[int]$ERROR_BMC_NO_ACCESS = 8699 # is a prime
[int]$ERROR_BMC_TIMEOUT = 8799 # is not a prime
[int]$ERROR_BMC_BUSY = 8999 # is a prime
$webRequest = [System.Net.WebRequest]::Create($url)
if ($Credentials -ne $Null) {
if ($AuthType -eq "Basic") {
# Do not wait for the 401 response, send the credentials with the initial request
$AuthData = [Convert]::ToBase64String([Text.Encoding]::Default.GetBytes($Credentials.UserName + ':' + $Credentials.Password));
$webRequest.Headers.Add('Authorization', "Basic $AuthData")
# no response (object), check for the timeout value.
# If the connection gets closed during early send/receive,
# this is typically within a few seconds, otherwise the configured timeout will have expired
if ($resTime -ne $Null -and [int]$resTime.TotalSeconds -lt 5) {
[int]$retryDelay = (($retries +1) * $DEFAULT_RETRY_INCREMENT)
# LogScriptEventWithEventSource -EventSource $IP -EventLevel $WARNING_LEVEL -EventNumber $ERROR_BMC_NO_RESPONSE -Message ("'$url' no response / connection closed ")
if ($errorMsg -ne $Null) { DebugWarn "$IP - '$url' no response / connection closed within $($resTime.TotalSeconds) seconds - will retry in $retryDelay seconds ($errorMsg)"}
else { DebugWarn "$IP - '$url' no response / connection closed within $($resTime.TotalSeconds) seconds - will retry in $retryDelay seconds (no details available)"}
if ($innerException -ne $Null) { DebugWarn "InnerException:`r`n$innerException" }
if ($stackTrace -ne $Null ) { DebugWarn "Stack Trace:`r`n$stackTrace" }
Start-Sleep -Seconds $retryDelay
} else {
# Note: do no report actual timeout seconds here, or alert suppression will not fully work due to different text
LogScriptEventWithEventSource -EventSource $IP -EventLevel $WARNING_LEVEL -EventNumber $ERROR_BMC_TIMEOUT -Message ("'$url' no response. Timeout was $RequestTimeout seconds")
DebugOut "$IP - '$url' no response within $($resTime.TotalSeconds) seconds. Timeout was $RequestTimeout seconds"
return
}
}
} catch {
# LogScriptEventWithEventSource -EventSource $IP -EventLevel $WARNING_LEVEL -EventNumber $SCRIPT_EVENT_NUMBER -Message ("'$url' generic Exception=$_")
DebugWarn "$IP - '$url' generic Exception=$_"
}
}
LogScriptEventWithEventSource -EventSource $IP -EventLevel $WARNING_LEVEL -EventNumber $ERROR_BMC_NO_RESPONSE -Message ("'$url' no response after $retries retries (last error: $errorMsg)")
DebugOut "$IP - '$url' no response after $retries retries (last error: $errorMsg)"
}
# This script part contains helper functions to perform various logging activities
# and is embedded into the final script via Visual Studio Authoring Extensions
# Log an event into the registry, Source will be 'Health Service Script'
# See https://msdn.microsoft.com/en-us/library/bb437630.aspx
[int]$WARNING_LEVEL = 2
[int]$ERROR_LEVEL = 1
[int]$INFO_LEVEL = 0
$LOGFILE_VERSION = 8.1.0.0
# Generic version
Function RaiseEvent {
Param (
[parameter(Mandatory=$true)]
[string]$EventSource = "Fujitsu Out-Of-Band",
[parameter(Mandatory=$true)]
[int]$EventLevel,
[parameter(Mandatory=$true)]
[int]$EventNumber,
[parameter(Mandatory=$true)]
[string]$Message
)
# Backwards compatible wrapper
Function LogScriptEvent {
Param (
[parameter(Mandatory=$true)]
[ValidateRange(0,2)]
[int]$EventLevel,
[parameter(Mandatory=$true)]
[int]$EventNumber,
[parameter(Mandatory=$true)]
[string]$Message
)
# Note: Log will be written always with Event Source 'Health Service Script'
if ($ScriptApi -ne $Null) {
# Note: do not use actual script name to consolidate Alert Suppression from parallel scripts
$ScriptApi.LogScriptEvent("Fujitsu Out-Of-Band", $EventNumber, $EventLevel, $Message)
# $ScriptApi.LogScriptEvent($PoShScriptName, $EventNumber, $EventLevel, $Message)
}
}
# --------------------------------------------------------------------------
# Global variables = variables, which are changed in different functions ...
# ... and the changed value shall be available in the calling function
# --------------------------------------------------------------------------
$global:DebugMode = $False
$global:DebugFile = $False
$global:OverWrite = $True
$global:DebugHosts = ""
$global:DebugForHost = "$False"
$global:ErrFilePrefix = "ERRORTrace"
$global:WarnFilePrefix = "WARNINGTrace"
$global:LogTargetName = ""
$global:LogFilePrefix = ""
$global:LogFilePath = "$Env:TEMP\SVISCOM\SVISCOM-OutOfBand"
$global:LogFileName = "$LogFilePath\$($LogFilePrefix).log"
# create the target directory, if it does not exist
if ( ! (Test-Path -Path $global:LogFilePath)) {
New-Item -ItemType directory -Path $global:LogFilePath | Out-Null
}
if (Test-Path -Path $global:LogFilePath) {
$pathOK = $True
}
if (Test-Path -Path $Xm_FileName) {
$txt = get-content $Xm_FileName
foreach ($line in $txt) {
if ($line.contains($LOGFILE_VERSION)) {
$fileOK = $True
break
}
}
}
if (($pathOK -eq $True) -and ($fileOK -eq $False)) {
# we write a new SVISCOM-OutOfBand.xm_ file every time the MP is changed to make sure all
# INI-Values are documented for use by the customer if anything changes.
if (Test-Path -Path $Xm_FileName) {
Remove-Item -Path $Xm_FileName -Force | Out-Null
}
#Create xm_ file
New-Item -Path $Xm_FileName -ItemType File | Out-Null
Add-Content -Path $Xm_FileName -Value @"
<$SectionRoot>
<!--
$SVISCOMLogXmlName Debug XML file Version $LOGFILE_VERSION
With this file logging for PowerShell scripts within the
- Fujitsu Out-Of-Band Management Pack and
- Optional Extension Management Packs for the Fujitsu Out-Of-Band Management Pack
can be enabled.
Rename the file type from '.xm_' to '.xml' to enable reading this file.
Note: You have to enable debug for a script and also select the server in
the '<$TagHostsDiscovery>' or '<$TagHostsMonitoring>' section to generate traces (see below).
The following sections specify for which PowerShell scripts the traces will be generated;
Each of the sections represents a single PowerShell script.
'<$TagDebugMode>' enables logging (yes) or disables logging (no)
'<$TagOverWrite>' defines continuous logging (no) or single script run logging (yes)
-->
<!-- DISCOVERIES -->
<!-- The following section enables trace files for the Out-Of-Band Server discovery script -->
<$SectionServerDiscovery>
<$TagDebugMode>yes</$TagDebugMode>
<$TagOverWrite>no</$TagOverWrite>
</$SectionServerDiscovery>
<!-- The following section enables trace files for the SMASH device discovery script -->
<$SectionSmashDiscovery>
<$TagDebugMode>yes</$TagDebugMode>
<$TagOverWrite>no</$TagOverWrite>
</$SectionSmashDiscovery>
<!-- The following section enables trace files for the RAID discovery script -->
<$SectionRaidDiscovery>
<$TagDebugMode>yes</$TagDebugMode>
<$TagOverWrite>no</$TagOverWrite>
</$SectionRaidDiscovery>
<!-- The following section enables trace files for the Performance Monitor discovery script -->
<$SectionPerformanceDiscovery>
<$TagDebugMode>yes</$TagDebugMode>
<$TagOverWrite>no</$TagOverWrite>
</$SectionPerformanceDiscovery>
<!-- MONITORS -->
<!-- The following section enables trace files for the main server Hardware Components (CPU/Memory/Fan/PowerSupply) monitoring script -->
<$SectionHardwareComponentMonitor>
<$TagDebugMode>yes</$TagDebugMode>
<$TagOverWrite>no</$TagOverWrite>
</$SectionHardwareComponentMonitor>
<!-- The following section enables trace files for the 'Component Status' monitoring script -->
<$SectionComponentStatusMonitor>
<$TagDebugMode>yes</$TagDebugMode>
<$TagOverWrite>no</$TagOverWrite>
</$SectionComponentStatusMonitor>
<!-- The following section enables trace files for the RAID monitoring script -->
<$SectionRaidMonitor>
<$TagDebugMode>yes</$TagDebugMode>
<$TagOverWrite>no</$TagOverWrite>
</$SectionRaidMonitor>
<!-- The following section enables trace files for the Performance monitoring script -->
<$SectionPerformanceMonitor>
<$TagDebugMode>yes</$TagDebugMode>
<$TagOverWrite>no</$TagOverWrite>
</$SectionPerformanceMonitor>
<!--
The following sections specify for which servers the traces will be generated:
In the '<$TagHostsDiscovery>' and '<$TagHostsMonitoring>' sections
single or multiple servers can be specified for verbose debug output
during the discovery and/or during monitoring.
Use '<$TagHostsDiscovery>' for selecting hosts for the discovery trace.
Use '<$TagHostsMonitoring>' for selecting hosts for the monitoring trace.
Use 'all' (without quote signs) for all Fujitsu Out-Of-Band Servers monitored by SCOM.
Use a single IP address or a comma separated list to select multiple single servers
Example:
<$TagHostsDiscovery>all</$TagHostsDiscovery>
<$TagHostsMonitoring>192.168.1.100,192.168.1.101,192.168.1.102</$TagHostsMonitoring>
will generate discovery traces for all Fujitsu Out-Of-Band Servers and
will generate monitoring traces only for servers with the IP address
192.168.1.100 192.168.1.101 and 192.168.1.102
-->
<$TagHostsDiscovery>all</$TagHostsDiscovery>
<$TagHostsMonitoring>all</$TagHostsMonitoring>
</$SectionRoot>
"@
}
}
if (Test-Path -Path $global:LogFilePath) {
if (Test-Path -Path $XmlFileName) {
[xml]$xmlfile = Get-Content $XmlFileName
if ($xmlfile.$SectionRoot.$section.$TagDebugMode -ne $null) {
if ($($xmlfile.$SectionRoot.$Section.$TagDebugMode).ToUpper() -eq "YES") {
$global:DebugMode = $True
$global:DebugFile = $True
}
}
if ($xmlfile.$SectionRoot.$section.$TagOverWrite -ne $null) {
if ($($xmlfile.$SectionRoot.$Section.$TagOverWrite).ToUpper() -eq "NO") {
$global:OverWrite = $False
}
}
if ($xmlfile.$SectionRoot.$HostTag -ne $null) {
$global:DebugHosts = $($xmlfile.$SectionRoot.$HostTag).ToLower()
}
# Check if DEBUG shall run for this server.
# There are two possibilities to check: "all" server DEBUG is on or this server is in the list.
if ($global:DebugHosts -eq "all") {
$global:DebugForHost = $True
} else {
# Check if this host is in the list of DebugHosts
$ListOfHosts = $($global:DebugHosts).split(',')
DebugOut "Searching for host: $ServerName"
DebugOut "in list of DebugHosts: $global:DebugHosts"
if ($ServerName.ToLower() -in $ListOfHosts) {
$global:DebugForHost = $True
}
}
} # else file does not exist
} # else directory does not exist
}
Function CreateLogFile
{
# For some reason checking for "$True" with "if ($global:a -and $global:b)" is not evaluated correctly!!!
# It works OK in a test with a simple PS script ... no idea why ... Thus we use:
if ($global:DebugForHost -eq $True) {
if ($global:DebugFile -eq $True) {
# Create the target directory, if it does not exist
if (!(Test-Path -Path $global:LogFilePath)) {
New-Item -ItemType directory -Path $global:LogFilePath | Out-Null
}
# Check if file exists and delete if it does and OverWrite is set to TRUE
if (Test-Path -Path $global:LogFileName) {
DebugOut ""
DebugOut "Log file already exists at: $global:LogFileName"
if ($global:OverWrite -eq $True) {
Remove-Item -Path $global:LogFileName -Force | Out-Null
}
}
# If the file has just been removed (OverWrite = YES) or the file does not exist: create it
if (!(Test-Path -Path $global:LogFileName)) {
#Create log file
New-Item -Path $global:LogFileName -ItemType File | Out-Null
}