Parse logs for Matomo (Piwik) on Windows [using Powershell]

Automatic log parsing on Windows machines fot Matomo (Piwik).

Once again, thanks to: Adrian Ligiewicz (aka the Master of Powershell)

Remember to setup your start location in scheduler because script won’t find json file! Also change your paths according to your setup!

Same thing for dinosaurs (using bat)

 

One of my blog visitors has contributed a code to parse logs from N days in the past.

Thanks Stick!




Comments

0 responses to “Parse logs for Matomo (Piwik) on Windows [using Powershell]”

  1. Stick Avatar
    Stick

    I was finally able to get this working, but I found that this only does for the given day. How can this be changed to parse all logs in a folder?

    1. Stick Avatar
      Stick

      I added the following to your code.

      # how many days to go back
      $PastLogs = 30
      foreach($i in 1..$PastLogs)
      {

      # Run command
      foreach ($site in $sites)
      {

      # Automatically generated vars
      $LOG_FILE=”u_ex” + (Get-Date (Get-Date).AddDays(-$i) -UFormat “%y%m%d”) + “.log”
      $LOG_PATH=”$LOGS_DIR\” + ($site).DIR + “\$LOG_FILE”

      $PY_ARGs=” $IMPORT_LOGS –url=$URL –idsite=” + ($site).ID + ” –token-auth=$TOKEN –recorders=$THREADS –enable-http-errors –enable-http-redirects –enable-static –enable-bots $LOG_PATH”
      Start-Process $PY_BIN $PY_ARGs -wait
      # Uncomment for debug:
      # $PY_ARGs
      Write-Host “Parsed log file: $LOG_PATH”
      }
      }

      1. Konrad Fedorczyk Avatar
        Konrad Fedorczyk

        Hi!
        Thanks for this great addition to my code. I’ll add this to main article content.

        1. Stick Avatar
          Stick

          Thank you for the great code! It has allowed me to have a great place to start. I now can batch load months at a time and include email notifications when the process starts and when it ends.