Monitor logs folder and search for specific pattern

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
amitw
Posts: 28
Joined: Tue Jun 28, 2016 8:07 am

Monitor logs folder and search for specific pattern

Post 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
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Monitor logs folder and search for specific pattern

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Monitor logs folder and search for specific pattern

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
amitw
Posts: 28
Joined: Tue Jun 28, 2016 8:07 am

Re: Monitor logs folder and search for specific pattern

Post by amitw »

Thanks alot.
Can i make this script work also with NSclient ?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Monitor logs folder and search for specific pattern

Post 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
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked