{#- ---------------------------------------------------------------------------- Macro for rendering the main menu of the application. Entries in the menu are automatically hidden based on the permissions of the current user. ----------------------------------------------------------------------------- #} {%- macro render_menu_main() -%} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the authentication and anonymous submenus of the application. These menus get special handling. ----------------------------------------------------------------------------- #} {%- macro render_submenu_auth() -%} {%- if current_user.is_authenticated %} {%- else %} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the item action menus. ----------------------------------------------------------------------------- #} {%- macro render_menu_actions(action_menu) %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering the locale switcher widget. ----------------------------------------------------------------------------- #} {%- macro render_locale_switcher() %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macros for rendering various usefull widgets. ----------------------------------------------------------------------------- #} {%- macro render_alert(category, dismissible = True) %} {%- if category == 'error' %} {%- set category = 'danger' %} {% elif category == 'message' %} {%- set category = 'info' %} {%- endif %}
{%- if dismissible %} {%- endif %} {{ get_fa_icon('alert-' + category) }} {{ caller() }}
{%- endmacro %} {%- macro render_pager(endpoint, qparams, ii_low, ii_high, ii_limit) %} {%- set x = qparams.__setitem__('page', (qparams.get('page', 1) - 1)) %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a form widget in default style. ----------------------------------------------------------------------------- #} {%- macro render_form_item_default(form_item, with_errors = True) %}
{{ form_item.label }} {{ form_item(class_='form-control') }} {%- if with_errors %} {%- for err in form_item.errors %} {{ get_fa_icon('form-error') }} {{ err }}{%- if not loop.last %}
{%- endif %} {%- endfor %} {%- endif %}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a form select widget with selectpicker class. ----------------------------------------------------------------------------- #} {%- macro render_form_item_select(form_item, with_errors = True) %}
{{ form_item.label }} {{ form_item(class_='form-control selectpicker',**{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3', 'data-none-selected-text': gettext('Nothing selected') }) }} {%- if with_errors %} {%- for err in form_item.errors %} {{ get_fa_icon('form-error') }} {{ err }}{%- if not loop.last %}
{%- endif %} {%- endfor %} {%- endif %}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a form widget with datetime selection class. ----------------------------------------------------------------------------- #} {%- macro render_form_item_datetime(form_item, ident, with_errors = True) %}
{{ form_item.label }}
{{ form_item(class_='form-control') }} {{ get_fa_icon('calendar') }}
{%- if with_errors %} {%- for err in form_item.errors %} {{ get_fa_icon('form-error') }} {{ err }}{%- if not loop.last %}
{%- endif %} {%- endfor %} {%- endif %}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a static form widget. ----------------------------------------------------------------------------- #} {%- macro render_form_item_static(form_item_label, form_item_value) %}

{{ form_item_value }}

{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a radio button form widget. ----------------------------------------------------------------------------- #} {%- macro render_form_item_radiobutton(form_item, with_errors = True) %}
{{ form_item.label }}
{%- for subfield in form_item %} {{ subfield }} {{ subfield.label }} {%- endfor %}
{%- if with_errors %} {%- for err in form_item.errors %} {{ get_fa_icon('form-error') }} {{ err }}{%- if not loop.last %}
{%- endif %} {%- endfor %} {%- endif %}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering a list of errors associated with given form widget. ----------------------------------------------------------------------------- #} {%- macro form_errors(errors) %} {%- for err in errors %} {{ get_fa_icon('form-error') }} {{ err }}{%- if not loop.last %}
{%- endif %} {%- endfor %} {%- endmacro %} {%- macro form_errors_labeled(item) %} {%- for err in item.errors %}
{{ get_fa_icon('form-error') }} {{ item.label.text }} {{ err }}
{%- endfor %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macro for rendering raw view of item internals. ----------------------------------------------------------------------------- #} {%- macro render_raw_item_view(item) %}

{{ get_fa_icon('debug') }} {{ gettext('Raw item') }}


{{ item | pprint }}
{%- endmacro %} {%- macro render_raw_var(label, var) %}

{{ get_fa_icon('debug') }} {{ gettext('Variable dump:') }} {{ label }}


{%- endmacro %} {#- ---------------------------------------------------------------------------- Macros for rendering NVD3 charts. ----------------------------------------------------------------------------- #} {%- macro render_chart_pie(chidprefix, chstats, chstatkey, chtitle) %} {%- set chid = '' + chidprefix + '_' + chstatkey %} {%- set chdata = chstats[chstatkey] %} {%- set chkeys = chstats['list_' + chstatkey] %}

{{ chtitle }}

{%- for chitemkey in chkeys %} {%- endfor %}
  {{ gettext('Name') }} # %
{{ loop.index }} {{ chitemkey }} {{ babel_format_decimal(chdata.get(chitemkey, 0)) }} {{ babel_format_percent(chdata.get(chitemkey, 0) / chstats.get('sum_' + chstatkey, 1)) }}
  {{ gettext('Sum') }} {{ babel_format_decimal(chstats.get('sum_' + chstatkey, 0)) }} {{ babel_format_percent(1.0) }}

{{ get_fa_icon('sum') }} Sum {{ babel_format_decimal(chstats.get('sum_' + chstatkey, 0)) }} {{ babel_format_percent(1.0) }}
{{ get_fa_icon('cnt') }} Cnt {{ babel_format_decimal(chstats.get('cnt_' + chstatkey, 0)) }} {{ get_fa_icon('na') }}
{{ get_fa_icon('min') }} Min {{ babel_format_decimal(chstats.get('min_' + chstatkey, 0)) }} {{ babel_format_percent(chstats.get('min_' + chstatkey, 0) / chstats.get('sum_' + chstatkey, 1)) }}
{{ get_fa_icon('max') }} Max {{ babel_format_decimal(chstats.get('max_' + chstatkey, 0)) }} {{ babel_format_percent(chstats.get('max_' + chstatkey, 0) / chstats.get('sum_' + chstatkey, 1)) }}
{{ get_fa_icon('avg') }} Avg {{ babel_format_decimal(chstats.get('avg_' + chstatkey, 0)) }} {{ babel_format_percent(chstats.get('avg_' + chstatkey, 0) / chstats.get('sum_' + chstatkey, 1)) }}
{%- endmacro %} {#- ---------------------------------------------------------------------------- Macros for rendering event report related widgets. ----------------------------------------------------------------------------- #} {%- macro render_report_label_type(report, with_label = False) %} {%- if report.type == 'summary' %} {{ get_fa_icon('r-t-summary') }}{% if with_label %} {{ gettext('summary') | upper }}{% endif %} {%- elif report.type == 'extra' %} {{ get_fa_icon('r-t-extra') }}{% if with_label %} {{ gettext('extra') | upper }}{% endif %} {%- endif %} {%- endmacro %} {%- macro render_report_label_severity(report, with_label = False) %} {%- if report.severity == 'low' %} {{ get_fa_icon('r-s-low') }}{% if with_label %} {{ gettext('low') | upper }}{% endif %} {%- elif report.severity == 'medium' %} {{ get_fa_icon('r-s-medium') }}{% if with_label %} {{ gettext('medium') | upper }}{% endif %} {%- elif report.severity == 'high' %} {{ get_fa_icon('r-s-high') }}{% if with_label %} {{ gettext('high') | upper }}{% endif %} {%- elif report.severity == 'critical' %} {{ get_fa_icon('r-s-critical') }}{% if with_label %} {{ gettext('critical') | upper }}{% endif %} {%- endif %} {%- endmacro %} {%- macro render_report_label_weight(report) %} {%- if report.evcount_rep < 10 %} {{ get_fa_icon('weight') }} {{ report.evcount_rep}} {%- elif report.evcount_rep < 100 %} {{ get_fa_icon('weight') }} {{ report.evcount_rep}} {%- elif report.evcount_rep < 1000 %} {{ get_fa_icon('weight') }} {{ report.evcount_rep}} {%- else %} {{ get_fa_icon('weight') }} {{ report.evcount_rep}} {%- endif %} {%- endmacro %} {#- ---------------------------------------------------------------------------- Macros for rendering event related widgets. ----------------------------------------------------------------------------- #} {%- macro render_event_label_severity(event, with_label = False) %} {%- set tmpval = event.get_severity() %} {%- if not tmpval or tmpval == 'unknown' %} {{ get_fa_icon('r-s-unknown') }}{% if with_label %} {{ gettext(tmpval) | upper }}{% endif %} {%- elif tmpval == 'low' %} {{ get_fa_icon('r-s-low') }}{% if with_label %} {{ gettext(tmpval) | upper }}{% endif %} {%- elif tmpval == 'medium' %} {{ get_fa_icon('r-s-medium') }}{% if with_label %} {{ gettext(tmpval) | upper }}{% endif %} {%- elif tmpval == 'high' %} {{ get_fa_icon('r-s-high') }}{% if with_label %} {{ gettext(tmpval) | upper }}{% endif %} {%- elif tmpval == 'critical' %} {{ get_fa_icon('r-s-critical') }}{% if with_label %} {{ gettext(tmpval) | upper }}{% endif %} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_category(itemlist, marklist = None, align_right = False, separate_dropdown = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- undisclosed --')}} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_severity(itemlist, marklist = None, align_right = False, separate_dropdown = False, without_label = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown and not without_label %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- if subitem == 'low' %} {%- set tmpcolor = 'btn-info' %} {%- set tmpicon = 'r-s-low' %} {%- elif subitem == 'medium' %} {%- set tmpcolor = 'btn-primary' %} {%- set tmpicon = 'r-s-medium' %} {%- elif subitem == 'high' %} {%- set tmpcolor = 'btn-warning' %} {%- set tmpicon = 'r-s-high' %} {%- elif subitem == 'critical' %} {%- set tmpcolor = 'btn-danger' %} {%- set tmpicon = 'r-s-critical' %} {%- else %} {%- set tmpcolor = 'btn-default' %} {%- set tmpicon = 'r-s-unknown' %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- undisclosed --')}} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_class(itemlist, marklist = None, align_right = False, separate_dropdown = False, without_label = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown and not without_label %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- undisclosed --')}} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_group(itemlist, marklist = None, align_right = False, separate_dropdown = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- unassigned --')}} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_hostaddr(itemlist, marklist = None, align_right = False, separate_dropdown = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- undisclosed --')}} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_hostport(itemlist, marklist = None, align_right = False, separate_dropdown = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- undisclosed --')}} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_hosttype(itemlist, marklist = None, align_right = False, separate_dropdown = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- undisclosed --')}} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_protocol(itemlist, marklist = None, align_right = False, separate_dropdown = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- undisclosed --')}} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_detector(itemlist, marklist = None, align_right = False, separate_dropdown = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- undisclosed --')}} {%- endif %} {%- endmacro %} {%- macro render_event_search_widget_detectortype(itemlist, marklist = None, align_right = False, separate_dropdown = False) %} {%- if itemlist %} {%- for subitem in itemlist %} {%- if separate_dropdown %} {% if marklist and subitem in marklist %}{{ subitem }}{%- else %}{{ subitem }}{%- endif %} {%- endif %}
{%- endfor %} {%- else %} {{ gettext('-- undisclosed --')}} {%- endif %} {%- endmacro %}