Exemplo n.º 1
0
def api_all_arm_restart():
    if "park_name" in request.form:
        park_name = request.form.get("park_name")
        ssh, _ = frp.get_conn(conn_name=park_name)
        if "current_ip" in request.form:
            current_ip = request.form.get("current_ip")
            ssh, _ = make_tunnel(ssh, current_ip)
            _, stdout, _ = ssh.exec_command("cd /home/park;sh restart.sh")
            return json.dumps({"result": 0})
    else:
        host = request.form.get('hostname')
        port = int(request.form.get('port'))
        ssh, _ = try_login(host=host, port=port)
    try:
        path = os.path.join(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),
            "static", "scripts", "all_arm_restart.py")
        job = RemoteScriptJob(ssh, path)
        job.run()

        for out_put in job.read_all():
            if "success" in out_put.str:
                return json.dumps({"result": 0})
        return json.dumps({"result": 1})
    except Exception as e:
        return json.dumps({"result": str(e)})
Exemplo n.º 2
0
def test():
    os.chdir('../../../')
    from log_fetch import IRainLogType
    import datetime
    ssh_client, _ = frp.get_conn(u'凯德东')
    tunnel, _ = make_tunnel(ssh_client, '192.168.55.247')
    print get_log(IRainLogType.PARK_OUT,
                  datetime.date.today(),
                  u'凯德东',
                  force_download=True,
                  ssh_client=tunnel)
Exemplo n.º 3
0
def api_disk_usage():
    if "park_name" in request.args:
        current_ip = request.args.get("current_ip")
        conn, _ = frp.get_conn(request.args.get('park_name'))
        ssh, _ = make_tunnel(conn, current_ip)
    else:
        host = request.args.get('hostname')
        port = int(request.args.get('port'))
        ssh, _ = try_login(host=host, port=port)
    usage = disk_usage(ssh)
    return jsonify({"timestamp": int(time.time()), "usage": usage})
Exemplo n.º 4
0
def api_net_usage():
    if "park_name" in request.args:
        current_ip = request.args.get("current_ip")
        conn, _ = frp.get_conn(request.args.get('park_name'))
        ssh, _ = make_tunnel(conn, current_ip)
    else:
        host = request.args.get('hostname')
        port = int(request.args.get('port'))
        ssh, _ = try_login(host=host, port=port)
    usage = net_inout_bytes(ssh)
    return jsonify({
        "timestamp": int(time.time()),
        "inbound": usage[0],
        "outbound": usage[1]
    })
Exemplo n.º 5
0
def test():
    from src.frp.frp import frp
    from job_system import jobsystem
    import os
    from src.utils.quick import make_tunnel

    os.chdir('../../')
    conn, _ = frp.get_conn(u'凯德东')
    tunnel, _ = make_tunnel(conn, '192.168.55.247')
    j = RemoteScriptJob(tunnel, 'static/scripts/park_info_extract.py')
    jobsystem.add_job(j)
    # jobsystem.start_job(j.job_id, ('陕A326CL', '"2018-06-10 16:23:03"'))
    jobsystem.run(j.job_id, ('陕AQ22K8', '"2018-06-06 00:17:20"'))

    for log in jobsystem.read_all(j.job_id):
        print log.str
Exemplo n.º 6
0
    def run(self):
        self._p_start()
        # get park_out record within park_date
        conn, ver = frp.get_conn(self.park_name)

        if ver == 2:
            self._info(
                JobLog(99, LogType.INFO, self.park_time,
                       u'non 3399 not support yet', None))
            self._p_end()
            return

        mysql_addr, _ = get_mysql_addr(conn)

        # vpr, terminal_ip, out_time
        record = None
        sql = """select d.out_used_plate, c.ip, d.out_time from depot_terminal as c join (select * from depot_site as a join (select out_used_plate, out_time, out_site_name from records_inout where out_time = '%s' and out_used_plate='%s') as b on a.name = b.out_site_name) as d on c.id = d.terminal_id;""" % (
            str(self.park_time), self.vpr)
        for r in execute_shell(
                conn,
                'mysql -uroot -piraindb10241GB -h%s irain_park -sNe "%s"' %
            (mysql_addr, sql)):
            record = r.split('\t')
            break

        terminal_ip = record[1]
        tunnel, _ = make_tunnel(conn, terminal_ip)

        park_info = {}

        for log in run_script(tunnel, 'static/scripts/park_info_extract.py',
                              (self.vpr, '"%s"' % self.park_time)):
            value = eval(log.str)
            for k, v in value.items():
                if isinstance(v, datetime.datetime):
                    value[k] = str(v)
                elif k == u'出口计费详情':
                    value[k] = [(x[0], str(x[1]), str(x[2]), x[3]) for x in v]
            park_info.update(value)

        # 场内支付情况
        if u'历史计费订单' in park_info:
            charge_no = park_info[u'历史计费订单']

            all_arm = get_all_terminal_ip(conn)
            for arm_ip in all_arm:
                squeeze_ip = arm_ip.replace('.', '')
                if charge_no.find(squeeze_ip) == 0:
                    sync_arm_tunnel, _ = make_tunnel(conn, arm_ip)

                    for log in run_script(
                            sync_arm_tunnel,
                            'static/scripts/idata_info_extract.py',
                        (charge_no, '"%s"' % self.park_time.date())):
                        value = eval(log.str)

                        for k, v in value.items():
                            if isinstance(v, datetime.datetime):
                                value[k] = str(v)
                            elif k == u'历史计费详情':
                                value[k] = [(x[0], str(x[1]), str(x[2]), x[3])
                                            for x in v]
                        park_info.update(value)
                    sync_arm_tunnel.close()

        p_r = park_records(tunnel, self.vpr, self.park_time.date())
        r = filter(lambda x: x[5] == str(self.park_time), p_r)[0]

        cloud_tml = cloud_terminal(tunnel)
        cloud_tunnel, _ = make_tunnel(tunnel, cloud_tml)

        # 进出车上报情况
        for log in run_script(cloud_tunnel,
                              'static/scripts/sync_inout_extract.py',
                              (r[2], )):
            value = eval(log.str)
            for k, v in value.items():
                if isinstance(v, datetime.datetime):
                    value[k] = str(v)
            park_info.update(value)

        for k, v in park_info.items():
            if k not in mapping:
                continue
            new_k = mapping[k]
            park_info[new_k] = v
            del park_info[k]

        self._info(
            JobLog(99, LogType.INFO, self.park_time, u'park_flow', park_info))

        self._p_end()

        tunnel.close()
        cloud_tunnel.close()