Hi All,
I have a custom powershell check which is set to scan the event viewer logs for particular entries, module is below;
Param(
[Int32]$periodcount=4,
[Int32]$hours=4,
[string]$source=“MSSQL*”,
[string]$logname=“application”,
[string]$entity=“Information”,
[string]$message=“The log for database”
)$ts = New-TimeSpan -hours $hours
$after=(get-date) - $ts
$logentries=Get-EventLog -LogName “$logname” -EntryType “$entity” -Source “$source” -After “$after” -Message “$message”
$count=($logentries | measure).Countif ( $count -gt $periodcount ) {
write-host “FAIL | Check Event Viewer | logentries=$count”
($logentries | % { $_.Message }) | write-host
exit 2
} else {
write-host “OK | logentries=$count”
exit 0
}
Here is my service;
apply Service “DatabaseLog” {
import “dba-service”
display_name = “Database log not available”
command_endpoint = host.vars.client_endpoint
check_command = “database-log-missing”
vars.notification = {
dba.pagerduty = false
dba.mail = false
}
assign where host.vars.lgs
}
And the command;
object CheckCommand “database-log-missing” {
import “plugin-check-command”
command = [ “powershell.exe” ]
arguments = {
“-command” = {
value = “& ‘C:\Program Files\ICINGA2\sbin\modules\database_not_available.ps1’”
order = -1
}
“;exit” = {
value = “$LastExitCode$”
}
}
}
The “LastExitCode” part of the command is something I recently added in an attempt to resolve this issue, but the same problem occurs regardless of its presence.
Now what I’m seeing is the module will exit with the correct code, either 0 or 2, but Icinga will see exit code other than 0 as a warning state. What can I do to get Icinga exit as critical?