Hi All,
I am trying to monitor a webpage to get a certain value from a site. While trying to run the script on the Orion Server, it is working perfectly, whereas if trying to run the same script over the application monitoring template receiving the following error:
The 'SetBufferContents' member is not supported by ApmPsHostRawUserInterface
Below is the script for the same:
Few information are removed for security reasons:
#################Exit Codes for Service Status######################
# 0 - Up
# 1 - Down
# 2 - Warning
# 3 - Critical
# Any other Value - Unknown (Example -4)
$Error1 =0
#Try-Catch to check if Solarwinds is able to reach the link or not
#-----------------------------------------------------------------------------------------------------------------------------------
##Function to load assemply to avoid the error "Cannot find an overload for "getElementById" and the argument count: "1"."
Function LoadAssembly ($Path)
{
$fs = ([System.IO.FileInfo] (Get-Item -Path $Path)).OpenRead()
$buffer = New-Object Byte[] $fs.Length
$n = $fs.Read($buffer, 0, $fs.Length)
$fs.Close()
if ( $n -gt 0 )
{
[System.Reflection.Assembly]::Load($buffer)
}
else
{
Write-Warning "Cannot load an assembly from an empty file."
}
}
## Calling the function Loadassemply, it has been added in a variable so that it would not display any value
$ignore = LoadAssembly ("C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll")
#-----------------------------------------------------------------------------------------------------------------------------------
try{
$username = "xxxxx"
$password = "xxxxx"
#Creating New Internet Explorer object
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$false
$ie.navigate("xx.xx.xx.xx")
while($ie.ReadyState -ne 4) {start-sleep -m 100};
#-----------------------------------------------------------------------------------------------------------------------------------
#For Bypassing SSL Certificate Error Page if Any
if ($ie.document.url -Match "invalidcert")
{
#"Bypassing SSL Certificate Error Page";
$sslbypass=$ie.Document.getElementsByTagName("a") | where-object {$_.id -eq "overridelink"};
$sslbypass.click();
#"sleep for 10 seconds while final page loads";
start-sleep -s 10;
};
#-----------------------------------------------------------------------------------------------------------------------------------
$ie.document.getElementById("username").value= "$username"
$ie.document.getElementById("password").value = "$password"
$ie.document.getElementById("save_button").click()
start-sleep 10
cls
$Licenseusage = 0
$sampleArray =$result = @()
($ie.Document.body.innertext) > "C:\Users\admin\Documents\test-vcs.txt"
$ie.quit()
$sampleArray = get-content "C:\Users\admin\Documents\test-vcs.txt"
Remove-Item "C:\Users\admin\Documents\test-vcs.txt"
for($i=0; $i -lt $sampleArray.Count; $i++){
if($sampleArray[$i].contains("Traversal calls")){
while(-not($sampleArray[$i].Contains("RegistrationsCurrent0"))){
$result += $sampleArray[$i]
$i++
}
}
if($result -ne $null){break}
}
$usage = [int]((($result[6] -split "License usage current") -split "%")[-2])
Write-Host "Statistic.LicenseUsed: $($usage)";
Write-Host "Message.LicenseUsed: $([String]::Join(", ", $usage))";
if($usage -gt 10){
exit 3
}
else # all services are up
{
exit 0
}
}
catch [exception] #If not able to connect to the server
{
Write-Host "Statistic.Error: $($Error1.Length)";
Write-Host "Message.Error: $([String]::Join(", ", "$_"))";
exit 5
}
Kindly let me know how we can resolve the issue.
Regards,
Ujjwal