Can't Import IIS logs


#1

I have just installed Piwik on Windows Server 2012 and this is my first attempt to import logs into Piwik. Here is what I typed on the command line:

E:\Piwik\piwik\misc\log-analytics>python import_logs.py --url=http://arf E:\logf
iles2\Intranet\ARF_net_iis05\W3SVC769991110\ex140118.log
Fatal error: Unauthorized

The “Everyone” group has full control for the logfiles2 directory.


(Matthieu Aubry) #2

Unauthorized <- do you know where does this error comes from?


#3

No, I am assuming that the message is coming from import_logs.py because of the error format. If that is what you mean. This is not a Windows OS error unless it bubbled from Windows. I am an administrator on the server and I used the administrator console.


#4

you say you used administrator acces but did you try as SU root?


#5

I am using Windows not Linux or Unix.


(Matthieu Aubry) #6

It’s not a Piwik message, it’s a windows message or some other tool. Maybe this is caused by these lines: https://github.com/piwik/piwik/blob/master/misc/log-analytics/import_logs.py#L604


#7

You referred me to a location in the import_logs.py script which references a file called updatetoken.php which does not exist on my system. I don’t know what else to do to fix this issue. I have given the “Everyone” group in Windows read and write access to all the Piwik, Python and log file directories on the server.


(Matthieu Aubry) #8

if the file updatetoken does not exist in your machine there is a problem, because it’s there in the Piwik ZIP package


#9

I upgraded Piwik from 2.0.3 to 2.1.0 and ran the import_logs.py script with the same parameters as before and it said to use the idsite parameter so here are the results.

E:\Piwik\piwik\misc\log-analytics>import_logs.py --url=http://arf E:\logfiles2\I
ntranet\ARF_net_iis05\W3SVC769991110\ex140112.log --idsite=2
Traceback (most recent call last):
File “E:\Piwik\piwik\misc\log-analytics\import_logs.py”, line 1720, in <module

resolver = config.get_resolver()

File “E:\Piwik\piwik\misc\log-analytics\import_logs.py”, line 621, in get_reso
lver
return StaticResolver(self.options.site_id)
File “E:\Piwik\piwik\misc\log-analytics\import_logs.py”, line 966, in init

'SitesManager.getSiteFromId', idSite=self.site_id

File “E:\Piwik\piwik\misc\log-analytics\import_logs.py”, line 948, in call_api

return cls._call_wrapper(cls._call_api, None, None, method, **kwargs)

File “E:\Piwik\piwik\misc\log-analytics\import_logs.py”, line 937, in _call_wr
apper
raise Piwik.Error(message)
main.Error: Unauthorized

Do you know what this means?


(Matthieu Aubry) #10

if you visit http://arf from the terminal can you see the piwik working?


#11

Piwik appears to be working. I can log into it and see the arf stats but there are none because I can’t import the log data.


#12

I have also installed Piwik on a Windows 7 desktop I used the Web Platform Installer for Windows and I get the same error messages.

C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics>import_logs.py --url=http://arf ex140112.log --idsite=1
Traceback (most recent call last):
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 1720, in
resolver = config.get_resolver()
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 621, in get_resolver
return StaticResolver(self.options.site_id)
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 966, in init
’SitesManager.getSiteFromId’, idSite=self.site_id
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 948, in call_api
return cls._call_wrapper(cls._call_api, None, None, method, **kwargs)
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 937, in _call_wrapper
raise Piwik.Error(message)
main.Error: Unauthorized


#13

I ran into this very same problem and figure out a solution to the problem. The unauthorized is actually coming from the Piwik server and its because the token auth key isn’t being sent correctly. To fix this I had to put my api key in the command line for the import_logs.py script, using the attribute --token-auth. Once I did that it fixed my problem.


#14

Using --token-auth on the command string did not work for me. This is not the real token_auth

C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics>import_logs.py --url=http://arf ex140112.log --idsite=1 -
-token-auth=833232966857b71db867105f56153397
Traceback (most recent call last):
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 1720, in
resolver = config.get_resolver()
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 621, in get_resolver
return StaticResolver(self.options.site_id)
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 966, in init
’SitesManager.getSiteFromId’, idSite=self.site_id
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 948, in call_api
return cls._call_wrapper(cls._call_api, None, None, method, **kwargs)
File “C:\Users\22015\Documents\My Web Sites\piwik\misc\log-analytics\import_logs.py”, line 937, in _call_wrapper
raise Piwik.Error(message)
main.Error: Unauthorized


#15

Found the problem !!

Enable Anonymous authentication in your IIS … edit it and choose ‘Application Pool’ instead of a specific user. If this works then you can change the Anonymous authentication to the user of your choice.

PS. You can also enable anonymous authentication only to your piwik virtual directory.


(Matthieu Aubry) #16

Hi guys, great to see you following up! I created an issue to discuss this problem: Log Analytics: on IIS Error: Unauthorized · Issue #6286 · matomo-org/matomo · GitHub


#17

I’m running on Apache, not IIS, yet, this thread seems to be the only place discussing the error output message I’m getting.

Here’s my output:


./import_logs.py --url=https://domain /var/log/other-domain/nginx-access-ssl.log --idsite=2  --token-auth=<STRING REMOVED> --log-hostname=other-domain
Traceback (most recent call last):
  File "./import_logs.py", line 1734, in <module>
    resolver = config.get_resolver()
  File "./import_logs.py", line 647, in get_resolver
    return StaticResolver(self.options.site_id)
  File "./import_logs.py", line 988, in __init__
    'SitesManager.getSiteFromId', idSite=self.site_id
  File "./import_logs.py", line 971, in call_api
    return cls._call_wrapper(cls._call_api, None, None, method, **kwargs)
  File "./import_logs.py", line 960, in _call_wrapper
    raise Piwik.Error(message)
__main__.Error: Unauthorized

I’m running:
[ul]
[li] Ubuntu 14.04
[/li][li] PHP 5.5.9
[/li][li] Apache 2.4.7
[/li][li] mysql 5.5.38
[/li][/ul]

I’ve tried running the command-line query both as root and as my apache user.

My site’s only accessible via https, I wonder if the problem is in there? My ssl cert is valid, but still. I’m running low on ideas.

--------- EDITED ---------
Sigh. So I guess following the order of command-line arguments as I saw them in some example documentation led me astray. If I put the file name to be imported as the last argument, then it seems to work… Actually, it fails, but in a reasonable, sane way. /facepalm. I’m leaving my post up to help others… I hope.


(Matthieu Aubry) #18

Sigh. So I guess following the order of command-line arguments as I saw them in some example documentation led me astray.

Oh that’d be frustrating! do you remember where you saw the wrong doc, we’d love to fix it!