# POST /security/jails/test

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the security group.

Test an unsaved ban rule pattern against a log file

- Who may call it: administrator
- Token scope, any of: security, all
- Answers: 200 OK

Supply the absolute log file path in log and a single-line regular expression of 1 to 500 printable ASCII characters in pattern, with <HOST> where the IP address appears. Path components can contain letters, digits, dots, hyphens, and underscores. The API returns 400 for an invalid path, including a .. component, or an invalid pattern.

UrbeStack runs fail2ban-regex on up to 1,000 of the most recent lines. The response includes the total, matched, and missed line counts and up to three matching lines. The test has a timeout of 330 seconds.

## As a command

- [urbestack-jail-test](https://urbestack.com/docs/commands/urbestack-jail-test.md): Tests a ban rule or a regular expression against up to 1,000 of the most recent lines from a log file or systemd journal.

## Request body

JSON, the type [JailTest](https://urbestack.com/docs/api/types/JailTest.md).

- `log` (string, up to 255 characters, required)
- `pattern` (string, up to 500 characters, required)

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/security/jails/test" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "log": "",
    "pattern": "text"
  }'
```

Response, 200 OK:

```
{
  "examples": [
    "text"
  ],
  "filter": "text",
  "lines": 1,
  "log": "",
  "matched": 1,
  "missed": 1
}
```

## Errors

- 400: '<n>' is a name fail2ban keeps for itself
- 400: <what> is a number of seconds, or with a unit: 10m, 1h, 2d, 1w
- 400: <what> must be between 
- 400: A log is an absolute path of letters, digits, dots, dashes and underscores
- 400: A log path may not contain ..
- 400: A pattern is 1 to 500 printable characters on one line
- 400: A pattern needs <HOST> where the address is
- 400: A rule name is 1 to 32 lowercase letters, digits and dashes
- 400: A scope is all, mail or web
- 400: Give a rule name, or a log and a pattern
- 400: The pattern is not a regular expression: 
- 400: Tries must be a number from 1 to 1000
- 400: fail2ban-regex could not run the test: <why>
- 401: Authentication required
- 404: <source> does not exist
