Lenovo.HardwareMgmtPack.UUSServer.Discover (DataSourceModuleType)
Element properties: Member Modules:
Overrideable Parameters:
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"/>
<xsd:element name="AutoManage" 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$"/>
<OverrideableParameter ID="AutoManage" ParameterType="string" Selector="$Config/AutoManage$"/>
</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,$automanage)
Set-ExecutionPolicy Unrestricted -Force:$true -Scope CurrentUser
$Error_Code = @{"c0"="IPMI command failed : Node busy.";"c1"="IPMI command failed: The command is not valid.";
"c2"="IPMI command failed : The command is not valid for given LUN.";
"c3"="IPMI command failed : Time-out while processing command.";
"c4"="IPMI command failed : Out of space.";
"c5"="IPMI command failed : Reservation canceled or reservation ID is not valid.";
"c6"="IPMI command failed : Request data truncated.";
"c7"="IPMI command failed : Request data length is not valid.";
"c8"="IPMI command failed : Request data field length limit exceeded.";
"c9"="IPMI command failed : Parameter out of range.";
"ca"="IPMI command failed : Cannot return number of requested data bytes.";
"cb"="IPMI command failed : Requested sensor, data, or record not present.";
"cc"="IPMI command failed : Data field in request is not valid.";
"cd"="IPMI command failed : Command illegal for specified sensor or record type.";
"ce"="IPMI command failed : Command response could not be provided.";
"cf"="IPMI command failed : Cannot execute duplicated request.";
"d0"="IPMI command failed : Command response could not be provided. SDR repository in update mode.";
"d1"="IPMI command failed : Command response could not be provided. Device in firmware update mode.";
"d2"="IPMI command failed : Command response could not be provided. BMC initialization in progress.";
"d3"="IPMI command failed : Destination unavailable.";
"d4"="IPMI command failed : Cannot execute command. Insufficient privilege level.";
"d5"="IPMI command failed : Cannot execute command. Command, or request parameters, not supported in present state.";
}
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((0x00,128,190) -contains $oReturnVal.CompletionCode){
if ($oReturnVal.ResponseData[2] -eq $mediaTypeLan) {
return $iLanForLoopVar
}
}
else{
$temp = $oReturnVal.CompletionCode.ToString('x')
$error_message = $Error_code[$temp]
if($error_message){throw $error_message}
else{throw "IPMI command failed"}
}
}
return -1
}
}
function get-BmcIp ($computerName, $ipParam) {
process {
[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((0x00,128,190) -contains $oReturnVal.CompletionCode){
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 ++)
{
if($oReturnVal.ResponseData[$i]){$temp = $oReturnVal.ResponseData[$i].ToString('x')}
else{return ""}
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 ""
}
}
else{
$temp = $oReturnVal.CompletionCode.ToString('x')
$error_message = $Error_code[$temp]
if($error_message){throw $error_message}
else{throw "IPMI command failed"}
}
}
}
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))
if((0x00,128,190) -contains $oReturnVal.CompletionCode){
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]
}
else{
$temp = $oReturnVal.CompletionCode.ToString('x')
$error_message = $Error_code[$temp]
if($error_message){throw $error_message}
else{throw "IPMI command failed"}
}
}
return ""
}
}
Function Get-RandomString() {
param(
[int]$length=10,
[char[]]$sourcedata
)
for($loop=1; $loop –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((0x00,128,190) -contains $oReturnVal.CompletionCode)
{
return $true
}
else
{
$temp = $oReturnVal.CompletionCode.ToString('x')
$error_message = $Error_code[$temp] + " set user name failed"
return $false, $error_message
}
}
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((0x00,128,190) -contains $oReturnVal.CompletionCode)
{
return $true
}
else
{
$temp = $oReturnVal.CompletionCode.ToString('x')
$error_message = $Error_code[$temp] + " Set user password failed"
return $false,$error_message
}
}
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((0x00,128,190) -contains $oReturnVal.CompletionCode)
{
return $true
}
else
{
$temp = $oReturnVal.CompletionCode.ToString('x')
$error_message = $Error_code[$temp] + " Set user enable failed"
return $false,$error_message
}
}
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((0x00,128,190) -contains $oReturnVal.CompletionCode)
{
return $true
}
else
{
$temp = $oReturnVal.CompletionCode.ToString('x')
$error_message = $Error_code[$temp] + " Set user Privilege failed"
return $false, $error_message
}
}
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))
if((0x00,128,190) -contains $oReturnVal.CompletionCode){
$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
}
}
else{
$temp = $oReturnVal.CompletionCode.ToString('x')
$error_message = $Error_code[$temp]
if($error_message){throw $error_message}
else{throw "IPMI command failed"}
}
}
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){
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}
try{
$uusmsg = Invoke-WebRequest -Uri $url -Method Post -Body (ConvertTo-Json $body) -UseBasicParsing -TimeoutSec 60
}
catch [System.Net.WebException]{
throw "Call RestAPI has timed out."
}
return $uusmsg
}
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)
$lenovoWinInstance = $discoveryData.CreateClassInstance("$MPElement[Name='IBM.WinComputer']$")
$lenovoWinInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $computerName)
$lenovoWinInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$lenovoWinInstance.AddProperty("$MPElement[Name='IBM.WinComputer']/BMCAutoDiscovery$", $Comment)
$discoveryData.AddInstance($lenovoWinInstance)
$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
}
try{
# by default, SecurityProtocol is sslv3 and tls
# add 768 (tls11) and 3072(tls12) for case if web server only supports tls11 or tls12 protocol
# not use [System.Net.SecurityProtocolType]::Tls11/Tls12 directly because it only exists in .Net 4.5 or later
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 768 -bor 3072
}catch{}
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $delegate
try{
if($automanage){
if($automanage -ne "disable" -and $uusip -and $uusport -and $uuspbkey -and $uuscert )
{
$randomkey = ""
$Comment = ""
$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 & 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().startswith('2'))
{
$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
$rt = set-UserEnable $userid
if($rt[0] -ne $true)
{
$logstring = $rt[1]
WriteLog $logstring $RegDebug 5
throw $logstring
}
else
{
$priv = 0x02
$rt = Set-UserPrivilege $channel $userid $priv
if($rt[0] -ne $true)
{
$logstring = $rt[1]
WriteLog $logstring $RegDebug 5
throw $logstring
}
else
{
$opcode = "new"
$response = CallRestAPI $opcode $enuuid $enuusipv4 $enuusipv6
if($response.StatusCode.ToString().startswith('2'))
{
$logstring = "BMC auto discovery sucess."
WriteLog $logstring $RegDebug 5
$startdate = Get-Date -format 'yyyy-MM-dd'
Set-Register $username $startdate
$Comment = "Complete"
CreateInstance
}
else
{
$msg = "Failed to Call XClarity Integrator RestAPI to manage BMC, StatusCode is :" + $response.StatusCode.ToString()
throw $msg
}
}
}
}
else
{
$msg ="reset password failed, make sure it meet Minimum password change interval," + $rtn[1]
throw $msg
}
}
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 new account"
WriteLog $logstring $RegDebug 5
throw $logstring
}
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().startswith('2'))
{
$logstring = "BMC auto discovery sucess."
WriteLog $logstring $RegDebug 5
$StartDate = Get-Date -format 'yyyy-MM-dd'
Set-Register $username $startdate
$Comment = "Complete"
CreateInstance
}
else
{
$msg = "Failed to Call UUS RestAPI to manage BMC, StatusCode is :" + $response.StatusCode
throw $msg
}
}
else
{
throw $rtn[1]
}
}
}
}
else
{
$logstring = "BMC was already managed on UUS"
WriteLog $logstring $RegDebug 5
$Comment = "Complete"
CreateInstance
}
}
else
{
$msg = "XClarity Integrator failed due to some reason"
throw $msg
}
}
else
{
$msg = "Call XClarity Integrator RestAPI to Check BMC status failed, StatusCode is :" + $response.StatusCode.ToString()
throw $msg
}
}
else
{
$msg = "ipv4 and ipv6 are none."
throw $msg
}
}
else
{
if($automanage -eq "disable")
{
$Comment = "Disable"
$logstring = "automanage is disable"
WriteLog $logstring $RegDebug 5
CreateInstance
}
else
{
$logstring = "Config Params was not overrided, skip the auto discovery step."
WriteLog $logstring $RegDebug 5
$Comment = $logstring
CreateInstance
}
}
}
}
Catch {
WriteLog 'error happened' $RegDebug 5
$msg=$error[0]
WriteLog $msg $RegDebug 5
$msg = $msg.ToString()
if($msg.startswith('IPMI command failed'))
{
$Comment = $msg
}
else
{
$Comment = "Error : " + $msg
}
CreateInstance
}
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>
<Parameter>
<Name>automanage</Name>
<Value>$Config/AutoManage$</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>