def test_update_endpoint(self):
     """
         Test whether the function returns the right values.
     """
     from flask_monitoringdashboard.database.endpoint import get_endpoint_by_name, update_endpoint
     with session_scope() as db_session:
         current_value = get_endpoint_by_name(db_session, NAME).monitor_level
         new_value = 1 if current_value != 1 else 2
         update_endpoint(db_session, NAME, new_value)
         self.assertEqual(get_endpoint_by_name(db_session, NAME).monitor_level, new_value)
Ejemplo n.º 2
0
def set_endpoint_rule(session, endpoint_name, monitor_level):
    """
    :param session: session for the database
    :param endpoint_name: name of the endpoint
    :param monitor_level: integer, representing the monitoring-level
    """
    update_endpoint(session, endpoint_name, value=monitor_level)

    # Remove wrapper
    original = getattr(config.app.view_functions[endpoint_name], 'original', None)
    if original:
        config.app.view_functions[endpoint_name] = original
    session.commit()

    add_decorator(get_endpoint_by_name(session, endpoint_name))
Ejemplo n.º 3
0
def rules():
    """
    Renders a table with all rules from the user_app. The fmd_dashboard rules are excluded
    In case of the POST request, the data from the form is validated and processed, such that the required rules are
    monitored
    :return:
    """
    if request.method == 'POST':
        with session_scope() as db_session:
            endpoint_name = request.form['name']
            value = int(request.form['value'])
            update_endpoint(db_session, endpoint_name, value=value)

            # Remove wrapper
            original = getattr(user_app.view_functions[endpoint_name], 'original', None)
            if original:
                user_app.view_functions[endpoint_name] = original

        with session_scope() as db_session:
            add_decorator(get_endpoint_by_name(db_session, endpoint_name))

        return 'OK'

    with session_scope() as db_session:
        last_accessed = get_last_requested(db_session)
        all_rules = []
        for rule in get_rules():
            db_rule = get_endpoint_by_name(db_session, rule.endpoint)
            all_rules.append({
                'color': get_color(rule.endpoint),
                'rule': rule.rule,
                'endpoint': rule.endpoint,
                'methods': rule.methods,
                'last_accessed': get_value(last_accessed, rule.endpoint, default=None),
                'form': get_monitor_form(rule.endpoint, db_rule.monitor_level)
            })
    return render_template('fmd_rules.html', rules=all_rules, information=get_rules_info())
Ejemplo n.º 4
0
def test_update_endpoint(session, endpoint):
    update_endpoint(session, endpoint.name, 2)
    assert get_endpoint_by_name(session, endpoint.name).monitor_level == 2