SAM 6.2.4
I have a Windows powershell component that is supposed to search for "denied" in activemq.log file.
I keep getting "Not defined" or file not found.
Message: File 'd:\apache-activemq-5.9.0\data\activemq.log' not found.
I am using a domain account and testing against a 2012 R2 VM server
Contents of PowerShell Script:
$lines = $null
$line = $null
$logfile_path = $args.get(0);
$regex = $args.get(1);
$Error.Clear();
if ( !$logfile_path )
{
Write-Host "Message: Can't find $logfile_path argument. Check documentation."
exit 1
}
if ( !$regex )
{
Write-Host "Message: Can't find $regex argument. Check documentation."
exit 1
}
if ( Test-Path $logfile_path )
{ }
else
{
Write-Host "Message: File $logfile_path not found."
exit 1
}
$filename = "$logfile_path"
$t = (Get-Childitem env:temp).value
$filename = $filename.Replace(':','_')
$filename = $filename.Replace('\','_')
$file_path = "$t\SW_Script_Monitor-$filename"
if ( Test-Path $file_path )
{
$known_rows = get-content $file_path
}
else
{
$known_rows = 0
}
$resn = @()
$resl = @()
$total = (get-childitem $logfile_path | select-string -pattern $regex | select linenumber, line | measure-object).count
if ($Error.Count -ne 0)
{
Write-Host "$($Error[0])"
exit 1
}
if ( $total -lt $known_rows )
{
$known_rows = 0
$known_rows > $file_path
}
$temp = $total - $known_rows
$known_rows = $temp + $known_rows
$known_rows > $file_path
for ( $i = 0 ; $i -le $total; $i++ )
{
$resn += @($i)
$resl += @($i) }
$i = 1
$stat = get-childitem $logfile_path | select-string -pattern $regex | select linenumber, line | ForEach-Object {
$resn[$i] = $_.linenumber
$resl[$i] = $_.line
$i = $i + 1
}
if ($temp -eq 0)
{
write-host "Statistic: $temp"
write-host "Message: No newly found strings"
exit 0
}
if ($temp -gt 0)
{
$lines = @()
write-host "Statistic: $temp"
If($temp -gt 1)
{
for ( $i = 1 ; $i -le $temp; $i++ )
{
$lines += $resl[$count - $i] + '\\n'
$lines = ([string]$lines)
$charslines = $lines | Measure-Object -Character | Select -ExpandProperty characters
$lines = ([string]$lines)
}
if ($charslines -gt 2500)
{
Write-Host Message: Numbers of newly found strings $temp \\n Message has been truncated to 2500 characters original message included $charslines. Please check actual file for additional information. \\n Lines that included the error are. \\n $lines.substring(0,2500)
}
else
{
Write-Host Message: Number of newly founds strings $temp \\n Lines that included the error are. \\n $lines
}
}
else
{
$line = $resl[$resl.Count - 1]
$charsline = $line | Measure-Object -Character | Select -ExpandProperty characters
if ($charsline -gt 2500)
{
write-host Message: Number of newly found strings $temp. \\n Message has been truncated to 2500 characters original message included $charslines \\n Line that included the error in.\\n $line.substring(0,2500)
}
else
{
Write-Host Message: Number of newly found strings $temp \\n Lines that included the error is. \\n $line
}
}
}
Things I have tried:
-proved path is correct on server
- Tried d:\.... and UNC path as above
- Tried SAM component as local and remote powershell ( remote gives ( not defined)
- proved error exists in file ( if not the script thas logic in it to tell me "No newly found strings"
- Duplicated same log on different server, same error
- ensured I can open the log file and view error.
- changed .log to .txt to see if that was the hang up.
Please help.