Module: TrainPlugins::Juniper::ErrorHandling
- Included in:
- Connection
- Defined in:
- lib/train-juniper/connection/error_handling.rb
Overview
Handles error detection, classification, and messaging
Constant Summary collapse
- JUNOS_ERRORS =
JunOS error patterns organized by type
{ configuration: [/^error:/i, /configuration database locked/i], syntax: [/syntax error/i], command: [/invalid command/i, /unknown command/i], argument: [/missing argument/i] }.freeze
- JUNOS_ERROR_PATTERNS =
Flattened error patterns for quick matching
JUNOS_ERRORS.values.flatten.freeze
Instance Method Summary collapse
-
#bastion_auth_error?(error) ⇒ Boolean
Check if error is bastion authentication related.
-
#bastion_error_message(error) ⇒ String
Build helpful bastion error message.
-
#handle_connection_error(error) ⇒ Object
Handle connection errors with helpful messages.
-
#junos_error?(output) ⇒ Boolean
Check for JunOS error patterns.
Instance Method Details
#bastion_auth_error?(error) ⇒ Boolean
Check if error is bastion authentication related
43 44 45 46 |
# File 'lib/train-juniper/connection/error_handling.rb', line 43 def bastion_auth_error?(error) @options[:bastion_host] && (error..include?('Permission denied') || error..include?('command failed')) end |
#bastion_error_message(error) ⇒ String
Build helpful bastion error message
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/train-juniper/connection/error_handling.rb', line 51 def (error) <<~ERROR Failed to connect to Juniper device #{@options[:host]} via bastion #{@options[:bastion_host]}: #{error.} Possible causes: 1. Incorrect bastion credentials (user: #{@options[:bastion_user] || @options[:user]}) 2. Network connectivity issues to bastion host 3. Bastion host SSH service not available on port #{@options[:bastion_port]} 4. Target device not reachable from bastion Authentication options: - Password: Use --bastion-password (or JUNIPER_BASTION_PASSWORD env var) - SSH Key: Use --key-files option to specify SSH private key files - SSH Agent: Ensure your SSH agent has the required keys loaded For more details, see: https://mitre.github.io/train-juniper/troubleshooting/#bastion-authentication ERROR end |
#handle_connection_error(error) ⇒ Object
Handle connection errors with helpful messages
30 31 32 33 34 35 36 37 38 |
# File 'lib/train-juniper/connection/error_handling.rb', line 30 def handle_connection_error(error) @logger.error("SSH connection failed: #{error.}") if bastion_auth_error?(error) raise Train::TransportError, (error) else raise Train::TransportError, "Failed to connect to Juniper device #{@options[:host]}: #{error.}" end end |
#junos_error?(output) ⇒ Boolean
Check for JunOS error patterns
21 22 23 24 25 |
# File 'lib/train-juniper/connection/error_handling.rb', line 21 def junos_error?(output) return false if output.nil? || output.empty? JUNOS_ERROR_PATTERNS.any? { |pattern| output.match?(pattern) } end |