ScaleArc 3.3 API License Dynamic IPScan Discovery

ScaleArc.3.3.API.License.Dynamic.IPScan.Discovery (Discovery)

Element properties:

TargetMicrosoft.SystemCenter.ManagementServer
EnabledTrue
Frequency120
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Default

Source Code:

<Discovery ID="ScaleArc.3.3.API.License.Dynamic.IPScan.Discovery" Enabled="true" Target="SC!Microsoft.SystemCenter.ManagementServer" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="ScaleArc.3.3.API.License.Dynamic.Class">
<Property TypeID="ScaleArc.3.3.API.License.Dynamic.Class" PropertyID="IPAddress"/>
<Property TypeID="ScaleArc.3.3.API.License.Dynamic.Class" PropertyID="LicenseType"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="ScaleArc.3.3.API.NotMonitored.Dynamic.Class">
<Property TypeID="ScaleArc.3.3.API.NotMonitored.Dynamic.Class" PropertyID="IPAddress"/>
<Property TypeID="ScaleArc.3.3.API.NotMonitored.Dynamic.Class" PropertyID="LicenseType"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>120</IntervalSeconds>
<SyncTime>00:10</SyncTime>
<ScriptName>ScaleArc.3.3.API.License.Dynamic.IPScan.Discovery.Script.ps1</ScriptName>
<ScriptBody><Script>
param($sourceId,$managedEntityId,$computerName,$User,$Pwd,$SQLUser,$SQLPwd)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Add-Type -AssemblyName System.Data
$api = new-object -comObject 'MOM.ScriptAPI'
$DBServerPath = Get-ItemProperty "HKLM:SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup"
$SQLInstance = $DBServerPath.DatabaseServerName
$DB = "ScaleArcMon_Utility"

$connectionString = "Server=$SQLInstance;uid=" + $SQLUser + "; pwd=" + $SQLPwd + ";Database=$DB;"

$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString

$connection.Open()
$query = &#x201C;SELECT * FROM ScaleArcScannedIPs&#x201D;

$command = $connection.CreateCommand()
$command.CommandText = $query

$result = $command.ExecuteReader()
$output = while ($result.Read()) { $result[0] + "`n"}
#$output
[string]$check = $output
if($check -eq $null -or $check -eq "")
{
$api.LogScriptEvent("ScaleArc.3.3.API.License.Dynamic.IPScan.Discovery.Script.ps1", 2, 0 , "ScaleArc.3.3.API.License.Dynamic.IPScan.Discovery.Script failed. Error: `n $error")
$connection.Close()
}
else
{
$discoveryData = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)

foreach($entry in $output)
{
$URLData = ""
$Jparse = ""
$LicenseType = ""
[string]$ip = $entry
$ip = $ip.trim()
$web = new-object net.webclient
$checkurl = "https://" + $ip
$CheckURLData = $web.DownloadString($checkurl)
if($CheckURLData -match "ScaleArc")
{
$cmd = "Invoke-RestMethod " + '"' + "http://" + $ip + "/api/login" + '"' + " -Body " + "'" + '{"username":' + '"' + $User + '"' + ',"password":"' + $Pwd + '"}' + "'" + " -Method Post"
$cmdexec = Invoke-Expression $cmd
$apikey = $cmdexec.data.apikey

if($apikey -eq $null -or $apikey -eq "")
{
$api.LogScriptEvent("ScaleArc.3.3.API.License.Dynamic.IPScan.Discovery.Script.ps1", 8, 0 , "ScaleArc.3.3.API.License.Dynamic.IPScan.Discovery.Script failed.. No Valid APIKey generated for IP: $ip :: User:$User :: CMD: $cmdexec. Error: `n $error")
$connection.Close()
}
else
{
$URL = "https://" + $ip + "/api/license?apikey=" + $apikey
$URLData = $web.DownloadString($URL)
$Jparse = $URLData | ConvertFrom-Json

$apikeyenc = [System.Text.Encoding]::UTF8.GetBytes($apikey)
$encapikey = [System.Convert]::ToBase64String($apikeyenc)

$LicenseType = $Jparse.data.("edition_type")

if($LicenseType -ne "" -and $LicenseType -Match "Platinum")
{

$instance = $discoveryData.CreateClassInstance("$MPElement[Name='ScaleArc.3.3.API.License.Dynamic.Class']$")
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$instance.AddProperty("$MPElement[Name='ScaleArc.3.3.API.License.Dynamic.Class']/IPAddress$", $ip)
$instance.AddProperty("$MPElement[Name='ScaleArc.3.3.API.License.Dynamic.Class']/LicenseType$", $LicenseType)
$instance.AddProperty("$MPElement[Name='ScaleArc.3.3.API.License.Dynamic.Class']/APIKey$", $encapikey)
$discoveryData.AddInstance($instance)
$api.LogScriptEvent("ScaleArc.3.3.API.License.Dynamic.IPScan.Discovery.Script.ps1", 72, 0 , "ScaleArc Server with IP: $ip is having $LicenseType License.")
}
else
{
$instance = $discoveryData.CreateClassInstance("$MPElement[Name='ScaleArc.3.3.API.NotMonitored.Dynamic.Class']$")
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$instance.AddProperty("$MPElement[Name='ScaleArc.3.3.API.NotMonitored.Dynamic.Class']/IPAddress$", $ip)
$instance.AddProperty("$MPElement[Name='ScaleArc.3.3.API.NotMonitored.Dynamic.Class']/LicenseType$", $LicenseType)
$instance.AddProperty("$MPElement[Name='ScaleArc.3.3.API.NotMonitored.Dynamic.Class']/APIKey$", $encapikey)
$discoveryData.AddInstance($instance)
$api.LogScriptEvent("ScaleArc.3.3.API.License.Dynamic.IPScan.Discovery.Script.ps1", 27, 0 , "ScaleArc Server with IP: $ip is having $LicenseType License.")
}
}
}
}
}

$connection.Close()
$discoveryData

</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/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>User</Name>
<Value>$RunAs[Name="ScaleArc.3.3.API.Discovery.IPScan.API.Generate.Account"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>Pwd</Name>
<Value>$RunAs[Name="ScaleArc.3.3.API.Discovery.IPScan.API.Generate.Account"]/Password$</Value>
</Parameter>
<Parameter>
<Name>SQLUser</Name>
<Value>$RunAs[Name="ScaleArc.3.3.API.Discovery.UtilityDB.Connect.Discovery.Account"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>SQLPwd</Name>
<Value>$RunAs[Name="ScaleArc.3.3.API.Discovery.UtilityDB.Connect.Discovery.Account"]/Password$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>180</TimeoutSeconds>
</DataSource>
</Discovery>