Class: ZoneSetHealthCheck

Inherits:
Command
  • Object
show all
Defined in:
lib/zone_hc.rb

Instance Attribute Summary

Attributes inherited from Command

#desc, #name

Instance Method Summary collapse

Methods inherited from Command

#add_arg, #add_cmd, #add_flow, #add_flow_from_usage, #add_input, #add_option, #add_options, #command_name?, #flow_passes_parse, #flow_passes_preconditions, #get_args_used, #init, #initialize, #option_help_string, #run, #show_help, #show_help_option

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#add_hc_condObject



22
23
24
25
26
27
28
29
# File 'lib/zone_hc.rb', line 22

def add_hc_cond
  struct = @input['struct']
  if struct.has_key? 'HealthCheck'
    nil
  else
    "invalid drill down level (#{level}) for setting health check"
  end  
end

#create_argsObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/zone_hc.rb', line 2

def create_args
  add_arg('http-type', 'for HTTP or secure HTTP health checks', ['HTTP', 'HTTPs'])
  add_arg('uri', 'URI to which health checks will be directed', /.*/)
  add_arg('ip-version', 'IP version', "ip_versions")
  add_arg('check-interval', 'number of seconds between health checks', /\d+/)
  add_arg('fail-threshold', 'number of consecutive succeeds/fails for status change (1-10)', /([1-9]|10)/)
  add_arg('email-address', 'email address to which notifications will be sent', /.*/)
  add_arg('http-method', 'HTTP method for health check', 'http_methods')
  add_arg('content-verification', 'text that will be used to verify health check', /.*/)
  add_arg('reintegration-method', 'how and unhealthy server/domain will be integrated back', 'hc_rm')
  add_arg('tcp-type', 'for TCP or TCP SSL health checks', ['TCP Open', 'TCP SSL'])
  add_arg('ip-address', 'ip address to which TCP health checks will be directed (IPv4 or IPv6)', /[\d:\.]+/)
  add_arg('port', 'ip port to which TCP health checks will be directed (1-65535)', /\d+/)
end

#create_flowsObject



17
18
19
20
# File 'lib/zone_hc.rb', line 17

def create_flows
  add_flow_from_usage("<http-type> <uri> <ip-version> <check-interval> <fail-threshold> <email-address> [<http-method>='GET'] [<content-verification>] [<reintegration-method>='Automatic']", :add_hc_cond)
  add_flow_from_usage("<tcp-type> <ip-address> <port> <check-interval> <fail-threshold> <email-address> [<content-verification>] [<reintegration-method>='Automatic']", :add_hc_cond)
end

#execute(arghash, rest) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/zone_hc.rb', line 31

def execute(arghash, rest)
  struct = @input['struct']
  level = @input["level"]
  zone = @input['zone']
  @zone_struct = @input["toplevel"]
  http_type = arghash['http-type']
  if http_type
    content_verification = arghash['content-verification']
    if content_verification.nil?
      content_verification = ''
    end
    hc = {
      'CheckInterval' => arghash['check-interval'].to_i,
      'CheckTypeId' => arghash['http-type'],
      'ContentVerification' => content_verification,
      'EmailNotificationAddress' => arghash['email-address'],
      'FailedCheckThreshold' => arghash['fail-threshold'].to_i,
      'HTTPMethodId' => arghash['http-method'],
      'IPAddress' => '',
      'IPVersion' => arghash['ip-version'],
      'PortNumber' => nil,
      'ReintegrationMethodId' => arghash['reintegration-method'],
      'Status' => 4,
      'StatusName' => 'Unknown',
      'Uri' => arghash['uri']
    }
  else
    hc = {
      'CheckInterval' => arghash['check-interval'].to_i,
      'CheckTypeId' => arghash['tcp-type'],
      'ContentVerification' => content_verification,
      'EmailNotificationAddress' => arghash['email-address'],
      'FailedCheckThreshold' => arghash['fail-threshold'].to_i,
      'HTTPMethodId' => nil,
      'IPAddress' => arghash['ip-address'],
      'IPVersion' => nil,
      'PortNumber' => arghash['port'].to_i,
      'ReintegrationMethodId' => arghash['reintegration-method'],
      'Status' => 4,
      'StatusName' => 'Unknown',
      'Uri' => ''
    }
  end
  struct['HealthCheck'] = hc
  StructurePrint.new("-").structure_print(struct['HealthCheck'], level+'.HealthCheck')
  zone.write_zone_file(@zone_struct, false)
end