Register Message
- do_action(string $action, string $slug, array $args) void
- Parameters:
$action (
string) – Must bewp_fail2ban_register_message.$slug (
string) – The plugin slug used in Register Plugin.$args['slug'] (
string) – The message slug.$args['fail'] (
string) – Recommended action.$args['priority'] (
int) –syslog priority to use. Only the following priorities are supported:
LOG_CRIT
LOG_ERR
LOG_WARNING
LOG_NOTICE
LOG_INFO
LOG_DEBUG
$args['event_class'] (
string) –Class of Event. This is one of:
- Auth
Authentication-related Events.
- Block
Blocking Events.
- Comment
Comment-related Events.
- XMLRPC
XML-RPC-related Events.
- Password
Password-related Events.
- REST
REST API-related Events.
- Spam
Spam-related Events.
$args['event_id'] (
int) – Event ID - 16 bits you may do with as you please.$args['message'] (
string) – Message with substitutions. Note that “ from <IP>” is appended.$args['vars'] (
string[]) –An array of substitutions mapped to regular expressions.
When logging a message the substitutions are checked and substituted if present. The regex will be used to generate a matching rule for fail2ban.
- Throws:
InvalidArgumentException– Missing entry or invalid type. Themessagewill give details.UnexpectedValueException– Invalid value. Themessagewill say which.
Example
1$args = [
2 'slug' => 'my-plugin-msg-slug-1',
3 'fail' => 'hard',
4 'priority' => LOG_NOTICE,
5 'event_class' => 'Password',
6 'event_id' => 0x001F,
7 'message' => 'Message with ___VAR1___ and ___VAR2___',
8 'vars' => [
9 'VAR1' => '\d+',
10 'VAR2' => '*.'
11 ]
12];
13try {
14 do_action('wp_fail2ban_register_message', 'my-plugin-slug', $args);
15} catch(\InvalidArgumentException $e) {
16 // Missing entry or invalid type
17} catch(\UnexpectedValueException $e) {
18 // Invalid value
19}