class Ucert::AixTracker
Class to handle AIX user account IDs
Attributes
aix_2_ad_user[R]
aix_passwd_file_list[RW]
Class constant variables
aix_passwd_files[RW]
Class constant variables
aix_user_entitlement[R]
aix_user_status_report[RW]
Class constant variables
file_aix_user_map[RW]
Class constant variables
verbose[RW]
Class constant variables
Public Class Methods
new(params ={})
click to toggle source
Instance default variables
# File lib/ucert/aix_tracker.rb, line 19 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # AIX user entitlement report generation: # Contact IT Department to provide a copy of the ''/etc/passwd' file on each AIX system # rename the 'passwd' file to 'hostname.txt' and send them to us. # # define a list of AIX password files that we'll need to obain and upload to the server here @aix_passwd_file_list=["EGIFTS1.txt", "NYSWIFT1.txt", "T24_APP1.txt", "T24_DBP.txt"] @aix_passwd_files = @aix_passwd_file_list.map {|x| File.dirname(__FILE__) + "/../../data/aix/" + x} # AIX to AD user map file @file_aix_user_map = File.dirname(__FILE__)+"/../../data/aix/aix_user_map.txt" # Load user map from the local cacsh file @aix_2_ad_user=load_known_user_map_from_file(@file_aix_user_map) # Load the user entitlement instance variable from the user report @aix_user_entitlement=parse_aix_passwd_files(@aix_passwd_files) # Procedure to add DN foreign key to the @aix_user_entitlement, by performing the AD search insert_dn # Save the user map to local cache file save! end
Public Instance Methods
db_search_by_dn(dn)
click to toggle source
Search user entitlement record by AD DN
# File lib/ucert/aix_tracker.rb, line 160 def db_search_by_dn (dn) begin puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose @aix_user_entitlement.each do |key, val| return val if @aix_user_entitlement[key]['DN'].eql? dn end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: search_by_dn
dn_2_index(dn)
click to toggle source
Retrieve the user index from the @aix_user_entitlement data structure
# File lib/ucert/aix_tracker.rb, line 83 def dn_2_index (dn) begin (1..@aix_user_entitlement.count).map do |index| return index if @aix_user_entitlement[index]["DN"]==dn end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Private Instance Methods
insert_dn()
click to toggle source
Procedures to add additonal field 'dn' into the @aix_user_entitlement data structure, by perform the AD search
# File lib/ucert/aix_tracker.rb, line 94 def insert_dn begin tracker = Ucert::AdTracker.new(:verbose=>false) @aix_user_entitlement.each do |index, record| puts "\n\nPerform DN lookup for record: #{record}" if @verbose key1 = record["username"] my_key = record["username"] puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @aix_2_ad_user.key?(my_key) dn=@aix_2_ad_user[my_key] # additional logic to update the existing DN record unless tracker.ad_person_records.key?(dn) dn = update_dn(tracker,dn) end puts "Found in the local cache file: #{dn}" if @verbose else if dn.nil? and !key1.nil? puts "Perform 2nd order search only if the 1st one fail, by using: #{key1}" if @verbose dn = tracker.ad_search_by_text(key1, "person") puts "Found: #{dn}" unless dn.nil? if @verbose end end @aix_user_entitlement[index]['DN'] = dn end tracker=nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
parse_aix_passwd_files(files)
click to toggle source
Parsing the db Access user entitlement report in text format
# File lib/ucert/aix_tracker.rb, line 41 def parse_aix_passwd_files (files) begin puts "Parse the user entitlement report: #{files}" if @verbose aix_user_entitlement=Hash.new files.map do |file| hostname=file.split("/").last.split(".")[0] puts "\nProcessing file: #{file}, for host: #{hostname}" if @verbose user_index=String.new line_cnt=0 doc = File.open(file,'r') doc.each_line do |line| #aix_user_entitlement[user_index]=Hash.new unless aix_user_entitlement.key?(user_index) line_cnt+=1 line.chomp! puts "Line number: #{line_cnt}, line: #{line}" if @verbose if line.include?":" user_index=line.split(":")[0].strip puts "User: #{user_index}" if @verbose aix_user_entitlement[user_index]=Hash.new unless aix_user_entitlement.key?(user_index) aix_user_entitlement[user_index]["username"]=user_index unless aix_user_entitlement[user_index]["username"] aix_user_entitlement[user_index]["accesses"]=Hash.new unless aix_user_entitlement[user_index]["accesses"] aix_user_entitlement[user_index]["accesses"][hostname]=Hash.new unless aix_user_entitlement[user_index]["accesses"].key?(hostname) aix_user_entitlement[user_index]["accesses"][hostname].merge!({"hostname"=>hostname}) aix_user_entitlement[user_index]["accesses"][hostname].merge!({"username"=>user_index}) next end if line.include?"=" entry=line.split("=") k=entry[0].strip v=entry[1].strip aix_user_entitlement[user_index]["accesses"][hostname].merge!({k=>v}) end end doc=nil end return aix_user_entitlement rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
print_user_entitlement()
click to toggle source
Print out the user entitlement table in plain text, to be imported into database
# File lib/ucert/aix_tracker.rb, line 125 def print_user_entitlement begin puts "user Entitlement Report in Plain-text Format" if @verbose @aix_user_entitlement.first[1].each {|k,v| print k,"|"} if @verbose puts if @verbose @aix_user_entitlement.values.map do |rec| rec.each {|k,v| print v,"|"} puts end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: print_user
save_aix_user_map!(file=@file_aix_user_map)
click to toggle source
Save the Prime to AD user mapping relation into the cache file
# File lib/ucert/aix_tracker.rb, line 141 def save_aix_user_map!(file=@file_aix_user_map) puts "Saving the known AIX to AD user mapping relationship to file: #{file} ..." if @verbose begin timestamp=Time.now f=File.open(file, 'w') f.write "# local AIX to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}" @aix_user_entitlement.each do |key, record| value = record['DN'] f.write "\n#{key}|#{value}" end f.close puts "AIX to AD user map file is successfully saved to: #{file}" if @verbose rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose end end
Also aliased as: save!