|
| 1 | +#!/opt/puppetlabs/puppet/bin/ruby |
| 2 | + |
| 3 | +# st1105_master_port_check |
| 4 | +# Checks the port requirements for a puppet master and prints a short description of the port and it's status. |
| 5 | +# PE only and this is to be run against the Puppet Master. |
| 6 | + |
| 7 | +require 'socket' |
| 8 | +require 'json' |
| 9 | + |
| 10 | +destination = Socket.gethostbyname(Socket.gethostname).first |
| 11 | +portdesc = { |
| 12 | + '8140' => "The master uses this port to accept inbound traffic/requests from agents. |
| 13 | + The console sends requests to the master on this port. Certificate requests are passed over this port unless ca_port is set differently. |
| 14 | + Puppet Server status checks are sent over this port.", |
| 15 | + '443' => 'This port provides host access to the console. The console accepts HTTPS traffic from end users on this port.', |
| 16 | + '4433' => 'This port is used as a classifier/console services API endpoint. The master communicates with the console over this port.', |
| 17 | + '8081' => 'PuppetDB accepts traffic/requests on this port. The master and console send traffic to PuppetDB on this port. PuppetDB status checks are sent over this port.', |
| 18 | + '8142' => 'Orchestrator and the Run Puppet button use this port on the master of masters to accept inbound traffic/responses from agents via the Puppet Execution Protocol agent.', |
| 19 | + '8143' => 'Orchestrator uses this port to accept connections from Puppet Communications Protocol brokers to relay communications. |
| 20 | + The orchestrator client also uses this port to communicate with the orchestration services running on the master of masters. |
| 21 | + If you install the client on a workstation, this port must be available on the workstation.', |
| 22 | + '5432' => 'This port is used in a High Availability configuration to replicate data between the master and replica.', |
| 23 | + '8170' => 'Code Manager uses this port to deploy environments, run webhooks, and make API calls.', |
| 24 | +} |
| 25 | + |
| 26 | +def port_test(dest, port) |
| 27 | + begin |
| 28 | + Socket.tcp(dest, port, connect_timeout: 5) |
| 29 | + rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT |
| 30 | + return false |
| 31 | + end |
| 32 | + true |
| 33 | +end |
| 34 | + |
| 35 | +results_json = [] |
| 36 | + |
| 37 | +portdesc.keys.each do |port_no| |
| 38 | + # If port is open |
| 39 | + result = if port_test(destination, port_no) |
| 40 | + { |
| 41 | + 'destination' => destination.to_s, |
| 42 | + 'port' => port_no, |
| 43 | + 'result' => 'pass', |
| 44 | + 'description' => portdesc[port_no], |
| 45 | + } |
| 46 | + # If port is closed |
| 47 | + else |
| 48 | + { |
| 49 | + 'destination' => destination.to_s, |
| 50 | + 'port' => port_no, |
| 51 | + 'result' => 'fail', |
| 52 | + 'description' => portdesc[port_no], |
| 53 | + } |
| 54 | + end |
| 55 | + results_json << result |
| 56 | +end |
| 57 | + |
| 58 | +puts JSON.pretty_generate(results_json) |
0 commit comments