Jump to content

New Plugin - Device Locations


Recommended Posts

Posted (edited)

Device Locations Plugin for Emby

Purpose

This plugin improves observability of users accessing your server remotely. All private ipv4 and ipv6 ip addresses are ignored.

  • help understand if users are sharing their accounts with other people
  • additional stats are added to help understand device behavior
    • when are devices active? This can help tune servers during peak activity
    • which areas have the most activity? This may inform content delivery strategies
    •  which users authenticate on devices? 

Installation

  1. Download the dll and move it to the plugin directory
  2. Restart your server

Requirements

  1. Register for a free account at https://www.ip2location.io/ to obtain an API key used for enriching location data
    1. If you are using a paid account you can remove the attribution in the plugin settings, otherwise, you need to keep the attribution to remain compliant
  2. Update the plugin settings with the API key

Enriching data

There are 2 scheduled tasks that need to run before full results are available. 

  1. Sync activity data - Runs hourly and syncs Emby activity events to the plugin
  2. Enrich location data - Runs daily and enriches geoIP data to the plugin data. You can update settings to configure the max number of requests to ip2location PER run. This is useful if you're testing and/or have a significant number of authentication events (large user base, etc). The ip2location API allows 30k requests / month. 

TODO:

  • Add ipv4/ipv6 validation when sync'ing Emby data
  • Add caching when enriching data

EmbyDeviceLocations.dll

Edited by mwongjay
Add todo
  • Like 4
  • Thanks 4
Posted

Strange. The map shows a few locations, but the tasks fails:

2024-02-04 18:56:06.828 Error EmbyDeviceLocations: Error fetching location results from provider
    *** Error Report ***
    Version: 4.8.0.80
    Command line: <removed>\AppData\Roaming\Emby-Server\system\EmbyServer.dll -noautorunwebapp
    Operating system: Microsoft Windows 10.0.26040
    Framework: .NET 6.0.26
    OS/Process: x64/x64
    Runtime: <removed>/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 8
    Data path: <removed>\AppData\Roaming\Emby-Server\programdata
    Application path: <removed>\AppData\Roaming\Emby-Server\system
    MediaBrowser.Model.Net.HttpException: MediaBrowser.Model.Net.HttpException: BadRequest
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsyncInternal(HttpRequestOptions options, String httpMethod)
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsync(HttpRequestOptions options, String httpMethod)
       at EmbyDeviceLocations.Services.LocationService.EnrichGeoIPAsync(IProgress`1 progress, CancellationToken cancellationToken)
    Source: Emby.Server.Implementations
    TargetSite: Void MoveNext()
    
2024-02-04 18:56:06.829 Error TaskManager: Error
    *** Error Report ***
    Version: 4.8.0.80
    Command line: <removed>\AppData\Roaming\Emby-Server\system\EmbyServer.dll -noautorunwebapp
    Operating system: Microsoft Windows 10.0.26040
    Framework: .NET 6.0.26
    OS/Process: x64/x64
    Runtime: <removed>/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 8
    Data path: <removed>\AppData\Roaming\Emby-Server\programdata
    Application path: <removed>\AppData\Roaming\Emby-Server\system
    MediaBrowser.Model.Net.HttpException: MediaBrowser.Model.Net.HttpException: BadRequest
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsyncInternal(HttpRequestOptions options, String httpMethod)
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsync(HttpRequestOptions options, String httpMethod)
       at EmbyDeviceLocations.Services.LocationService.EnrichGeoIPAsync(IProgress`1 progress, CancellationToken cancellationToken)
       at EmbyDeviceLocations.ScheduledTasks.EnrichGeoIPTask.<>c__DisplayClass11_0.<<Execute>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
       at EmbyDeviceLocations.ScheduledTasks.EnrichGeoIPTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
       at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
    Source: Emby.Server.Implementations
    TargetSite: Void MoveNext()
    
2024-02-04 18:56:06.830 Info TaskManager: Enrich location data Failed after 0 minute(s) and 9 seconds

Posted
7 minutes ago, Dibbes said:

Strange. The map shows a few locations, but the tasks fails:

2024-02-04 18:56:06.828 Error EmbyDeviceLocations: Error fetching location results from provider
    *** Error Report ***
    Version: 4.8.0.80
    Command line: <removed>\AppData\Roaming\Emby-Server\system\EmbyServer.dll -noautorunwebapp
    Operating system: Microsoft Windows 10.0.26040
    Framework: .NET 6.0.26
    OS/Process: x64/x64
    Runtime: <removed>/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 8
    Data path: <removed>\AppData\Roaming\Emby-Server\programdata
    Application path: <removed>\AppData\Roaming\Emby-Server\system
    MediaBrowser.Model.Net.HttpException: MediaBrowser.Model.Net.HttpException: BadRequest
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsyncInternal(HttpRequestOptions options, String httpMethod)
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsync(HttpRequestOptions options, String httpMethod)
       at EmbyDeviceLocations.Services.LocationService.EnrichGeoIPAsync(IProgress`1 progress, CancellationToken cancellationToken)
    Source: Emby.Server.Implementations
    TargetSite: Void MoveNext()
    
2024-02-04 18:56:06.829 Error TaskManager: Error
    *** Error Report ***
    Version: 4.8.0.80
    Command line: <removed>\AppData\Roaming\Emby-Server\system\EmbyServer.dll -noautorunwebapp
    Operating system: Microsoft Windows 10.0.26040
    Framework: .NET 6.0.26
    OS/Process: x64/x64
    Runtime: <removed>/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 8
    Data path: <removed>\AppData\Roaming\Emby-Server\programdata
    Application path: <removed>\AppData\Roaming\Emby-Server\system
    MediaBrowser.Model.Net.HttpException: MediaBrowser.Model.Net.HttpException: BadRequest
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsyncInternal(HttpRequestOptions options, String httpMethod)
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsync(HttpRequestOptions options, String httpMethod)
       at EmbyDeviceLocations.Services.LocationService.EnrichGeoIPAsync(IProgress`1 progress, CancellationToken cancellationToken)
       at EmbyDeviceLocations.ScheduledTasks.EnrichGeoIPTask.<>c__DisplayClass11_0.<<Execute>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
       at EmbyDeviceLocations.ScheduledTasks.EnrichGeoIPTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
       at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
    Source: Emby.Server.Implementations
    TargetSite: Void MoveNext()
    
2024-02-04 18:56:06.830 Info TaskManager: Enrich location data Failed after 0 minute(s) and 9 seconds

Can you enable debug logging and run that scheduled task again? There should be a debug log with the url preceding the http request.

Posted

Server Debug Logging is on, but I don't get anything else that above:

2024-02-04 19:21:00.837 Debug EmbyDeviceLocations: EnrichGeoIPAsync - GeoIP API Url: https://api.ip2location.io/?key=<deleted>&ip=fe8<deleted>
2024-02-04 19:21:00.837 Info HttpClient: GET https://api.ip2location.io/?key=‌C35<deleted>&ip=fe8<deleted>
2024-02-04 19:21:00.926 Error EmbyDeviceLocations: Error fetching location results from provider
    *** Error Report ***
    Version: 4.8.0.80
    Command line: <deleted>\AppData\Roaming\Emby-Server\system\EmbyServer.dll -noautorunwebapp
    Operating system: Microsoft Windows 10.0.26040
    Framework: .NET 6.0.26
    OS/Process: x64/x64
    Runtime: <deleted>/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 8
    Data path: <deleted>\AppData\Roaming\Emby-Server\programdata
    Application path: <deleted>\AppData\Roaming\Emby-Server\system
    MediaBrowser.Model.Net.HttpException: MediaBrowser.Model.Net.HttpException: BadRequest
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsyncInternal(HttpRequestOptions options, String httpMethod)
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsync(HttpRequestOptions options, String httpMethod)
       at EmbyDeviceLocations.Services.LocationService.EnrichGeoIPAsync(IProgress`1 progress, CancellationToken cancellationToken)
    Source: Emby.Server.Implementations
    TargetSite: Void MoveNext()
    
2024-02-04 19:21:00.926 Error TaskManager: Error
    *** Error Report ***
    Version: 4.8.0.80
    Command line: <deleted>\AppData\Roaming\Emby-Server\system\EmbyServer.dll -noautorunwebapp
    Operating system: Microsoft Windows 10.0.26040
    Framework: .NET 6.0.26
    OS/Process: x64/x64
    Runtime: <deleted>/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 8
    Data path: <deleted>\AppData\Roaming\Emby-Server\programdata
    Application path: <deleted>\AppData\Roaming\Emby-Server\system
    MediaBrowser.Model.Net.HttpException: MediaBrowser.Model.Net.HttpException: BadRequest
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsyncInternal(HttpRequestOptions options, String httpMethod)
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsync(HttpRequestOptions options, String httpMethod)
       at EmbyDeviceLocations.Services.LocationService.EnrichGeoIPAsync(IProgress`1 progress, CancellationToken cancellationToken)
       at EmbyDeviceLocations.ScheduledTasks.EnrichGeoIPTask.<>c__DisplayClass11_0.<<Execute>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
       at EmbyDeviceLocations.ScheduledTasks.EnrichGeoIPTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
       at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
    Source: Emby.Server.Implementations
    TargetSite: Void MoveNext()
    
2024-02-04 19:21:00.926 Info TaskManager: Enrich location data Failed after 0 minute(s) and 0 seconds

It seems to work though:

image.thumb.png.3b82f3e7e680028b7a19b10c4204565a.png

image.thumb.png.c5d4dc7d04a919c0928ecd055fb9a9f0.png

image.thumb.png.b7b5edfdfaa5087a7fac79f82a570183.png

Posted (edited)
11 minutes ago, Dibbes said:

Server Debug Logging is on, but I don't get anything else that above:

2024-02-04 19:21:00.837 Debug EmbyDeviceLocations: EnrichGeoIPAsync - GeoIP API Url: https://api.ip2location.io/?key=<deleted>&ip=fe8<deleted>
2024-02-04 19:21:00.837 Info HttpClient: GET https://api.ip2location.io/?key=‌C35<deleted>&ip=fe8<deleted>
2024-02-04 19:21:00.926 Error EmbyDeviceLocations: Error fetching location results from provider
    *** Error Report ***
    Version: 4.8.0.80
    Command line: <deleted>\AppData\Roaming\Emby-Server\system\EmbyServer.dll -noautorunwebapp
    Operating system: Microsoft Windows 10.0.26040
    Framework: .NET 6.0.26
    OS/Process: x64/x64
    Runtime: <deleted>/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 8
    Data path: <deleted>\AppData\Roaming\Emby-Server\programdata
    Application path: <deleted>\AppData\Roaming\Emby-Server\system
    MediaBrowser.Model.Net.HttpException: MediaBrowser.Model.Net.HttpException: BadRequest
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsyncInternal(HttpRequestOptions options, String httpMethod)
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsync(HttpRequestOptions options, String httpMethod)
       at EmbyDeviceLocations.Services.LocationService.EnrichGeoIPAsync(IProgress`1 progress, CancellationToken cancellationToken)
    Source: Emby.Server.Implementations
    TargetSite: Void MoveNext()
    
2024-02-04 19:21:00.926 Error TaskManager: Error
    *** Error Report ***
    Version: 4.8.0.80
    Command line: <deleted>\AppData\Roaming\Emby-Server\system\EmbyServer.dll -noautorunwebapp
    Operating system: Microsoft Windows 10.0.26040
    Framework: .NET 6.0.26
    OS/Process: x64/x64
    Runtime: <deleted>/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 8
    Data path: <deleted>\AppData\Roaming\Emby-Server\programdata
    Application path: <deleted>\AppData\Roaming\Emby-Server\system
    MediaBrowser.Model.Net.HttpException: MediaBrowser.Model.Net.HttpException: BadRequest
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsyncInternal(HttpRequestOptions options, String httpMethod)
       at Emby.Server.Implementations.HttpClientManager.CoreHttpClientManager.SendAsync(HttpRequestOptions options, String httpMethod)
       at EmbyDeviceLocations.Services.LocationService.EnrichGeoIPAsync(IProgress`1 progress, CancellationToken cancellationToken)
       at EmbyDeviceLocations.ScheduledTasks.EnrichGeoIPTask.<>c__DisplayClass11_0.<<Execute>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
       at EmbyDeviceLocations.ScheduledTasks.EnrichGeoIPTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
       at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
    Source: Emby.Server.Implementations
    TargetSite: Void MoveNext()
    
2024-02-04 19:21:00.926 Info TaskManager: Enrich location data Failed after 0 minute(s) and 0 seconds

It seems to work though:

image.thumb.png.3b82f3e7e680028b7a19b10c4204565a.png

image.thumb.png.c5d4dc7d04a919c0928ecd055fb9a9f0.png

image.thumb.png.b7b5edfdfaa5087a7fac79f82a570183.png

Can you DM me the actual ipv6 address from the line below: 

2024-02-04 19:21:00.837 Debug EmbyDeviceLocations: EnrichGeoIPAsync - GeoIP API Url: https://api.ip2location.io/?key=<deleted>&ip=fe8<deleted>
The request is failing when it makes a request for that ipv6 address. Without seeing the full address I cannot understand what the issue is

Edited by mwongjay
Posted

@DibbesThe ipv6 address you sent me has a "%" in it which is not a valid ipv6 address. The sync scheduled task grabs the ip addresses from Emby's data so it appears their activity events do not validate ip addresses. I will need to account for this.

Posted
16 minutes ago, mwongjay said:

@DibbesThe ipv6 address you sent me has a "%" in it which is not a valid ipv6 address. The sync scheduled task grabs the ip addresses from Emby's data so it appears their activity events do not validate ip addresses. I will need to account for this.

I sent a direct request to ip2location with the ipv6 address and the response was "invalid ip" so I didn't think it was valid. After your message I dug deeper and it is the network interface. I will still need to remove the nic specifier before making the request. Interestingly, when I do get a response with that ip the result is:

{
    "ip": "<ommitted>",
    "country_code": "-",
    "country_name": "-",
    "region_name": "-",
    "city_name": "-",
    "latitude": null,
    "longitude": null,
    "zip_code": "-",
    "time_zone": "-",
    "asn": "-",
    "as": "-",
    "is_proxy": false
}

I have yet to see that response in my testing 

Posted
2 minutes ago, mwongjay said:

After your message I dug deeper and it is the network interface. I will still need to remove the nic specifier before making the request. Interestingly, when I do get a response with that ip the result is:

Yeah, it's a common thing on servers with multiple NICs or Virtual NICs... 

Posted

Seems to work flawlessly now... thanks

  • 1 year later...
Posted (edited)

Getting Error on Dashboard: 

Sync activity data Failed on AURORA
Running time: 0 seconds
4/10/25, 5:59 AM
Every hour when it runs.
 
Log:
2025-04-10 05:59:45.218 Info Server: http/1.1 POST http://192.168.0.16:8096/emby/ScheduledTasks/Running/cc0d6fa5b3de0d7df74f0341ddce1256?X-Emby-Client=Emby Windows&X-Emby-Device-Name=AURORA-E&X-Emby-Device-Id=720c0fc7-b5d5-4b5a-44ae-0834d2af317b&X-Emby-Client-Version=2.222.2.0&X-Emby-Token=x_secret2_x&X-Emby-Language=en-us. Source Ip: 192.168.0.16, UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0
2025-04-10 05:59:45.218 Info TaskManager: Executing Sync activity data
2025-04-10 05:59:45.218 Info Server: http/1.1 Response 204 to 192.168.0.16. Time: 0ms. POST http://192.168.0.16:8096/emby/ScheduledTasks/Running/cc0d6fa5b3de0d7df74f0341ddce1256?X-Emby-Client=Emby Windows&X-Emby-Device-Name=AURORA-E&X-Emby-Device-Id=720c0fc7-b5d5-4b5a-44ae-0834d2af317b&X-Emby-Client-Version=2.222.2.0&X-Emby-Token=x_secret2_x&X-Emby-Language=en-us
2025-04-10 05:59:45.219 Info EmbyDeviceLocations.ScheduledTasks: Starting User Device Activity Sync
2025-04-10 05:59:45.219 Debug EmbyDeviceLocations: AuthenticationRepository - Devices2 table has IpAddress col: True
2025-04-10 05:59:45.219 Debug EmbyDeviceLocations: AuthenticationRepository - SQL query to run: SELECT Devices2.Id, Devices2.ReportedName, Tokens_2.UserId, Devices2.IpAddress from Devices2 INNER JOIN Tokens_2 on Devices2.Id = Tokens_2.DeviceId WHERE Tokens_2.UserId is not null
2025-04-10 05:59:45.220 Debug EmbyDeviceLocations: AuthenticationRepository - Emby user device count: 84
2025-04-10 05:59:45.220 Debug EmbyDeviceLocations: GetActivityLogs - ActivityLog table has UserId col: False
2025-04-10 05:59:45.220 Debug EmbyDeviceLocations: GetActivityLogs - CommandText: SELECT Id, TypeId, Name, ShortOverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 0  AND ActivityLog.TypeId in (2,24) AND InternalUserId IS NOT NULL AND ShortOverview IS NOT NULL ORDER BY DateCreatedMs
2025-04-10 05:59:45.220 Info App: Sqlite: 1 - no such column: TypeId in "SELECT Id, TypeId, Name, ShortOverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 0  AND ActivityLog.TypeId in (2,24) AND InternalUserId IS NOT NULL AND Sh
2025-04-10 05:59:45.220 Error TaskManager: Error
    *** Error Report ***
    Version: 4.8.11.0
    Command line: C:\Users\gihay\AppData\Roaming\Emby-Server\system\EmbyServer.dll
    Operating system: Microsoft Windows 10.0.26200
    Framework: .NET 6.0.36
    OS/Process: x64/x64
    Runtime: C:/Users/gihay/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 12
    Data path: C:\Users\gihay\AppData\Roaming\Emby-Server\programdata
    Application path: C:\Users\gihay\AppData\Roaming\Emby-Server\system
    SQLitePCL.pretty.SQLiteException: Error: no such column: TypeId - SELECT Id, TypeId, Name, ShortOverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 0  AND ActivityLog.TypeId in (2,24) AND InternalUserId IS NOT NULL AND ShortOverview IS NOT NULL ORDER BY DateCreatedMs
    SQLitePCL.pretty.SQLiteException: Exception of type 'SQLitePCL.pretty.SQLiteException' was thrown.
       at SQLitePCL.pretty.SQLiteDatabaseConnection.PrepareStatement(String sql, ReadOnlySpan`1& tail)
       at SQLitePCL.pretty.DatabaseConnection.PrepareStatement(IDatabaseConnection This, String sql)
       at EmbyDeviceLocations.Data.ActivityLogRepository.GetActivityLogs(Int64 minDateCreatedToFetch, ActivityLogFilter filter, EmbyActivityLogType[] activityLogTypes)
       at EmbyDeviceLocations.Services.LocationService.SyncUserDeviceActivity(IProgress`1 progress, CancellationToken cancellationToken)
       at EmbyDeviceLocations.ScheduledTasks.SyncDeviceActivityTask.<>c__DisplayClass11_0.<Execute>b__0()
       at System.Threading.Tasks.Task.InnerInvoke()
       at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location ---
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    --- End of stack trace from previous location ---
       at EmbyDeviceLocations.ScheduledTasks.SyncDeviceActivityTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
       at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
    Source: SQLitePCL.pretty
    TargetSite: SQLitePCL.pretty.IStatement PrepareStatement(System.String, System.ReadOnlySpan`1[System.Byte] ByRef)
    
2025-04-10 05:59:45.220 Info TaskManager: Sync activity data Failed after 0 minute(s) and 0 seconds
2025-04-10 05:59:45.638 Info Server: http/1.1 POST http://192.168.0.16:8096/emby/Sessions/Playing/Progress?X-Emby-Client=Emby for Android&X-Emby-Device-Name=SM-S918U&X-Emby-Device-Id=8fb07d30367857ac&X-Emby-Client-Version=3.4.36&X-Emby-Token=x_secret1_x&X-Emby-Language=en-us&reqformat=json. Source Ip: host1, UserAgent: Mozilla/5.0 (Linux; Android 14; SM-S918U Build/UP1A.231005.007; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/134.0.6998.135 Mobile Safari/537.36
 
I am running EMBY  Version 4.8.11.0  and the latest posted version of your plugin.
 Is there something I need to do?
Edited by gihayes
darkassassin07
Posted

Gave this a shot and have the same error.

Fresh pluggin install with no previous data, server v4.8.11.0.

Just tried to run the first 'sync activity data' task and got:

 

2025-04-10 07:36:16.732 Info EmbyDeviceLocations.ScheduledTasks: Starting User Device Activity Sync
2025-04-10 07:36:16.737 Info EmbyDeviceLocations: Opening read connection
2025-04-10 07:36:16.737 Info EmbyDeviceLocations: Default journal_mode for /config/data/authentication.db is delete
2025-04-10 07:36:16.741 Info EmbyDeviceLocations: Opening read connection
2025-04-10 07:36:16.741 Info EmbyDeviceLocations: Default journal_mode for /config/data/activitylog.db is delete
2025-04-10 07:36:16.742 Info App: Sqlite: 1 - no such column: TypeId in "SELECT Id, TypeId, Name, ShortOverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 0  AND ActivityLog.TypeId in (2,24) AND InternalUserId IS NOT NULL AND Sh
2025-04-10 07:36:16.746 Error TaskManager: Error
	*** Error Report ***
	Version: 4.8.11.0
	Command line: /system/EmbyServer.dll -programdata /config -ffdetect /bin/ffdetect -ffmpeg /bin/ffmpeg -ffprobe /bin/ffprobe -restartexitcode 3
	Operating system: Linux version 6.1.0-18-amd64 (debian-kernel@lists.debian.org) (gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT
	Framework: .NET 6.0.36
	OS/Process: x64/x64
	Runtime: system/System.Private.CoreLib.dll
	Processor count: 12
	Data path: /config
	Application path: /system
	SQLitePCL.pretty.SQLiteException: Error: no such column: TypeId - SELECT Id, TypeId, Name, ShortOverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 0  AND ActivityLog.TypeId in (2,24) AND InternalUserId IS NOT NULL AND ShortOverview IS NOT NULL ORDER BY DateCreatedMs
	SQLitePCL.pretty.SQLiteException: Exception of type 'SQLitePCL.pretty.SQLiteException' was thrown.
	   at SQLitePCL.pretty.SQLiteDatabaseConnection.PrepareStatement(String sql, ReadOnlySpan`1& tail)
	   at SQLitePCL.pretty.DatabaseConnection.PrepareStatement(IDatabaseConnection This, String sql)
	   at EmbyDeviceLocations.Data.ActivityLogRepository.GetActivityLogs(Int64 minDateCreatedToFetch, ActivityLogFilter filter, EmbyActivityLogType[] activityLogTypes)
	   at EmbyDeviceLocations.Services.LocationService.SyncUserDeviceActivity(IProgress`1 progress, CancellationToken cancellationToken)
	   at EmbyDeviceLocations.ScheduledTasks.SyncDeviceActivityTask.<>c__DisplayClass11_0.<Execute>b__0()
	   at System.Threading.Tasks.Task.InnerInvoke()
	   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
	--- End of stack trace from previous location ---
	   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
	--- End of stack trace from previous location ---
	   at EmbyDeviceLocations.ScheduledTasks.SyncDeviceActivityTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
	   at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
	Source: SQLitePCL.pretty
	TargetSite: SQLitePCL.pretty.IStatement PrepareStatement(System.String, System.ReadOnlySpan`1[System.Byte] ByRef)
	
2025-04-10 07:36:16.746 Info TaskManager: Sync activity data Failed after 0 minute(s) and 0 seconds

 

mwongjay
Posted

There were some backwards compatibility issues with a couple queries. Thanks to @darkassassin07for helping test the plugin! Working version that accounts for schema changes and different activity log types.

EmbyDeviceLocations.dll

  • Like 1
mwongjay
Posted
On 4/10/2025 at 7:15 AM, gihayes said:

Getting Error on Dashboard: 

Sync activity data Failed on AURORA
Running time: 0 seconds
4/10/25, 5:59 AM
Every hour when it runs.
 
Log:
2025-04-10 05:59:45.218 Info Server: http/1.1 POST http://192.168.0.16:8096/emby/ScheduledTasks/Running/cc0d6fa5b3de0d7df74f0341ddce1256?X-Emby-Client=Emby Windows&X-Emby-Device-Name=AURORA-E&X-Emby-Device-Id=720c0fc7-b5d5-4b5a-44ae-0834d2af317b&X-Emby-Client-Version=2.222.2.0&X-Emby-Token=x_secret2_x&X-Emby-Language=en-us. Source Ip: 192.168.0.16, UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0
2025-04-10 05:59:45.218 Info TaskManager: Executing Sync activity data
2025-04-10 05:59:45.218 Info Server: http/1.1 Response 204 to 192.168.0.16. Time: 0ms. POST http://192.168.0.16:8096/emby/ScheduledTasks/Running/cc0d6fa5b3de0d7df74f0341ddce1256?X-Emby-Client=Emby Windows&X-Emby-Device-Name=AURORA-E&X-Emby-Device-Id=720c0fc7-b5d5-4b5a-44ae-0834d2af317b&X-Emby-Client-Version=2.222.2.0&X-Emby-Token=x_secret2_x&X-Emby-Language=en-us
2025-04-10 05:59:45.219 Info EmbyDeviceLocations.ScheduledTasks: Starting User Device Activity Sync
2025-04-10 05:59:45.219 Debug EmbyDeviceLocations: AuthenticationRepository - Devices2 table has IpAddress col: True
2025-04-10 05:59:45.219 Debug EmbyDeviceLocations: AuthenticationRepository - SQL query to run: SELECT Devices2.Id, Devices2.ReportedName, Tokens_2.UserId, Devices2.IpAddress from Devices2 INNER JOIN Tokens_2 on Devices2.Id = Tokens_2.DeviceId WHERE Tokens_2.UserId is not null
2025-04-10 05:59:45.220 Debug EmbyDeviceLocations: AuthenticationRepository - Emby user device count: 84
2025-04-10 05:59:45.220 Debug EmbyDeviceLocations: GetActivityLogs - ActivityLog table has UserId col: False
2025-04-10 05:59:45.220 Debug EmbyDeviceLocations: GetActivityLogs - CommandText: SELECT Id, TypeId, Name, ShortOverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 0  AND ActivityLog.TypeId in (2,24) AND InternalUserId IS NOT NULL AND ShortOverview IS NOT NULL ORDER BY DateCreatedMs
2025-04-10 05:59:45.220 Info App: Sqlite: 1 - no such column: TypeId in "SELECT Id, TypeId, Name, ShortOverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 0  AND ActivityLog.TypeId in (2,24) AND InternalUserId IS NOT NULL AND Sh
2025-04-10 05:59:45.220 Error TaskManager: Error
    *** Error Report ***
    Version: 4.8.11.0
    Command line: C:\Users\gihay\AppData\Roaming\Emby-Server\system\EmbyServer.dll
    Operating system: Microsoft Windows 10.0.26200
    Framework: .NET 6.0.36
    OS/Process: x64/x64
    Runtime: C:/Users/gihay/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
    Processor count: 12
    Data path: C:\Users\gihay\AppData\Roaming\Emby-Server\programdata
    Application path: C:\Users\gihay\AppData\Roaming\Emby-Server\system
    SQLitePCL.pretty.SQLiteException: Error: no such column: TypeId - SELECT Id, TypeId, Name, ShortOverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 0  AND ActivityLog.TypeId in (2,24) AND InternalUserId IS NOT NULL AND ShortOverview IS NOT NULL ORDER BY DateCreatedMs
    SQLitePCL.pretty.SQLiteException: Exception of type 'SQLitePCL.pretty.SQLiteException' was thrown.
       at SQLitePCL.pretty.SQLiteDatabaseConnection.PrepareStatement(String sql, ReadOnlySpan`1& tail)
       at SQLitePCL.pretty.DatabaseConnection.PrepareStatement(IDatabaseConnection This, String sql)
       at EmbyDeviceLocations.Data.ActivityLogRepository.GetActivityLogs(Int64 minDateCreatedToFetch, ActivityLogFilter filter, EmbyActivityLogType[] activityLogTypes)
       at EmbyDeviceLocations.Services.LocationService.SyncUserDeviceActivity(IProgress`1 progress, CancellationToken cancellationToken)
       at EmbyDeviceLocations.ScheduledTasks.SyncDeviceActivityTask.<>c__DisplayClass11_0.<Execute>b__0()
       at System.Threading.Tasks.Task.InnerInvoke()
       at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location ---
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    --- End of stack trace from previous location ---
       at EmbyDeviceLocations.ScheduledTasks.SyncDeviceActivityTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
       at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
    Source: SQLitePCL.pretty
    TargetSite: SQLitePCL.pretty.IStatement PrepareStatement(System.String, System.ReadOnlySpan`1[System.Byte] ByRef)
    
2025-04-10 05:59:45.220 Info TaskManager: Sync activity data Failed after 0 minute(s) and 0 seconds
2025-04-10 05:59:45.638 Info Server: http/1.1 POST http://192.168.0.16:8096/emby/Sessions/Playing/Progress?X-Emby-Client=Emby for Android&X-Emby-Device-Name=SM-S918U&X-Emby-Device-Id=8fb07d30367857ac&X-Emby-Client-Version=3.4.36&X-Emby-Token=x_secret1_x&X-Emby-Language=en-us&reqformat=json. Source Ip: host1, UserAgent: Mozilla/5.0 (Linux; Android 14; SM-S918U Build/UP1A.231005.007; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/134.0.6998.135 Mobile Safari/537.36
 
I am running EMBY  Version 4.8.11.0  and the latest posted version of your plugin.
 Is there something I need to do?

Try the latest version and let me know if that fixes it for you

  • Thanks 1
Posted
On 4/11/2025 at 10:32 AM, mwongjay said:

Try the latest version and let me know if that fixes it for you

It works! Great! Thanks 👍

Posted

Trying to use this on a Synology NAS but not seeing anything pop up on the screen after the scheduled tasks run:

Here's the log:

2025-04-17 16:25:51.657 Info TaskManager: Executing Enrich location data
2025-04-17 16:25:51.657 Info Server: http/1.1 Response 204 to host1. Time: 1ms. POST http://192.168.0.2:8096/emby/ScheduledTasks/Running/[masked]?X-Emby-Client=Emby Web&X-Emby-Device-Name=Chrome Windows&X-Emby-Device-Id=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEyMC4wLjAuMCBTYWZhcmkvNTM3LjM2fDE3MDMzNDE5NjkzNDc1&X-Emby-Client-Version=4.8.11.0&X-Emby-Token=x_secret1_x&X-Emby-Language=en-us
2025-04-17 16:25:51.658 Info EmbyDeviceLocations.ScheduledTasks: Starting enrich GeoIP
2025-04-17 16:25:51.658 Debug EmbyDeviceLocations: EnrichGeoIPAsync - Successfully enriched 0 locations
2025-04-17 16:25:51.658 Info EmbyDeviceLocations.ScheduledTasks: Finished enrich GeoIP
2025-04-17 16:25:51.658 Info TaskManager: Enrich location data Completed after 0 minute(s) and 0 seconds

And here's what I am seeing on the scheduled task:

image.png.a7d963efb431069bec94a82f02754583.png

And finally my map:

image.thumb.png.3bfc74d431ec4678dd1f53ca3a3defa1.png

Any suggestions on what I am doing wrong?

darkassassin07
Posted

The enrich task had no data to work with. Did you run the sync, then run the enrich?

 

The times in the screenshot show sync task was run afterwards.

Posted

Ran it in the order you said, no change:

image.png.1a328c85cb9e606e3d24f224bf0e6a1b.png

mwongjay
Posted (edited)
On 4/17/2025 at 5:11 PM, Jator said:

Trying to use this on a Synology NAS but not seeing anything pop up on the screen after the scheduled tasks run:

Here's the log:

2025-04-17 16:25:51.657 Info TaskManager: Executing Enrich location data
2025-04-17 16:25:51.657 Info Server: http/1.1 Response 204 to host1. Time: 1ms. POST http://192.168.0.2:8096/emby/ScheduledTasks/Running/[masked]?X-Emby-Client=Emby Web&X-Emby-Device-Name=Chrome Windows&X-Emby-Device-Id=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEyMC4wLjAuMCBTYWZhcmkvNTM3LjM2fDE3MDMzNDE5NjkzNDc1&X-Emby-Client-Version=4.8.11.0&X-Emby-Token=x_secret1_x&X-Emby-Language=en-us
2025-04-17 16:25:51.658 Info EmbyDeviceLocations.ScheduledTasks: Starting enrich GeoIP
2025-04-17 16:25:51.658 Debug EmbyDeviceLocations: EnrichGeoIPAsync - Successfully enriched 0 locations
2025-04-17 16:25:51.658 Info EmbyDeviceLocations.ScheduledTasks: Finished enrich GeoIP
2025-04-17 16:25:51.658 Info TaskManager: Enrich location data Completed after 0 minute(s) and 0 seconds

And here's what I am seeing on the scheduled task:

image.png.a7d963efb431069bec94a82f02754583.png

And finally my map:

image.thumb.png.3bfc74d431ec4678dd1f53ca3a3defa1.png

Any suggestions on what I am doing wrong?

The plugin only captures user authentication events for devices having a non-private ipv4 or ipv6 address. Make sure the devices you are expecting to see aren’t connected via a vpn or tunnel where they would be handed an ip address in a private subnet range. Then have a user log out and log in on that device that is outside your internal network. As for the scheduled tasks the geo ip enriching only enriches existing activity log events so running it before the activity sync won’t cause a problem if the logs aren’t synced per say it just won’t show the results until after each activity sync which occurs hourly. Based on the current behavior it appears likely you do not have authentication events having an external ip and therefore no data to enrich. 

Edited by mwongjay
seanbuff
Posted
56 minutes ago, mwongjay said:

Based on the current behavior it appears likely you do not have authentication events having an external ip and therefore no data to enrich.

I'm seeing a similar thing, I installed this plugin just over a week ago and have plenty of remote IPv4 authentications daily.

There are lots of events plotted by hour:
image.thumb.png.52f903adf484e376922a3d9498804354.png

But Location Activity is blank:
image.thumb.png.0c6220a302e374f37ecd61afa58240ce.png

API key has been added successfully, but Scheduled tasks complete in 0 secs

image.png.0645148c0df16f604c557d960ecef12e.png


I'm running the latest Beta server if that makes a difference ...

mwongjay
Posted
12 hours ago, seanbuff said:

I'm seeing a similar thing, I installed this plugin just over a week ago and have plenty of remote IPv4 authentications daily.

There are lots of events plotted by hour:
image.thumb.png.52f903adf484e376922a3d9498804354.png

But Location Activity is blank:
image.thumb.png.0c6220a302e374f37ecd61afa58240ce.png

API key has been added successfully, but Scheduled tasks complete in 0 secs

image.png.0645148c0df16f604c557d960ecef12e.png


I'm running the latest Beta server if that makes a difference ...

I started looking into this a bit further and discovered Emby has changed where ip addresses are stored in recent beta versions. The last log activity in my own db having a successful cross reference lookup was 3/30/2025 so a release after that date includes this change. If you have been operating Emby prior to this update in April and have non-private ipv4/6 addresses that aren't showing up you can enable debug logging and run the scheduled tasks to get additional logging information that might help identify what's going on. Meanwhile I'll need to get another version out that accounts for the latest change.

mwongjay
Posted

Update to address changes in beta version 4.9.0.43+

  • Merge source fields containing ip addresses
  • Update ipv4 and ipv6 regex to support new overview format

EmbyDeviceLocations.dll

mwongjay
Posted (edited)

@seanbuff@JatorLet me know if this latest version changes the behavior you were seeing on your server

Edited by mwongjay
  • Thanks 1
darkassassin07
Posted (edited)

@mwongjay

Nothing is ever simple, lol.

 

Emby server v4.8.11.0

 

2025-04-20 08:44:43.524 Info EmbyDeviceLocations.ScheduledTasks: Starting User Device Activity Sync
2025-04-20 08:44:43.529 Info EmbyDeviceLocations: Opening read connection
2025-04-20 08:44:43.530 Info EmbyDeviceLocations: Default journal_mode for /config/data/authentication.db is delete
2025-04-20 08:44:43.537 Info EmbyDeviceLocations: Opening read connection
2025-04-20 08:44:43.537 Info EmbyDeviceLocations: Default journal_mode for /config/data/activitylog.db is delete
2025-04-20 08:44:43.538 Info App: Sqlite: 1 - no such function: CONCAT in "SELECT Id, Type, Name, CONCAT(ShortOverview, Overview) as COverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 1744869745737  AND ActivityLog.Type in ('A
2025-04-20 08:44:43.545 Error TaskManager: Error
	*** Error Report ***
	Version: 4.8.11.0
	Command line: /system/EmbyServer.dll -programdata /config -ffdetect /bin/ffdetect -ffmpeg /bin/ffmpeg -ffprobe /bin/ffprobe -restartexitcode 3
	Operating system: Linux version 6.1.0-18-amd64 (debian-kernel@lists.debian.org) (gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT
	Framework: .NET 6.0.36
	OS/Process: x64/x64
	Runtime: system/System.Private.CoreLib.dll
	Processor count: 12
	Data path: /config
	Application path: /system
	SQLitePCL.pretty.SQLiteException: Error: no such function: CONCAT - SELECT Id, Type, Name, CONCAT(ShortOverview, Overview) as COverview, DateCreatedMs, InternalUserId from ActivityLog WHERE DateCreatedMs > 1744869745737  AND ActivityLog.Type in ('AuthenticationSucceeded','user.authenticated') AND InternalUserId IS NOT NULL AND LENGTH(COverview) > 0 ORDER BY DateCreatedMs
	SQLitePCL.pretty.SQLiteException: Exception of type 'SQLitePCL.pretty.SQLiteException' was thrown.
	   at SQLitePCL.pretty.SQLiteDatabaseConnection.PrepareStatement(String sql, ReadOnlySpan`1& tail)
	   at SQLitePCL.pretty.DatabaseConnection.PrepareStatement(IDatabaseConnection This, String sql)
	   at EmbyDeviceLocations.Data.ActivityLogRepository.GetActivityLogs(Int64 minDateCreatedToFetch, ActivityLogFilter filter, EmbyActivityLogType[] activityLogTypes)
	   at EmbyDeviceLocations.Services.LocationService.SyncUserDeviceActivity(IProgress`1 progress, CancellationToken cancellationToken)
	   at EmbyDeviceLocations.ScheduledTasks.SyncDeviceActivityTask.<>c__DisplayClass11_0.<Execute>b__0()
	   at System.Threading.Tasks.Task.InnerInvoke()
	   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
	--- End of stack trace from previous location ---
	   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
	--- End of stack trace from previous location ---
	   at EmbyDeviceLocations.ScheduledTasks.SyncDeviceActivityTask.Execute(CancellationToken cancellationToken, IProgress`1 progress)
	   at Emby.Server.Implementations.ScheduledTasks.ScheduledTaskWorker.ExecuteInternal(TaskOptions options)
	Source: SQLitePCL.pretty
	TargetSite: SQLitePCL.pretty.IStatement PrepareStatement(System.String, System.ReadOnlySpan`1[System.Byte] ByRef)
	
2025-04-20 08:44:43.545 Info TaskManager: Sync activity data Failed after 0 minute(s) and 0 seconds

 

 

/edit;  v4.9.0.30 throws the same error.

Edited by darkassassin07

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...