<commit_before>import datetime
import time

from flask import (Response, current_app, jsonify, render_template, request,
                   url_for)
from flask_cors import cross_origin

from alerta.app import db
from alerta.auth.decorators import permission
from alerta.exceptions import ApiError
from alerta.models.alert import Alert
from alerta.models.heartbeat import Heartbeat
from alerta.models.metrics import Counter, Gauge, Timer
from alerta.models.switch import Switch, SwitchState
from alerta.version import __version__

from . import mgmt

try:
    from alerta import build  # type: ignore
except Exception:
    from alerta import dev as build  # type: ignore


switches = [
    Switch('auto-refresh-allow', 'Alerta console auto-refresh',
           'Allow consoles to auto-refresh alerts', SwitchState.ON),
    Switch('sender-api-allow', 'API alert submission', 'Allow alerts to be submitted via the API', SwitchState.ON)
]
total_alert_gauge = Gauge('alerts', 'total', 'Total alerts', 'Total number of alerts in the database')

started = time.time() * 1000


@mgmt.route('/management', methods=['OPTIONS', 'GET'])
@cross_origin()
def management():

    endpoints = [
        url_for('mgmt.manifest'),
        url_for('mgmt.properties'),
        url_for('mgmt.switchboard'),
        url_for('mgmt.good_to_go'),
        url_for('mgmt.health_check'),
        url_for('mgmt.housekeeping'),
        url_for('mgmt.status'),
        url_for('mgmt.prometheus_metrics')
    ]
    return render_template('management/index.html', endpoints=endpoints)


@mgmt.route('/management/manifest', methods=['OPTIONS', 'GET'])
@cross_origin()
@permission('read:management')
def manifest():

    manifest = {
        'release': __version__,
        'build': build.BUILD_NUMBER,
        'date': build.BUILD_DATE,
        'revision': build.BUILD_VCS_NUMBER
    }

    return jsonify(manifest)


@mgmt.route('/management/properties', methods=['OPTIONS', 'GET'])
@cross_origin()
@permission('admin:management')
def properties():

    properties = ''<commit_msg>Add envvars to mgmt props endpoint (#667)<commit_after>import datetime
import os
import time

from flask import (Response, current_app, jsonify, render_template, request,
                   url_for)
from flask_cors import cross_origin

from alerta.app import db
from alerta.auth.decorators import permission
from alerta.exceptions import ApiError
from alerta.models.alert import Alert
from alerta.models.heartbeat import Heartbeat
from alerta.models.metrics import Counter, Gauge, Timer
from alerta.models.switch import Switch, SwitchState
from alerta.version import __version__

from . import mgmt

try:
    from alerta import build  # type: ignore
except Exception:
    from alerta import dev as build  # type: ignore


switches = [
    Switch('auto-refresh-allow', 'Alerta console auto-refresh',
           'Allow consoles to auto-refresh alerts', SwitchState.ON),
    Switch('sender-api-allow', 'API alert submission', 'Allow alerts to be submitted via the API', SwitchState.ON)
]
total_alert_gauge = Gauge('alerts', 'total', 'Total alerts', 'Total number of alerts in the database')

started = time.time() * 1000


@mgmt.route('/management', methods=['OPTIONS', 'GET'])
@cross_origin()
def management():

    endpoints = [
        url_for('mgmt.manifest'),
        url_for('mgmt.properties'),
        url_for('mgmt.switchboard'),
        url_for('mgmt.good_to_go'),
        url_for('mgmt.health_check'),
        url_for('mgmt.housekeeping'),
        url_for('mgmt.status'),
        url_for('mgmt.prometheus_metrics')
    ]
    return render_template('management/index.html', endpoints=endpoints)


@mgmt.route('/management/manifest', methods=['OPTIONS', 'GET'])
@cross_origin()
@permission('read:management')
def manifest():

    manifest = {
        'release': __version__,
        'build': build.BUILD_NUMBER,
        'date': build.BUILD_DATE,
        'revision': build.BUILD_VCS_NUMBER
    }

    return jsonify(manifest)


@mgmt.route('/management/properties', methods=['OPTIONS', 'GET'])
@cross_origin()
@permission('admin:management')
def properties():

    properties = ''

    for k, v in os.environ.items():
        properties += '{}: {}\n'.format(k, v)
{'fraction_non_alphanumeric': 0.12413956800379777, 'fraction_numerical': 0.0026109660574412533, 'mean_word_length': 3.9928909952606637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1651485', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1223, 'n_words': 326}