Hello,
I am creating an Application Template with a PowerShell Component monitor. It's a verification that clients can upload to an sftp site.
I have a test account called SOLARWINDS and it has secure cred file that are using in the session. The PS Component is set to run on the Remote Host.
The PowerShell code works on the test machine through various tests.
When I add the PowerShell Component monitor to an Application Template and test it against the same Node, it returns undefined.
I am hoping to know where the code is having the issue in the Component Monitor.
#################################
# SolarWinds Application Monitor#
# Requires WinSCP (All Users) #
#################################
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# setting locations for sftp file transfers
$localDirectory = "C:\TestUpload\"
$remoteDirectory = "/"
# setting location of Secure creds
$KeyFile = "C:\scripts\sftp-upload-securecreds\Auxiliary_Files\sftp-transaction-connect.key"
$PasswordFile = "C:\scripts\sftp-upload-securecreds\Auxiliary_Files\sftp-transaction-connect-SOLARWINDS.password"
# getting secure creds for the SOLARWINDS user account
$ServiceAccountCredentials = Get-SecureCreds -AccountName SOLARWINDS -KeyFile $KeyFile -PasswordFile $PasswordFile
# Set up sftp session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "mb.payments.ca"
PortNumber = "22"
UserName = $($ServiceAccountCredentials.UserName)
Password = $($ServiceAccountCredentials.GetNetworkCredential().Password)
SshHostKeyFingerprint = "ssh-rsa 2048zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
}
################
# SCRIPT START #
################
# Create session
$session = New-Object WinSCP.Session
# Connect
$session.Open($sessionOptions)
# Wait for 5 seconds before getting $connectionStatus
Start-Sleep -Seconds 5
if ( !$session.Opened)
{
write-host "Statistic: 1"
Write-Host "Message: Can't sftp connect to $sessionOptions"
exit 1
}
else
{
# Transfer files from local to remote
$transfer = $session.PutFiles("$localDirectory\*", "$remoteDirectory/")
if ($transfer.IsSuccess -eq $true) {
write-host "Statistic: 0"
write-host "Message: sftp file transfer complete."
exit 0
}
write-host "Statistic: 1"
write-host "Message: sftp file transfer failed"
exit 1
}
##############################################################################