UNIX/Linux-Ermittlungsaufgabe "Verfügbare Agents aufzählen"
Microsoft.Unix.EnumerateAvailableAgents.Task (Task)
Element properties: Member Modules:
Source Code: <Task ID="Microsoft.Unix.EnumerateAvailableAgents.Task" Accessibility="Public" Enabled="true" Target="SC!Microsoft.SystemCenter.ManagementServicePool" Timeout="300" Remotable="true">
<Category>Custom</Category>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>EnumerateAvailableAgents.ps1</ScriptName>
<ScriptBody><Script>
Set-PSDebug -Strict
#Get Path to OpsMgr Directory from Registry
$RegPathValue= Get-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup" -name InstallDirectory
$OpsMgrDirectory = $RegPathValue.InstallDirectory
#Assign UnixAgents directory to variable
$SCXAgentTargetDirectory = $OpsMgrDirectory + "AgentManagement\UnixAgents"
$ResourcesDirectory = $OpsMgrDirectory + "Health Service State\Resources\"
#Define XML fragment
$SCXAgentsXml = New-Object xml
$SCXAgentsXmlRoot = $SCXAgentsXml.CreateElement("SupportedAgents")
[void]$SCXAgentsXml.AppendChild($SCXAgentsXmlRoot)
#Create DiscoveryScript element
$SCXDiscoveryScriptElement = $SCXAgentsXml.CreateElement("DiscoveryScript")
[void]$SCXAgentsXmlRoot.AppendChild($SCXDiscoveryScriptElement)
$SCXDiscoveryScript = Get-ChildItem -path "$SCXAgentTargetDirectory\GetOSVersion.sh"
#Add Discovery Script Directory Attribute
$SCXDiscoveryScriptDirectoryAttr = $SCXAgentsXml.CreateAttribute("Directory")
$SCXDiscoveryScriptDirectoryAttr.PSBase.Value = $SCXDiscoveryScript.Directory
[void]$SCXDiscoveryScriptElement.SetAttributeNode($SCXDiscoveryScriptDirectoryAttr)
#Add Discovery Script Name attribute
$SCXDiscoveryScriptNameAttr = $SCXAgentsXml.CreateAttribute("Name")
$SCXDiscoveryScriptNameAttr.PSBase.Value = $SCXDiscoveryScript.Name
[void]$SCXDiscoveryScriptElement.SetAttributeNode($SCXDiscoveryScriptNameAttr)
#Recursively Enumerate Agent Kits in \UnixAgents
If (Test-Path -Path "$SCXAgentTargetDirectory"){
$SCXAgents = Get-ChildItem -path $SCXAgentTargetDirectory -recurse -include *.gz,*.rpm,*.deb,*.Z
ForEach ($SCXAgent in $SCXAgents){
#Create Agent element
$SCXKitElement = $SCXAgentsXml.CreateElement("Kit")
[void]$SCXAgentsXmlRoot.AppendChild($SCXKitElement)
#Add agent Path Attribute
$SCXAgentPathAttr = $SCXAgentsXml.CreateAttribute("Directory")
$SCXAgentPathAttr.PSBase.Value = $SCXAgent.Directory
[void]$SCXKitElement.SetAttributeNode($SCXAgentPathAttr)
#Add agent Name attribute
$SCXAgentNameAttr = $SCXAgentsXml.CreateAttribute("Name")
$SCXAgentNameAttr.PSBase.Value = $SCXAgent.Name
[void]$SCXKitElement.SetAttributeNode($SCXAgentNameAttr)
}
}
If (Test-Path -path $ResourcesDirectory){
$SCXAgents = Get-ChildItem $ResourcesDirectory -recurse | where {((!$_.PsIsContainer) -and ($_.Name -Match "^scx-.+(.rpm|.Z|.gz|.deb)$"))}
ForEach ($SCXAgent in $SCXAgents){
#Create Agent element
$SCXKitElement = $SCXAgentsXml.CreateElement("Kit")
[void]$SCXAgentsXmlRoot.AppendChild($SCXKitElement)
#Add agent Path Attribute
$SCXAgentPathAttr = $SCXAgentsXml.CreateAttribute("Directory")
$SCXAgentPathAttr.PSBase.Value = $SCXAgent.Directory
[void]$SCXKitElement.SetAttributeNode($SCXAgentPathAttr)
#Add agent Name attribute
$SCXAgentNameAttr = $SCXAgentsXml.CreateAttribute("Name")
$SCXAgentNameAttr.PSBase.Value = $SCXAgent.Name
[void]$SCXKitElement.SetAttributeNode($SCXAgentNameAttr)
}
}
#Return XML fragment
write-host $SCXAgentsXml.outerxml.ToString()
</Script> </ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</WriteAction>
</Task>