At the moment I am loading in some data from an XML file to configure some parameters for my script to run, however the $keywords and $maxCounts are not getting the correct values when they are being sent to the CheckForKeywords function
function Main()
{
#### VARIABLES RELATING TO THE LOG FILE
#contains the log path and log file mask
$logPaths = @()
$logFileMasks = @()
# key value pair for the strings to match and the max count of matches before they are considered an issue
$keywords = @(,@())
$maxCounts = @(,@())
#### FUNCTION CALLS
LoadLogTailerConfig $logConfigPath ([ref]$logPaths) ([ref]$logFileMasks) ([ref]$keywords) ([ref]$maxCounts)
for ($i = 0; $i -lt $logPaths.Count; $i++)
{
$tail = GetLogTail $numLinesToTail $logPaths[$i] $logFileMasks[$i]
$tailIssueTable = CheckForKeywords $tail $keywords[$i] $maxCounts[$i]
}
}
# Loads in configuration data for the utility to use
function LoadLogTailerConfig($logConfigPath, [ref]$logPaths, [ref]$logFileMasks, [ref]$keywords, [ref]$maxCounts)
{
Write-Debug "Loading config file data from $logConfigPath"
[xml]$configData = Get-Content "C:\Testing\Configuration\config.xml"
foreach ($log in $configData.Logs.Log) {
$logPaths.Value += $log.FilePath
$logFileMasks.Value += $log.FileMask
$kwp = @()
$kwc = @()
foreach ($keywordSet in $log.Keywords.Keyword)
{
$kwp += $keywordSet.Pattern
$kwc += $keywordSet.MaxMatches
}
$keywords.Value += $kwp
$maxCounts.Value += $kwc
}
}
# Returns body text for email containing details on keywords in the log file and their frequency
function CheckForKeywords($tail, $keywords, $maxCounts)
{
$issuesFound = 0
for ($i = 0; $i -lt $keywords.Count; $i++)
{
$keywordCount = ($tail | Select-String $keywords[$i] -AllMatches).Matches.Count
Write-Debug $keywords.Count
Write-Debug (("Match count for {0} : {1}" -f $keywords[$i], $keywordCount))
if ($keywordCount -gt $maxCounts)
{
#do stuff
}
}
return ""
}
Main
CheckForKeywordsneeds to be before the line you call it from