Trigger Autoban to process a single watchdog entry?

Created on 16 March 2025, 23 days ago

Problem/Motivation

Currently, Autoban reads the latest dblog entries during cron and executes the rules. Is there a way, when a specific request is written to dblog, to trigger it to run on that request?

I'm not talking about "Forced mode" (if that still even exists). I just want to be able to run the rules against one request (dblog / watchdog entry).

Steps to reproduce

I can use hook_watchdog to identify a specific dblog entry being written. Is there a Autoban method I can send that dblog info to in order to have autoban execute on it?

Proposed resolution

I know I could probably just trigger Autoban cron to execute

    // Load the Autoban service and trigger rule processing.
    $autoban = \Drupal::service('autoban');
    $autoban->cron(); // This runs all Autoban rules; adjust if you need specificity.

But is there a way to trigger Autoban to process just one dblog entry?

πŸ’¬ Support request
Status

Active

Version

1.10

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States somebodysysop

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @somebodysysop
  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine

    @somebodysysop,
    try

    $controller = \Drupal::service('autoban');
    $banned_ip = $controller->getBannedIp($rule);
    $banned = $controller->banIpList($banned_ip, $rule);
    

    You need to create an Autoban rule before and use the rule ID ($rule).
    $banned is the count of the banned IP from the

    $banned_ip list. 
    
Production build 0.71.5 2024