def get_system_log(self, args): """Gets the system log. If all arguments are omitted, will return the most recent 100 entries. Optional Arguments: * `object_id` - An object_id filter to limit the results. * `object_type` - An object_type filter to limit the results. * `log_type` - A log_type filter. ('Security' or 'Object') * `action` - An action filter. * `filter` - A filter to limit the results. * `from` - a date string to set as the "from" marker. (mm/dd/yyyy format) * `to` - a date string to set as the "to" marker. (mm/dd/yyyy format) * `records` - a maximum number of results to get. Returns: A list of [Log Entry Objects](restapi/api-response-objects.html#LogEntry){:target="_blank"}. """ # this is a admin function, kick out if not api._ADMIN: return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.") out = [] rows = catocommon.get_security_log(oid=args.get("object_id"), otype=args.get("object_type"), user=args.get("user"), logtype=args.get("log_type"), action=args.get("action"), search=args.get("filter"), num_records=args.get("num_records"), _from=args.get("from"), _to=args.get("to")) if rows: logrow = {} for row in rows: logrow["LogDate"] = row["log_dt"] logrow["Action"] = row["action"] logrow["LogType"] = row["log_type"] logrow["ObjectType"] = row["object_type"] logrow["User"] = row["full_name"] logrow["ObjectID"] = row["object_id"] logrow["Log"] = row["log_msg"] out.append(logrow) if out: if args.get("output_format") == "json": return R(response=catocommon.ObjectOutput.IterableAsJSON(out)) elif args.get("output_format") == "text": return R(response=catocommon.ObjectOutput.IterableAsText(out, ["User", "Action", "LogDate", "Log"], args.get("output_delimiter"), args.get("header"))) else: return R(response=catocommon.ObjectOutput.IterableAsXML(out, "log", "item")) else: return R(err_code=R.Codes.GetError, err_detail="Error retrieving Log.")
def wmGetLog(self): sObjectID = uiCommon.getAjaxArg("sObjectID") sObjectType = uiCommon.getAjaxArg("sObjectType") sSearch = uiCommon.getAjaxArg("sSearch") sRecords = uiCommon.getAjaxArg("sRecords", "100") sFrom = uiCommon.getAjaxArg("sFrom", "") sTo = uiCommon.getAjaxArg("sTo", "") logtype = "Security" if not sObjectID and not sObjectType else "Object" rows = catocommon.get_security_log(oid=sObjectID, otype=sObjectType, logtype=logtype, search=sSearch, num_records=sRecords, _from=sFrom, _to=sTo) out = [] if rows: for row in rows: r = [] r.append(row["log_dt"]) r.append(uiCommon.packJSON(row["full_name"])) r.append(uiCommon.packJSON(uiCommon.SafeHTML(row["log_msg"]))) out.append(r) return json.dumps({"log": out})