微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

nrpe的powershell参数

如何解决nrpe的powershell参数

我想用powershell脚本传递两个论点。

这是常规检查

test = cmd / c回显脚本\ test.ps1;退出($ lastexitcode)| powershell.exe-命令-

这是我想要的想法。设置警告和严重。

test = cmd / c echo scripts \ test.ps1 -w 10 -c 50 ;退出($ lastexitcode)| powershell.exe-命令-

如果警告设置为超过10,则它将返回出口1

如果临界值设置为50以上,它将返回出口2

不确定如何在脚本中执行此操作。

这是现在的样子。

$condition = (Get-Service | Where-Object Status -eq "Running").Count

if ($argument warn) {
    Write-Output "Warning:" $condition
    exit 1 
}

ElseIf ($argument critical) {
        Write-Output "Critical:" $condition
        exit 2
}

解决方法

您可以使用

Object.entries(obj).forEach(([key,value])=> ...);

并在您的PowerShell脚本顶部,插入以下内容:

powershell -file "(Path to your PowerShell Script).ps1 -w10 -c50"

,然后在脚本中使用变量。

了解有关命名参数的更多信息,因此您不必按参数的使用顺序输入参数,并且在想要进行更改时,脚本中断的可能性就较小。

,

尽管我不确定这是否是您的意思,但是您可以使用 param()块启动脚本,以便它接受类似

的参数
param (
    [int]$WarningLevel = 0,[int]$CriticalLevel = 0
)

$condition = (Get-Service | Where-Object {$_.Status -eq "Running"}).Count

if ($CriticalLevel -gt 0 -and $condition -gt $CriticalLevel) {
    Write-Output "Critical: Way too many proc's: $condition"
    Exit 2
}
elseif ($WarningLevel -gt 0 -and  $condition -gt $WarningLevel) {
    Write-Output "Warning: proc's filling up: $condition"
    Exit 1 
}
Write-Output "All OK"
Exit 0

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。