Module: Supermicro::Utility
- Included in:
- Client
- Defined in:
- lib/supermicro/utility.rb
Instance Method Summary collapse
- #accounts ⇒ Object
- #clear_sel_log ⇒ Object
- #create_account(username:, password:, role: "Administrator") ⇒ Object
- #delete_account(username) ⇒ Object
- #sel_log ⇒ Object
- #sel_summary(limit: 10) ⇒ Object
- #service_info ⇒ Object
- #sessions ⇒ Object
- #update_account_password(username:, new_password:) ⇒ Object
Instance Method Details
#accounts ⇒ Object
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 |
# File 'lib/supermicro/utility.rb', line 120 def accounts response = authenticated_request(:get, "/redfish/v1/AccountService/Accounts?$expand=*($levels=1)") if response.status == 200 begin data = JSON.parse(response.body) accounts = data["Members"]&.map do |account| { "id" => account["Id"], "username" => account["UserName"], "enabled" => account["Enabled"], "locked" => account["Locked"], "role_id" => account["RoleId"], "description" => account["Description"] } end || [] return accounts rescue JSON::ParserError raise Error, "Failed to parse accounts response: #{response.body}" end else raise Error, "Failed to get accounts. Status code: #{response.status}" end end |
#clear_sel_log ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/supermicro/utility.rb', line 62 def clear_sel_log puts "Clearing System Event Log...".yellow # Try to clear System health logs first response = authenticated_request( :post, "/redfish/v1/Systems/1/LogServices/Log1/Actions/LogService.ClearLog", body: {}.to_json, headers: { 'Content-Type': 'application/json' } ) if response.status == 404 # Fallback to Manager logs response = authenticated_request( :post, "/redfish/v1/Managers/1/LogServices/Log1/Actions/LogService.ClearLog", body: {}.to_json, headers: { 'Content-Type': 'application/json' } ) end if response.status.between?(200, 299) puts "SEL cleared successfully.".green return true else raise Error, "Failed to clear SEL: #{response.status} - #{response.body}" end end |
#create_account(username:, password:, role: "Administrator") ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/supermicro/utility.rb', line 147 def create_account(username:, password:, role: "Administrator") puts "Creating account #{username} with role #{role}...".yellow body = { "UserName" => username, "Password" => password, "RoleId" => role, "Enabled" => true } response = authenticated_request( :post, "/redfish/v1/AccountService/Accounts", body: body.to_json, headers: { 'Content-Type': 'application/json' } ) if response.status.between?(200, 299) puts "Account created successfully.".green return true else raise Error, "Failed to create account: #{response.status} - #{response.body}" end end |
#delete_account(username) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/supermicro/utility.rb', line 172 def delete_account(username) accounts_list = accounts account = accounts_list.find { |a| a["username"] == username } unless account raise Error, "Account #{username} not found" end puts "Deleting account #{username}...".yellow response = authenticated_request( :delete, "/redfish/v1/AccountService/Accounts/#{account["id"]}" ) if response.status.between?(200, 299) puts "Account deleted successfully.".green return true else raise Error, "Failed to delete account: #{response.status} - #{response.body}" end end |
#sel_log ⇒ Object
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 |
# File 'lib/supermicro/utility.rb', line 8 def sel_log # Supermicro uses Systems/1/LogServices/Log1/Entries for system health event logs # Try Systems log first (health events) response = authenticated_request(:get, "/redfish/v1/Systems/1/LogServices/Log1/Entries?$expand=*($levels=1)") if response.status == 200 debug "Retrieved system health event logs", 2, :green return parse_log_entries(response) elsif response.status == 404 # Fallback to Manager logs (maintenance events) debug "Systems log not found, trying Manager logs", 2, :yellow response = authenticated_request(:get, "/redfish/v1/Managers/1/LogServices/Log1/Entries?$expand=*($levels=1)") if response.status == 200 debug "Retrieved manager maintenance logs", 2, :green return parse_log_entries(response) elsif response.status == 404 debug "No log services available on this system", 1, :yellow return [] end end if response.status != 200 debug "Failed to get system logs. Status code: #{response.status}", 1, :yellow return [] end end |
#sel_summary(limit: 10) ⇒ Object
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 117 118 |
# File 'lib/supermicro/utility.rb', line 91 def sel_summary(limit: 10) puts "\n=== System Event Log ===".green entries = sel_log if entries.empty? puts "No log entries found.".yellow return entries end puts "Total entries: #{entries.length}".cyan puts "\nMost recent #{limit} entries:".cyan entries.first(limit).each do |entry| severity_color = case entry["severity"] when "Critical" then :red when "Warning" then :yellow when "OK" then :green else :white end puts "\n[#{entry['created']}] #{entry['severity']}".send(severity_color) puts " #{entry['message']}" puts " ID: #{entry['id']} | MessageID: #{entry['message_id']}" if entry['message_id'] end entries end |
#service_info ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/supermicro/utility.rb', line 249 def service_info response = authenticated_request(:get, "/redfish/v1") if response.status == 200 begin data = JSON.parse(response.body) { "service_version" => data["RedfishVersion"], "uuid" => data["UUID"], "product" => data["Product"], "vendor" => data["Vendor"], "oem" => data["Oem"] } rescue JSON::ParserError raise Error, "Failed to parse service info response: #{response.body}" end else raise Error, "Failed to get service info. Status code: #{response.status}" end end |
#sessions ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/supermicro/utility.rb', line 224 def sessions response = authenticated_request(:get, "/redfish/v1/SessionService/Sessions?$expand=*($levels=1)") if response.status == 200 begin data = JSON.parse(response.body) sessions = data["Members"]&.map do |session| { "id" => session["Id"], "username" => session["UserName"], "created_time" => session["CreatedTime"], "client_ip" => session.dig("Oem", "Supermicro", "ClientIP") || session["ClientOriginIPAddress"] } end || [] return sessions rescue JSON::ParserError raise Error, "Failed to parse sessions response: #{response.body}" end else raise Error, "Failed to get sessions. Status code: #{response.status}" end end |
#update_account_password(username:, new_password:) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/supermicro/utility.rb', line 195 def update_account_password(username:, new_password:) accounts_list = accounts account = accounts_list.find { |a| a["username"] == username } unless account raise Error, "Account #{username} not found" end puts "Updating password for account #{username}...".yellow body = { "Password" => new_password } response = authenticated_request( :patch, "/redfish/v1/AccountService/Accounts/#{account["id"]}", body: body.to_json, headers: { 'Content-Type': 'application/json' } ) if response.status.between?(200, 299) puts "Password updated successfully.".green return true else raise Error, "Failed to update password: #{response.status} - #{response.body}" end end |