-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemby_clearactivityerror.rb
45 lines (36 loc) · 1.22 KB
/
emby_clearactivityerror.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/ruby
begin
require 'sqlite3'
rescue LoadError
puts "The 'sqlite3' gem is not installed. Installing..."
system('gem install sqlite3')
Gem.clear_paths
require 'sqlite3'
end
db_file = '/var/lib/emby/data/activitylog.db'
query = 'DELETE FROM ActivityLog WHERE LogSeverity = ?'
db = SQLite3::Database.new(db_file)
if File.exist?(db_file)
error_entries = db.execute('SELECT * FROM ActivityLog WHERE LogSeverity = ?', 'Error')
if error_entries.any?
timestamp = Time.now.strftime('%m/%d/%Y %I:%M %p')
File.open('emby_clearactivityerror.log', 'a') do |log_file|
log_file.puts("Error(s) found! Timestamp of execution: #{timestamp}")
error_entries.each do |entry|
log_timestamp = entry[5] ? Time.at(entry[5] / 1000).strftime('%m/%d/%Y %I:%M %p') : "Unknown Time"
log_file.puts("LogMessage: #{entry[1]}, LogTimeStamp: #{log_timestamp}, LogIP: #{entry[3]}")
end
end
db.execute(query, 'Error')
if db.changes > 0
puts "Deleted #{db.changes} error entries from #{db_file}."
else
puts "Failed to delete error entries from #{db_file}."
end
else
puts "No error entries found."
end
db.close
else
puts "Database file #{db_file} does not exist."
end