The command (up_time) returned an invalid return code: 255
The command (up_time) returned an invalid return code: 255
hello every one,
I am new to nagios,
I need to set up a nagios server with passive checks at my clients (outside my network)
So I use NSClient ++ with NSCA
My configuration works for all my clients except for one AD server.
The command (up_time) returned an invalid return code: 255
The script up_time works fine when I run it locally.
My config nsclient.ini
[/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
timeout=120
[/settings/external scripts/scripts]
list_file=cmd /c "dir c:\\"
up_time = cmd /c echo scripts\up_time.ps1; exit($lastexitcode) | powershell.exe -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 -
Example of a script :
function Get-SystemUptime
{
$operatingSystem = Get-WmiObject Win32_OperatingSystem
[Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)
}
Get-SystemUptime ($computer = "localhost") >$NULL
$lastboot = [System.Management.ManagementDateTimeconverter]::ToDateTime(
"$((gwmi Win32_OperatingSystem -computername $computer).LastBootUpTime)")
$uptime = (Get-Date) - $lastboot
Write-Host "Duree de fonctionnement : " $uptime.days "jours" $uptime.hours "heures" $uptime.minutes "minutes"
# le code d'erreur est toujours a 0 pour que l'état dans nagios soit toujours a OK
exit 0
If you have idea i'd please to try them
I am new to nagios,
I need to set up a nagios server with passive checks at my clients (outside my network)
So I use NSClient ++ with NSCA
My configuration works for all my clients except for one AD server.
The command (up_time) returned an invalid return code: 255
The script up_time works fine when I run it locally.
My config nsclient.ini
[/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
timeout=120
[/settings/external scripts/scripts]
list_file=cmd /c "dir c:\\"
up_time = cmd /c echo scripts\up_time.ps1; exit($lastexitcode) | powershell.exe -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 -
Example of a script :
function Get-SystemUptime
{
$operatingSystem = Get-WmiObject Win32_OperatingSystem
[Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime)
}
Get-SystemUptime ($computer = "localhost") >$NULL
$lastboot = [System.Management.ManagementDateTimeconverter]::ToDateTime(
"$((gwmi Win32_OperatingSystem -computername $computer).LastBootUpTime)")
$uptime = (Get-Date) - $lastboot
Write-Host "Duree de fonctionnement : " $uptime.days "jours" $uptime.hours "heures" $uptime.minutes "minutes"
# le code d'erreur est toujours a 0 pour que l'état dans nagios soit toujours a OK
exit 0
If you have idea i'd please to try them
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: The command (up_time) returned an invalid return code: 2
How are you running this from the Nagios server? I see this in the config which I would expect to be enabled
Code: Select all
NRPEServer = disabled
Re: The command (up_time) returned an invalid return code: 2
All services are passive with NSCA, i have desabled active check on my services, this is why it is desabled
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: The command (up_time) returned an invalid return code: 2
You might need to bypass the execution policy for this command to run, try
Code: Select all
up_time = cmd /c echo scripts\up_time.ps1; exit($lastexitcode) | powershell.exe -noprofile -executionpolicy bypass -command -
Re: The command (up_time) returned an invalid return code: 2
Code: Select all
up_time = cmd /c echo scripts\up_time.ps1; exit($lastexitcode) | powershell.exe -noprofile -executionpolicy bypass -command -
if you have other ideas
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: The command (up_time) returned an invalid return code: 2
What are you seeing in the nsclient logs?Arenne wrote:I tried but it does not workCode: Select all
up_time = cmd /c echo scripts\up_time.ps1; exit($lastexitcode) | powershell.exe -noprofile -executionpolicy bypass -command -
if you have other ideas
Re: The command (up_time) returned an invalid return code: 2
scottwilkerson wrote:What are you seeing in the nsclient logs?Arenne wrote:I tried but it does not workCode: Select all
up_time = cmd /c echo scripts\up_time.ps1; exit($lastexitcode) | powershell.exe -noprofile -executionpolicy bypass -command -
if you have other ideas
here is the nsclient.log
Code: Select all
2019-05-14 11:18:48: error:c:\source\master\modules\NRPEServer\NRPEServer.cpp:121: Certificate not found: C:\Program Files\NSClient++/security/certificate.pem (generating a default certificate)
2019-05-14 11:18:48: error:c:\source\master\modules\NRPEServer\NRPEServer.cpp:121: CA not found: C:\Program Files\NSClient++/security/ca.pem (generating a default CA)
2019-05-14 11:48:28: error:c:\source\master\service\plugin_manager.cpp:475: Unknown command(s): check_serviceoff 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_and_forward, check_backupexec, check_counter, check_cpu, check_critical, check_drivesize, check_eventlog, check_files, check_maj, check_memory, check_multi, check_negate, check_network, check_nscp, check_nscp_version, 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, disk_fail, filter_perf, hyperv_snapshot, list_file, negate, render_perf, space_disk, submit_nsca, timeout, up_time, veeam_backup, vmware_snapshot, windows_backup, xform_perf}, plugins {, 0, 1, 2, 3, 4, 5, 6}
2019-05-14 11:48:29: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 8 30 seconds to late from thread 104
2019-05-14 11:48:29: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 5 30 seconds to late from thread 103
2019-05-14 11:48:29: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 2 30 seconds to late from thread 102
2019-05-14 11:48:29: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 4 30 seconds to late from thread 101
2019-05-14 11:58:58: error:c:\source\master\service\plugin_manager.cpp:475: Unknown command(s): check_serviceoff 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_and_forward, check_backupexec, check_counter, check_cpu, check_critical, check_drivesize, check_eventlog, check_files, check_maj, check_memory, check_multi, check_negate, check_network, check_nscp, check_nscp_version, 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, disk_fail, filter_perf, hyperv_snapshot, list_file, negate, render_perf, space_disk, submit_nsca, timeout, up_time, veeam_backup, vmware_snapshot, windows_backup, xform_perf}, plugins {, 0, 1, 2, 3, 4, 5, 6}
2019-05-14 11:58:58: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 8 28 seconds to late from thread 103
2019-05-14 11:58:58: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 2 28 seconds to late from thread 104
2019-05-14 11:58:58: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 4 28 seconds to late from thread 102
2019-05-14 11:58:58: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 5 29 seconds to late from thread 100
2019-05-14 12:09:27: error:c:\source\master\service\plugin_manager.cpp:475: Unknown command(s): check_serviceoff 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_and_forward, check_backupexec, check_counter, check_cpu, check_critical, check_drivesize, check_eventlog, check_files, check_maj, check_memory, check_multi, check_negate, check_network, check_nscp, check_nscp_version, 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, disk_fail, filter_perf, hyperv_snapshot, list_file, negate, render_perf, space_disk, submit_nsca, timeout, up_time, veeam_backup, vmware_snapshot, windows_backup, xform_perf}, plugins {, 0, 1, 2, 3, 4, 5, 6}
2019-05-14 12:09:27: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 8 29 seconds to late from thread 101
2019-05-14 12:09:27: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 2 29 seconds to late from thread 103
2019-05-14 12:09:27: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 4 29 seconds to late from thread 104
2019-05-14 12:09:27: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 5 29 seconds to late from thread 100
2019-05-14 12:19:56: error:c:\source\master\service\plugin_manager.cpp:475: Unknown command(s): check_serviceoff 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_and_forward, check_backupexec, check_counter, check_cpu, check_critical, check_drivesize, check_eventlog, check_files, check_maj, check_memory, check_multi, check_negate, check_network, check_nscp, check_nscp_version, 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, disk_fail, filter_perf, hyperv_snapshot, list_file, negate, render_perf, space_disk, submit_nsca, timeout, up_time, veeam_backup, vmware_snapshot, windows_backup, xform_perf}, plugins {, 0, 1, 2, 3, 4, 5, 6}
2019-05-14 12:19:56: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 8 29 seconds to late from thread 104
2019-05-14 12:19:56: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 2 29 seconds to late from thread 102
2019-05-14 12:19:57: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 4 29 seconds to late from thread 101
2019-05-14 12:19:57: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 5 29 seconds to late from thread 103
2019-05-14 12:30:26: error:c:\source\master\service\plugin_manager.cpp:475: Unknown command(s): check_serviceoff 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_and_forward, check_backupexec, check_counter, check_cpu, check_critical, check_drivesize, check_eventlog, check_files, check_maj, check_memory, check_multi, check_negate, check_network, check_nscp, check_nscp_version, 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, disk_fail, filter_perf, hyperv_snapshot, list_file, negate, render_perf, space_disk, submit_nsca, timeout, up_time, veeam_backup, vmware_snapshot, windows_backup, xform_perf}, plugins {, 0, 1, 2, 3, 4, 5, 6}
2019-05-14 12:30:26: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 8 29 seconds to late from thread 101
2019-05-14 12:30:26: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 2 29 seconds to late from thread 102
2019-05-14 12:30:26: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 4 29 seconds to late from thread 100
2019-05-14 12:30:26: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 5 29 seconds to late from thread 101
2019-05-14 12:40:55: error:c:\source\master\service\plugin_manager.cpp:475: Unknown command(s): check_serviceoff 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_and_forward, check_backupexec, check_counter, check_cpu, check_critical, check_drivesize, check_eventlog, check_files, check_maj, check_memory, check_multi, check_negate, check_network, check_nscp, check_nscp_version, 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, disk_fail, filter_perf, hyperv_snapshot, list_file, negate, render_perf, space_disk, submit_nsca, timeout, up_time, veeam_backup, vmware_snapshot, windows_backup, xform_perf}, plugins {, 0, 1, 2, 3, 4, 5, 6}
2019-05-14 12:40:55: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 8 29 seconds to late from thread 101
2019-05-14 12:40:55: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 2 29 seconds to late from thread 103
2019-05-14 12:40:55: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 4 29 seconds to late from thread 104
2019-05-14 12:40:55: error:c:\source\master\include\scheduler\simple_scheduler.cpp:189: Ran scheduled item 5 29 seconds to late from thread 102
Re: The command (up_time) returned an invalid return code: 2
Can you get the full nsclient.ini file and upload it to the ticket so we can check all of the settings?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: The command (up_time) returned an invalid return code: 2
yes i can, here is the the full nsclient.ini.
I install NSClient ++ with a script so the configuration is the same for all my servers. And today I just saw that one of my other servers does not stop changing status from a normal situation to the same error code
I install NSClient ++ with a script so the configuration is the same for all my servers. And today I just saw that one of my other servers does not stop changing status from a normal situation to the same error code
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
timeout=120
[/settings/external scripts/scripts]
list_file=cmd /c "dir c:\\"
up_time = cmd /c echo scripts\up_time.ps1; exit($lastexitcode) | powershell.exe -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 -
Re: The command (up_time) returned an invalid return code: 2
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.
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.
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 -
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 -
Be sure to check out our Knowledgebase for helpful articles and solutions!