Lenovo.HardwareMgmtPack.UUSServer.Discover (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.Discovery.Scheduler Default
PSScript ProbeAction Microsoft.Windows.PowerShellDiscoveryProbe Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
TimeoutSecondsint$Config/TimeoutSeconds$
UUSServerIPstring$Config/UUSServerIP$
UUSPortstring$Config/UUSPort$
UUSPbKeystring$Config/UUSPbKey$
UUSCertstring$Config/UUSCert$

Source Code:

<DataSourceModuleType ID="Lenovo.HardwareMgmtPack.UUSServer.Discover" Accessibility="Internal">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element name="SyncTime" type="xsd:string"/>
<xsd:element name="UUSServerIP" type="xsd:string"/>
<xsd:element name="UUSPort" type="xsd:string"/>
<xsd:element name="UUSPbKey" type="xsd:string"/>
<xsd:element name="UUSCert" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
<OverrideableParameter ID="UUSServerIP" ParameterType="string" Selector="$Config/UUSServerIP$"/>
<OverrideableParameter ID="UUSPort" ParameterType="string" Selector="$Config/UUSPort$"/>
<OverrideableParameter ID="UUSPbKey" ParameterType="string" Selector="$Config/UUSPbKey$"/>
<OverrideableParameter ID="UUSCert" ParameterType="string" Selector="$Config/UUSCert$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime>$Config/SyncTime$</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PSScript" TypeID="Windows!Microsoft.Windows.PowerShellDiscoveryProbe">
<ScriptName>IBMAutoDiscovery.ps1</ScriptName>
<ScriptBody><Script>
param($sourceId,$managedEntityId,$computerName,$managementGroupName,$uusip,$uusport,$uuspbkey,$uuscert)
Set-ExecutionPolicy Unrestricted -Force:$true -Scope CurrentUser
function Get-RegistryValue($key, $value)
{
(Get-ItemProperty $key $value).$value
}

function WriteLog($str, $RegDebug, $debugLevel)
{
if ($RegDebug -gt $debugLevel)
{
#Write-Host $str
if ([System.Diagnostics.EventLog]::SourceExists("Lenovo.EventLogSource") -eq $false)
{
[System.Diagnostics.EventLog]::CreateEventSource("Lenovo.EventLogSource", "Operations Manager")
}
Write-EventLog -LogName 'Operations Manager' -Source 'Lenovo.EventLogSource' -EventId 116 -EntryType Information -Message $str
}
}

$fqdn = ""
$RegDebug = Get-RegistryValue 'HKLM:\SOFTWARE\Lenovo\Lenovo SCOM MP\Debug' 'Level'
if($RegDebug -eq $null)
{
$RegDebug = '0'
}
$RegDebug = [Convert]::ToInt32($RegDebug,10)

$logstring = "RegDebug = " + $RegDebug
WriteLog $logstring $RegDebug 5

$paramStr='sourceId={0},managedEntityId={1},computerName={2},managementGroupName={3}' -f $sourceId,$managedEntityId,$computerName,$managementGroupName
WriteLog $paramStr $RegDebug 5

function IsLenovoHardware($hardware)
{
$result = -1

if ($result -eq -1)
{
if ($hardware.Vendor -imatch "Lenovo")
{
$result = 1
}
elseif ($hardware.Vendor -imatch "Lnvo")
{
$result = 1
}
elseif ($hardware.Vendor -imatch "Lvo")
{
$result = 1
}
elseif ($hardware.Vendor -imatch "Leno")
{
$result = 1
}
else
{
$result = -1
}
}
return $result
}

function get-BmcMediaChannelLan ($computerName) {
process {

[byte]$mediaTypeLan = 0x04
[byte[]]$dataContainer = @(0)

$obj = Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI -ComputerName $computerName
if($obj -is [ARRAY]){
$oIPMI = $obj[0]
}
else{
$oIPMI = $obj
}
$oInputParam = $oIPMI.GetMethodParameters("RequestResponse")
$oInputParam.Command = 0x42
$oInputParam.Lun = 0x00
$oInputParam.NetworkFunction = 0x06
$oInputParam.ResponderAddress = 0x20

[Int16]$iLanForLoopVar = 1
[byte]$ChannelMax = 0x0b
for(; $iLanForLoopVar -le $ChannelMax; $iLanForLoopVar++) {
$dataContainer = @($iLanForLoopVar)
$oInputParam.RequestData = $dataContainer
$oInputParam.RequestDataSize = $dataContainer.length
$oReturnVal = $oIPMI.PSBase.InvokeMethod("RequestResponse", $oInputParam, (New-Object System.Management.InvokeMethodOptions))

if ($oReturnVal.ResponseData[2] -eq $mediaTypeLan) {
return $iLanForLoopVar
}
}

return -1
}
}

function get-BmcIp ($computerName, $ipParam) {
process {
try{
[byte]$channel = get-BmcMediaChannelLan($computerName)

if ($channel -lt 0) {
return ""
}
[byte]$parameterIp = $ipParam
[byte]$parameterSelector = $parameterIp

$obj=Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI -ComputerName $computerName
if($obj -is [ARRAY]){
$oIPMI = $obj[0]
}
else{
$oIPMI = $obj
}
$oInputParam = $oIPMI.GetMethodParameters("RequestResponse")
$oInputParam.Command = 0x02
$oInputParam.Lun = 0x00
$oInputParam.NetworkFunction = 0x0c
$oInputParam.ResponderAddress = 0x20
[byte[]]$dataContainer = @($channel, $parameterSelector, 0, 0)
$oInputParam.RequestData = $dataContainer
$oInputParam.RequestDataSize = $dataContainer.length
$oReturnVal = $oIPMI.PSBase.InvokeMethod("RequestResponse", $oInputParam, (New-Object System.Management.InvokeMethodOptions))
if($ipParam -eq 3)
{
return "{0}.{1}.{2}.{3}" -f $oReturnVal.ResponseData[2], $oReturnVal.ResponseData[3], $oReturnVal.ResponseData[4], $oReturnVal.ResponseData[5]
}
elseif($ipParam -eq 56 -or $ipParam -eq 200)
{
$onoff = 0
$rst = ""
for($i = 4; $i -le 19 ; $i ++)
{
$temp = $oReturnVal.ResponseData[$i].ToString('x')
if ($temp.Length -lt 2)
{
$rst += "0" + $temp
}
else
{
$rst += $temp
}
$onoff += 1
if($onoff -eq 2 -and $i -lt 19 )
{
$rst += ":"
$onoff = 0
}
}
return $rst
}else
{
return ""
}
}
catch{
return ""
}
}
}

function checkIpEnable($computerName){
process {
[byte]$channel = get-BmcMediaChannelLan($computerName)
if ($channel -lt 0) {
return ""
}
[byte]$parameterIp = 51
[byte]$parameterSelector = $parameterIp

$obj=Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI -ComputerName $computerName
if($obj -is [ARRAY]){
$oIPMI = $obj[0]
}
else{
$oIPMI = $obj
}
$oInputParam = $oIPMI.GetMethodParameters("RequestResponse")
$oInputParam.Command = 0x02
$oInputParam.Lun = 0x00
$oInputParam.NetworkFunction = 0x0c
$oInputParam.ResponderAddress = 0x20
[byte[]]$dataContainer = @($channel, $parameterSelector, 0, 0)
$oInputParam.RequestData = $dataContainer
$oInputParam.RequestDataSize = $dataContainer.length
$oReturnVal = $oIPMI.PSBase.InvokeMethod("RequestResponse", $oInputParam, (New-Object System.Management.InvokeMethodOptions))
if($oReturnVal.ResponseData[0] -eq 0){
return $oReturnVal.ResponseData[2]
}
else{
return -1
}
}

}
function get-BmcSysGuid ($computerName) {
process {
$obj=Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI -ComputerName $computerName
if($obj -is [ARRAY]){
$oIPMI = $obj[0]
}
else{
$oIPMI = $obj
}
if ($oIPMI) {
$oInputParam = $oIPMI.GetMethodParameters("RequestResponse")
$oInputParam.Command = 0x37
$oInputParam.Lun = 0x00
$oInputParam.NetworkFunction = 0x06
$oInputParam.ResponderAddress = 0x20
$oInputParam.RequestDataSize = 0
$oReturnVal = $oIPMI.PSBase.InvokeMethod("RequestResponse", $oInputParam, (New-Object System.Management.InvokeMethodOptions))
return "{0:x2}{1:x2}{2:x2}{3:x2}{4:x2}{5:x2}{6:x2}{7:x2}{8:x2}{9:x2}{10:x2}{11:x2}{12:x2}{13:x2}{14:x2}{15:x2}" -f $oReturnVal.ResponseData[1], $oReturnVal.ResponseData[2], $oReturnVal.ResponseData[3], $oReturnVal.ResponseData[4], $oReturnVal.ResponseData[5], $oReturnVal.ResponseData[6], $oReturnVal.ResponseData[7], $oReturnVal.ResponseData[8], $oReturnVal.ResponseData[9], $oReturnVal.ResponseData[10], $oReturnVal.ResponseData[11], $oReturnVal.ResponseData[12], $oReturnVal.ResponseData[13], $oReturnVal.ResponseData[14], $oReturnVal.ResponseData[15], $oReturnVal.ResponseData[16]
}
return ""
}
}

Function Get-RandomString() {
param(
[int]$length=10,
[char[]]$sourcedata
)
for($loop=1; $loop &#x2013;le $length; $loop++) {
$TempPassword+=($sourcedata | GET-RANDOM | %{[char]$_})
}
return $TempPassword
}

Function GenRequestData($userid,$opcode,$str,$len){
$arr = [int[]]($str.ToString().ToCharArray())
$rtnarr=@($userid)
if($opcode)
{
$rtnarr += $opcode
}
for($i = 0; $i -lt $len; $i++)
{
if($arr[$i])
{
$rtnarr += $arr[$i]
}
else
{
$rtnarr += 0x00
}
}
return $rtnarr
}

Function set-UserName($userid,$username){
[byte[]]$dataContainer = GenRequestData $userid $null $username 16
$obj = Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI
if($obj -is [ARRAY]){
$oIPMI = $obj[0]
}
else{
$oIPMI = $obj
}
$oInputParam = $oIPMI.GetMethodParameters("RequestResponse")
$oInputParam.Command = 0x45
$oInputParam.Lun = 0x00
$oInputParam.NetworkFunction = 0x06
$oInputParam.ResponderAddress = 0x20
$oInputParam.RequestData = $dataContainer
$oInputParam.RequestDataSize = $dataContainer.Length
$oReturnVal = $oIPMI.PSBase.InvokeMethod("RequestResponse", $oInputParam, (New-Object System.Management.InvokeMethodOptions))
if($oReturnVal.CompletionCode -eq 0x00)
{
return $true
}
else
{
return $false,"set user name failed"
}
}

Function set-UserPassword($userid,$pwd){
$opcode = 0x02
[byte[]]$dataContainer = GenRequestData $userid $opcode $pwd 16
$obj = Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI
if($obj -is [ARRAY]){
$oIPMI = $obj[0]
}
else{
$oIPMI = $obj
}
$oInputParam = $oIPMI.GetMethodParameters("RequestResponse")
$oInputParam.Command = 0x47
$oInputParam.Lun = 0x00
$oInputParam.NetworkFunction = 0x06
$oInputParam.ResponderAddress = 0x20
$oInputParam.RequestData = $dataContainer
$oInputParam.RequestDataSize = $dataContainer.Length
$oReturnVal = $oIPMI.PSBase.InvokeMethod("RequestResponse", $oInputParam, (New-Object System.Management.InvokeMethodOptions))
if($oReturnVal.CompletionCode -eq 0x00)
{
return $true
}
else
{
return $false,"Set user password failed"
}
}

Function set-UserEnable($userid){
[byte[]]$dataContainer = @($userid,0x01)
$obj = Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI
if($obj -is [ARRAY]){
$oIPMI = $obj[0]
}
else{
$oIPMI = $obj
}
$oInputParam = $oIPMI.GetMethodParameters("RequestResponse")
$oInputParam.Command = 0x47
$oInputParam.Lun = 0x00
$oInputParam.NetworkFunction = 0x06
$oInputParam.ResponderAddress = 0x20
$oInputParam.RequestData = $dataContainer
$oInputParam.RequestDataSize = $dataContainer.Length
$oReturnVal = $oIPMI.PSBase.InvokeMethod("RequestResponse", $oInputParam, (New-Object System.Management.InvokeMethodOptions))
if($oReturnVal.CompletionCode -eq 0x00)
{
return $true
}
else
{
return $false,"Set user enable failed"
}
}

Function Set-UserPrivilege($channel,$userid,$priv){
[byte[]]$dataContainer = @($channel,$userid,$priv)
[byte[]]$responseData = @(100)
$obj = Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI
if($obj -is [ARRAY]){
$oIPMI = $obj[0]
}
else{
$oIPMI = $obj
}
$oInputParam = $oIPMI.GetMethodParameters("RequestResponse")
$oInputParam.Command = 0x43
$oInputParam.Lun = 0x00
$oInputParam.NetworkFunction = 0x06
$oInputParam.ResponderAddress = 0x20
$oInputParam.RequestData = $dataContainer
$oInputParam.RequestDataSize = $dataContainer.Length
$oReturnVal = $oIPMI.PSBase.InvokeMethod("RequestResponse", $oInputParam, (New-Object System.Management.InvokeMethodOptions))
if($oReturnVal.CompletionCode -eq 0x00)
{
return $true
}
else
{
return $false,"Set user Privilege failed"
}
}

Function Get-UserId($username){
$userid = @()
$obj = Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI
if($obj -is [ARRAY]){
$oIPMI = $obj[0]
}
else{
$oIPMI = $obj
}
$oInputParam = $oIPMI.GetMethodParameters("RequestResponse")
$oInputParam.Command = 0x46
$oInputParam.Lun = 0x00
$oInputParam.NetworkFunction = 0x06
$oInputParam.ResponderAddress = 0x20
for($i = 2; $i -le 12; $i++)
{
[byte[]]$dataContainer = @($i)
$oInputParam.RequestData = $dataContainer
$oInputParam.RequestDataSize = $dataContainer.Length
$oReturnVal = $oIPMI.PSBase.InvokeMethod("RequestResponse", $oInputParam, (New-Object System.Management.InvokeMethodOptions))
$oUserName = [System.Text.Encoding]::ASCII.GetString($oReturnVal.ResponseData[1..17])
$patern = "^" + $username
if($oUserName[1] -gt 0x30)
{
if($oUserName -match $patern)
{
return $true,$i,$oUserName
}
}
else
{
$userid += $i
}
}
return $false,$userid[0]
}

Function CreateAccount($userid,$username){
if($username -eq $null)
{
$username = "lxciscom"
}
if($userid -eq $null)
{
return 1,"User id is null"
}
$len = 16 - $username.Length
$rdmstr = Get-RandomString -length $len -sourcedata (48..57+65..90+97..122)
$username = $username + $rdmstr
$rt = set-UserName $userid $username
if($rt[0] -ne $true)
{
return 1,$rt[1]
}
$password = Get-RandomString -length 16 -sourcedata (35..38+40..94+96..126)
$rt = set-UserPassword $userid $password
if($rt[0] -ne $true)
{
return 1,$rt[1]
}
$rt = set-UserEnable $userid
if($rt[0] -ne $true)
{
return 1,$rt[1]
}
$priv = 0x02
$rt = Set-UserPrivilege $channel $userid $priv
if($rt[0] -ne $true)
{
return 1,$rt[1]
}
#2 new account was created sucess
return 2,$username,$password
}

Function CallRestAPI($opcode,$uuid,$ipv4,$ipv6){
try{
If($uusip){
$fqdn = $uusip
}
else {
$key = "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups\" + $managementGroupName + "\Parent Health Services\0"
$value = "NetworkName"
$fqdn = Get-RegistryValue $key $value
}
$port = $uusport
$url = "https://" + $fqdn + ":" + $port + "/immcimlistener"
WriteLog $url $RegDebug 5
$body = @{
"opcode"=$opcode;
"computername"=$computerName;
"uuid"=$uuid;
"ipv4"=$ipv4;
"ipv6"=$ipv6;
"randomkey"=$randomkey}
$uusmsg = Invoke-WebRequest -Uri $url -Method Post -Body (ConvertTo-Json $body) -UseBasicParsing
return $uusmsg
}
catch{
WriteLog 'error happened' $RegDebug 5
$msg=$error[0]
WriteLog $msg $RegDebug 5
}
}

Function Set-Register($username,$startdate)
{
Set-ItemProperty -Path "HKLM:\SOFTWARE\Lenovo\Lenovo SCOM MP\Account" -Name "UserName" -Value $username
Set-ItemProperty -Path "HKLM:\SOFTWARE\Lenovo\Lenovo SCOM MP\Account" -Name "StartDate" -Value $startdate
}

Function EncryptData($str)
{
if($str -ne "")
{
$cipherbytes = $rsa.Encrypt([System.Text.Encoding]::UTF8.GetBytes($str),$false)
$enstr = [System.Convert]::ToBase64String($cipherbytes)
return $enstr
}
else
{
return ""
}
}

Function CreateInstance()
{
$logstring = "Start Create Instance"
WriteLog $logstring $RegDebug 5
$api = New-Object -comObject 'MOM.ScriptAPI'
$discoveryData = $api.CreateDiscoveryData(0, $sourceId, $managedEntityId)
$instance = $discoveryData.CreateClassInstance("$MPElement[Name='Lenovo.HardwareMgmtPack.UUSServer']$")
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $computerName)
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$instance.AddProperty("$MPElement[Name='Lenovo.HardwareMgmtPack.UUSServer']/ComputerName$", $computerName)
$instance.AddProperty("$MPElement[Name='Lenovo.HardwareMgmtPack.UUSServer']/BMCUuid$", $enuuid)
$instance.AddProperty("$MPElement[Name='Lenovo.HardwareMgmtPack.UUSServer']/BMCIp$", $enuusipv4 + "_" + $enuusipv6)
$instance.AddProperty("$MPElement[Name='Lenovo.HardwareMgmtPack.UUSServer']/BMCUser$", $enuser)
$instance.AddProperty("$MPElement[Name='Lenovo.HardwareMgmtPack.UUSServer']/BMCPassword$", $enpwd)
$instance.AddProperty("$MPElement[Name='Lenovo.HardwareMgmtPack.UUSServer']/RandomKey$", $randomkey)
$discoveryData.AddInstance($instance)
$discoveryData
$logstring = "Return Instance"
WriteLog $logstring $RegDebug 5
}
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]([System.Convert]::FromBase64String($uuscert))
$delegate = {
param (
[object] $Sender,
[System.Security.Cryptography.X509Certificates.X509Certificate] $Certificate,
[System.Security.Cryptography.X509Certificates.X509Chain] $Chain,
[System.Net.Security.SslPolicyErrors] $SslPolicyErrors
)
if ($null -ne $cert){
$cacert = $Chain.ChainElements[0].Certificate
if($cacert -eq $cert){
return $true
}
else{
return $false
}
}
return $false
}
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $delegate

try{
$randomkey = ""
$channel = get-BmcMediaChannelLan($computerName)
$logstring = "BMC Media Channel Lan is : " + $channel
WriteLog $logstring $RegDebug 5
$reg = Test-Path "HKLM:\SOFTWARE\Lenovo\Lenovo SCOM MP\Account"
if($reg -eq $false)
{
#set the init register value
New-Item -Path "HKLM:\SOFTWARE\Lenovo\Lenovo SCOM MP" -Name "Account" -Value "Default Value" -Force
Set-Register "lxciscom" "2017-07-20"
}

$ipEnable = checkIpEnable($computerName)

$ipv4 = get-BmcIp $computerName 3
$ipv6 = get-BmcIp $computerName 56
if($ipv6 -eq "")
{
#param 200 is for immv2 to get ipv6 local link
$ipv6 = get-BmcIp $computerName 200
}

$logstring = "BMC ipv4 &amp; ipv6 status code is:" + $ipEnable + ", BMC ipv4 is: " + $ipv4 + ", ipv6 is: " + $ipv6
WriteLog $logstring $RegDebug 5
$uuid = get-BmcSysGuid($computerName)
$logstring = "BMC uuid is: " + $uuid
WriteLog $logstring $RegDebug 5
if($ipv4 -ne "" -or $ipv6 -ne "")
{
#check the bmc managed status on uus
$opcode = "check"
$rsa = New-Object System.Security.Cryptography.RSACryptoServiceProvider
$rsa.FromXmlString($uuspbkey)
$enuuid = EncryptData $uuid
if($ipv4)
{
$enuusipv4 = EncryptData $ipv4
}
else
{
$enuusipv4 = ""
}
if($ipv6)
{
$enuusipv6 = EncryptData $ipv6
}
else
{
$enuusipv6 = ""
}
$response = CallRestAPI $opcode $enuuid $enuusipv4 $enuusipv6
if($response.StatusCode.toString() -eq "200")
{
$ckrst = $response.toString().split(",")
if($ckrst[0] -eq "Success")
{
#get the account name which start with "lxciscom" on BMC
$rt = Get-UserId "lxciscom"
$userid = $rt[1]
if($ckrst[1] -eq "False")
{
$logstring = "BMC un-managed on UUS"
WriteLog $logstring $RegDebug 5
$randomkey = Get-RandomString -length 10 -sourcedata (48..57+65..90+97..122)
if($rt[0]) #ACCOUNT EXIST
{
$logstring = "BMC auto account already exists, reset its password and manage it"
WriteLog $logstring $RegDebug 5
$username = $rt[2]
$password = Get-RandomString -length 16 -sourcedata (35..38+40..94+96..126)
$enuser = EncryptData $username
$enpwd = EncryptData $password
$rtn = set-UserPassword $userid $password
if($rtn[0]){
$logstring = "New password was Set for user " + $username
WriteLog $logstring $RegDebug 5
$opcode = "new"
$response = CallRestAPI $opcode $enuuid $enuusipv4 $enuusipv6
if($response.StatusCode.ToString() -eq '200')
{
$logstring = "BMC auto discovery sucess."
WriteLog $logstring $RegDebug 5
$startdate = Get-Date -format 'yyyy-MM-dd'
Set-Register $username $startdate
CreateInstance
}
else
{
$logstring = "Failed to Call UUS RestAPI to manage BMC, StatusCode is :" + $response.StatusCode.ToString()
WriteLog $logstring $RegDebug 5
}
}
else
{
$logstring = "reset password failed, make sure it meet Minimum password change interval" + $rtn[1]
WriteLog $logstring $RegDebug 5
}
}
else
{
$logstring = "BMC auto account no exist, create the accout and manage it on uus"
WriteLog $logstring $RegDebug 5
if($rt[1] -ge 0x0b)
{
$logstring = "the count of BMC account meet the limit, failed to create auto account"
WriteLog $logstring $RegDebug 5
}
else
{
$rtn = CreateAccount $userid $null
if($rtn[0] -eq 2)
{
$username = $rtn[1]
$password = $rtn[2]
$enuser = EncryptData $username
$enpwd = EncryptData $password
$opcode = "new"
$response = CallRestAPI $opcode $enuuid $enuusipv4 $enuusipv6
if($response.StatusCode.ToString() -eq '200')
{
$logstring = "BMC auto discovery sucess."
WriteLog $logstring $RegDebug 5
$StartDate = Get-Date -format 'yyyy-MM-dd'
Set-Register $username $startdate
CreateInstance
}
else
{
$logstring = "Failed to Call UUS RestAPI to manage BMC, StatusCode is :" + $response.StatusCode
WriteLog $logstring $RegDebug 5
}
}
else
{
$logstring = $rtn[1]
WriteLog $logstring $RegDebug 5
}
}
}
}
else
{
$logstring = "BMC was already managed on UUS"
WriteLog $logstring $RegDebug 5
}
}
else
{
$logstring = "UUS failed due to some reason"
WriteLog $logstring $RegDebug 5
}
}
else
{
$logstring = "Call UUS RestAPI to Check BMC status failed, StatusCode is :" + $response.StatusCode.ToString()
WriteLog $logstring $RegDebug 5
}
}
}
Catch {
WriteLog 'error happened' $RegDebug 5
$msg=$error[0]
WriteLog $msg $RegDebug 5
}
finally{
$logstring = "finally"
WriteLog $logstring $RegDebug 5
}
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>sourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>managedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>computerName</Name>
<Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>managementGroupName</Name>
<Value>$Target/ManagementGroup/Name$</Value>
</Parameter>
<Parameter>
<Name>uusip</Name>
<Value>$Config/UUSServerIP$</Value>
</Parameter>
<Parameter>
<Name>uusport</Name>
<Value>$Config/UUSPort$</Value>
</Parameter>
<Parameter>
<Name>uuspbkey</Name>
<Value>$Config/UUSPbKey$</Value>
</Parameter>
<Parameter>
<Name>uuscert</Name>
<Value>$Config/UUSCert$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PSScript">
<Node ID="DS"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>