Opened 13 months ago

Closed 13 months ago

Last modified 12 months ago

#524 closed defect (fixed)

Blank extended command definitions overwrite populated simple definitions

Reported by: ga15859 Owned by: mickem
Priority: 1 Milestone: 0.4.0
Component: CheckExternalScripts Version: 0.4.0
Severity: Bugs Keywords:
Cc:

Description

I apologize if I'm missing something basic, but I have two issues - one that existed in .163 as well, one that appears new in .169.

ISSUE APPEARING IN 169

It appears that everything under /settings/external scripts/scripts generates the following error when the commands are run:

ExternalCommands: failed to create process ( ): 2: The system cannot find the file specified.

This did not occur in .163 at all, but perhaps the config file rules have changed? I've pasted my entire external scripts section below.

ISSUE APPEARING IN 163 AND 169

This one very well could be a config issue, but it appears the timeout value recorded under settings/external scripts does not get honored. My Windows Updates visual basic check script takes more than 30 seconds for some servers, and it constantly times out right at 30 seconds now, saying no response from the server. Note this occurs simply running the check_nrpe check itself, completely independent of Nagios and its various checks. You'll see below I have set timeout to 600, but it still dies at 30 seconds.

EXTERNAL SCRIPTS SECTION:

; Section for external scripts configuration options (CheckExternalScripts).
[/settings/external scripts]

; COMMAND ARGUMENT PROCESSING - This option determines whether or not the we will allow clients to specify arguments to commands that are executed.
allow arguments = true

; COMMAND ALLOW NASTY META CHARS - This option determines whether or not the we will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments.
allow nasty characters = true

; SCRIPT DIRECTORY - Load all scripts in a directory and use them as commands. Probably dangerous but useful if you have loads of scripts :)
script path = 

; COMMAND TIMEOUT - The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones.
timeout = 600


; A list of aliases available. An alias is an internal command that has been "wrapped" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)
[/settings/external scripts/alias]


; A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>
[/settings/external scripts/scripts]
check_mssql_nt = check_mssql_nt.exe $ARG1$
check_ad = check_ad.exe --dc --noeventlog
check_kav_adminkit=perl.exe check_kav_adminkit.pl $ARG1$ $ARG2$

; A list of wrappped scripts (ie. using the template mechanism)
[/settings/external scripts/wrapped scripts]

; Check the Active Directory time offset
check_ad_time=check_ad_time.vbs

; Check for Microsoft Windows Updates
check_windows_updates=CheckWindowsUpdates.vbs

; Check the status of Windows RAID arrays
check_windows_raids=check_windows_raids.wsf

check_kav_kit=check_kav_adminkit.pl %ARGS%

; A list of templates for wrapped scripts
[/settings/external scripts/wrappings]

; DOS Batch Scripts
bat = scripts\%SCRIPT% %ARGS%

; Powershell Scripts
ps1 = cmd /c echo scripts\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -

; Visual Basic Scripts
vbs = cscript.exe //T:540 //NoLogo scripts\lib\wrapper.vbs %SCRIPT% %ARGS%

; Windows Script File Scripts
wsf = cscript.exe //T:540 //NoLogo %SCRIPT% %ARGS%

pl = perl.exe %SCRIPT% %ARGS%

Attachments (1)

NSClientFiles.zip (1.1 MB) - added by ga15859 13 months ago.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 13 months ago by ga15859

  • Component changed from None to CheckExternalScripts
  • Owner set to mickem

Sorry, updated INI - ignore earlier one.

; Section for external scripts configuration options (CheckExternalScripts).
[/settings/external scripts]

; COMMAND ARGUMENT PROCESSING - This option determines whether or not the we will allow clients to specify arguments to commands that are executed.
allow arguments = true

; COMMAND ALLOW NASTY META CHARS - This option determines whether or not the we will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments.
allow nasty characters = true

; SCRIPT DIRECTORY - Load all scripts in a directory and use them as commands. Probably dangerous but useful if you have loads of scripts :)
script path = 

; COMMAND TIMEOUT - The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones.
timeout = 600


; A list of aliases available. An alias is an internal command that has been "wrapped" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)
[/settings/external scripts/alias]


; A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>
[/settings/external scripts/scripts]
check_mssql_nt = check_mssql_nt.exe $ARG1$
check_ad = check_ad.exe --dc --noeventlog

; A list of wrappped scripts (ie. using the template mechanism)
[/settings/external scripts/wrapped scripts]

; Check the Active Directory time offset
check_ad_time=check_ad_time.vbs

; Check for Microsoft Windows Updates
check_windows_updates=CheckWindowsUpdates.vbs

; Check the status of Windows RAID arrays
check_windows_raids=check_windows_raids.wsf

; Check Kaspersky administration kit
check_kav_adminkit=check_kav_adminkit.pl $ARG1$ $ARG2$

; A list of templates for wrapped scripts
[/settings/external scripts/wrappings]

; DOS Batch Scripts
bat = scripts\%SCRIPT% %ARGS%

; Powershell Scripts
ps1 = cmd /c echo scripts\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -

; Visual Basic Scripts
vbs = cscript.exe //T:540 //NoLogo scripts\lib\wrapper.vbs %SCRIPT% %ARGS%

; Windows Script File Scripts
wsf = cscript.exe //T:540 //NoLogo %SCRIPT% %ARGS%

; Perl Script files
pl = perl.exe %SCRIPT% %ARGS%

comment:2 Changed 13 months ago by mickem

I used your config as-is only adding in the following:

[/modules]
CheckExternalScripts = 1

ANd itsemo work fine here.

Could you run in test mode and past the logs?

nscp test

Michael Medin

comment:3 follow-up: Changed 13 months ago by mickem

As for the other issue cscript also has a timeout (T:540) but you seem to set that a large value as well...

Again could you run the long running command and debug paste the logs?

Michael Medin

Changed 13 months ago by ga15859

comment:4 in reply to: ↑ 3 Changed 13 months ago by ga15859

Ok so I stopped the NSClient service, deleted existing log, opened a command prompt, typed nscp test, program outputted to console and started up. I then ran this command:

# ./check_nrpe -t 540 -H COLOADMIN1 -c check_ad
ExternalCommands: failed to create process ( ): 2: The system cannot find the file specified.

And I noticed that no new log file was generated, nor was additional output generated on the console (??). Sorry, I'm not really helping you here am I?? Since I'm confused I've added a zip file with the scripts in question and the config files. Can you see if this helps?

comment:5 Changed 13 months ago by mickem

  • Milestone changed from 0.4.0 to 0.4.1

Well it is technically configuration but one I probably caused you :)

But first off:

Here is the clue something is wrong:

d kExternalScripts.cpp:143  Registring command: check_ad[check_ad] = {command: , arguments: }
d kExternalScripts.cpp:143  Registring command: check_ad_time[check_ad_time] = {command: cscript.exe, arguments: //T:540 //NoLogo scripts\lib\wrapper.vbs check_ad_time.vbs}
d kExternalScripts.cpp:143  Registring command: check_kav_adminkit[check_kav_adminkit] = {command: perl.exe, arguments: check_kav_adminkit.pl $ARG1$ $ARG2$}
d kExternalScripts.cpp:143  Registring command: check_mssql_nt[check_mssql_nt] = {command: , arguments: }                                      
d kExternalScripts.cpp:143  Registring command: check_windows_raids[check_windows_raids] = {command: cscript.exe, arguments: //T:540 //NoLogo check_windows_raids.wsf}
d kExternalScripts.cpp:143  Registring command: check_windows_updates[check_windows_updates] = {command: cscript.exe, arguments: //T:540 //NoLogo scripts\lib\wrapper.vbs CheckWindowsUpdates.vbs}

Notice how check_ad has a blank command...

The reason for this is that you actually use the "extended" syntax (that what automagicall conversion gets you which is why I recomend againast relaying on it currently)...

First you have your simple definition:

[/settings/external scripts/scripts]
...
check_ad = check_ad.exe --dc --noeventlog

Then you have the extended definition:

; Command definition for: check_ad
[/settings/external scripts/scripts/check_ad]

But here you have omitted the all important command key:

; Command definition for: check_ad
[/settings/external scripts/scripts/check_ad]
command=check_ad.exe --dc --noeventlog

This causes confusion and nsclient++ becomes confused and thinks the extended command is "better" and picks it.

This will be fixed in two ways:

  1. conversion should not generate empty sections (this is not supported by the metadata currently but will be fixed in 0.4.1).
  2. When reading emptyh extended sections it probably should not use them if they are empty...

But the simple way to solve your issue now is to manually remove the automatically generated empty section blocks you don't actually need...

; A list of avalible remote target systems
[/settings/targets]


; Command definition for: check_ad
[/settings/external scripts/scripts/check_ad]


; Command definition for: check_ad_time
[/settings/external scripts/scripts/check_ad_time]


; Command definition for: check_kav_adminkit
[/settings/external scripts/scripts/check_kav_adminkit]


; Command definition for: check_mssql_nt
[/settings/external scripts/scripts/check_mssql_nt]


; Command definition for: check_windows_raids
[/settings/external scripts/scripts/check_windows_raids]


; Command definition for: check_windows_updates
[/settings/external scripts/scripts/check_windows_updates]


; Command definition for: default
[/settings/external scripts/scripts/default]

Michael Medin

comment:6 Changed 13 months ago by ga15859

  • Summary changed from Two problems with external scripts to Blank extended command definitions overwrite populated simple definitions

Indeed you have pinpointed the issue with those commands not existing! By any chance does upgrading from 163 to 169 re-insert these blank sections? I could swear I had removed them, but it's probably user error.

I'm going to create a new bug - as I should have done to begin with - to track the command timeout issue, once I get some new logs to you. Thanks!

comment:7 Changed 13 months ago by mickem

Sounds good... I will try to see if I can fix this in the near future.
And the installer has an option for generating configuration which could cause this issue (so, yes could have been upgrade)...

comment:8 Changed 13 months ago by ga15859

Updated from 0.4.0.169 to 0.4.0.170 and it re-inserted the blank sections. Also, FYI, bug 526 contains the timeout issue. Thanks again for your great work!

comment:9 Changed 13 months ago by mickem

  • Milestone changed from 0.4.1 to 0.4.0
  • Resolution set to fixed
  • Status changed from new to closed
  • Version changed from 0.4.0-rc to 0.4.0

They will be re inserted until 0.4.1 (to big change to fix in 0.4.0).
But from the next build they will no longer interfere (ie. the parser will ignore them)

Michael Medin

comment:10 Changed 13 months ago by mickem

Build 172 should fix this (by not importing empty statements)

comment:11 Changed 13 months ago by ga15859

  • Resolution fixed deleted
  • Status changed from closed to reopened

I'm afraid it doesn't appear to work. Upgraded from .169 to .172, the "blank" sections were reinserted (as expected), but the commands were broken again:

ExternalCommands: failed to create process ( ): 2: The system cannot find the file specified. 

I had to re-remove the blank sections for my external commands to work.

comment:12 Changed 13 months ago by mickem

Could you past the ini file from it not working...

comment:13 Changed 13 months ago by mickem

This is what I used to test it:

[/modules]

; Check External Scripts - A simple wrapper to run external scripts and batch files.
CheckExternalScripts = 1

; CheckSystem - Various system related checks, such as CPU load, process state, service state memory usage and PDH counters.
CheckSystem = 1


; Section for external scripts configuration options (CheckExternalScripts).
[/settings/external scripts]

; COMMAND ARGUMENT PROCESSING - This option determines whether or not the we will allow clients to specify arguments to commands that are executed.
allow arguments = false

; COMMAND ALLOW NASTY META CHARS - This option determines whether or not the we will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments.
allow nasty characters = false

; SCRIPT DIRECTORY - Load all scripts in a directory and use them as commands. Probably dangerous but useful if you have loads of scripts :)
script path = 

; COMMAND TIMEOUT - The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones.
timeout = 60


; A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>
[/settings/external scripts/scripts]
foo = scripts\foo.bat


; Command definition for: foo
[/settings/external scripts/scripts/foo]

; ALIAS - The alias (service name) to report to server
; alias = 

; COMMAND - Command to execute
; command = 

Which gives me:

d vice\logger_impl.cpp:371  Creating logger: console                                                                                                                          
d rvice\NSClient++.cpp:374  NSClient++ 0,4,0,172 2012-05-08 x64 Loading settings and logger...                                                                                
d ngs_manager_impl.cpp:170  No entries found looking in (adding default): d:/source/nscp/build/x64//boot.ini                                                                  
d ngs_manager_impl.cpp:179  Boot order: old://${exe-path}/nsc.ini, ini://${shared-path}/nsclient.ini                                                                          
d ngs_manager_impl.cpp:182  Activating: ini://${shared-path}/nsclient.ini                                                                                                     
d ngs_manager_impl.cpp:73   Creating instance for: ini://${shared-path}/nsclient.ini                                                                                          
d ngs/settings_ini.hpp:268  Reading INI settings from: d:/source/nscp/build/x64//nsclient.ini                                                                                 
d ngs/settings_ini.hpp:234  Loading: d:/source/nscp/build/x64//nsclient.ini from ini://${shared-path}/nsclient.ini                                                            
l rvice\NSClient++.cpp:385  NSClient++ 0,4,0,172 2012-05-08 x64 booting...                                                                                                    
d rvice\NSClient++.cpp:386  Booted settings subsystem...                                                                                                                      
d rvice\NSClient++.cpp:453  On crash: restart: NSClientpp                                                                                                                     
d rvice\NSClient++.cpp:465  Archiving crash dumps in: d:/source/nscp/build/x64//crash-dumps                                                                                   
d rvice\NSClient++.cpp:532  booting::loading plugins                                                                                                                          
d rvice\NSClient++.cpp:298  Found: CheckExternalScripts                                                                                                                       
d rvice\NSClient++.cpp:298  Found: CheckSystem                                                                                                                                
d rvice\NSClient++.cpp:830  addPlugin(d:/source/nscp/build/x64//modules/CheckExternalScripts.dll as )                                                                         
d rvice\NSClient++.cpp:830  addPlugin(d:/source/nscp/build/x64//modules/CheckSystem.dll as )                                                                                  
d rvice\NSClient++.cpp:807  Loading plugin: Check External Scripts                                                                                                            
e scripts\commands.hpp:91   Failed to parse arguments for command 'foo', using old split string method: unknown escape sequence: scripts\foo.bat                              
d kExternalScripts.cpp:143  Registring command: foo[foo] = {command: scripts\foo.bat, arguments: }                                                                            
d rvice\NSClient++.cpp:807  Loading plugin: CheckSystem                                                                                                                       
d rvice\NSClient++.cpp:604  NSClient++ - 0,4,0,172 2012-05-08 Started!                                                                                                        

comment:14 Changed 13 months ago by ga15859

I'm afraid I've already upgraded everything to 172, but if you take the INI attached to this case and the ZIP I sent you earlier (with the external scripts), you should be able to recreate it by installing .170 with my INI, then upgrade to 172.

comment:15 Changed 13 months ago by mickem

  • Resolution set to fixed
  • Status changed from reopened to closed

Sorry... missed the empty commands= and alias= keys...
Fixed in latest build (please verify build 173).

Michael Medin

comment:16 Changed 12 months ago by ga15859

I shall verify today. Thanks again Michael!

Note: See TracTickets for help on using tickets.