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!

Published by

Konrad Fedorczyk

Konrad Fedorczyk

I'm interested in programming and gamedev. I especially luv HTML5 and everything connected to web technologies.

4 thoughts on “Parse logs for Matomo (Piwik) on Windows [using Powershell]”

  1. 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. 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. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *