You are viewing limited content. For full access, please sign in.

Question

Question

schedule audit trail reports

asked on November 20, 2023

Is there an option to generate monthly and daily reports on Laserfiche Audit trail using scheduled jobs with-out manually editing the date range in UI. The UI give option "Relative Date Range" but it doesn't work for daily reports unless the schedule runs exactly at midnight and I choose the range as one day.

I am looking for options to generate last days report using a scheduled job. 

0 0

Replies

replied on November 21, 2023 Show version history

Hi, Aju,

 

Audit Trail has not formally supported scheduled report. As a workaround, I wrote a script Update-ReportToLastDay.ps1 that modifies the date range of an existing saved report to the last day (in time zone of the machine where the script runs). Combined with the script Export-AuditReport.ps1 (mentioned in Audit Trail 11 FAQ), it is viable to work out a scheduled task that can meet your need. The basic workflow is likely to be:

 

  1. On the Audit Trail Reporting page, design a report by applying filters as desired. You can leave the "Date range" filter as it is. The filter will be replaced in Update-ReportToLastDay.ps1
  2. Use the Configure Column Display dialog box to select the columns to include in the report.
  3. Save the report and note the report ID visible from the browser address bar:

    https://ServerName/AuditTrail/reports/ABCD1234EFGH-IJKLM?lang=en&dataSource=repositoryandserver&view=table

  4. Open the Task Scheduler on Windows to create a scheduled task
  5. Use this task to run the PowerShell script with the following parameters
    Update-ReportToLastDay.ps1 -Repository "repositoryname(servername)" -ReportId "ABCD1234EFGH-IJKLM"
    Export-AuditReport.ps1 -Repository "repositoryname(servername)" -ReportId "ABCD1234EFGH-IJKLM" -ExportFile "reportfilename.xlsx"
    
  6. By default, the exported report file will be located in C:\ProgramData\Laserfiche\AuditAnalytics\Export.

 

I've tried the script Update-ReportToLastDay.ps1 on latest version (11.0.2306.3549) of Audit Trail. Note that the script relies on some Audit Trail implementation details that may not be guaranteed in future Audit Trail release.

 

Update-ReportToLastDay.ps1:

# Copyright (c) Laserfiche.

param(
  [Parameter(Mandatory=$true)]
  [string] $Repository,
  [Parameter(Mandatory=$true)]
  [string] $ReportId,
  [string] $Username,
  [SecureString] $Password,
  [string] $BaseUrl = "http://localhost/AuditTrail"
)

if(-not $BaseUrl.EndsWith("/"))
{
    $BaseUrl = "$BaseUrl/"
}

if (-not [string]::IsNullOrEmpty($Username))
{
    $credential = New-Object System.Management.Automation.PSCredential($Username, $Password)
}

if ($credential -eq $null)
{
    $savedReportResponse = Invoke-WebRequest "$($BaseUrl)api/SavedReport/Get?reportId=$($ReportId)&dataSource=$($Repository)&isDraft=false" -UseDefaultCredentials
}
else
{
    $savedReportResponse = Invoke-WebRequest "$($BaseUrl)api/SavedReport/Get?reportId=$($ReportId)&dataSource=$($Repository)&isDraft=false" -Credential $credential    
}

$startDate = (Get-Date).AddDays(-1).ToString("yyyy-MM-dd")
$endDate = (Get-Date).ToString("yyyy-MM-dd")
$timeFilter = @{
      "colDisplayName"="Event time";
      "colId"="eventTime";
      "predDisplayName"="by date";
      "predId"="IN_DATE_RANGE";
      "nodeID"=0;
      "fieldType"= "DATETIME";
      "dateRange"= @{
        "rangeType"= "RANGE";
        "startTimeObj"= @{
          "datetime"= (Get-Date -Date $startDate).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.000Z");
          "isDateValid"= $true;
          "isTimeValid"= $false;
          "utcDateString"= (Get-Date -Date $startDate).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.000Z")
        };
        "endTimeObj"= @{
          "datetime"= (Get-Date -Date $endDate).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.000Z");
          "isDateValid"= $true;
          "isTimeValid"= $false;
          "utcDateString"= (Get-Date -Date $endDate).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.000Z")
        };
        "ageInDays"=7
      };
      "escape"= $false
    }
    
$savedReport = $savedReportResponse.Content | ConvertFrom-Json
$otherPreFilters = $savedReport.preFilters | Where {$_.colId -ne "eventTime"}
if ($otherPreFilters -ne $null)
{
    $savedReport.preFilters = $otherPreFilters,$timeFilter
}
else
{
    $savedReport.preFilters[0] = $timeFilter
}

if ($credential -eq $null)
{
    Invoke-WebRequest -Method POST "$($BaseUrl)api/SavedReport/Post?reportName=$($savedReport.reportName)&reportId=$($ReportId)&shared=true&force=true&dataSource=$($Repository)" -body $($savedReport | ConvertTo-Json -Depth 20) -UseDefaultCredentials -ContentType "application/json" 
}
else
{
    Invoke-WebRequest -Method POST "$($BaseUrl)api/SavedReport/Post?reportName=$($savedReport.reportName)&reportId=$($ReportId)&shared=true&force=true&dataSource=$($Repository)" -body $($savedReport | ConvertTo-Json -Depth 20) -Credential $credential -ContentType "application/json" 
}

 

2 0
replied on November 22, 2023

Thanks Jiajun Hu, I believe this work-around will help us to automate our daily reports.

Appreciate your support!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.