Can I use "import_logs.py" for Piwik under basic auth

I try to run with “–url=http://USERNAME: PASSWORD@my-piwik-domain/piwik”.
But occured errors.

How can I use import_logs.py with authorication ID and passwd?

Hi there,

I think this feature is not implemented yet. We could add --http-user and --http-password parameters to the Log Analytics. I’ve created an issue here: Support when Piwik is behind HTTP Auth · Issue #70 · matomo-org/piwik-log-analytics · GitHub - feel free to leave a comment there as well!

Thans matt.

In case of Piwik2.9.1, we succeeded log importing under basic auth environment with inserting codes below to line#884 of import_logs.py.

username = '(User Name)'
password = '(Password)'
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, url, username, password)
opener = urllib2.build_opener(urllib2.HTTPSHandler(), urllib2.HTTPBasicAuthHandler(password_mgr))
urllib2.install_opener(opener)

Username and password is directly written in the code.

I know this is an old post, but if you want to use command line args (it did it with 2.15.0):

Before:

    option_parser.add_option(
        '--debug', '-d', dest='debug', action='count', default=0,
        help="Enable debug output (specify multiple times for more verbose)",
    )

Add:

    option_parser.add_option(
        '--auth-user', dest='auth_user',
        help="Basic auth user",
    )
    option_parser.add_option(
        '--auth-password', dest='auth_password',
        help="Basic auth password",
    )

After:

request = urllib2.Request(url + path, data, headers)

Add:

    if config.options.auth_user is not None:
        base64string = base64.encodestring('%s:%s' % (config.options.auth_user, config.options.auth_password)).replace('\n', '')
        request.add_header("Authorization", "Basic %s" % base64string)

My root crontab looks like (change paths, user, password, etc. as needed):

5 0 * * * /var/www/html/piwik/misc/log-analytics/import_logs.py --url https://www.mysite.com/piwik --auth-user=someuser --auth-password=somepassword --exclude-path=/piwik/index.php --enable-http-errors --enable-reverse-dns --idsite=1 date --date=yesterday +/var/log/apache2/access-ssl-\%Y-\%m-\%d.log > /opt/scripts/import-logs.log

At least this way you are externalizing the credentials. Then in Apache use something like:

<Location /piwik>
    AuthType basic
    AuthName "Site requires authentication"
    # Where all the external login/passwords are
    AuthUserFile /etc/apache2/somefile
    Require valid-user
</Location>

Hi @sgjava nice one! A pull request would be very welcome for this nice little change :slight_smile: GitHub - matomo-org/piwik-log-analytics: Import any kind of server logs in Piwik for powerful log analytics. Universal log file parsing and reporting.

Looks like this was finally included. I just installed the latest version, thanks!