Example #1
0
def create_blackout(tenant):

    data = request.json

    tenant = generateDBName(tenant)

    if request.json and 'environment' in request.json:
        environment = request.json['environment']
    else:
        return jsonify(status="error", message="must supply 'environment' as parameter"), 400

    resource = request.json.get("resource", None)
    service = request.json.get("service", None)
    event = request.json.get("event", None)
    group = request.json.get("group", None)
    tags = request.json.get("tags", None)
    start_time = request.json.get("startTime", None)
    end_time = request.json.get("endTime", None)
    duration = request.json.get("duration", None)

    if start_time:
        start_time = datetime.datetime.strptime(start_time, '%Y-%m-%dT%H:%M:%S.%fZ')
    if end_time:
        end_time = datetime.datetime.strptime(end_time, '%Y-%m-%dT%H:%M:%S.%fZ')

    try:
        blackout = db.create_blackout(tenant,environment, resource, service, event, group, tags, start_time, end_time, duration)
    except Exception as e:
        return jsonify(status="error", message=str(e)), 500

    return jsonify(status="ok", blackout=blackout), 201, {'Location': '%s/%s' % (request.base_url, blackout)}
Example #2
0
def create_blackout():

    environment = request.json.get('environment', None)
    if not environment:
        return jsonify(
            status="error",
            message="Must supply non-empty 'environment' for blackouts."), 400

    resource = request.json.get("resource", None)
    service = request.json.get("service", None)
    event = request.json.get("event", None)
    group = request.json.get("group", None)
    tags = request.json.get("tags", None)
    customer = request.json.get("customer", None)
    start_time = request.json.get("startTime", None)
    end_time = request.json.get("endTime", None)
    duration = request.json.get("duration", None)

    if start_time:
        start_time = datetime.datetime.strptime(start_time,
                                                '%Y-%m-%dT%H:%M:%S.%fZ')
    if end_time:
        end_time = datetime.datetime.strptime(end_time,
                                              '%Y-%m-%dT%H:%M:%S.%fZ')

    try:
        blackout = db.create_blackout(environment, resource, service, event,
                                      group, tags, customer, start_time,
                                      end_time, duration)
    except Exception as e:
        return jsonify(status="error", message=str(e)), 500

    return jsonify(status="ok", id=blackout['id'], blackout=blackout), 201, {
        'Location': absolute_url('/blackout/' + blackout['id'])
    }
Example #3
0
def create_blackout():

    if request.json and 'environment' in request.json:
        environment = request.json.get('environment', None) or ''
    else:
        return jsonify(status="error", message="must supply 'environment' as parameter"), 400

    resource = request.json.get("resource", None)
    service = request.json.get("service", None)
    event = request.json.get("event", None)
    group = request.json.get("group", None)
    tags = request.json.get("tags", None)
    customer = request.json.get("customer", None)
    start_time = request.json.get("startTime", None)
    end_time = request.json.get("endTime", None)
    duration = request.json.get("duration", None)

    if start_time:
        start_time = datetime.datetime.strptime(start_time, '%Y-%m-%dT%H:%M:%S.%fZ')
    if end_time:
        end_time = datetime.datetime.strptime(end_time, '%Y-%m-%dT%H:%M:%S.%fZ')

    try:
        blackout = db.create_blackout(environment, resource, service, event, group, tags, customer, start_time, end_time, duration)
    except Exception as e:
        return jsonify(status="error", message=str(e)), 500

    return jsonify(status="ok", blackout=blackout), 201, {'Location': absolute_url('/blackout/' + blackout)}
Example #4
0
def telegram():

    data = request.json
    if 'callback_query' in data:
        command, alert = data['callback_query']['data'].split(' ', 1)

        if command == '/ack':
            db.set_status(alert, 'ack', 'status change via Telegram')
        elif command == '/close':
            db.set_status(alert, 'closed', 'status change via Telegram')
        elif command == '/blackout':
            environment, resource, event = alert.split('|', 2)
            db.create_blackout(environment,resource=resource, event=event)

        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="no callback_query in Telegram message"), 400
Example #5
0
def telegram():

    data = request.json
    if 'callback_query' in data:
        command, alert = data['callback_query']['data'].split(' ', 1)

        if command == '/ack':
            db.set_status(alert, 'ack', 'status change via Telegram')
        elif command == '/close':
            db.set_status(alert, 'closed', 'status change via Telegram')
        elif command == '/blackout':
            environment, resource, event = alert.split('|', 2)
            db.create_blackout(environment,resource=resource, event=event)

        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="no callback_query in Telegram message"), 400
Example #6
0
def telegram():
    data = request.json
    if 'callback_query' in data:
        author = data['callback_query']['from']
        command, alert = data['callback_query']['data'].split(' ', 1)
        user = "******".format(author.get('first_name'),
                              author.get('last_name'))

        action = command.lstrip('/')
        if action in ['open', 'ack', 'close']:
            db.set_status(alert, action, 'status change via Telegram')
        elif action in ['watch', 'unwatch']:
            db.untag_alert(alert, [
                "{}:{}".format(action, user),
            ])
        elif action == 'blackout':
            environment, resource, event = alert.split('|', 2)
            db.create_blackout(environment, resource=resource, event=event)

        send_message_reply(alert, action, user, data)
        return jsonify(status="ok")
    else:
        return jsonify(status="error",
                       message="no callback_query in Telegram message"), 400
Example #7
0
 def create(self):
     return Blackout.from_db(db.create_blackout(self))
Example #8
0
 def create(self):
     return Blackout.from_db(db.create_blackout(self))
Example #9
0
 def create(self) -> 'Blackout':
     blackout = Blackout.from_db(db.create_blackout(self))
     process_blackout(blackout, action='create')
     return blackout