<# Version: 0.2 Date: Sep 17, 2020 Author: ivan.stetka@live.com Summary: This is a Nagios NCPA plugin for check dbClean log file ReDat eXperience -P -logPath # dbClean log file path on ReDat eXperience # [default: 'C:\\appserv\\dbclean\\log\\'] -c -critical # critical threshold (minimum count of deleted records) # [default: 0] -w -warning # warning threshold (minimum count of deleted records) # [default: 3000] # acceptable range 1-100000 On host side copy plugin to folder 'C:\Program Files (x86)\Nagios\NCPA\plugins\' Nagios example: ./check_ncpa.py -H '' -t '' -M 'plugins/check_dbClean_logfile_REX.pl' -a "-P 'C:\appserv\dbclean\log\' -w 3000" edit Nagios cfg: dbClean runs at 5:00, so you need to create or use the timeperiod "24x7_except_00-06" and just check service once a day normal_check_interval 1440 check_command check_ncpa_Ma!'plugins/check_dbClean_logfile_REX.ps1'!"-P 'C:\\appserv\\dbclean\\log\\' -w 1000" #> param ( [parameter(Mandatory = $true)] [Alias("P")] [string] $logPath, [parameter(Mandatory = $true)] [Alias("w")] [int] $warn, [parameter(Mandatory = $false)] [Alias("c")] [float] $crit ) $logPath = invoke-expression $logPath $STATES = @{ OK = 0; WARNING = 1; CRITICAL= 2; UNKNOWN = 3 } if (-not($crit)) {$crit = 0} $count = 0 function perf { Write-Output ("| Deleted=$count;$warn;$crit;") } if ($warn -lt 1 -OR $warn -gt 100000) { Write-Output "Incorrect warning threshold '$warn'." Exit($STATES.UNKNOWN) } if ($warn -lt $crit) { Write-Output "The critical threshold '$crit' cannot be greater than warning threshold '$warn'." Exit($STATES.UNKNOWN) } $actualDate = get-date -UFormat '%Y-%m-%d' $logFile = $logPath + 'dbclean-' + $actualDate + '.log' $additText = "logfile: $logFile" if (Test-Path -Path $logFile -PathType Leaf) { if (Get-Content $logFile | Where-Object {$_ -match $actualDate + ' \d+:\d+:\d+,\d+ +INFO --- \[ +main\] +audit:\d+ +: Deleted records from Catalog and archive: (\d+)'}){ $count = $matches[1] } else { Write-Output "CRITICAL: No match log text (maybe problem with dbClean or Java certificate).`nChecked $additText " Exit($STATES.CRITICAL) } } else { Write-Output "CRITICAL: Log file not found.`nExpected $additText" Exit($STATES.CRITICAL) } if ($count -eq 0) { Write-Output "CRITICAL: $count deleted records (maybe problem with dbClean or Java certificate).`nChecked $additText" perf Exit($STATES.CRITICAL) } elseif ($count -le $crit) { Write-Output "CRITICAL: Only $count deleted records.`nChecked $additText" perf Exit($STATES.CRITICAL) } elseif ($count -le $warn) { Write-Output "WARNING: Only $count deleted records.`nChecked $additText" perf Exit($STATES.WARNING) } else { Write-Output "OK: Today ($actualDate) deleted $count records from Catalog eXperience DB.$additText" perf Exit($STATES.OK) } Write-Output "CRITICAL: unexpected plugin error." Exit($STATES.CRITICAL)