Check Windows Files

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.
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: Check Windows Files

Post by rlinux57 »

Where do i will placed that script and what would be its command definition ?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check Windows Files

Post by rkennedy »

As I mentioned, test it first so that you can ensure it will work. It will require you have Python installed.

Code: Select all

python check_in_logfiles.py '<pattern file>' '<log file>'
Replace the variables accordingly.
Former Nagios Employee
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: Check Windows Files

Post by rlinux57 »

It is working on linux but, i have to check files on windows from nagios server ?
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Check Windows Files

Post by dwhitfield »

That python script has no ratings. https://exchange.nagios.org/directory/P ... pl/details has two ratings, both of which are 5 stars.

In both cases, the maintainer email is listed on the plugin page. Additionally, the perl script maintainer has left a github repo where you can file a bug report if you can't get it work on Windows: https://github.com/pmcaulay/nagios-plugins. The perl script says it works in Windows, but the python script doesn't say anything.

You can tell by the print statements in the python script that it is python 2, so you'll likely need to install https://www.python.org/downloads/release/python-2712/ on the Windows box. Alternatively, you could share the directory in Windows where the files you want to check reside.

What version of Windows are you using? We may be able to do some testing, but we don't have access to every version of Windows.
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: Check Windows Files

Post by rlinux57 »

Client OS is windows server 2012 R2
I have installed pyhton on windows as per your direction, And placed python script at this path

Code: Select all

C:\Program Files\NSClient++\scripts\check_files_win
My nsclient file code:

Code: Select all

# If you want to fill this file with all avalible options run the following command:
#   nscp settings --generate --add-defaults --load-all
# If you want to activate a module and bring in all its options use:
#   nscp settings --activate-module <MODULE NAME> --add-defaults
# For details run: nscp settings --help


; Undocumented section
[/settings/default]

; Undocumented key
; password = ********************

; Undocumented key
allowed hosts = NAGIOS SERVER IP

check_files_win = check_files_win
; Undocumented section
[/settings/NRPE/server]

; Undocumented key
 ssl options = no-sslv2,no-sslv3

; Undocumented key
; verify mode = peer-cert
verify mode = none
; Undocumented key
insecure = true
allow arguments = true
allow nasty characters = true

; Undocumented section
[/modules]

; Undocumented key
CheckExternalScripts = 1
check_files_win = C:\Program Files\NSClient++\scripts\check_files_win
; Undocumented key
CheckHelpers = 1

; Undocumented key
CheckEventLog = 1

; Undocumented key
CheckNSCP = 1

; Undocumented key
CheckDisk = 1

; Undocumented key
CheckSystem = 1

; Undocumented key
NSClientServer = 1

; Undocumented key
NRPEServer = 1
nsclient.logs on windows server:

Code: Select all

2016-10-18 10:43:24: error:c:\source\nscp\include\nscapi\nscapi_core_helper.cpp:95: Failed to execute command: check_files_win
2016-10-18 10:50:30: error:c:\source\nscp\service\NSClient++.cpp:894: Unknown command(s): check_files_win available commands: commands {, alias_cpu, alias_cpu_ex, alias_disk, alias_disk_loose, alias_event_log, alias_file_age, alias_file_size, alias_mem, alias_process, alias_process_count, alias_process_hung, alias_process_stopped, alias_sched_all, alias_sched_long, alias_sched_task, alias_service, alias_service_ex, alias_up, alias_volumes, alias_volumes_loose, check_always_critical, check_always_ok, check_always_warning, check_counter, check_cpu, check_critical, check_drivesize, check_eventlog, check_files, check_memory, check_multi, check_negate, check_nscp, check_ok, check_os_version, check_pagefile, check_pdh, check_process, check_service, check_timeout, check_uptime, check_version, check_warning, checkalwayscritical, checkalwaysok, checkalwayswarning, checkcounter, checkcpu, checkcritical, checkdrivesize, checkeventlog, checkfiles, checkmem, checkmultiple, checkok, checkprocstate, checkservicestate, checkuptime, checkversion, checkwarning, filter_perf, negate, render_perf, timeout, xform_perf}, plugins {, 0, 1, 2, 3, 4, 5}
2016-10-18 10:50:30: error:c:\source\nscp\include\nscapi\nscapi_core_wrapper.cpp:159: Failed to execute command
2016-10-18 10:50:30: error:c:\source\nscp\include\nscapi\nscapi_core_helper.cpp:95: Failed to execute command: check_files_win
2016-10-18 10:50:45: error:c:\source\nscp\service\NSClient++.cpp:894: Unknown command(s): check_files_win.py available commands: commands {, alias_cpu, alias_cpu_ex, alias_disk, alias_disk_loose, alias_event_log, alias_file_age, alias_file_size, alias_mem, alias_process, alias_process_count, alias_process_hung, alias_process_stopped, alias_sched_all, alias_sched_long, alias_sched_task, alias_service, alias_service_ex, alias_up, alias_volumes, alias_volumes_loose, check_always_critical, check_always_ok, check_always_warning, check_counter, check_cpu, check_critical, check_drivesize, check_eventlog, check_files, check_memory, check_multi, check_negate, check_nscp, check_ok, check_os_version, check_pagefile, check_pdh, check_process, check_service, check_timeout, check_uptime, check_version, check_warning, checkalwayscritical, checkalwaysok, checkalwayswarning, checkcounter, checkcpu, checkcritical, checkdrivesize, checkeventlog, checkfiles, checkmem, checkmultiple, checkok, checkprocstate, checkservicestate, checkuptime, checkversion, checkwarning, filter_perf, negate, render_perf, timeout, xform_perf}, plugins {, 0, 1, 2, 3, 4, 5}
2016-10-18 10:50:45: error:c:\source\nscp\include\nscapi\nscapi_core_wrapper.cpp:159: Failed to execute command
2016-10-18 10:50:45: error:c:\source\nscp\include\nscapi\nscapi_core_helper.cpp:95: Failed to execute command: check_files_win.py
Below are few commands and output from nagios server:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H windows client server ip
Output:
I (0.4.4.23 2016-04-05) seem to be doing fine...

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H windows client server ip -t 30 -c check_files_win -a "C:\\abc.txt" "C:\\xyz.txt"
Output:
Unknown command(s): check_files_win
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check Windows Files

Post by rkennedy »

Try to execute the script on the Windows machine, before going for the whole setup.

Code: Select all

python C:\Program Files\NSClient++\scripts\check_files_win "C:\\abc.txt" "C:\\xyz.txt"
I am trying to make sure that this plugin actually works for you, BEFORE attempting to set it up with NSClient++. The problem for why it's not working is it needs to be under the specific External Scripts section, not just anywhere in the configuration file.

Code: Select all

; A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>
[/settings/external scripts/scripts]
You will also need to make sure it's executed properly, which your current definition is not correct. Please get it working over the command line of Windows FIRST, and once we know it's working then set it up through NSClient++.
Former Nagios Employee
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: Check Windows Files

Post by rlinux57 »

Yes it's perfectly working at windows server, but when i checked from nagios server it gives me:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H WindowsIP -t 30 -c check_files_win -a "C:\\xyz.txt" "C:\\abc.txt"
Output after some time:
CHECK_NRPE: Socket timeout after 30 seconds.

nsclient:

Code: Select all

[/settings/external scripts/scripts]
check_files_win = C:\Program Files\NSClient++\scripts\check_files_win.py
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Check Windows Files

Post by dwhitfield »

I don't have a good sense for how long the test should take, but if it is a long file, I could see it taking a while. Let's try -t 120 just to start.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Check Windows Files

Post by rkennedy »

In addition to what @dwhitfield posted, you'll want to adjust the the NSClient++ parameters so that you are passing $ARG$ variables.

Code: Select all

check_files_win = C:\Program Files\NSClient++\scripts\check_files_win.py $ARG1$ $ARG2$
Could you also show the full input / output of you running it over the CLI without parameters, and with parameters?
Former Nagios Employee
rlinux57
Posts: 324
Joined: Mon Dec 08, 2014 12:03 am

Re: Check Windows Files

Post by rlinux57 »

That's not a long file which takes time.
I have tried

Code: Select all

check_files_win = C:\Program Files\NSClient++\scripts\check_files_win.py $ARG1$ $ARG2$
but no success it gives

Code: Select all

Arguments not allowed see nsclient.log for details.
But arguments are allowed

Code: Select all

allow arguments = true
allow nasty characters = true

Another way:

Code: Select all

[/settings/external scripts/scripts]
check_files_win = C:\Python27\python.exe C:\Program Files\NSClient++\scripts\check_files_win.py C:\xyz.txt C:\abc.txt
Nagios Server:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H WinIP -t 40 -c check_files_win
Output:
C:\Python27\python.exe: can't open file 'C:\Program': [Errno 2] No such file or directory

And if we used it without

Code: Select all

C:\Python27\python.exe

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H WinIP -t 40 -c check_files_win
Output:
Failed to execute check_files_win seems more like a script maybe you need a script executable first: failed to lookup error code: 193 (reason: 87)
Please find windows powershell screenshot.
Attachments
windowscli.png
Locked