Check File Content

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Re: Check File Content

Postby DrNox » Tue Sep 12, 2017 10:06 am

I got NRPE and NSCP install :)
But i want to read inside the file to found a string : "Infected files: " + a number
If this number is 0 it s OK else Critical
Then i'am back to the beginning
French Baguette
User avatar
DrNox
 
Posts: 37
Joined: Wed Apr 19, 2017 9:20 am

Re: Check File Content

Postby scottwilkerson » Tue Sep 12, 2017 10:18 am

so based on the site I posted from one of our contractors
http://sites.box293.com/nagios/guides/common-checks/files-folders
There is a section marked Make Sure Files Exists That Match A Pattern

You can use something like the following depending on your NSClient version:

Make Sure Files Exists That Match A Pattern
The following file exists: "C:\Downloads\test1\test-123.txt" AND it has some text added to it (so it doesn't have a byte size of 0).
These commands find any files that start with test-
Generate a critical alert if no files are found.

NSClient++ 0.3.9
No additional configuration is required.
Command:
Code: Select all
check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\Downloads\\test1' pattern='test-*' 'filter=size gt 0b' max-dir-depth=0 MinCrit=0


Output when files are found:
Code: Select all
test-123.txt|'found files'=1;0;0


Output when NO files are found:
Code: Select all
found files: 0 < critical|'found files'=0;0;0


NSClient++ 0.4.1
No additional configuration is required.
Command:
Code: Select all
check_nrpe -H 192.168.142.1 -t 30 -c CheckFiles -a path='C:\\Downloads\\test1' pattern='test-*' max-dir-depth=0 MinCrit=0


Output when files are found:
Code: Select all
test-123.txt|'found files'=1;0;0


Output when NO files are found:
Code: Select all
found files: 0 < critical|'found files'=0;0;0


NSClient++ 0.4.3.138 onwards
No additional configuration is required.
Command:
Code: Select all
check_nrpe -H 192.168.142.1 -t 30 -c check_files -a path='C:\\Downloads\\test1\\' pattern=test-* 'critical=count<1' max-depth=1 'empty-state=critical'


Output when file is found:
Code: Select all
OK: All 1 files are ok|'count'=1;0;1


Output when file is NOT found:
Code: Select all
No files found|'count'=0;0;1
User avatar
scottwilkerson
CTO
 
Posts: 7620
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Check File Content

Postby DrNox » Wed Sep 13, 2017 5:03 am

Thank for your answer.
I think I have expressed myself badly.
What I meant was that i want to read inside the file ( Ligne 5 or Ligne 6 inside, for example) not the name of my file.
In my case I don't know which line is my string : "Infected files: " + a number .
French Baguette
User avatar
DrNox
 
Posts: 37
Joined: Wed Apr 19, 2017 9:20 am

Re: Check File Content

Postby scottwilkerson » Wed Sep 13, 2017 8:40 am

Ok, I guess I would have to refer you back to the plugin you were working with first, and you can install the windows version on a windows machine running NSClient++ or NCPA.

The easiest method by far would be to spin up a Nagios Log Server if that was an option as the functionality is built-in
https://www.nagios.com/products/nagios-log-server/
User avatar
scottwilkerson
CTO
 
Posts: 7620
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Check File Content

Postby DrNox » Wed Sep 13, 2017 9:04 am

okey,thanks for your help

But I didn't see any possibility to install it on Windows (https://labs.consol.de/nagios/check_logfiles/)
French Baguette
User avatar
DrNox
 
Posts: 37
Joined: Wed Apr 19, 2017 9:20 am

Re: Check File Content

Postby scottwilkerson » Wed Sep 13, 2017 9:50 am

DrNox wrote:okey,thanks for your help

But I didn't see any possibility to install it on Windows (https://labs.consol.de/nagios/check_logfiles/)


There is definitely some homework. If you download the check_logfiles-3.8.1.tar.gz file, when you extract it there is a text file called README.windows-exe which contains instructions

How to create a windows native binary
check_logfiles.exe

0) Deinstall ActiveState Perl VMWare Remote CLI
and any other Perl packages you can find.

1) Install Strawberry Perl
from http://strawberryperl.com/

2) Prepare your environment so that strawberry perl
is the preferred perl interpreter.
set PATH=C:\strawberry\c\bin;C:\strawberry\perl\bin;%PATH%
Better: Deinstall ActiveState Perl and any other Perl packages you can find.

3) Install PAR::Packer
perl -MCPAN -eshell
install PAR
install PAR::Packer
You will see error messages and the installation will fail.
No problem! We can repair it.
cd C:\strawberry\cpan\build
a)
cd PAR-0.980-<a lot of crap>
perl Makefile.PL
dmake
dmake install
b)
cd PAR-Packer-0.980-<a lot of crap>
edit myldr/Makefile.PL and add
$file =~ s/^lib// if $^O eq "MSWin32";
after line 142.
perl Makefile.PL
dmake
dmake install

4) Build the plugin
cd check_logfiles-x.x.x.x
perl winconfig.pl

5) Compile the plugin
cd plugins-scripts
pp -M PerlIO -M Digest::MD5 -M Encode::Encoding -M Encode::Unicode -M Encode::Unicode::UTF7 -M Net::Domain -M Win32::NetResource -M Win32::Daemon -M Time::Piece -M Time::Local -M Win32::EventLog -M Win32::TieRegistry -M Win32::WinError -M Date::Manip -o check_logfiles.exe check_logfiles
(maybe you need to install Win32::NetResource and Win32::Daemon)
(Win32::Service is useful, too)

6) Package the plugin
C:\Programme\WinZip\WINZIP32.EXE -a check_logfiles.zip plugins-scripts\check_logfiles

If it does not work it's not my fault. It worked for me and my PC.
I read the documentation and played around until it worked.
If it does not work for you, read the documentation and play around.
At least for a week.
If it still does not work, forget check_logfiles.
Use check_hanswurscht instead. The source of check_hanswurscht is:

printf "hello hanswurscht\n";

Now try to create a windows binary with
pp -o check_hanswurscht.exe check_hanswurscht

Do not contact me if check_hanswurscht.exe doesn't work.
Please contact Strawberry and tell them:
"hi, i am a hanswurscht and i have a problem..."

User avatar
scottwilkerson
CTO
 
Posts: 7620
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Check File Content

Postby DrNox » Thu Sep 14, 2017 2:42 am

OoO whaou
It's gonna be hard, but thanks for your help, I will try !
I come back to you if i got some issues ^^
French Baguette
User avatar
DrNox
 
Posts: 37
Joined: Wed Apr 19, 2017 9:20 am

Re: Check File Content

Postby tmcdonald » Thu Sep 14, 2017 2:23 pm

We'll keep this post open for you.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tmcdonald
Support Lead / Operations Engineer
 
Posts: 8683
Joined: Mon Sep 23, 2013 8:40 am

Re: Check File Content

Postby DrNox » Thu Sep 21, 2017 2:55 am

Hello,

Finally i used the check_file and not this plugin.
You can close the post :)
French Baguette
User avatar
DrNox
 
Posts: 37
Joined: Wed Apr 19, 2017 9:20 am

Re: Check File Content

Postby scottwilkerson » Thu Sep 21, 2017 10:41 am

Glad you found a solution!
User avatar
scottwilkerson
CTO
 
Posts: 7620
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Previous

Return to Nagios Core

Who is online

Users browsing this forum: Google [Bot] and 13 guests