Documentation forServer & Application Monitor

Log Parser (PowerShell)

Use this template to monitor a specific log file and determine the total number of lines that match your search criteria.

For reference, see Use SAM templates, application monitors, and component monitors.

Prerequisites

WinRM is installed and properly configured on the target server. For reference, see Use PowerShell in SAM.

Credentials

Administrator on target server.

Specify the correct arguments for each monitored component in the Script Arguments field. Otherwise, the monitor will return with a status error of Undefined.

Component monitors

Total number of strings found

The total number of strings that match the search criteria. Additionally in the message field, this monitor returns all strings that match the search criteria. In the returning message, this component returns all lines that match the search criteria divided by ";"

This monitor uses the following arguments:

  • LogFilePath,RegularExpression where LogFilePath - This is the path of the target log file on the target server. The path cannot contain any spaces.
  • RegularExpression - This is used for regular expression searches to find a desired string in the log file. Searches are not case sensitive; however, a search cannot contain spaces.

Below is an example using the Scripts Arguments field to search the number of strings that match the word "error" in the powertest.log file:
d:\powertest.log,^error

Number of newly found strings

The number of newly found strings. Additionally, in the message field, this monitor returns all new strings that match search criteria.

This monitor uses the following arguments:

  • LogFilePath,RegularExpression where LogFilePath - This is the path of the target log file on the target server. The path cannot contain any spaces.
  • RegularExpression - This is used for regular expression searches to find a desired string in the log file. Searches are not case sensitive; however, a search cannot contain spaces.

Below is an example using the Scripts Arguments field to search for the number of newly found strings since the last script execution. In this case, just the new instances of the searched word, “error” is returned. In the returning message, this component returns all lines that match the search criteria divided by ";":
d:\powertest.log,^error

Found String in # Position

The number position of the string found from the end that matches the search criteria, as well as the string itself. By default, this counter also shows the last string.

This monitor uses the following arguments

  • LogFilePath,RegularExpression,Position where LogFilePath - This is the path of the target log file on the target server. The path cannot contain any spaces.
  • RegularExpression - This is used for regular expression searches to find a desired string in the log file. Searches are not case sensitive; however, a search cannot contain spaces.
  • Position - This value determines the position from the last string of the log file. By default, a value of 1 will return the last string found.

For example, the following script argument searches for the position of the word "error" in relation to the end of the log file: d:\powertest.log,^error,1