Commit 01466693 authored by Alex Tayts's avatar Alex Tayts
Browse files

add resolve_to and command options

parent 33705fb0
Loading
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -52,10 +52,13 @@ server_patching::validate::services:
server_patching::validate::processes:
  - name: falcond
    running: true
  - name: java
    command: solr 
server_patching::validate::urls:
  - url: https://server.stanford.edu/application-status
  - url: https://netdb.stanford.edu/status-DLK87ufdskjf
    status: 200
  - url: https://server.stanford.edu
  - url: https://netdb.stanford.edu
    resolve_to: 171.67.5.154
    status: 302
server_patching::validate::ports:
  - port: 22
+14 −10
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ Default value: `[]`

Data type: `Array[Struct[{
    'name'       => String,
    'command'    => Optional[String],
    'running'    => Optional[Boolean]}]]`

Array of hashes, where each hash describes the name of a process
@@ -141,6 +142,7 @@ Options:
* **:name** `String`: The name of the process to check.
* **:running** `Boolean`: The desired state of the process, `true` if the process should be running
or `false` if it is not supposed to. Defaults to `true`.
* **:command** `Boolean`: Search string for a command line arguments of a process.

Default value: `[]`

@@ -148,6 +150,7 @@ Default value: `[]`

Data type: `Array[Struct[{
    'url'        => Stdlib::HTTPUrl,
    'resolve_to' => Optional[Stdlib::IP::Address],
    'status'     => Optional[Integer[100,510]]}]]`

Array of hashes, where each hash describes the web URL
@@ -157,6 +160,7 @@ Options:

* **:url** `Stdlib::HTTPUrl`: The HTTP URL to check.
* **:status** `Integer`: The HTTP status code :url is expected to return. Defaults to `200`.
* **:resolve_to** `Integer`: Force the domain specified in a URL to resolve to this IP address.

Default value: `[]`

+18 −10
Original line number Diff line number Diff line
@@ -74,6 +74,9 @@
#   The desired state of the process, `true` if the process should be running
#   or `false` if it is not supposed to. Defaults to `true`.
#
# @option processes [Boolean] :command
#   Search string for a command line arguments of a process.
#
# @param urls
#   Array of hashes, where each hash describes the web URL
#   and the HTTP status code it is supposed to return
@@ -84,6 +87,9 @@
# @option urls [Integer] :status
#   The HTTP status code :url is expected to return. Defaults to `200`.
#
# @option urls [Integer] :resolve_to
#   Force the domain specified in a URL to resolve to this IP address.
#
# @param ports
#   Array of hashes, where each hash contains a port number, protocol,
#   IP protocol version (IPv4/IPv6) and whether anything is expected
@@ -122,9 +128,11 @@ class server_patching::validate (
    'active'     => Optional[Boolean]}]] $services = [],
  Array[Struct[{
    'name'       => String,
    'command'    => Optional[String],
    'running'    => Optional[Boolean]}]] $processes = [],
  Array[Struct[{
    'url'        => Stdlib::HTTPUrl,
    'resolve_to' => Optional[Stdlib::IP::Address],
    'status'     => Optional[Integer[100,510]]}]] $urls = [],
  Array[Struct[{
    'port'       => Stdlib::Port,
+6 −2
Original line number Diff line number Diff line
<%- | Array[Hash] $processes | -%>
<%- $processes.each |$process| { %>
<%- $processes.each |$process| { -%>
  <%- $desired = { true => 0, false => 1 }[$process['running']] -%>
# process <%= $process['name'] %>
pgrep <%= $process['name'] %> > /dev/null
echo -n "Process <%= $process['name'] -%>..."
<%- if 'command' in $process { -%>
pgrep -a <%= $process['name'] %> | grep <%= $process['command'] %> > /dev/null
<%- } else { -%>
pgrep <%= $process['name'] %> > /dev/null
<%- } -%>
if [ $? -eq <%= $desired %> ]; then
    echo " OK."
else
+22 −2
Original line number Diff line number Diff line
<%- | Array[Hash] $urls | -%>
<%- $urls.each |$url| { %>
<%- $urls.each |$url| { -%>
# url: <%= $url['url'] %>
status=$(curl -I -XGET --insecure -m 3 <%= $url['url'] %> 2>/dev/null | head -n 1 | cut -d' ' -f2)
<%-
if 'resolve_to' in $url {
  $pattern = '^(?:(https?):\/\/)?(?:[^@\/\n]+@)?([^:\/\n]+):?(\d+)?.*'
  $replace = 'proto: \1:domain: \2:port: \3'
  $url_data = Hash(regsubst($url['url'], $pattern, $replace, 'IG').split(':').map |$x| { $x.strip() })
  $domain = $url_data['domain']

  if $url_data['port'].empty {
    $port = $url_data['proto'] ? {
      'http'  => '80',
      'https' => '443',
      default => '443'
    }
  } else {
    $port = $url_data['port']
  }

  $resolve = " --resolve ${domain}:${port}:${url['resolve_to']}"
} else { $resolve = '' }
-%>
echo -n "Web URL <%= $url['url'] -%>..."
status=$(curl -I -XGET --insecure -m 3<%= $resolve %> <%= $url['url'] %> 2>/dev/null | head -n 1 | cut -d' ' -f2)
if [ $status -eq <%= $url['status'] %> ]; then
    echo " OK."
else