Ejemplo n.º 1
0
def edit_user():
    session = Session()
    user_data = request.json
    print(user_data)
    response_object = user_repository.edit_user(session, user_data)
    session.close()
    return jsonify(response_object)
Ejemplo n.º 2
0
def get_work_orders(page, size):
    init_db()
    session = Session()
    workorders_json = work_order_controller.get_work_orders_schema(
        session, page, size)
    session.close()
    return jsonify(workorders_json)
Ejemplo n.º 3
0
def register():
    session = Session()
    json_data = request.json
    print(json_data)
    user = user_repository.generate_user(session, json_data)
    session.close()
    return jsonify(user)
Ejemplo n.º 4
0
def generate_device():
    session = Session()
    device_to_save = request.get_json()
    if device_to_save:
        message, error = device_repository.generate_device(
            session, device_to_save)
        session.close()
        return jsonify(message, error)
Ejemplo n.º 5
0
def fetch_work_order_detail(id):
    workorder_to_fetch = id
    session = Session()
    fetched_workorder = work_order_controller.fetch_work_orders_schema(
        session, workorder_to_fetch)
    session.close()
    print(fetched_workorder)
    return jsonify(fetched_workorder)
Ejemplo n.º 6
0
def delete_work_order(id):
    # workorder_to_delete = request.get_json()
    # print(workorder_to_delete)
    print(id)
    session = Session()
    work_order_controller.delete_work_orders_schema(session, id)
    session.close()
    return jsonify(True)
Ejemplo n.º 7
0
def get_devices_from_type(devicetype):
    session = Session()
    devices_json = device_controller.get_devices_schema_from_type(
        session,
        devicetype
    )
    session.close()
    return jsonify(devices_json)
Ejemplo n.º 8
0
def generate_script():
    session = Session()
    script = request.get_json()
    # try:
    status, report, log = script_service.run_script(script)
    script_repository.generate_script(script, status, report, log, session)
    session.close()
    return jsonify(status=status, report=report)
Ejemplo n.º 9
0
def edit_workorder(id):
    session = Session()
    workorder_changes = request.get_json()
    print(workorder_changes["client"]["code"])
    # changing the schema of that specific workorder in the database
    # work_order_controller.edit_work_order_schema(
    # session, id, workorder_changes)
    session.close()
    return jsonify(workorder_changes)
Ejemplo n.º 10
0
def get_scripts(scriptType, page, size):
    session = Session()
    scripts = script_controller.get_scripts_schema(
        session,
        scriptType,
        page,
        size)
    session.close()
    return jsonify(scripts)
Ejemplo n.º 11
0
def get_cron_jobs(page, size):
    session = Session()
    cronjobs_json = cron_job_controller.get_cron_jobs_schema(
        session,
        page,
        size
    )
    session.close()
    return jsonify(cronjobs_json)
Ejemplo n.º 12
0
def delete_user(id):
    print(id)
    session = Session()
    user_controller.delete_user_schema(
        session,
        id
    )
    session.close()
    return jsonify(True)
Ejemplo n.º 13
0
def delete_device():
    try:
        device = request.get_json()
        session = Session()
        print(device['hostname'])
        status = device_repository.delete_device(session, device['hostname'])
        session.close()
        return jsonify(status=status, device=device['hostname'])
    except IntegrityError:
        return jsonify(status="integrityError", device=device['hostname'])
Ejemplo n.º 14
0
def login():
    session = Session()
    secrete_key = Config.SECRET_KEY
    json_data = request.get_json()
    # status, code = user_repository.check_user(
    # session, json_data, secrete_key)
    auth = user_repository.auth(session, json_data, secrete_key)
    session.close()
    # print(status)
    # return jsonify({'status': status, code: code})
    return jsonify(auth)
Ejemplo n.º 15
0
def generate_workorder_radio():

    session = Session()
    workorder_to_save = request.get_json()
    print("workorder to save ", workorder_to_save)
    bol, message, services, workorder_to_save["client"]["name"] = workorder_radio_service.generate_workorder_file(
        workorder_to_save, session)
    if bol:
        workorder__radio_repository.generate_work_order(
            session, workorder_to_save, services)
    session.close()
    return jsonify(workorder_to_save, bol, message), 201
Ejemplo n.º 16
0
def upload_devices():
    session = Session()
    devices = request.get_json()
    print(devices)
    del devices[0]
    if devices:
        device_repository.upload_devices(session, devices)
        session.close()

        return jsonify("The devices uploaded succesfully", 200)
    else:
        return jsonify("The excel File is empty please check your parameters",
                       199)
Ejemplo n.º 17
0
def add_device():
    session = Session()
    new_device = Device("9422", "172.65.112.13", "3")
    session.add(new_device)
    session.commit()
    session.close()
    click.echo('device added')
Ejemplo n.º 18
0
def stop_cronjob(id):
    try:
        session = Session()
        cronjob = session.query(CronJob).filter(CronJob.id == id).first()
        if cronjob.status != 'Stopped':
            cronjob_service.disable_cron_job(id)
            cronjob_repository.edit_cronjob(session, cronjob, 'Stopped')
            session.close()
            return jsonify(response='error', msg='Cronjob {0} was disabled'.format(id))
        else:
            return jsonify(response='error', msg='Cronjob {0} is already disabled'.format(id))
    except AttributeError as e:
        return jsonify(response='error', msg='Cronjob {0} was not found, {1}'.format(id, str(e)))
    except Exception as e:
        return jsonify(response='error', msg='An error occurred while disabling cronjob {0}, {1}'.format(id, str(e)))
Ejemplo n.º 19
0
def activate_cronjob(id):
    try:
        session = Session()
        cronjob = session.query(CronJob).filter(CronJob.id == id).first()
        print(cronjob.status)
        if cronjob.status == 'Stopped':
            cronjob_service.enable_cron_job(id)
            cronjob_repository.edit_cronjob(session, cronjob, 'Enabled')
            session.close()
            return jsonify(response='success', msg='Cronjob {0} was activated'.format(id))
        else:
            return jsonify(response='error', msg='Cronjob {0} is already running'.format(id))
    except AttributeError as e:
        return jsonify(response='error', msg='Cronjob {0} was not found'.format(id))
    except Exception as e:
        return jsonify(response='error', msg='An error occurred while activating cronjob {0}'.format(id, str(e)))
Ejemplo n.º 20
0
def run_script():
    session = Session()
    script = request.get_json()
    status, report, log = script_service.run_script(script)
    if status != script["status"] or report != script[
            "report"] or log != script["log"]:
        edited_script = script_controller.edit_script_schema(
            script, session, status, report, log)
        changed = "Changed"
    else:
        edited_script = {}
        changed = "Not changed"
    session.close()
    return jsonify(edited_script=edited_script,
                   response=changed,
                   status=status)
Ejemplo n.º 21
0
def generate_cron_job():
    session = Session()
    cronjob_from_request = request.get_json()
    print("cronjob_from_request: ", cronjob_from_request)
    # try:
    # The cronjob is only added and is not committed until it runs
    # successfully; in case of an error: session.rollback()
    cron_job, message, response = cronjob_repository.generate_cron_job(
        session, cronjob_from_request, 'Pending', datetime.datetime.now())
    if (response):
        status = cronjob_service.add_cron_job(cronjob_from_request, cron_job)
        session.commit()
        session.close()
    else:
        status = "Error"
        session.rollback()
        message = 'schedule failed'

    return jsonify(cronjob_from_request, status, response, message), 201
Ejemplo n.º 22
0
def get_work_orders_radio(page, size):
    session = Session()
    workorders_json = work_order_radio_controller.get_work_orders_schema(
        session, page, size)
    session.close()
    return jsonify(workorders_json)
Ejemplo n.º 23
0
def run_script(script):
    status = "Failed"
    report = "A problem has occurred when trying to run the script!"
    log = ""
    try:
        path = "".join([
            Config.SCRIPTS_PATH,
            script['scriptType'].replace('_', '/'),
            '/',
            script['scriptName'],
        ])
        session = Session()
        device_ip_list = ""
        try:
            script_devices = get_devices_schema_from_hostnamelist(
                session, script['devices'])

            for device in script_devices:
                device_ip_list = " ".join([device_ip_list, device["ipSystem"]])
        except Exception as e:
            pass

        session.close()
        type_path = script['scriptType'].replace('_', '/')
        command = "".join([
            'python ', '"', path, '"', " ", '"', device_ip_list, '"', " ", '"',
            type_path, '"'
        ])
        print(command)
        stream = os.popen(command)
        #stream = os.popen(" ".join(['python', path]))
        log = stream.read()
        print('log', log)
        report = convert_xlsx2html(
            "".join([
                Config.OUTPUT_EXCEL_PATH,
                script['scriptType'].replace('_', '/'), '/',
                script['scriptName'].replace('.py', '.xlsx')
            ]), script['scriptName'].replace('.py', ''))
        # pdfkit.from_file('pandas_output.html', 'pandas_out.pdf')
        # path = Config.SCRIPTS_PATH+script['scriptType'].replace('_', '/')
        # +'/'+script['scriptName']
        # result = subprocess.run(['python', path],
        #                         stderr=subprocess.PIPE,
        #                         stdout=subprocess.PIPE)
        # report = result.stderr.decode('utf-8') +result.stdout.decode('utf-8')
        status = "Success"
    except AttributeError as attErr:
        #path = Config.SCRIPTS_PATH+script['scriptType'].replace('_','/')+'/'+script['scriptName']
        #process = subprocess.Popen(['python', path],shell = True,stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        #status = "Success"
        #resOut, resErr = process.communicate()
        #report = "stdout:\n" + resOut + "\nstderr:\n" + resErr
        execute = execfile(
            make_path(
                Config.SCRIPTS_PATH + script['scriptType'].replace('_', '/') +
                '/', script['scriptName']), globals())
        report = message
        status = 'Success'
        log = report
    except Exception as exception:
        #print ("exception",str(exception))
        status = "Error"
        report = str(exception)
        log = str(exception)
    finally:
        return status, report, log
Ejemplo n.º 24
0
def get_all_devices():
    session = Session()
    devices_json = device_controller.get_all_devices_schema(session)
    session.close()
    return jsonify(devices_json)
Ejemplo n.º 25
0
def get_devices(page, size):
    session = Session()
    devices_json = device_controller.get_devices_schema(session, page, size)
    # print(devices_json)
    session.close()
    return jsonify(devices_json)
Ejemplo n.º 26
0
def get_users():
    session = Session()
    users_json = user_controller.get_user_schema(session)
    session.close()
    return jsonify(users_json)
Ejemplo n.º 27
0
def delete_role(id):
    session = Session()
    role_controller.delete_role_schema(session, id)
    session.close()
    return jsonify(True)
Ejemplo n.º 28
0
def get_roles():
    session = Session()
    roles_json = role_controller.get_roles_schema(session)
    session.close()
    return jsonify(roles_json)
Ejemplo n.º 29
0
def register_role():
    session = Session()
    json_data = request.json
    role = role_repository.generate_role(session, json_data)
    session.close()
    return jsonify(role)
Ejemplo n.º 30
0
def delete_users():
    session = Session()
    user_controller.delete_users_schema(session)
    session.close()
    return jsonify(True)