Class: Ucert::Madison535Tracker
- Inherits:
-
Object
- Object
- Ucert::Madison535Tracker
- Includes:
- Utils
- Defined in:
- lib/ucert/madison535_tracker.rb
Overview
Class to handle Madison 535 building pass user report
Instance Attribute Summary collapse
-
#file_madison535_user_map ⇒ Object
Class constant variables.
-
#madison535_2_ad_user ⇒ Object
readonly
Returns the value of attribute madison535_2_ad_user.
-
#madison535_user_access ⇒ Object
readonly
Returns the value of attribute madison535_user_access.
-
#madison535_user_access_report ⇒ Object
Class constant variables.
-
#madison535_user_access_report_2 ⇒ Object
Class constant variables.
-
#verbose ⇒ Object
Class constant variables.
Instance Method Summary collapse
-
#card_num_2_index(id) ⇒ Object
Retrieve the user index based on card number.
-
#dn_2_index(dn) ⇒ Object
Retrieve the user index from the @madison535_user_access data structure.
-
#initialize(params = {}) ⇒ Madison535Tracker
constructor
Instance default variables.
-
#madison535_search_by_dn(dn) ⇒ Object
(also: #search_by_dn)
Search user entitlement record by AD DN.
-
#parse_madison535_user_access_report_2(file = @madison535_user_access_report_2) ⇒ Object
Parsing the Madison535 user entitlement report from GO.
Methods included from Utils
#file_2_list, #is_fqdn?, #is_ip?, #is_url?, #list_2_file, #load_known_user_map_from_file, #nslookup, #search_ad, #update_dn
Constructor Details
#initialize(params = {}) ⇒ Madison535Tracker
Instance default variables
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ucert/madison535_tracker.rb', line 21 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # Madison535 user entitlement report generation: # Contact IT/GO for the Secured Access List report. Note you'll need to export the PDF report into Excel Workbook, # then scrubbing the data further, into the exact format we need here @madison535_user_access_report = File.dirname(__FILE__)+"/../../data/madison535/535madison_bldg_pass.xlsx" # This one is from GO directly @madison535_user_access_report_2 = File.dirname(__FILE__)+"/../../data/madison535/535madison_bldg_pass_2.xlsx" # Madison535 to AD user map file @file_madison535_user_map = File.dirname(__FILE__)+"/../../data/madison535/madison535_user_map.txt" @madison535_user_access = Hash.new # Load user map from the local cacsh file @madison535_2_ad_user=load_known_user_map_from_file(@file_madison535_user_map) # Read the building security report @madison535_user_access=parse_madison535_user_access_report(@madison535_user_access_report) # Procedure to add DN foreign key to the @madison535_user_access, by performing the AD search insert_dn # Read the floor security report from GO parse_madison535_user_access_report_2(@madison535_user_access_report_2) insert_dn # Save the user map to local cache file save! end |
Instance Attribute Details
#file_madison535_user_map ⇒ Object
Class constant variables
16 17 18 |
# File 'lib/ucert/madison535_tracker.rb', line 16 def file_madison535_user_map @file_madison535_user_map end |
#madison535_2_ad_user ⇒ Object (readonly)
Returns the value of attribute madison535_2_ad_user.
18 19 20 |
# File 'lib/ucert/madison535_tracker.rb', line 18 def madison535_2_ad_user @madison535_2_ad_user end |
#madison535_user_access ⇒ Object (readonly)
Returns the value of attribute madison535_user_access.
18 19 20 |
# File 'lib/ucert/madison535_tracker.rb', line 18 def madison535_user_access @madison535_user_access end |
#madison535_user_access_report ⇒ Object
Class constant variables
16 17 18 |
# File 'lib/ucert/madison535_tracker.rb', line 16 def madison535_user_access_report @madison535_user_access_report end |
#madison535_user_access_report_2 ⇒ Object
Class constant variables
16 17 18 |
# File 'lib/ucert/madison535_tracker.rb', line 16 def madison535_user_access_report_2 @madison535_user_access_report_2 end |
#verbose ⇒ Object
Class constant variables
16 17 18 |
# File 'lib/ucert/madison535_tracker.rb', line 16 def verbose @verbose end |
Instance Method Details
#card_num_2_index(id) ⇒ Object
Retrieve the user index based on card number
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/ucert/madison535_tracker.rb', line 168 def card_num_2_index (id) begin (1..@madison535_user_access.count).map do |index| return index if @madison535_user_access[index]["Card #"]==id.strip end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end |
#dn_2_index(dn) ⇒ Object
Retrieve the user index from the @madison535_user_access data structure
157 158 159 160 161 162 163 164 165 |
# File 'lib/ucert/madison535_tracker.rb', line 157 def dn_2_index (dn) begin (1..@madison535_user_access.count).map do |index| return index if @madison535_user_access[index]["DN"]==dn end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end |
#madison535_search_by_dn(dn) ⇒ Object Also known as: search_by_dn
Search user entitlement record by AD DN
258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/ucert/madison535_tracker.rb', line 258 def madison535_search_by_dn (dn) begin puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose @madison535_user_access.each do |key, val| return val if @madison535_user_access[key]['DN'].eql? dn end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end |
#parse_madison535_user_access_report_2(file = @madison535_user_access_report_2) ⇒ Object
Parsing the Madison535 user entitlement report from GO
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ucert/madison535_tracker.rb', line 92 def parse_madison535_user_access_report_2 (file=@madison535_user_access_report_2) #begin puts "Start parsing Excel workbook file: #{file}" if @verbose madison535_user_access=Hash.new workbook = RubyXL::Parser.parse(file) worksheet=workbook.worksheets.first row_cnt=0 header=Array.new user_index=@madison535_user_access.count worksheet.count.times do |row| record = Hash.new row_cnt+=1 puts "Parsing workbook row: #{row_cnt}" if @verbose entry=Array.new # Processing Header Row if row_cnt==1 1.upto(worksheet[row].size) do |col| if worksheet[row][col].nil? header.push(nil) else header.push(worksheet[row][col].value.to_s) end end next else # Processing the record 1.upto(worksheet[row].size) do |col| if worksheet[row][col].nil? entry.push(nil) else entry.push(worksheet[row][col].value.to_s.strip) end end end record = header.zip(entry).to_h.reject {|k,v| k.nil?} card_num = record["Card #"].strip my_index = card_num_2_index(card_num) puts "User record: #{record}" if @verbose puts "Card num: #{card_num}" if @verbose puts "User index: #{my_index}" if @verbose if my_index.nil? # 'new' user not found in the building security report user_index += 1 record["Company"]="CMBNY" record["DN"]=nil @madison535_user_access[user_index]=Hash.new unless @madison535_user_access.key(user_index) @madison535_user_access[user_index]=record else puts "User Index: #{user_index}" if @verbose #record["First Name"] = @madison535_user_access[my_index]["First Name"] #record["Last Name"] = @madison535_user_access[my_index]["Last Name"] record["Company"] = @madison535_user_access[my_index]["Company"] record["DN"] = @madison535_user_access[my_index]["DN"] #record["Company"] = @madison535_user_access[user_index]["Company"] @madison535_user_access[my_index] = Hash.new unless @madison535_user_access.key?(my_index) @madison535_user_access[my_index] = record end end workbook=nil #rescue => ee #puts "Exception on method #{__method__}: #{ee}" #end end |