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
Monitor logs folder and search for specific pattern
-
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: Monitor logs folder and search for specific pattern
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
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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Monitor logs folder and search for specific pattern
I'm not aware of a plugin that will perform both of these steps, but a simple powershell script can get this info:
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
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
}
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.
Re: Monitor logs folder and search for specific pattern
Thanks alot.
Can i make this script work also with NSclient ?
Can i make this script work also with NSclient ?
-
- 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
Yes, we have a guide on adding powershell scripts to NSClient hereamitw wrote:Thanks alot.
Can i make this script work also with NSclient ?
https://support.nagios.com/kb/article.php?id=528