Macros Plugin Environment

General List

All available variables and filters within the macros plugin:

Variable Type Content
extra dict doc [dict], hub [dict], crowdsec [dict], cli [dict], config [dict], bouncers [dict], plugins [dict], metabase [dict], wizard [dict], ref [dict], event [dict], expr [dict], filter [dict], onsuccess [dict], statics [dict], parsers [dict], scenarios [dict], collections [dict], timeMachine [dict], overflow [dict], whitelists [dict], signal [dict], stage [dict], leakspeed [dict], capacity [dict], duration [dict], prometheus [dict], api [dict]
config dict cli_dir = '/etc/crowdsec/cscli/', crowdsec_dir = '/etc/crowdsec/config/', acquis_path = '/etc/crowdsec/config/acquis.yaml'
environment dict system = 'Linux', system_version = '4.14.193-113.317.amzn1.x86_64', python_version = '3.7.4', mkdocs_version = '1.1', macros_plugin_version = '0.4.6', jinja2_version = '2.11.1'
git dict short_commit = '748d30e', commit = '748d30e889618a7d05d4919acdc71110029b3faf', author = 'Jesse Donat', tag = 'v0.3.5', date = '2020-10-20 01:46:32 -0500', message = 'Update to improve installation readability (#311)', raw = 'commit 748d30e889618a7d05d4919acdc71110029b3faf\nAuthor: Jesse Donat \nDate: Tue Oct 20 01:46:32 2020 -0500\n\n Update to improve installation readability (#311)'
context function (obj, e)

Default mkdocs_macro List the defined variables

macros_info function ()

Test/debug function: list useful documentation on the mkdocs_macro environment.

now function ()

Get the current time (returns a datetime object). Used alone, it provides a timestamp. To get the year use now().year, for the month number now().month, etc.

fix_url function (url, r)

If url is relative, fix so that it points to website's root. This is necessary because relative links in markdown must be adapted in html ('img/foo.png' => '../img/img.png').

doc dict new_issue = '[new documentation issue](', discourse = '[CrowdSecurity discourse](', community = '[community]('
hub dict name = 'Crowdsec Hub', htmlname = '[Crowdsec Hub](', url = '', plugins_url = '', scenarios_url = '', parsers_url = '', collections_url = ''
crowdsec dict name = 'Crowdsec', Name = 'Crowdsec', bin = 'crowdsec-agent', path = '/usr/bin/crowdsec-agent', url = '', bugreport = '', main_log = '/var/log/crowdsec.log', download_url = ''
cli dict name = 'cscli', Name = 'Cscli', bin = 'cscli', path = '/usr/bin/cscli', main_doc = '/cscli/cscli/', url = '', bugreport = '', api_doc = '/cscli/cscli_api/', ban_doc = '/cscli/cscli_ban/', metrics_doc = '/cscli/cscli_metrics/', remove_doc = '/cscli/cscli_remove/', install_doc = '/cscli/cscli_install/', list_doc = '/cscli/cscli_list/', update_doc = '/cscli/cscli_update/', upgrade_doc = '/cscli/cscli_upgrade/', backup_doc = '/cscli/cscli_backup/', simulation_doc = '/cscli/cscli_simulation/'
bouncers dict name = 'bouncers', Name = 'Bouncers', url = '', htmlname = '[bouncers](/bouncers/)', Htmlname = '[Bouncers](/bouncers/)'
plugins dict name = 'backend plugins', configpath = '/etc/crowdsec/plugins/backend/', binpath = '/usr/local/lib/crowdsec/plugins/'
metabase dict name = 'metabase', url = ''
wizard dict name = 'wizard', url = '', bin = './', bugreport = ''
ref dict parser = '[parser](/references/parsers/)', Parser = '[Parser](/references/parsers/)', scenario = '[scenarios](/references/scenarios/)', Scenario = '[Scenarios](/references/scenarios/)', acquis = '[acquisition](/guide/crowdsec/acquisition/)', Acquis = '[Acquisition](/guide/crowdsec/acquisition/)', output = '[output](/references/output/)', Output = '[Output](/references/output/)'
event dict name = 'event', Name = 'Event', htmlname = '[event](/getting_started/concepts/#event)', Htmlname = '[Event](/getting_started/concepts/#event)'
expr dict name = 'expr', Name = 'Expr', htmlname = '[expr](/write_configurations/expressions/)', Htmlname = '[Expr](/write_configurations/expressions/)'
filter dict name = 'filter', Name = 'Filter', htmlname = '[filter](/references/parsers/#filter)', Htmlname = '[Filter](/references/parsers/#filter)'
onsuccess dict name = 'onsuccess', Name = 'Onsuccess', htmlname = '[onsuccess](/references/parsers/#onsuccess)', Htmlname = '[Onsuccess](/references/parsers/#onsuccess)'
statics dict name = 'statics', Name = 'Statics', htmlname = '[statics](/references/parsers/#statics)', Htmlname = '[Statics](/references/parsers/#statics)'
parsers dict name = 'parsers', Name = 'Parsers', htmlname = '[parsers](/getting_started/concepts/#parser)', Htmlname = '[Parsers](/getting_started/concepts/#parser)'
scenarios dict name = 'scenarios', Name = 'Scenarios', htmlname = '[scenarios](/getting_started/concepts/#scenario)', Htmlname = '[Scenarios](/getting_started/concepts/#scenario)'
collections dict name = 'collections', Name = 'Collections', htmlname = '[collections](/getting_started/concepts/#collections)', Htmlname = '[Collections](/getting_started/concepts/#collections)'
timeMachine dict name = 'timeMachine', Name = 'TimeMachine', htmlname = '[timeMachine](/getting_started/concepts/#timemachine)', Htmlname = '[TimeMachine](/getting_started/concepts/#timemachine)'
overflow dict name = 'overflow', Name = 'Overflow', htmlname = '[overflow](/getting_started/concepts/#overflow-or-signaloccurence)', Htmlname = '[Overflow](/getting_started/concepts/#overflow-or-signaloccurence)'
whitelists dict name = 'whitelists', Name = 'Whitelists', htmlname = '[whitelists](/write_configurations/whitelist/)', Htmlname = '[Whitelists](/write_configurations/whitelist/)'
signal dict name = 'alert', Name = 'Alert', htmlname = '[alert](/getting_started/concepts/#overflow-or-signaloccurence)', Htmlname = '[Alert](/getting_started/concepts/#overflow-or-signaloccurence)'
stage dict name = 'stage', Name = 'Stage', htmlname = '[stage](/getting_started/concepts/#stages)', Htmlname = '[Stage](/getting_started/concepts/#stages)'
leakspeed dict name = 'leakspeed', Name = 'Leakspeed', htmlname = '[leakspeed](/references/scenarios/#leakspeed)', Htmlname = '[Leakspeed](/references/scenarios/#leakspeed)'
capacity dict name = 'capacity', Name = 'Capacity', htmlname = '[capacity](/references/scenarios/#capacity)', Htmlname = '[Capacity](/references/scenarios/#capacity)'
duration dict name = 'duration', Name = 'Duration', htmlname = '[duration](/references/scenarios/#duration)', Htmlname = '[Duration](/references/scenarios/#duration)'
prometheus dict name = 'prometheus', htmlname = '[prometheus]('
api dict name = 'API', htmlname = '[API](TBD)', topX [dict]
filters dict pretty [function]
filters_builtin dict abs [builtin_function_or_method], attr [function], batch [function], capitalize [function], center [function], count [builtin_function_or_method], d [function], default [function], dictsort [function], e [builtin_function_or_method], escape [builtin_function_or_method], filesizeformat [function], first [function], float [function], forceescape [function], format [function], groupby [function], indent [function], int [function], join [function], last [function], length [builtin_function_or_method], list [function], lower [function], map [function], min [function], max [function], pprint [function], random [function], reject [function], rejectattr [function], replace [function], reverse [function], round [function], safe [function], select [function], selectattr [function], slice [function], sort [function], string [builtin_function_or_method], striptags [function], sum [function], title [function], trim [function], truncate [function], unique [function], upper [function], urlencode [function], urlize [function], wordcount [function], wordwrap [function], xmlattr [function], tojson [function]
navigation Navigation Page(title='Home', url='.')
Section(title='Getting Started')
Page(title='Installation', url='getting_started/installation/')
Page(title='Crowdsec Tour', url='getting_started/crowdsec-tour/')
Page(title='Concepts & Glossary', url='getting_started/concepts/')
Page(title='FAQ', url='getting_started/FAQ/')
Page(title='Overview', url='guide/crowdsec/overview/')
Page(title='Acquisition', url='guide/crowdsec/acquisition/')
Page(title='Parsers', url='guide/crowdsec/parsers/')
Page(title='Enrichers', url='guide/crowdsec/enrichers/')
Page(title='Scenarios', url='guide/crowdsec/scenarios/')
Page(title='Cscli', url='guide/cscli/')
Page(title='Simulation Mode', url='guide/crowdsec/simulation/')
Section(title='Cheat Sheets')
Page(title='Ban Management', url='cheat_sheets/ban-mgmt/')
Page(title='Configuration Management', url='cheat_sheets/config-mgmt/')
Link(title='Hub's taxonomy', url='')
Page(title='Debugging Parsers & Scenarios', url='cheat_sheets/debugging_configs/')
Page(title='Overview', url='observability/overview/')
Page(title='Logs', url='observability/logs/')
Page(title='Prometheus', url='observability/prometheus/')
Page(title='Command line', url='observability/command_line/')
Page(title='Dashboard', url='observability/dashboard/')
Page(title='Parsers format', url='references/parsers/')
Page(title='Scenarios format', url='references/scenarios/')
Page(title='Outputs format', url='references/output/')
Section(title='Write Configurations')
Page(title='Requirements', url='write_configurations/requirements/')
Page(title='Acquisition', url='write_configurations/acquisition/')
Page(title='Parsers', url='write_configurations/parsers/')
Page(title='Scenarios', url='write_configurations/scenarios/')
Page(title='Whitelists', url='write_configurations/whitelist/')
Page(title='Expressions', url='write_configurations/expressions/')
Page(title='Overview', url='bouncers/')
Link(title='Installation', url='')
Link(title='Configuration', url='')
Link(title='Installation', url='')
Link(title='Configuration', url='')
Link(title='Installation', url='')
Link(title='Configuration', url='')
Link(title='Installation', url='')
Link(title='Configuration', url='')
Link(title='Installation', url='')
Link(title='Configuration', url='')
Link(title='General', url='contributing/')
Page(title='Writing Output Plugins', url='references/plugins_api/')
Section(title='Cscli commands')
Page(title='API', url='cscli/cscli_api/')
Page(title='Backup', url='cscli/cscli_backup/')
Page(title='Bans', url='cscli/cscli_ban/')
Page(title='Metrics', url='cscli/cscli_metrics/')
Page(title='Update', url='cscli/cscli_update/')
Page(title='Install configurations', url='cscli/cscli_install/')
Page(title='Remove configurations', url='cscli/cscli_remove/')
Page(title='Upgrade configurations', url='cscli/cscli_upgrade/')
Page(title='List configurations', url='cscli/cscli_list/')
Page(title='Inspect configurations', url='cscli/cscli_inspect/')
Page(title='Manage simulation', url='cscli/cscli_simulation/')
Page(title='Dashboard', url='cscli/cscli_dashboard/')
Page(title='About', url='about/')
page Page Page(title='About', url='about/')

Config Information

Standard MkDocs configuration information. Do not try to modify.

e.g. {{ config.docs_dir }}

See also the MkDocs documentation on the config object.

Variable Type Content
cli_dir str '/etc/crowdsec/cscli/'
crowdsec_dir str '/etc/crowdsec/config/'
acquis_path str '/etc/crowdsec/config/acquis.yaml'

Page Attributes

Provided by MkDocs. These attributes change for every page (the attributes shown are for this page).

e.g. {{ page.title }}

See also the MkDocs documentation on the page object.

Variable Type Content
file File page [Page], src_path = '', abs_src_path = '/codebuild/output/src382546968/src/crowdsec/docs/', name = 'about', dest_path = 'about/index.html', abs_dest_path = '/codebuild/output/src382546968/src/crowdsec/site/about/index.html', url = 'about/'
title str 'About'
parent NoneType None
children NoneType None
previous_page Page Page(title='Dashboard', url='cscli/cscli_dashboard/')
next_page NoneType None
_Page__active bool False
is_section bool False
is_page bool True
is_link bool False
update_date str '2020-10-20'
canonical_url NoneType None
abs_url NoneType None
edit_url str ''
markdown str '# Crowdsec\n\n{{ macros_info() }}\n'
content NoneType None
toc list []
meta dict

To have all titles of all pages, use:

{% for page in navigation.pages %}
- {{ page.title }}
{% endfor% }

Plugin Filters

These filters are provided as a standard by the macros plugin.

Variable Type Content
pretty function (var_list, rows, header)

Default mkdocs_macro Prettify a dictionary or object (used for environment documentation, or debugging)

Builtin Jinja2 Filters

These filters are provided by Jinja2 as a standard.

See also the Jinja2 documentation on builtin filters).

Variable Type Content
abs builtin_function_or_method

Return the absolute value of the argument.

attr function (environment, obj, name, value)

Get an attribute of an object. foo|attr("bar") works like just that always an attribute is returned and items are not looked up.

batch function (value, linecount, fill_with, tmp, item)

A filter that batches items. It works pretty much like slice just the other way round. It returns a list of lists with the given number of items. If you provide a second parameter this is used to fill up missing items. See this example.

capitalize function (s)

Capitalize a value. The first character will be uppercase, all others lowercase.

center function (value, width)

Centers the value in a field of a given width.

count builtin_function_or_method

Return the number of items in a container.

d function (value, default_value, boolean)

If the value is undefined it will return the passed default value, otherwise the value of the variable.

default function (value, default_value, boolean)

If the value is undefined it will return the passed default value, otherwise the value of the variable.

dictsort function (value, case_sensitive, by, reverse, sort_func)

Sort a dict and yield (key, value) pairs. Because python dicts are unsorted you may want to use this function to order them by either key or value.

e builtin_function_or_method

escape(s) -> markup

escape builtin_function_or_method

escape(s) -> markup

filesizeformat function (value, binary, bytes, base, prefixes, i, prefix, unit)

Format the value like a 'human-readable' file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega, Giga, etc.), if the second parameter is set to True the binary prefixes are used (Mebi, Gibi).

first function (environment, seq)

Return the first item of a sequence.

float function (value, default)

Convert the value into a floating point number. If the conversion doesn't work it will return 0.0. You can override this default using the first parameter.

forceescape function (value)

Enforce HTML escaping. This will probably double escape variables.

format function (value, args, kwargs)

Apply the given values to a printf-style_ format string, like string % values.

groupby function (environment, value, attribute, expr)

Group a sequence of objects by an attribute using Python's :func:itertools.groupby. The attribute can use dot notation for nested access, like "". Unlike Python's groupby, the values are sorted first so only one group is returned for each unique value.

indent function (s, width, first, blank, indentfirst, newline, rv, lines)

Return a copy of the string with each line indented by 4 spaces. The first line and blank lines are not indented by default.

int function (value, default, base)

Convert the value into an integer. If the conversion doesn't work it will return 0. You can override this default using the first parameter. You can also override the default base (10) in the second parameter, which handles input with prefixes such as 0b, 0o and 0x for bases 2, 8 and 16 respectively. The base is ignored for decimal numbers and non-string values.

join function (eval_ctx, value, d, attribute, do_escape, idx, item)

Return a string which is the concatenation of the strings in the sequence. The separator between elements is an empty string per default, you can define it with the optional parameter.

last function (environment, seq)

Return the last item of a sequence.

length builtin_function_or_method

Return the number of items in a container.

list function (value)

Convert the value into a list. If it was a string the returned list will be a list of characters.

lower function (s)

Convert a value to lowercase.

map function (args, kwargs, seq, func, item)

Applies a filter on a sequence of objects or looks up an attribute. This is useful when dealing with lists of objects but you are really only interested in a certain value of it.

min function (environment, value, case_sensitive, attribute)

Return the smallest item from the sequence.

max function (environment, value, case_sensitive, attribute)

Return the largest item from the sequence.

pprint function (value, verbose)

Pretty print a variable. Useful for debugging.

random function (context, seq)

Return a random item from the sequence.

reject function (args, kwargs)

Filters a sequence of objects by applying a test to each object, and rejecting the objects with the test succeeding.

rejectattr function (args, kwargs)

Filters a sequence of objects by applying a test to the specified attribute of each object, and rejecting the objects with the test succeeding.

replace function (eval_ctx, s, old, new, count)

Return a copy of the value with all occurrences of a substring replaced with a new one. The first argument is the substring that should be replaced, the second is the replacement string. If the optional third argument count is given, only the first count occurrences are replaced.

reverse function (value, rv)

Reverse the object or return an iterator that iterates over it the other way round.

round function (value, precision, method, func)

Round the number to a given precision. The first parameter specifies the precision (default is 0), the second the rounding method.

safe function (value)

Mark the value as safe which means that in an environment with automatic escaping enabled this variable will not be escaped.

select function (args, kwargs)

Filters a sequence of objects by applying a test to each object, and only selecting the objects with the test succeeding.

selectattr function (args, kwargs)

Filters a sequence of objects by applying a test to the specified attribute of each object, and only selecting the objects with the test succeeding.

slice function (value, slices, fill_with, seq, length, items_per_slice, slices_with_extra, offset, slice_number, start, end, tmp)

Slice an iterator and return a list of lists containing those items. Useful if you want to create a div containing three ul tags that represent columns.

sort function (environment, value, reverse, case_sensitive, attribute, key_func)

Sort an iterable using Python's :func:sorted.

string builtin_function_or_method

soft_unicode(object) -> string

striptags function (value)

Strip SGML/XML tags and replace adjacent whitespace by one space.

sum function (environment, iterable, attribute, start)

Returns the sum of a sequence of numbers plus the value of parameter 'start' (which defaults to 0). When the sequence is empty it returns start.

title function (s)

Return a titlecased version of the value. I.e. words will start with uppercase letters, all remaining characters are lowercase.

trim function (value, chars)

Strip leading and trailing characters, by default whitespace.

truncate function (env, s, length, killwords, end, leeway, result)

Return a truncated copy of the string. The length is specified with the first parameter which defaults to 255. If the second parameter is true the filter will cut the text at length. Otherwise it will discard the last word. If the text was in fact truncated it will append an ellipsis sign ("..."). If you want a different ellipsis sign than "..." you can specify it using the third parameter. Strings that only exceed the length by the tolerance margin given in the fourth parameter will not be truncated.

unique function (environment, value, case_sensitive, attribute, getter, seen, item, key)

Returns a list of unique items from the given iterable.

upper function (s)

Convert a value to uppercase.

urlencode function (value, items)

Quote data for use in a URL path or query using UTF-8.

urlize function (eval_ctx, value, trim_url_limit, nofollow, target, rel, policies, rv)

Converts URLs in plain text into clickable links.

wordcount function (s)

Count the words in that string.

wordwrap function (environment, s, width, break_long_words, wrapstring, break_on_hyphens)

Wrap a string to the given width. Existing newlines are treated as paragraphs to be wrapped separately.

xmlattr function (_eval_ctx, d, autospace, rv)

Create an SGML/XML attribute string based on the items in a dict. All values that are neither none nor undefined are automatically escaped.

tojson function (eval_ctx, value, indent, policies, dumper, options)

Dumps a structure to JSON so that it's safe to use in <script> tags. It accepts the same arguments and returns a JSON string. Note that this is available in templates through the |tojson filter which will also mark the result as safe. Due to how this function escapes certain characters this is safe even if used outside of <script> tags.