External scripts and Powershell
Hi,
I've implemented an script to check the email flow in Powershell.
The script ends with an exit code like this:
exit 1234
The Powershell script is called from a cmd file:
echo off
cd "e:Program FilesServersCheck_Monitoringexternal"
powershell.exe -executionpolicy bypass -noprofile -file prova.ps1
echo %errorlevel%
If I execute manually the cmd file I can see the 1234 but when I try to use it with Serverscheck, the program doesn't recognize the 1234 value and the check falls. Could you check it?
Generate a file called prova.ps1 containing the command exit 1124
And generate another file called prova.cmd containing:
echo off
cd "e:Program FilesServersCheck_Monitoringexternal"
powershell.exe -executionpolicy bypass -noprofile -file prova.ps1
echo %errorlevel%
And check it from an external monitor with Serverscheck with the expected value 1234
The result is:
Estatus: DOWN?
Error Retornado: 1123 not returned by external check
Thanks,
Francesc
I've implemented an script to check the email flow in Powershell.
The script ends with an exit code like this:
exit 1234
The Powershell script is called from a cmd file:
echo off
cd "e:Program FilesServersCheck_Monitoringexternal"
powershell.exe -executionpolicy bypass -noprofile -file prova.ps1
echo %errorlevel%
If I execute manually the cmd file I can see the 1234 but when I try to use it with Serverscheck, the program doesn't recognize the 1234 value and the check falls. Could you check it?
Generate a file called prova.ps1 containing the command exit 1124
And generate another file called prova.cmd containing:
echo off
cd "e:Program FilesServersCheck_Monitoringexternal"
powershell.exe -executionpolicy bypass -noprofile -file prova.ps1
echo %errorlevel%
And check it from an external monitor with Serverscheck with the expected value 1234
The result is:
Estatus: DOWN?
Error Retornado: 1123 not returned by external check
Thanks,
Francesc
This discussion has been closed.
Comments
--------------------------------------------------------------
#
# ServersCheck Web Server
# PREMIUM Edition
#
# Number of monitors allowed: 10000000000000
#
# Installed on - SWCS352
#
# Loading language file: SP.lang
# version 9.0.17
#
# ServersCheck additional 10000025 users pack loaded.
#
# (c) Copyright 2003-2012 - ServersCheck BVBA
# www.serverscheck.com
#
#
#
#
#
# Start: Wed Jun 26 13:50:16 2013 - End: Wed Jun 26 13:50:16 2013
#
# Configuration server ready, serving on port "1272"...
#
#
# Wed Jun 26 13:50:18 2013 Reading configuration file - last was
# Wed Jun 26 13:50:18 2013 Reading conf file completed
# Wed Jun 26 13:50:18 2013 Importing current status of each monitor
# Wed Jun 26 13:50:18 2013 End importing current status of each monitor
# Wed Jun 26 13:50:22 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:50:29 2013 email type: 2
# Wed Jun 26 13:50:30 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:50:36 2013 vm: 0
# Wed Jun 26 13:50:38 2013 Logs from 1372197600:Wed Jun 26 00:00:00 2013 to 1372284000:Thu Jun 27 00:00:00 2013
# Wed Jun 26 13:50:38 2013 Scanning log: alerts-2013-6-26
# Wed Jun 26 13:50:40 2013 delete - 1371643389
# Wed Jun 26 13:50:46 2013 team: - prova.cmd<X>1234
# Wed Jun 26 13:50:46 2013 application:<X>
# Wed Jun 26 13:50:46 2013 wapplication:<X>
# Wed Jun 26 13:50:46 2013 team2: - # Wed Jun 26 13:50:46 2013 storing by line
# Wed Jun 26 13:50:46 2013 storing by uid 1371643389
393
# Wed Jun 26 13:50:46 2013 Reading configuration file - last was 0
# Wed Jun 26 13:50:46 2013 Reading conf file completed
# Wed Jun 26 13:50:46 2013 Reading configuration file - last was 0
# Wed Jun 26 13:50:46 2013 Reading conf file completed
# Wed Jun 26 13:50:46 2013 Logs from 1372197600:Wed Jun 26 00:00:00 2013 to 1372284000:Thu Jun 27 00:00:00 2013
# Wed Jun 26 13:50:46 2013 Scanning log: alerts-2013-6-26
# Wed Jun 26 13:50:48 2013 delete - 1371643389
# Wed Jun 26 13:50:52 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:51:00 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /checks.html
# Wed Jun 26 13:51:00 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:51:22 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:51:22 2013 Importing current status of each monitor
# Wed Jun 26 13:51:22 2013 End importing current status of each monitor
# Wed Jun 26 13:51:30 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:51:33 2013 Serving Wizard 3 in test mode? 1
# Wed Jun 26 13:51:33 2013 Serving Wizard 4
# Wed Jun 26 13:51:35 2013 E:Program FilesServersCheck_Monitoring/
# test Wed Jun 26 13:51:35 2013 Starting Monitoring Rule Thread test
# Wed Jun 26 13:51:35 2013 Running in test mode
# test Wed Jun 26 13:51:35 2013 testmode:1
# test Wed Jun 26 13:51:35 2013 TEST - Starting check
# Wed Jun 26 13:51:35 2013 NO file TEST - EXTERNAL
result: 12323
# test Wed Jun 26 13:51:36 2013 Graphing? eq true and 0>=300
# test Wed Jun 26 13:51:36 2013 TEST - DOWN? - 1234 not returned by external check -
# Wed Jun 26 13:51:40 2013 Serving Wizard 4_1 - 0
# Wed Jun 26 13:51:52 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:51:52 2013 Reading configuration file - last was 1372247446
# Wed Jun 26 13:51:52 2013 Reading conf file completed
# Wed Jun 26 13:52:00 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /checks.html
# Wed Jun 26 13:52:00 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:52:22 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:52:29 2013 Serving Wizard 3 in test mode? 1
# Wed Jun 26 13:52:29 2013 Serving Wizard 4
# Wed Jun 26 13:52:29 2013 Importing current status of each monitor
# Wed Jun 26 13:52:29 2013 End importing current status of each monitor
# Wed Jun 26 13:52:30 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:52:31 2013 E:Program FilesServersCheck_Monitoring/
# test Wed Jun 26 13:52:31 2013 Starting Monitoring Rule Thread test
# Wed Jun 26 13:52:31 2013 Running in test mode
# test Wed Jun 26 13:52:31 2013 testmode:1
# test Wed Jun 26 13:52:31 2013 TEST - Starting check
# Wed Jun 26 13:52:31 2013 NO file TEST - EXTERNAL
result: 1234
# test Wed Jun 26 13:52:32 2013 Graphing? eq true and 0>=300
# test Wed Jun 26 13:52:32 2013 TEST - OK - -
# Wed Jun 26 13:52:36 2013 Serving Wizard 4_1 - 0
# Wed Jun 26 13:52:52 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:52:59 2013 Reading configuration file - last was 1372247512
# Wed Jun 26 13:52:59 2013 Reading conf file completed
# Wed Jun 26 13:53:00 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /checks.html
# Wed Jun 26 13:53:00 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
# Wed Jun 26 13:53:22 2013 op - XXXXXX / XXXXXX - IP 172.XX.XX.XX - /ajax_stats1.html
------------------------------------------------------------------
But the same scripts in normal mode returns this message:
Estatus: DOWN?
Error Retornado: 1234 not returned by external check
The file PROVA.CMD contanins:
echo off
cd "E:Program FilesServersCheck_Monitoringexternal"
powershell.exe -executionpolicy bypass -noprofile -file prova.ps1
echo %errorlevel%
And the file PROVA.PS1 contains:
exit 1234
Both files are on the EXTERNAL folder. The expected value is 1234.
Francesc
In the second test it returned 1234 so status is OK
Then I modified again the file to return a 1234 and the check worked.
The problem is that the rule works fine in debug mode but not in normal mode.
Please, create 2 files with this contents:
prova.cmd:
echo off
cd "E:Program FilesServersCheck_Monitoringexternal"
powershell.exe -executionpolicy bypass -noprofile -file prova.ps1
echo %errorlevel%
prova.ps1:
exit 1234
Create a EXTERNAL check and try if the check falls but not in debug mode. Check it in normal mode and you'll see as the check falls even if the returned value is 1234.
Thanks,
Francesc
As a service it doesn't run from a specific directory - that is the main difference between running in debug mode and as a service.
Try putting in your prova.cmd the full path to prova.ps1.
It works with the complete path of the POWERSHELL script.
Thanks,
Francesc