Пример #1
0
def warning_processor():
    # android_push.apply_async(args=[user.uuid, message])
    admins = db.query(Admin).all()

    warns = db.query(Warnings).filter_by(warned=False).all()
    for warn in warns:
        uuids = []
        for admin in admins:
            if admin.notify_level <= warn.level:
                uuids.append(admin.uuid)
        hw = db.query(Hardwares).filter_by(id=warn.hardware_id).first()
        element = db.query(Elements).filter_by(id=hw.element_id).first()
        group = db.query(Groups).filter_by(id=element.group_id).first()
        msg = dict(id=unicode(warn.id), time_code=unicode(time.mktime(warn.timestamp.timetuple())), \
                   error_code=unicode(warn.event_code), group_fingerprint=group.identifier, \
                   element_fingerprint=element.fingerprint, machine_name=element.machine_name, \
                   ip_address_local=element.ip_address_local, ip_address_global=element.ip_address_global, \
                   hardware_name=hw.hardware_name, warning_level=unicode(warn.level), \
                   message=unicode(warn.event_code_description))
        android_push.apply_async(args=[uuids, msg])
        db.query(Warnings).filter_by(id=warn.id).update({Warnings.warned: True})
    db.commit()
Пример #2
0
    try:
        with db.begin_nested():
            db.query(Elements).filter_by(id=element.id).\
                update({Elements.machine_name:data["MachineName"],
                        Elements.ip_address_local:data["LocalIPAddress"],
                        Elements.ip_address_global:data["GlobalIPAddress"],
                        Elements.ip_address_gateway:data["GatewayIPAddress"],
                        Elements.report:data["HardwareReport"]})
    except Exception, e:
        print str(e)
        raise abort(500)

    results["element_id"] = element.fingerprint

    db.commit()
    return jsonify(results), 200


@manage_blueprint.route("/signup/", methods=["POST"])
#@login_required
def signup():
    #1. 받은 데이터의 키가 모두 존재하나 검사한다.
    #2. 일단 받아온 그룹이 존재하나 확인한다.
    #3. 그룹이 존재하지 않는다면 그룹을 등록한다.
    #4. 해당 그룹 아래에 엘리먼트를 등록하면서 랜덤 md5 를 생성한다.
    #5. 해당 엘리먼트의 하위에 하드웨어들을 등록하면서 랜덤 SHA1 을 등록한다.
    #6. 해당 하드웨어의 장치에 따라서 얻어올 센서값은 정해져 있으므로
    #   해당 센서값들을 하드웨어 종류에 맟춰서 등록한다.
    #   하드디스크의 SMART 값은 통쨰로 저장하는게 옳다.
    results = {}