API

class bhr_client.rest.Client(host, session, ident=None, timeout=30)[source]

BHR Client

block(cidr, source, why, duration=300, autoscale=False, skip_whitelist=False, extend=False)[source]

Send a block request to the BHR system

Parameters:
  • cidr – The IP Address or CIDR network to block
  • source – The source for this block. i.e., where the intel came from
  • why – The reason for the block
  • duration – The time to block in seconds, or a string like ‘1d’. Accepted suffixes are y, mo, d, h, m, s.
  • autoscale – Whether or not to auto scale the duration based on server side block history
  • skip_whitelist – Whether or not to bypass the server side whitelist
get_block_queue(timeout=0, added_since=None)[source]
get_expected(source=None)[source]
get_json(url, params=None)[source]
get_list(source=None, since=None)[source]

Return a the current block list as a list of dictionaries

get_unblock_queue()[source]
ident
mblock(block_records)[source]

Send a batch block request. :param block_records: A list of dictionaries whose keys are options to ‘block()’ For example: block_records = [dict(

cidr=ip, duration=30, source=”test”, why=”testing”,

) for ip in ips]

post_json(url, data)[source]
query(cidr)[source]

Return the block history for an address”

Parameters:cidr – The IP Address or CIDR network to look up
set_blocked(records)[source]

Mark a block record as blocked

This is not meant to be called directly

set_unblocked(records)[source]

Mark a block record as unblocked

This is not meant to be called directly

stats()[source]

Return Current block stats

tail(source=None, start=None)[source]
unblock_now(cidr, why)[source]

Send an unblock request to the BHR system

Parameters:
  • cidr – The IP Address or CIDR network to unblock
  • why – The reason for the block being removed
class bhr_client.rest.Delayer(initial=0, lower=1, upper=60, factor=2, sleep=<built-in function sleep>)[source]
reset()[source]
sleep()[source]
sleep_or_reset(had_data)[source]
bhr_client.rest.login(host, token=None, username=None, password=None, ident=None, ssl_no_verify=False, timeout=30)[source]

Create an authenticated client object. To authenticate pass either a token or a username + password.

Parameters:
  • host – the URL to the BHR system
  • token – A django-rest-framework api token
  • username
  • password
  • ident – Ident to use for backend block entry tracking
  • ssl_no_verify – Disable SSL certificate verification
bhr_client.rest.login_from_env()[source]

Create an authenticated client object using environment variables. This simply calls login(). The environment variables looked at are:

  • BHR_HOST - mapped to host
  • BHR_TOKEN - mapped to token
  • BHR_USERNAME - mapped to username
  • BHR_PASSWORD - mapped to password
  • BHR_IDENT - mapped to ident
  • BHR_SSL_NO_VERIFY - mapped to ssl_no_verify