Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-IcingaCheckScheduledTask NextRunTime Warning and Critical Threshold Bug #380

Open
audiocoach opened this issue Jan 12, 2024 · 3 comments
Assignees
Labels
bug Something isn't working Investigation The team is looking into the cause of the issue

Comments

@audiocoach
Copy link

audiocoach commented Jan 12, 2024

Hello,

I think I have found a bug in the Invoke-IcingaCheckScheduledTask. Let,s say you have a scheduled task which should run every 24 hours and want a warning if the next runtime for whatever reason is 48 hours or more in the future and a critical if the next run time is 72 hours or more in the future. But when you take these values for the "WarningNextRunTime" (=48 hours or 2 days) and "CriticalNextRunTime" (=72 hours or 3 days) you always get critical because the scheduled next run time is always lower than the current time + 3 days.
Even if you take lower threshold values there will be a point in time where you get a critical. Let's say the scheduled task runs every 24 hours at 06:00 and you take 1 hour as critical next runtime threshold. At 05:01 the check will return a critical because 06:00 is lower that 05:01 (current time) + 1 hour (critical next runtime threshold).

I think it can only work the other way around and you should get a warning if the next runtime is higher than the current time + the warning threshold value and a critical if the next runtime is higher than the current time + the critical threshold value.

Maybe it is easier to understand with some screenshots:

image

image

My environment:
Icinga 2.14.1
Icinga Web 2.12.1
Icinga Director 1.11
Icinga for Windows 1.11.1

@audiocoach
Copy link
Author

What I have found out so far is that this issue has someting to do with not documented "WarnDateTime" and "CritDateTime" thresholds which were introduced with this Feature: Icinga/icinga-powershell-framework#303. So it probably should be fixed in the framework and not in the plugin. Should I open a new issue in the powershell framework repository?

@audiocoach
Copy link
Author

audiocoach commented Mar 19, 2024

I think I found a solution for this bug. You have to modify the Compare-IcingaPluginThresholds.psm1 at line 204 from the powershell framework (located at C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-framework\lib\icinga\plugin) as follows:

            if (([string]::IsNullOrEmpty($ThresholdValue) -eq $FALSE) -And (($TimeThreshold) -le '0') -And ($DateTimeValue -eq 0 -Or $DateTimeValue -lt $CurrentDate)) {

an add the following at line 234:

            if (([string]::IsNullOrEmpty($ThresholdValue) -eq $FALSE) -And (($TimeThreshold) -gt '0') -And ($DateTimeValue -gt $CurrentDate)) {
                $IcingaThresholds.InRange = $FALSE;
                $IcingaThresholds.Message = 'is greater than';
                $IcingaThresholds.Range   = [string]::Format(
                    '{0} ({1}{2})',
                    ((Get-Date).ToString('yyyy\/MM\/dd HH:mm:ss')),
                    ( $( if ($TimeThreshold -gt 0) { '+'; } else { ''; } )),
                    $Threshold
                );
            }

With that if you enter postive values for the "WarningNextRunTime" and "CriticalNextRunTime" thresholds (e.g. 1d or 1h) it checks if the value (= Next Run Time) is greater than the current date + threshold and if so throws a warning or critical.

@LordHepipud LordHepipud self-assigned this Aug 14, 2024
@LordHepipud LordHepipud added bug Something isn't working Investigation The team is looking into the cause of the issue labels Aug 14, 2024
@LordHepipud LordHepipud added this to the v1.13.0 milestone Aug 14, 2024
@LordHepipud
Copy link
Collaborator

This should be fixed with v1.13.0 Beta-1 - could you please test this? The DateTime Range should now support the same plugin threshold guidelines as the regular ones, which means you should be able to do something like this:

-WarningNextRunTime '-2d:' -CriticalNextRunTime '-3d:'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Investigation The team is looking into the cause of the issue
Projects
None yet
Development

No branches or pull requests

2 participants