The command (up_time) returned an invalid return code: 255

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.
Arenne
Posts: 8
Joined: Wed May 22, 2019 4:55 am

Re: The command (up_time) returned an invalid return code: 2

Post by Arenne »

tgriep wrote:I setup that command in NSClient++ version 0.5.2.23 on a windows systems and the command ran for me without any errors.

To get it to work, I had to add a space between the exit and the ( like this example.

Code: Select all

up_time = cmd /c echo scripts\up_time.ps1; exit ($lastexitcode) | powershell.exe -noprofile -executionpolicy bypass -command -
Try changing that and see if it helps.

Also, you should add a wrappings section and put in the settings for ps1 scripts like this.

Code: Select all

[/settings/external scripts/wrappings]

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


I tried same error message ... , but my nsclient.ini is cleaner thx you. if you have other good idea :)
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: The command (up_time) returned an invalid return code: 2

Post by tgriep »

Can you show us where you are seeing the invalid return code message?

Add the following to the nsclient.ini file and restart the agent to enable trace level logging to the agent.

Code: Select all

; Configure log properties.
[/settings/log]

; LOG LEVEL - Log level to use. Available levels are error,warning,info,debug,trace
level = trace

; FILENAME - The file to write log data to. Set this to none to disable log to file.
file name = nsclient.log

; DATEMASK - The size of the buffer to use when getting messages this affects the speed and maximum size of messages you can recieve.
date format = %Y-%m-%d %H:%M:%S

[/settings/log/file]
; MAXIMUM FILE SIZE - When file size reaches this it will be truncated to 50% if set to 0 (default) truncation will be disabled
max size = 2048000

Can you post the full nsclient.log file here so we can view it?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Arenne
Posts: 8
Joined: Wed May 22, 2019 4:55 am

Re: The command (up_time) returned an invalid return code: 2

Post by Arenne »

Excuse me for the delay !

Code: Select all

2019-05-27 11:32:20: debug:c:\source\master\service\plugin_manager.cpp:306: Loading module C:\Program Files\NSClient++\modules\CheckDisk.dll ()
2019-05-27 11:32:20: debug:c:\source\master\service\plugin_manager.cpp:306: Loading module C:\Program Files\NSClient++\modules\CheckEventLog.dll ()
2019-05-27 11:32:20: debug:c:\source\master\service\plugin_manager.cpp:306: Loading module C:\Program Files\NSClient++\modules\CheckExternalScripts.dll ()
2019-05-27 11:32:20: debug:c:\source\master\service\plugin_manager.cpp:306: Loading module C:\Program Files\NSClient++\modules\CheckHelpers.dll ()
2019-05-27 11:32:20: debug:c:\source\master\service\plugin_manager.cpp:306: Loading module C:\Program Files\NSClient++\modules\CheckNSCP.dll ()
2019-05-27 11:32:20: debug:c:\source\master\service\plugin_manager.cpp:306: Loading module C:\Program Files\NSClient++\modules\CheckSystem.dll ()
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:306: Loading module C:\Program Files\NSClient++\modules\NSCAClient.dll ()
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:306: Loading module C:\Program Files\NSClient++\modules\Scheduler.dll ()
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:227: Loading plugin: CheckDisk
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:227: Loading plugin: CheckEventLog
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:227: Loading plugin: CheckExternalScripts
2019-05-27 11:32:21: debug:c:\source\master\modules\CheckExternalScripts\CheckExternalScripts.cpp:127: No aliases found (adding default)
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:227: Loading plugin: CheckHelpers
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:227: Loading plugin: CheckNSCP
2019-05-27 11:32:21: debug:c:\source\master\modules\CheckNSCP\CheckNSCP.cpp:51: Crash folder is: C:\Program Files\NSClient++/crash-dumps
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:227: Loading plugin: CheckSystem
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:227: Loading plugin: NSCAClient
2019-05-27 11:32:21: debug:c:\source\master\service\plugin_manager.cpp:227: Loading plugin: Scheduler
2019-05-27 11:32:21: debug:c:\source\master\modules\Scheduler\Scheduler.cpp:94: Adding scheduled item: uptime[1701061129] = {tpl: {alias: uptime, path: /settings/scheduler/schedules/uptime, is_tpl: false, parent: default, value: up_time, options : { } }, command: up_time, channel: NSCA, source_id: , target_id: , duration: 300s, 0% randomness}
2019-05-27 11:32:21: debug:c:\source\master\modules\Scheduler\Scheduler.cpp:94: Adding scheduled item: updates[975184483] = {tpl: {alias: updates, path: /settings/scheduler/schedules/updates, is_tpl: false, parent: default, value: check_maj, options : { } }, command: check_maj, channel: NSCA, source_id: , target_id: , duration: 300s, 0% randomness}
2019-05-27 11:32:21: debug:c:\source\master\modules\Scheduler\Scheduler.cpp:94: Adding scheduled item: space[1663067496] = {tpl: {alias: space, path: /settings/scheduler/schedules/space, is_tpl: false, parent: default, value: space_disk, options : { } }, command: space_disk, channel: NSCA, source_id: , target_id: , duration: 300s, 0% randomness}
2019-05-27 11:32:21: debug:c:\source\master\modules\Scheduler\Scheduler.cpp:94: Adding scheduled item: diskfail[0] = {tpl: {alias: diskfail, path: /settings/scheduler/schedules/diskfail, is_tpl: false, parent: default, value: disk_fail, options : { } }, command: disk_fail, channel: NSCA, source_id: , target_id: , duration: 300s, 0% randomness}
2019-05-27 11:32:21: trace:c:\source\master\include\scheduler\simple_scheduler.cpp:76: starting all threads
2019-05-27 11:32:21: trace:c:\source\master\include\scheduler\simple_scheduler.cpp:79: Thread pool contains: 6
2019-05-27 11:32:21: trace:c:\source\master\include\scheduler\simple_scheduler.cpp:76: starting all threads
2019-05-27 11:32:21: trace:c:\source\master\include\scheduler\simple_scheduler.cpp:79: Thread pool contains: 2
2019-05-27 11:32:21: debug:c:\source\master\service\NSClient++.cpp:317: NSClient++ - 0.5.2.35 2018-01-28 Started!
2019-05-27 11:32:21: debug:c:\source\master\service\NSClient++.cpp:441: Starting: DONE



19-05-27 11:32:22: debug:c:\source\master\modules\CheckSystem\pdh_thread.cpp:169: Loading counter: disk_queue_length_0 C: = \\SRV-DC\PhysicalDisk(0 C:)\% Disk Time
2019-05-27 11:32:22: debug:c:\source\master\modules\CheckSystem\pdh_thread.cpp:169: Loading counter: disk_queue_length_1 E: = \\SRV-DC\PhysicalDisk(1 E:)\% Disk Time
2019-05-27 11:32:22: debug:c:\source\master\modules\CheckSystem\pdh_thread.cpp:169: Loading counter: disk_queue_length_2 F: = \\SRV-DC\PhysicalDisk(2 F:)\% Disk Time
2019-05-27 11:32:22: debug:c:\source\master\modules\CheckSystem\pdh_thread.cpp:169: Loading counter: disk_queue_length__Total = \\SRV-DC\PhysicalDisk(_Total)\% Disk Time
2019-05-27 11:36:23: error:c:\source\master\modules\CheckSystem\pdh_thread.cpp:307: Failed to get network metrics: Failed to fetch network metrics, disabling...


19-05-27 11:42:50: trace:c:\source\master\modules\nscaclient\nsca_client.hpp:126: Target configuration: address: ://XX.XX.XX.XX, timeout: 30, retry: 2, data: { delay: 0, encoding: , encryption: 1, password: XXXXXX, payload length: 512, retries: 3, time offset: 0, }
2019-05-27 11:42:50: trace:c:\source\master\modules\nscaclient\nsca_client.hpp:144: Scheduling packet: host: SERVER-DC, service: uptime, code: 3, time: 1558957370, result: The command (up_time) returned an invalid return code: 255
2019-05-27 11:42:50: trace:c:\source\master\modules\nscaclient\nsca_client.hpp:166: Connecting to: host: XX.XX.XX.XX:5667, buffer_length: 512, time_delta: 0, password: XXX, encryption: 1(1), hostname: SERVER-DC, encoding: , ssl: ssl disabled



User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: The command (up_time) returned an invalid return code: 2

Post by tgriep »

Try enabling RemoteSigned globally for Powershell scripts on the server.
Open up Powershell on the Windows system and run this command to enable it.

Code: Select all

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
To check and see if it is enabled, run this

Code: Select all

Get-ExecutionPolicy -List
And you should see this.

Code: Select all

Scope              ExecutionPolicy
-----              ---------------
LocalMachine       RemoteSigned
Be sure to check out our Knowledgebase for helpful articles and solutions!
Arenne
Posts: 8
Joined: Wed May 22, 2019 4:55 am

Re: The command (up_time) returned an invalid return code: 2

Post by Arenne »

For rights, I have the same on all my machines, I even tried to put unrestricted for local machine, it does not solve the problem

Code: Select all

 LocalMachine                                                Unrestricted
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: The command (up_time) returned an invalid return code: 2

Post by tgriep »

Try swapping out your nsclient.ini file with the following example to see if there are other configuration issues.

Code: Select all

# If you want to fill this file with all available 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

[/settings/default]

allow arguments = True


[/settings/NSCA/client]

hostname=XXX



[/settings/NSCA/client/targets/default]
;address= XXX
address=XXX
encryption=XXX
password=XXX

[/settings/scheduler/schedules/default]
interval = 5mn
channel = NSCA

[/settings/scheduler/schedules]

uptime = up_time
diskfail = disk_fail
space = space_disk
backup-exec = check_serviceoff
updates = check_maj
hyperv-snapshot = hyperv_snapshot
vmware-snapshot = vmware_snapshot
windows-backup = windows_backup
veeam-backup = veeam_backup

[/modules]

CheckExternalScripts = enabled

CheckHelpers = enabled

CheckNSCP = enabled

CheckDisk = enabled

CheckSystem = enabled

NSClientServer = disabled

CheckEventLog = enabled

NSCAClient = enabled

Scheduler = enabled

NRPEServer = disabled


[/settings/external scripts]

allow arguments = true
allow nasty characters = true

; 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 = 120

; Script root folder - Root path where all scripts are contained (You can not upload/download scripts outside this folder).
script root = ${scripts}

; Load all scripts in a given folder - Load all scripts in a given directory and use them as commands.
script path = UNKNOWN


[/settings/external scripts/scripts]

list_file=cmd /c "dir c:\\"

up_time = cmd /c echo scripts\up_time.ps1; exit ($lastexitcode) | powershell.exe -noprofile -executionpolicy bypass -command -
disk_fail = cmd /c echo scripts\disk_fail.ps1; exit($lastexitcode) | powershell.exe -command -
space_disk = cmd /c echo scripts\space_disk.ps1; exit($lastexitcode) | powershell.exe -command -
check_backupexec = cmd /c echo scripts\check_backupexec.ps1; exit($lastexitcode) | powershell.exe -command -
hyperv_snapshot = cmd /c echo scripts\hyperv_snapshot.ps1; exit($lastexitcode) | powershell.exe -command -
vmware_snapshot = cmd /c echo scripts\vmware_snapshot.ps1; exit($lastexitcode) | powershell.exe -command -
check_maj = cmd /c echo scripts\maj.ps1; exit($lastexitcode) | powershell.exe -command -
windows_backup = cmd /c echo scripts\check_windows_backup.ps1; exit($lastexitcode) | powershell.exe -command -
veeam_backup = cmd /c echo scripts\veeam_backup.ps1; exit($lastexitcode) | powershell.exe -command -

[/settings/external scripts/wrappings]

; WRAPPING - An external script wrapping
ps1 = cmd /c echo scripts\\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -
If this does not work, try upgrading to the latest version on NSClient++ in case there is a bug and verify that the power shell script is not corrupted.
If that does not work, you may need to go to the forums on the NSClient++ site for more help.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked