I am having an issue where a Sensu check I am using does not work when it runs using the sensu-client, but if I run the same command that the check issues, I get good results with no errors. I'm attaching screenshots of Sensu running the command and me running the command to show that the command itself works when it is manually ran.
This is what happens when Sensu runs the command.
Here is what happens when I run the same command with PowerShell
Here is the PowerShell script that the Sensu check is issuing:
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[int]$WARNING,
[Parameter(Mandatory=$True,Position=2)]
[int]$CRITICAL
)
$ThisProcess = Get-Process -Id $pid
$ThisProcess.PriorityClass = "BelowNormal"
$Counter = ((Get-Counter '\SMTP Server(_TOTAL)\Cat: Categorizations failed (DS logon failure)').CounterSamples)
$Path = ($Counter.Path).Trim("\\") -replace " ","_" -replace "\\","." -replace "[\{\}]","" -replace "[\[\]]",""
$Value = [System.Math]::Truncate($Counter.CookedValue)
$Time = [int][double]::Parse((Get-Date -UFormat %s))
If ($Value -ge $CRITICAL) {
Write-Host "CatCategorizationsFailedDSLogonFailure CRITICAL: Value is at $Value"
Exit 2
}
Elseif ($Value -ge $WARNING) {
Write-Host "CatCategorizationsFailedDSLogonFailure WARNING: Value is at $Value"
Exit 1
}
Else {
Write-Host "CatCategorizationsFailedDSLogonFailure OK: Value is at $Value"
Exit 0
}
Would anybody here know why the command works when run manually, but fails when Sensu runs it?