Last active
April 20, 2017 14:42
-
-
Save Christian-G/5a7deaa617d411a4cbc31864cd906c3d to your computer and use it in GitHub Desktop.
SimpleSAMLphp log parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
class LogfileParser | |
XPATH_QUERY = "Response[@ID][@Version='2.0']" | |
SAML_XMLNS = 'urn:oasis:names:tc:SAML:2.0:assertion' | |
SAMLP_XMLNS = 'urn:oasis:names:tc:SAML:2.0:protocol' | |
def initialize(path, email) | |
raise ArgumentError unless File.exists?(path) | |
@log = File.open(path, "r") | |
@email = email | |
end | |
def read | |
buffer = false | |
lines = [] | |
@log.each_line { |line| | |
resp = line.split(/DEBUG \[[a-z0-9]*\]/)[1] | |
buffer = true if (resp && resp[/<samlp:Response xmlns/]) | |
if (resp && resp[/<\/samlp:Response>/]) | |
lines.push(resp) | |
xml = Nokogiri::XML(lines.join()) | |
xml.xpath(XPATH_QUERY, 'saml' => SAML_XMLNS, 'samlp' => SAMLP_XMLNS) | |
begin | |
xml.xpath('//saml:Attribute[@Name="TAL:user_id"]').each do |e| | |
puts e.xpath('./saml:AttributeValue').text() | |
end | |
xml.xpath('//saml:Attribute[@Name="GrouperGroups"]').each do |e| | |
puts e.xpath('./saml:AttributeValue').text() | |
end | |
rescue | |
end | |
buffer = false | |
lines = [] | |
end | |
lines.push(resp) if buffer | |
} | |
@log.close | |
end | |
end | |
p = LogfileParser.new(ARGV[0], ARGV[1]) | |
p.read() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment