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÷Wne)jFrXe)jG rXe!j-d\ƒne)jGZGe)jGr‰e)jF r‰ejHe)jGƒZGni e*dd]6e)jId^6e)jd_6e:d)6e/d36e8d66eGd:6e)jFd`6e=d=6eBdA6ZJyse'ƒ r e)jpþe)jK r daGHnJeeJƒZLeLjMƒeLjNƒeLjOƒe)jKrJeLjPƒn eLjQƒWn)e k r€ZRdbGeRjSGHedDƒnXedƒdS(esÖ This file contains the audit log file search utility which allows user to retrieve log entries according to the specified search criteria (i.e., from specific users, search patterns, date ranges, or query types). iÿÿÿÿN(tdatetime(tpattern_matching(t UtilError(t add_verbosity(t add_regexp(tadd_format_option_with_extras(tCaseInsensitiveChoicesOption(t audit_log(tAuditLog(t VERSION_FRMiiiisYERROR: Python version 2.7 or higher, but less than 3.0, must be used to run this utility.tMyParsercBseZd„ZRS(cCs|jS(N(tepilog(tselft formatter((s&..\utilities\scripts\mysqlauditgrep.pyt format_epilog3s(t__name__t __module__R(((s&..\utilities\scripts\mysqlauditgrep.pyR 1ss!MySQL Utilities - mysqlauditgrep s*mysqlauditgrep - audit log search utility s%prog [options] AUDIT_LOG_FILE tversiontprogramt descriptiontusagetadd_help_optiont option_classR ts--helptactionthelps"display this help message and exitsNDisplay the output in either GRID (default), TAB, CSV, VERTICAL and RAW formattraws--userss-utstoretdesttusersttypetstringtdefaultshFind log entries by user name. Accepts a comma-separated list of user names, for example: joe,sally,nicks --file-statst store_truetstatss!Display the audit log statistics.s --start-datet start_datesÉRetrieve log entries starting from the specified date/time. If not specified or the value is 0, all entries from the start of the log are displayed. Accepted formats: yyyy-mm-ddThh:mm:ss or yyyy-mm-dd.s --end-datetend_dates¼Retrieve log entries until the specified date/time.If not specified or the value is 0, all entries to the end of the log are displayed. Accepted formats: yyyy-mm-ddThh:mm:ss or yyyy-mm-dd.s-es --patterntpatterns,Search pattern to retrieve matching entries.s --query-typet query_types†Search for all SQL statements/commands from the given list of commands. Accepts a comma-separated list of commands. Supported values: s, s --event-typet event_types’Search for all recorded event types from the given list of supported log events. Accepts a comma-separated list of event types. Supported values: cCs4tjp3tjp3tjp3tjp3tjp3tjS(N(toptRR#R$R%R&R'(((s&..\utilities\scripts\mysqlauditgrep.pytexist_search_criteria†s$is4You must specify the audit log file to be processed.s2You can only process one audit log file at a time.s(The specified argument is not a file: %st0tTs%Y-%m-%dT%H:%M:%SsInvalid start date/time format s(yyyy-mm-ddThh:mm:ss): s%Y-%m-%ds(Invalid start date format (yyyy-mm-dd): sInvalid end date/time format t,s0The value for the option --users is not valid: 't'cCs |jƒS(N(tlower(tx((s&..\utilities\scripts\mysqlauditgrep.pytÎss5The value for the option --query-type is not valid: 'cCs |jƒS(N(R.(R/((s&..\utilities\scripts\mysqlauditgrep.pyR0Óss.The specified QUERY_TYPE value is not valid: 's' Supported values: cCs |jƒS(N(R.(R/((s&..\utilities\scripts\mysqlauditgrep.pyR0ßss5The value for the option --event-type is not valid: 'cCs |jƒS(N(R.(R/((s&..\utilities\scripts\mysqlauditgrep.pyR0äss.The specified EVENT_TYPE value is not valid: 's9The --pattern option is required if REGEXP option is set.tlog_namet verbositytformatt use_regexps!# # No search criteria defined. #sERROR:(ii(ii(Tt__doc__toptparsetos.pathtostsysRtmysql.utilities.commonRtmysql.utilities.exceptionRtmysql.utilities.common.optionsRRRRtmysql.utilities.commandRt!mysql.utilities.command.audit_logRtmysql.utilitiesR t version_infotexitt OptionParserR tNAMEt DESCRIPTIONtUSAGER3tpathtbasenametargvtFalsetparsert add_optiontNonetjoint QUERY_TYPESt EVENT_TYPESR)t parse_argsR(targstlentnum_argsterrortisfileR#t partitiontdatetsepttimetstrptimetsdatet ValueErrortstrftimeR$tedateRtsplittfiltert query_typesR&tmapt valid_qtstqtt event_typesR't valid_etstetR4R%tconvertSQL_LIKE2REGEXPR2toptionsR"tlogtopen_logt parse_logt close_logtshow_statisticstoutput_formatted_logteterrmsg(((s&..\utilities\scripts\mysqlauditgrep.pyts6   %                          &   &