예제 #1
0
def api_rules():
    if request.method == 'POST':
        conf = json.loads(request.data)
        if 'service' in conf:
            srv_id = conf['service']
        else:
            message = {
                'status': 500,
                'message': 'KeyError',
            }
            resp = jsonify(message)
            resp.status_code = 500
            return resp
        rf = fileBuilder(srv_id, conf['rules'], promPath)
        status = rf.writeFile()
        message = {
            'status': 200,
            'message': status,
        }
        resp = jsonify(message)
        resp.status_code = 200
        return resp
    elif request.method == 'GET':
        return '(GET) get alert for '
    elif request.method == 'PUT':
        return '(PUT) get alert for '
예제 #2
0
def api_rules():
    if request.method == 'POST':
        conf = json.loads(request.data)
        if 'service' in conf:
            srv_id = conf['service']
        else:
            message = {
                'status': 500,
                'message': 'KeyError',
            }
            resp = jsonify(message)
            resp.status_code = 500
            return resp
        rf = fileBuilder(srv_id, conf['rules'], promPath)
        status = rf.writeFile();
        code =200
        if 'FAILED' in status:
            code = 500
        message = {
                'status': code,
                'message': status,
            } 
        resp = jsonify(message)
        resp.status_code = code
        return resp
    elif request.method == 'GET':    
        return '(GET) get alert for '
    elif request.method == 'PUT':    
        return '(PUT) get alert for '
예제 #3
0
def add_job():
    job = json.loads(request.data)

    with open(promPath + 'prometheus.yml', 'r') as conf_file:
        config = yaml.load(conf_file)

    config['scrape_configs'].append(job)
    rf = fileBuilder('prometheus.yml', config, promPath)
    resp = rf.buildConf()

    message = {
        'status': 200,
        'message': resp,
    }
    return jsonify(message)
예제 #4
0
def remove_job():
    job = json.loads(request.data)
    jobName = job['job_name']

    with open(promPath + 'prometheus.yml', 'r') as conf_file:
        config = yaml.load(conf_file)

    config['scrape_configs'] = [job for job in config['scrape_configs'] if job['job_name'] != jobName]
    rf = fileBuilder('prometheus.yml', config, promPath)
    resp = rf.buildConf()

    message = {
        'status': 200,
        'message': resp,
    }
    return jsonify(message)
예제 #5
0
def api_conf():
    if request.method == 'GET':
        with open(promPath + 'prometheus.yml', 'r') as conf_file:
            conf = yaml.load(conf_file)
            js_obj = json.dumps(conf)
            # print(js_obj)
        return js_obj
    elif request.method == 'POST':
        conf = json.loads(request.data)
        rf = fileBuilder('prometheus.yml', conf, promPath)
        resp = rf.buildConf()
        message = {
            'status': 200,
            'message': resp,
        }
        return jsonify(message)
예제 #6
0
def api_conf():
    if request.method == 'GET':
        with open(promPath+'prometheus.yml', 'r') as conf_file:
            conf = yaml.load(conf_file)
            js_obj = json.dumps(conf)
            #print(js_obj)
        return js_obj
    elif request.method == 'POST':    
        conf = json.loads(request.data)
        rf = fileBuilder('prometheus.yml', conf, promPath)
        resp=rf.buildConf()
        message = {
                'status': 200,
                'message': resp,
            }
        return jsonify(message)