示例#1
0
def get_probe_edit_form(probe_class, resource_identifier=None):
    """get the form to edit a Probe"""

    probe_obj = Factory.create_obj(probe_class)
    if resource_identifier:
        resource = views.get_resource_by_id(resource_identifier)
        if resource:
            probe_obj.expand_params(resource)

    probe_info = probe_obj.get_plugin_vars()
    probe_vars = ProbeVars(None, probe_class,
                           probe_obj.get_default_parameter_values())

    # Get only the default Checks for this Probe class
    checks_avail = probe_obj.get_checks_info_defaults()
    checks_avail = probe_obj.expand_check_vars(checks_avail)

    for check_class in checks_avail:
        check_obj = Factory.create_obj(check_class)
        check_params = check_obj.get_default_parameter_values()
        probe_check_param_defs = \
            probe_info['CHECKS_AVAIL'][check_class]['PARAM_DEFS']
        for param in probe_check_param_defs:
            if 'value' in probe_check_param_defs[param]:
                check_params[param] = probe_check_param_defs[param]['value']

        # Appends 'check_vars' to 'probe_vars' (SQLAlchemy)
        CheckVars(probe_vars, check_class, check_params)

    return render_template('includes/probe_edit_form.html',
                           lang=g.current_lang,
                           probe=probe_vars,
                           probe_info=probe_info)
示例#2
0
def export_resource(identifier):
    """export resource as JSON or CSV"""

    resource = views.get_resource_by_id(identifier)

    history_csv = '%s/resource/%s/history/csv' % (CONFIG['GHC_SITE_URL'],
                                                  resource.identifier)
    history_json = '%s/resource/%s/history/json' % (CONFIG['GHC_SITE_URL'],
                                                    resource.identifier)
    if 'json' in request.url_rule.rule:
        last_run_report = '-'
        if resource.last_run:
            last_run_report = resource.last_run.report

        json_dict = {
            'identifier': resource.identifier,
            'title': resource.title,
            'url': resource.url,
            'resource_type': resource.resource_type,
            'owner': resource.owner.username,
            'min_response_time': resource.min_response_time,
            'average_response_time': resource.average_response_time,
            'max_response_time': resource.max_response_time,
            'reliability': resource.reliability,
            'status': format_run_status(resource.last_run),
            'first_run': format_checked_datetime(resource.first_run),
            'last_run': format_checked_datetime(resource.last_run),
            'history_csv': history_csv,
            'history_json': history_json,
            'last_report': format_obj_value(last_run_report)
        }
        return jsonify(json_dict)
    elif 'csv' in request.url_rule.rule:
        output = StringIO()
        writer = csv.writer(output)
        header = [
            'identifier', 'title', 'url', 'resource_type', 'owner',
            'min_response_time', 'average_response_time', 'max_response_time',
            'reliability', 'status', 'first_run', 'last_run', 'history_csv',
            'history_json'
        ]

        writer.writerow(header)
        writer.writerow([
            resource.identifier,
            resource.title,
            resource.url,
            resource.resource_type,
            resource.owner.username,
            resource.min_response_time,
            resource.average_response_time,
            resource.max_response_time,
            resource.reliability,
            format_run_status(resource.last_run),
            format_checked_datetime(resource.first_run),
            format_checked_datetime(resource.last_run),
            history_csv,
            history_json
        ])
        return output.getvalue(), 200, {'Content-type': 'text/csv'}
示例#3
0
def get_probe_edit_form(probe_class, resource_identifier=None):
    """get the form to edit a Probe"""

    probe_obj = Factory.create_obj(probe_class)
    if resource_identifier:
        resource = views.get_resource_by_id(resource_identifier)
        if resource:
            probe_obj.expand_params(resource)

    probe_info = probe_obj.get_plugin_vars()
    probe_vars = ProbeVars(
        None, probe_class, probe_obj.get_default_parameter_values())

    # Get only the default Checks for this Probe class
    checks_avail = probe_obj.get_checks_info_defaults()
    checks_avail = probe_obj.expand_check_vars(checks_avail)

    for check_class in checks_avail:
        check_obj = Factory.create_obj(check_class)
        check_params = check_obj.get_default_parameter_values()
        probe_check_param_defs = \
            probe_info['CHECKS_AVAIL'][check_class]['PARAM_DEFS']
        for param in probe_check_param_defs:
            if 'value' in probe_check_param_defs[param]:
                check_params[param] = probe_check_param_defs[param]['value']

        # Appends 'check_vars' to 'probe_vars' (SQLAlchemy)
        CheckVars(probe_vars, check_class, check_params)

    return render_template('includes/probe_edit_form.html',
                           lang=g.current_lang,
                           probe=probe_vars, probe_info=probe_info)
示例#4
0
def export_resource(identifier):
    """export resource as JSON or CSV"""

    resource = views.get_resource_by_id(identifier)

    history_csv = '%s/resource/%s/history/csv' % (CONFIG['GHC_SITE_URL'],
                                                  resource.identifier)
    history_json = '%s/resource/%s/history/json' % (CONFIG['GHC_SITE_URL'],
                                                    resource.identifier)
    if 'json' in request.url_rule.rule:
        last_run_report = '-'
        if resource.last_run:
            last_run_report = resource.last_run.report

        json_dict = {
            'identifier': resource.identifier,
            'title': resource.title.encode('utf-8'),
            'url': resource.url,
            'resource_type': resource.resource_type,
            'owner': resource.owner.username,
            'min_response_time': resource.min_response_time,
            'average_response_time': resource.average_response_time,
            'max_response_time': resource.max_response_time,
            'reliability': resource.reliability,
            'status': format_run_status(resource.last_run),
            'first_run': format_checked_datetime(resource.first_run),
            'last_run': format_checked_datetime(resource.last_run),
            'history_csv': history_csv,
            'history_json': history_json,
            'last_report': format_obj_value(last_run_report)
        }
        return jsonify(json_dict)
    elif 'csv' in request.url_rule.rule:
        output = StringIO()
        writer = csv.writer(output)
        header = [
            'identifier', 'title', 'url', 'resource_type', 'owner',
            'min_response_time', 'average_response_time', 'max_response_time',
            'reliability', 'status', 'first_run', 'last_run', 'history_csv',
            'history_json'
        ]

        writer.writerow(header)
        writer.writerow([
            resource.identifier,
            resource.title.encode('utf-8'),
            resource.url,
            resource.resource_type,
            resource.owner.username,
            resource.min_response_time,
            resource.average_response_time,
            resource.max_response_time,
            resource.reliability,
            format_run_status(resource.last_run),
            format_checked_datetime(resource.first_run),
            format_checked_datetime(resource.last_run),
            history_csv,
            history_json
        ])
        return output.getvalue(), 200, {'Content-type': 'text/csv'}
示例#5
0
def export_resource(identifier):
    """export resource as JSON or CSV"""

    resource = views.get_resource_by_id(identifier)

    history_csv = '%s/resource/%s/history/csv' % (GHC_SITE_URL,
                                                  resource.identifier)
    history_json = '%s/resource/%s/history/json' % (GHC_SITE_URL,
                                                    resource.identifier)
    if 'json' in request.url_rule.rule:
        json_dict = {
            'identifier': resource.identifier,
            'title': resource.title,
            'url': resource.url,
            'resource_type': resource.resource_type,
            'owner': resource.owner.username,
            'min_response_time': resource.min_response_time,
            'average_response_time': resource.average_response_time,
            'max_response_time': resource.max_response_time,
            'reliability': resource.reliability,
            'status': resource.last_run.success,
            'first_run': resource.first_run.checked_datetime.strftime(
                '%Y-%m-%dT%H:%M:%SZ'),
            'last_run': resource.last_run.checked_datetime.strftime(
                '%Y-%m-%dT%H:%M:%SZ'),
            'history_csv': history_csv,
            'history_json': history_json
        }
        return jsonify(json_dict)
    elif 'csv' in request.url_rule.rule:
        output = StringIO()
        writer = csv.writer(output)
        header = [
            'identifier', 'title', 'url', 'resource_type', 'owner',
            'min_response_time', 'average_response_time', 'max_response_tie',
            'reliability', 'status', 'first_run', 'last_run', 'history_csv',
            'history_json'
        ]
        writer.writerow(header)
        writer.writerow([
            resource.identifier,
            resource.title,
            resource.url,
            resource.resource_type,
            resource.owner.username,
            resource.min_response_time,
            resource.average_response_time,
            resource.max_response_time,
            resource.reliability,
            resource.last_run.success,
            resource.first_run.checked_datetime.strftime(
                '%Y-%m-%dT%H:%M:%SZ'),
            resource.last_run.checked_datetime.strftime(
                '%Y-%m-%dT%H:%M:%SZ'),
            history_csv,
            history_json
        ])
        return output.getvalue(), 200, {'Content-type': 'text/csv'}
示例#6
0
def api_probes_avail(resource_type=None, resource_id=None):
    """
    Get available (configured) Probes for this
    installation, optional for resource type
    """
    resource = None
    if resource_id:
        resource = views.get_resource_by_id(resource_id)

    probes = views.get_probes_avail(resource_type=resource_type,
                                    resource=resource)
    return jsonify(probes)
示例#7
0
def api_probes_avail(resource_type=None, resource_id=None):
    """
    Get available (configured) Probes for this
    installation, optional for resource type
    """
    resource = None
    if resource_id:
        resource = views.get_resource_by_id(resource_id)

    probes = views.get_probes_avail(resource_type=resource_type,
                                    resource=resource)
    return jsonify(probes)
示例#8
0
def export_resource(identifier):
    """export resource as JSON or CSV"""

    resource = views.get_resource_by_id(identifier)

    history_csv = '%s/resource/%s/history/csv' % (GHC_SITE_URL,
                                                  resource.identifier)
    history_json = '%s/resource/%s/history/json' % (GHC_SITE_URL,
                                                    resource.identifier)
    if 'json' in request.url_rule.rule:
        json_dict = {
            'identifier':
            resource.identifier,
            'title':
            resource.title,
            'url':
            resource.url,
            'resource_type':
            resource.resource_type,
            'owner':
            resource.owner.username,
            'average_response_time':
            resource.average_response_time,
            'reliability':
            resource.reliability,
            'status':
            resource.last_run.success,
            'last_check':
            resource.last_run.checked_datetime.strftime('%Y-%m-%dT%H:%M:%SZ'),
            'history_csv':
            history_csv,
            'history_json':
            history_json
        }
        return jsonify(json_dict)
    elif 'csv' in request.url_rule.rule:
        output = StringIO()
        writer = csv.writer(output)
        header = [
            'identifier', 'title', 'url', 'resource_type', 'owner',
            'average_response_time', 'reliability', 'status', 'last_check',
            'history_csv', 'history_json'
        ]
        writer.writerow(header)
        writer.writerow([
            resource.identifier, resource.title, resource.url,
            resource.resource_type, resource.owner.username,
            resource.average_response_time, resource.reliability,
            resource.last_run.success,
            resource.last_run.checked_datetime.strftime('%Y-%m-%dT%H:%M:%SZ'),
            history_csv, history_json
        ])
        return output.getvalue()
示例#9
0
def export_resource_history(identifier):
    """export resource history as JSON or CSV"""

    resource = views.get_resource_by_id(identifier)

    if 'json' in request.url_rule.rule:
        json_dict = {'runs': []}

        for run in resource.runs:
            json_dict['runs'].append({
                'owner':
                resource.owner.username,
                'resource_type':
                resource.resource_type,
                'checked_datetime':
                run.checked_datetime.strftime('%Y-%m-%dT%H:%M:%SZ'),
                'title':
                resource.title,
                'url':
                resource.url,
                'response_time':
                round(run.response_time, 2),
                'status':
                run.success
            })
        return jsonify(json_dict)
    elif 'csv' in request.url_rule.rule:
        output = StringIO()
        writer = csv.writer(output)
        header = [
            'owner', 'resource_type', 'checked_datetime', 'title', 'url',
            'response_time', 'status'
        ]
        writer.writerow(header)
        for run in resource.runs:
            writer.writerow([
                resource.owner.username,
                resource.resource_type,
                run.checked_datetime.strftime('%Y-%m-%dT%H:%M:%SZ'),
                resource.title,
                resource.url,
                run.response_time,
                run.success,
            ])
        return output.getvalue(), 200, {'Content-type': 'text/csv'}
示例#10
0
def export_resource_history(identifier):
    """export resource history as JSON or CSV"""

    resource = views.get_resource_by_id(identifier)

    if 'json' in request.url_rule.rule:
        json_dict = {'runs': []}

        for run in resource.runs:
            json_dict['runs'].append({
                'owner': resource.owner.username,
                'resource_type': resource.resource_type,
                'checked_datetime': run.checked_datetime.strftime(
                    '%Y-%m-%dT%H:%M:%SZ'),
                'title': resource.title,
                'url': resource.url,
                'response_time': round(run.response_time, 2),
                'status': run.success
            })
        return jsonify(json_dict)
    elif 'csv' in request.url_rule.rule:
        output = StringIO()
        writer = csv.writer(output)
        header = [
            'owner', 'resource_type', 'checked_datetime', 'title', 'url',
            'response_time', 'status'
        ]
        writer.writerow(header)
        for run in resource.runs:
            writer.writerow([
                resource.owner.username,
                resource.resource_type,
                run.checked_datetime.strftime(
                    '%Y-%m-%dT%H:%M:%SZ'),
                resource.title,
                resource.url,
                run.response_time,
                run.success,
            ])
        return output.getvalue(), 200, {'Content-type': 'text/csv'}
示例#11
0
def get_resource_by_id(identifier):
    """show resource"""

    response = views.get_resource_by_id(identifier)
    return render_template('resource.html', resource=response)
示例#12
0
def get_resource_by_id(identifier):
    """show resource"""

    response = views.get_resource_by_id(identifier)
    return render_template('resource.html', resource=response)
示例#13
0
def export_resource(identifier):
    """export resource as JSON or CSV"""

    resource = views.get_resource_by_id(identifier)

    history_csv = '%s/resource/%s/history/csv' % (CONFIG['GHC_SITE_URL'],
                                                  resource.identifier)
    history_json = '%s/resource/%s/history/json' % (CONFIG['GHC_SITE_URL'],
                                                    resource.identifier)
    if 'json' in request.url_rule.rule:
        json_dict = {
            'identifier':
            resource.identifier,
            'title':
            resource.title,
            'url':
            resource.url,
            'resource_type':
            resource.resource_type,
            'owner':
            resource.owner.username,
            'min_response_time':
            resource.min_response_time,
            'average_response_time':
            resource.average_response_time,
            'max_response_time':
            resource.max_response_time,
            'reliability':
            resource.reliability,
            'status':
            resource.last_run.success,
            'first_run':
            resource.first_run.checked_datetime.strftime('%Y-%m-%dT%H:%M:%SZ'),
            'last_run':
            resource.last_run.checked_datetime.strftime('%Y-%m-%dT%H:%M:%SZ'),
            'history_csv':
            history_csv,
            'history_json':
            history_json,
            'last_report':
            resource.last_run.report,
            'recipients':
            resource.dump_recipients()
        }
        return jsonify(json_dict)
    elif 'csv' in request.url_rule.rule:
        output = StringIO()
        writer = csv.writer(output)
        header = [
            'identifier',
            'title',
            'url',
            'resource_type',
            'owner',
            'min_response_time',
            'average_response_time',
            'max_response_tie',
            'reliability',
            'status',
            'first_run',
            'last_run',
            'history_csv',
            'history_json',
            'recipients',
        ]

        # serialize recipients into a string
        recipients = resource.dump_recipients()
        recipients_str = json.dumps(recipients)

        writer.writerow(header)
        writer.writerow([
            resource.identifier, resource.title, resource.url,
            resource.resource_type, resource.owner.username,
            resource.min_response_time, resource.average_response_time,
            resource.max_response_time, resource.reliability,
            resource.last_run.success,
            resource.first_run.checked_datetime.strftime('%Y-%m-%dT%H:%M:%SZ'),
            resource.last_run.checked_datetime.strftime('%Y-%m-%dT%H:%M:%SZ'),
            history_csv, history_json, recipients_str
        ])
        return output.getvalue(), 200, {'Content-type': 'text/csv'}