コード例 #1
0
def main():
    """Script entry point."""
    try:
        insert_history()
    except:
        err_msg = "insert_history() was not initialized"
        notify_support(err_msg, "History")
コード例 #2
0
def main():
    """Script entry point."""
    try:
        insert_history()
    except:
        err_msg = "insert_history() was not initialized"
        notify_support(err_msg, "History")
コード例 #3
0
def main():
    """Script entry point.

    This runs an audit check and inserts any necessary audit records.
    """
    try:
        insert_audit()
    except Exception, e:
        err_msg = "insert_audit() was not initialized " + str(e)
        notify_support(err_msg, "Audit")
コード例 #4
0
def _process_single_parent_results(cursor, parent_id, parent_history_code,
                                    parent_id_results):
    """Private method for processing child results for parent records
    that only have a single result. """
    p_id = parent_id
    p_history_code = parent_history_code
    p_id_results = parent_id_results
    p_provenance_id = int(p_id_results[0][0])
    child_hist = cursor.execute(CHILD_HIST_SELECT_QUERY %
                                (p_history_code, 'N', 'N'))
    c_results = cursor.fetchall()

    for child in c_results:
        c_id = int(child[0])
        c_uuid = int(child[2])
        c_service_id = int(child[3])
        c_category_id = int(child[4])
        c_event_id = int(child[5])
        c_username = str(child[6])
        c_createdate = int(child[7])

        c_histid_status = cursor.execute(PROV_HIST_SELECT_ID %
                                        (c_uuid, c_event_id,
                                        c_category_id,
                                        c_service_id, c_username,
                                        c_createdate))
        c_id_results = cursor.fetchall()

        if len(c_id_results) == 1:
            c_provenance_id = int(c_id_results[0][0])
            c_histid_status = cursor.execute(PROV_HIST_INSERT_ID %
                                            (c_provenance_id,
                                            p_provenance_id))
            if c_histid_status == 1:
                c_process_status = cursor.execute(
                                        PROV_HIST_UPDATE_STATUS
                                        % ('Y', c_id))
                if c_process_status == 1:
                    info_msg = ("Child row updated: [" +
                                "parent_provenance_id, " +
                                "child_provenance_id]:" +
                                "[" + str(p_id) + "," + str(c_id) +
                                "]")
                    track_history_info(info_msg)
                else:
                    err_msg = ("Failed to update child row " +
                                "status: [parent_provenance_id, " +
                                "child_provenance_id]:" + "[" +
                                str(p_id) + "," + str(c_id) + "]")
                    track_history_errors(err_msg)
                    notify_support(err_msg, SCRIPTNAME)
            else:
                err_msg = ("Failed History Recording, at child row"
                         + " [parent_provenance_id, " +
                         "child_provenance_id]:" + "[" + str(p_id)
                         + "," + str(c_id) + "]")
                track_history_errors(err_msg)
                notify_support(err_msg, SCRIPTNAME)
        else:
            err_msg = ("Error in retrieving child row from " +
                        "provenance table, multiple entries or " +
                        "no entry found. [parent_provenance_id, " +
                        "child_provenance_id]: [" + str(p_id) +
                        "," + str(c_id) + "]")
            track_history_errors(err_msg)
            notify_support(err_msg, SCRIPTNAME)

        p_process_status = cursor.execute(PROV_HIST_UPDATE_STATUS %
                                            ('Y', p_id))
        if p_process_status == 1:
            info_msg = ("History Recorded: [parent_provenance_id]:"
                        + "[" + str(p_id) + "]")
            track_history_info(info_msg)
        else:
            err_msg = ("Failed updating parent row status:" +
                        "[parent_provenance_id, " +
                        "child_provenance_id]:" + "[" + str(p_id) +
                        "," + str(c_id) + "]")
            track_history_errors(err_msg)
            notify_support(err_msg, SCRIPTNAME)
コード例 #5
0
def insert_history():
    """Handles inserting history records for provenance objects."""
    try:
        conn = MySQLdb.connect(host=PROV_DB_HOST, user=PROV_DB_USERNAME,
                                passwd=PROV_DB_PASSWORD, db=PROV_DB_NAME)
        cursor = conn.cursor()
    except:
        err_msg = "Connection failed to Provenance database."
        track_history_exceptions(err_msg)
        notify_support(err_msg, SCRIPTNAME)

    try:

        cursor.execute(PARENT_HIST_SELECT_QUERY % ('Y', 'N'))
        p_results = cursor.fetchall()

        if len(p_results) != 0:

            for parent in p_results:

                p_id = int(parent[0])
                p_history_code = str(parent[1])
                p_uuid = int(parent[2])
                p_service_id = int(parent[3])
                p_category_id = int(parent[4])
                p_event_id = int(parent[5])
                p_username = str(parent[6])
                p_createdate = int(parent[7])

                proc_return = cursor.execute(PROV_HIST_SELECT_ID % (p_uuid,
                                            p_event_id, p_category_id,
                                            p_service_id, p_username,
                                            p_createdate))
                p_id_results = cursor.fetchall()

                # parent ID results contain only 1 result record
                if len(p_id_results) == 1:
                    _process_single_parent_results(cursor, p_id,
                                                    p_history_code,
                                                    p_id_results)

                # parent ID results greater than 1 result record
                elif len(p_id_results) > 1:
                    err_msg = ("Multiple entries found for parent row. " +
                                "[parent_provenance_id]:" + "[" + str(p_id) +
                                "]")
                    track_history_exceptions(err_msg)
                    notify_support(err_msg, SCRIPTNAME)

                else:
                    err_msg = ("No entry found for parent row, but history " +
                                "tracking flag enabled. [parent_provenance_id,"
                                + "]:" + "[" + str(p_id) + "]")
                    track_history_exceptions(err_msg)
                    notify_support(err_msg, SCRIPTNAME)
        # finish up and close our cursor
        cursor.close()

    except Exception, exc:
        err_msg = ("Exception occured after establishing DB connection: " +
                    str(exc))
        track_history_exceptions(err_msg)
        notify_support(err_msg, SCRIPTNAME)
        cursor.close()
コード例 #6
0
def insert_audit():
    """<add a docstring when method is fully understood>"""
    scriptname = "Audit"

    try:
        conn = MySQLdb.connect(host=PROV_DB_HOST, user=PROV_DB_USERNAME,
                               passwd=PROV_DB_PASSWORD, db=PROV_DB_NAME,
                               port=PROV_DB_PORT)
        cursor = conn.cursor()
    except:
        err_msg = "Audit: Connection failed to Provenance database."
        track_history_exceptions(err_msg)
        notify_support(err_msg, scriptname)


    try:
        cursor.execute(AUDIT_SELECT % ('N'))
        results = cursor.fetchall()

        # inconsistent indent characters makes this even _harder_ to follow
        # THOU SHALL NOT HAVE 180+ line methods with nesting this DEEP!
        if len(results) != 0:

            for row in results:
                # Python has a built-in `id`, so use _id to avoid redefining.
                _id = int(row[0])
                uuid = int(row[1])
                service_id = int(row[2])
                category_id = int(row[3])
                event_id = int(row[4])
                username = str(row[5])
                proxy_username = str(row[6])
                event_data = str(row[7])
                request_ipaddress = str(row[8])
                created_date = int(row[9])

                all_data = "{Audit row : " + str(_id) + "}"
                # no proxy_username AND no event_data
                if proxy_username is None and event_data is None:
                    insert_status = cursor.execute(QUERY_NO_PROXY_DATA %
                                                (uuid, event_id, category_id,
                                                service_id, username,
                                                request_ipaddress,
                                                created_date))
                    if insert_status == 1:
                        update_status = cursor.execute(AUDIT_UPDATE_STATUS %
                                                        ('Y', _id))
                        if update_status == 1:
                            info_msg = "Audit Success: " + all_data
                            log_info(info_msg)
                        else:
                            err_msg = ("Audit Update: AUDIT_UPDATE_STATUS " +
                                        "query failed" + all_data)
                            log_errors(err_msg)
                            failed_inserts_audit(all_data)
                            notify_support(err_msg, scriptname)
                    else:
                        err_msg = ("Audit: QUERY_NO_PROXY_DATA query failed" +
                                    all_data)
                        log_errors(err_msg)
                        failed_inserts_audit(all_data)
                        notify_support(err_msg, scriptname)
                # no proxy_username case (inside the 'if len > 0')
                elif proxy_username != None:
                    insert_status = cursor.execute(QUERY_PROXY %
                                            (uuid, event_id, category_id,
                                            service_id, username,
                                            proxy_username, request_ipaddress,
                                            created_date))
                    if insert_status == 1:
                        update_status = cursor.execute(AUDIT_UPDATE_STATUS %
                                                        ('Y', _id))
                        if update_status == 1:
                            info_msg = "Audit Success: " + all_data
                            log_info(info_msg)
                        else:
                            err_msg = ("Audit Update: AUDIT_UPDATE_STATUS " +
                                        " query failed" + all_data)
                            log_errors(err_msg)
                            failed_inserts_audit(all_data)
                            notify_support(err_msg, scriptname)
                    else:
                        err_msg = "Audit: QUERY_PROXY query failed" + all_data
                        log_errors(err_msg)
                        failed_inserts_audit(all_data)
                        notify_support(err_msg, scriptname)
                # no event_data case (inside the 'if len > 0')
                elif event_data != None:
                    insert_status = cursor.execute(QUERY_DATA %
                                                (uuid, event_id, category_id,
                                                service_id, username,
                                                event_data, request_ipaddress,
                                                created_date))

                    if insert_status == 1:
                        update_status = cursor.execute(AUDIT_UPDATE_STATUS %
                                                        ('Y', _id))
                        if update_status == 1:
                            info_msg = "Audit Success: " + all_data
                            log_info(info_msg)
                        else:
                            err_msg = ("Audit Update: AUDIT_UPDATE_STATUS " +
                                        "query failed" + all_data)
                            log_errors(err_msg)
                            failed_inserts_audit(all_data)
                            notify_support(err_msg, scriptname)

                    else:
                        err_msg = "Audit: QUERY_DATA query failed" + all_data
                        log_errors(err_msg)
                        failed_inserts_audit(all_data)
                        notify_support(err_msg, scriptname)
                else:
                # final else block
                    insert_status = cursor.execute(QUERY_ALL %
                                                (uuid, event_id, category_id,
                                                service_id, username,
                                                proxy_username, event_data,
                                                request_ipaddress,
                                                created_date))
                    if insert_status == 1:
                        update_status = cursor.execute(AUDIT_UPDATE_STATUS %
                                                        ('Y', _id))
                        if update_status == 1:
                            info_msg = "Audit Success: " + all_data
                            log_info(info_msg)
                        else:
                            err_msg = ("Audit Update: AUDIT_UPDATE_STATUS " +
                                        "query failed" + all_data)
                            log_errors(err_msg)
                            failed_inserts_audit(all_data)
                            notify_support(err_msg, scriptname)
                    else:
                        err_msg = "Audit: QUERY_ALL query failed" + all_data
                        log_errors(err_msg)
                        failed_inserts_audit(all_data)
                        notify_support(err_msg, scriptname)

        # outside the if block ...
        cursor.close()

    except Exception, e:

        err_msg = "AUDIT EXCEPTION: " + str(e) + ": " + all_data
        log_exception(err_msg)
        failed_inserts_audit(all_data)
        notify_support(err_msg, scriptname)
        cursor.close()
コード例 #7
0
def _process_single_parent_results(cursor, parent_id, parent_history_code,
                                    parent_id_results):
    """Private method for processing child results for parent records
    that only have a single result. """
    p_id = parent_id
    p_history_code = parent_history_code
    p_id_results = parent_id_results
    p_provenance_id = int(p_id_results[0][0])
    child_hist = cursor.execute(CHILD_HIST_SELECT_QUERY %
                                (p_history_code, 'N', 'N'))
    c_results = cursor.fetchall()

    for child in c_results:
        c_id = int(child[0])
        c_uuid = int(child[2])
        c_service_id = int(child[3])
        c_category_id = int(child[4])
        c_event_id = int(child[5])
        c_username = str(child[6])
        c_createdate = int(child[7])

        c_histid_status = cursor.execute(PROV_HIST_SELECT_ID %
                                        (c_uuid, c_event_id,
                                        c_category_id,
                                        c_service_id, c_username,
                                        c_createdate))
        c_id_results = cursor.fetchall()

        if len(c_id_results) == 1:
            c_provenance_id = int(c_id_results[0][0])
            c_histid_status = cursor.execute(PROV_HIST_INSERT_ID %
                                            (c_provenance_id,
                                            p_provenance_id))
            if c_histid_status == 1:
                c_process_status = cursor.execute(
                                        PROV_HIST_UPDATE_STATUS
                                        % ('Y', c_id))
                if c_process_status == 1:
                    info_msg = ("Child row updated: [" +
                                "parent_provenance_id, " +
                                "child_provenance_id]:" +
                                "[" + str(p_id) + "," + str(c_id) +
                                "]")
                    track_history_info(info_msg)
                else:
                    err_msg = ("Failed to update child row " +
                                "status: [parent_provenance_id, " +
                                "child_provenance_id]:" + "[" +
                                str(p_id) + "," + str(c_id) + "]")
                    track_history_errors(err_msg)
                    notify_support(err_msg, SCRIPTNAME)
            else:
                err_msg = ("Failed History Recording, at child row"
                         + " [parent_provenance_id, " +
                         "child_provenance_id]:" + "[" + str(p_id)
                         + "," + str(c_id) + "]")
                track_history_errors(err_msg)
                notify_support(err_msg, SCRIPTNAME)
        else:
            err_msg = ("Error in retrieving child row from " +
                        "provenance table, multiple entries or " +
                        "no entry found. [parent_provenance_id, " +
                        "child_provenance_id]: [" + str(p_id) +
                        "," + str(c_id) + "]")
            track_history_errors(err_msg)
            notify_support(err_msg, SCRIPTNAME)

        p_process_status = cursor.execute(PROV_HIST_UPDATE_STATUS %
                                            ('Y', p_id))
        if p_process_status == 1:
            info_msg = ("History Recorded: [parent_provenance_id]:"
                        + "[" + str(p_id) + "]")
            track_history_info(info_msg)
        else:
            err_msg = ("Failed updating parent row status:" +
                        "[parent_provenance_id, " +
                        "child_provenance_id]:" + "[" + str(p_id) +
                        "," + str(c_id) + "]")
            track_history_errors(err_msg)
            notify_support(err_msg, SCRIPTNAME)
コード例 #8
0
def insert_history():
    """Handles inserting history records for provenance objects."""
    try:
        conn = MySQLdb.connect(host=PROV_DB_HOST, user=PROV_DB_USERNAME,
                               passwd=PROV_DB_PASSWORD, db=PROV_DB_NAME,
                               port=PROV_DB_PORT)
        cursor = conn.cursor()
    except:
        err_msg = "Connection failed to Provenance database."
        track_history_exceptions(err_msg)
        notify_support(err_msg, SCRIPTNAME)

    try:

        cursor.execute(PARENT_HIST_SELECT_QUERY % ('Y', 'N'))
        p_results = cursor.fetchall()

        if len(p_results) != 0:

            for parent in p_results:

                p_id = int(parent[0])
                p_history_code = str(parent[1])
                p_uuid = int(parent[2])
                p_service_id = int(parent[3])
                p_category_id = int(parent[4])
                p_event_id = int(parent[5])
                p_username = str(parent[6])
                p_createdate = int(parent[7])

                proc_return = cursor.execute(PROV_HIST_SELECT_ID % (p_uuid,
                                            p_event_id, p_category_id,
                                            p_service_id, p_username,
                                            p_createdate))
                p_id_results = cursor.fetchall()

                # parent ID results contain only 1 result record
                if len(p_id_results) == 1:
                    _process_single_parent_results(cursor, p_id,
                                                    p_history_code,
                                                    p_id_results)

                # parent ID results greater than 1 result record
                elif len(p_id_results) > 1:
                    err_msg = ("Multiple entries found for parent row. " +
                                "[parent_provenance_id]:" + "[" + str(p_id) +
                                "]")
                    track_history_exceptions(err_msg)
                    notify_support(err_msg, SCRIPTNAME)

                else:
                    err_msg = ("No entry found for parent row, but history " +
                                "tracking flag enabled. [parent_provenance_id,"
                                + "]:" + "[" + str(p_id) + "]")
                    track_history_exceptions(err_msg)
                    notify_support(err_msg, SCRIPTNAME)
        # finish up and close our cursor
        cursor.close()

    except Exception, exc:
        err_msg = ("Exception occured after establishing DB connection: " +
                    str(exc))
        track_history_exceptions(err_msg)
        notify_support(err_msg, SCRIPTNAME)
        cursor.close()