Выполните другой сценарий powershell с аргументами для Icinga2 Monitoring. - PullRequest
0 голосов
/ 24 июня 2019

У меня есть скрипт powershell, как показано ниже. Если я бегу, как показано ниже, это работает test1.ps1 check_host 10.0.6.104 check_port 1433

param (
           $check_host=$args[0],
           $check_port=$args[1]
)

#$check_host="10.0.6.104"
#$check_port="1433"

# Icinga Exit Codes
#0 = OK
#1 = Warning
#2 = Critical
#3 = Unknown

$t = New-Object Net.Sockets.TcpClient

$t.Connect($check_host,$check_port)
    if($t.Connected)
    {
        "Connection to $check_host via $check_port is OK"
        $returncode=0
        $t.Close()
    }
    else
    {

        "Cannot connect to $check_host via $check_port !"
        $returncode=2
    }

exit ($returncode)

, но запуск для формата icinga не работал

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -command "&'C:\Program Files\ICINGA2\sbin\test1.ps1 check_host 10.0.6.104 check_port 1433'" ;exit $LastExitCode

1 Ответ

0 голосов
/ 24 июня 2019

Содержание вашего скрипта не имеет значения для этого вопроса;Вопрос в том, как выполнить скрипт powershell с аргументами.Вы можете сделать это следующим образом:

powershell -File "%ProgramFiles%\ICINGA2\sbin\test1.ps1" -check_host 10.0.6.104 -check_port 1433

Документация для powershell.exe охватывает этот случай:

powershell -?

-File
    Runs the specified script in the local scope ("dot-sourced"), so that the
    functions and variables that the script creates are available in the
    current session. Enter the script file path and any parameters.
    File must be the last parameter in the command, because all characters
    typed after the File parameter name are interpreted
    as the script file path followed by the script parameters.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...