Page 1 of 1

Monitor logs folder and search for specific pattern

Posted: Wed Nov 21, 2018 4:09 am
by amitw
Hi All,

i'm trying to monitor a folder (Windows Server) and search for the latest file that was modified, then, i need to search inside that file for a specific string("error"), then, alert if the string found.

Appreciate your help.

Amit

Re: Monitor logs folder and search for specific pattern

Posted: Wed Nov 21, 2018 12:59 pm
by benjaminsmith
Hi @amitw

Please take a look at the document below for example log checks in Nagios depending on what agent you're using to monitor the Windows Server.

Log Checks
https://support.nagios.com/kb/article/l ... s-787.html

Re: Monitor logs folder and search for specific pattern

Posted: Wed Nov 21, 2018 1:18 pm
by cdienger
I'm not aware of a plugin that will perform both of these steps, but a simple powershell script can get this info:

Code: Select all

$results = Get-ChildItem 'C:\directory\' -File | Sort {$_.LastWriteTime} | select -last 1 | Select-String -Pattern error

if ($results -eq $null) {
	"string not found"
	exit 0
} else {
	"String Found"
	$results
	exit 2
}
It'd reside on the Windows server and be called by an agent like NCPA:

https://www.nagios.org/ncpa/
https://support.nagios.com/kb/article/n ... a-722.html

Plugin guidelines can be found at:

https://nagios-plugins.org/doc/guidelines.html

Re: Monitor logs folder and search for specific pattern

Posted: Wed Nov 28, 2018 1:36 am
by amitw
Thanks alot.
Can i make this script work also with NSclient ?

Re: Monitor logs folder and search for specific pattern

Posted: Wed Nov 28, 2018 5:49 pm
by scottwilkerson
amitw wrote:Thanks alot.
Can i make this script work also with NSclient ?
Yes, we have a guide on adding powershell scripts to NSClient here
https://support.nagios.com/kb/article.php?id=528