@app.route("/register", methods=['POST', 'PUT'])
def register():
    if request.headers.get('X-REGISTER-KEY') != app.config['REGISTER_KEY']:
        abort(412)
    if not request.json:
        abort(400)
    if not _valid_registration(request.json):
        abort(400)
    hid = request.json['hostname']
    checks = request.json['checks']
    roles = request.json['roles']
    ip_addr = request.json.get('ip', request.remote_addr)
    if ip_addr == '':
        ip_addr = request.remote_addr
    try:
        pkey = genPrimaryKey64("%s%s" % (hid, ip_addr))
        q = r.table("hosts").insert({
                "id": pkey,
                "hostname": hid,
                "ip": ip_addr,
                "checks": checks,
                "roles": roles
            },conflict="update").run(rdb.conn)
        q = r.table("checks").filter({"hostname": hid}).delete().run(rdb.conn) #we're about to reinstart all so just delete all incase checks got removed
        bulk_load = []
        for i in checks:
            bulk_load.append({'id': genPrimaryKey64((hid, ip_addr, i) % "%s%s%s"),
                              'hostname': hid, 'ip': ip_addr,
                              'check': i, 'last': 0, 'next': _rand_start(),
                              'interval': checks[i]['interval'],
                              'follow_up': checks[i]['follow_up'],
                              'pending': False,
                              'status': None, 'in_maintenance': False,
                              'suspended': False, 'out': '',
                              'priority': checks[i].get('priority', 1)})
            q = r.table("checks").insert(bulk_load, conflict="update").run(rdb.conn)
    except Exception as err:
        logger.error(err)
        return jsonify({'status': 'fail', 'error': str(err)}), 400
    return jsonify({'status': 'ok'})
dataset/ETHPy150Open pandemicsyn/stalker/stalkerweb/stalkerweb/views.py/register/swapped operands of `%`