Class: OptparseNagiosProbe
- Inherits:
-
Object
- Object
- OptparseNagiosProbe
- Defined in:
- lib/probe/optparse_nagios_probe.rb
Overview
OptparseNagiosProbe - opennebula-nagios probes ARGV parser class.
Constant Summary collapse
- VERSION =
0.99
Class Method Summary collapse
Class Method Details
.parse(args) ⇒ Object
24 25 26 27 28 29 30 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 78 79 80 81 82 83 84 85 86 87 88 89 90 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 119 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/probe/optparse_nagios_probe.rb', line 24 def self.parse(args) = OpenStruct.new .debuglevel = 0 .hostname = 'localhost' .port = 2633 .path = '/' .protocol = :http .username = 'oneadmin' .password = 'onepass' .service = :oned .occi = :occi .timeout = 60 .user_cred = nil .voms = false opts_ = OptionParser.new do |opts| opts. = 'Usage: check_opennebula.rb [options]' opts.separator '' opts.separator 'Connection options:' opts.on('--protocol [http|https]', [:http, :https], "Protocol to use, defaults to 'http'") do |protocol| .protocol = protocol end opts.on('--hostname [HOSTNAME]', String, "Host to be queried, defaults to 'localhost'") do |hostname| .hostname = hostname end opts.on('--port [PORT_NUMBER]', Integer, "Port to be queried, defaults to '2633'") do |port| .port = port end opts.on('--path [PATH]', String, 'Path to the service endpoint'\ + "(the last part of the URI, should always start with a slash), defaults to '/'") do |path| .path = path end opts.on('--username [USERNAME]', String, 'Username for authentication purposes, '\ + "defaults to 'oneadmin'") do |username| .username = username end opts.on('--password [PASSWORD]', String, 'Password for authentication purposes, '\ + "defaults to 'onepass'") do |password| .password = password end opts.separator '' opts.separator 'Session options:' opts.on('--timeout [SECONDS]', Integer, "Timeout time in seconds, defaults to '60'") do |timeout| .timeout = timeout end opts.separator '' opts.separator 'Service options:' opts.on('--service [SERVICE_NAME]', [:oned, :occi, :econe, :rocci], 'Name of the cloud service'\ + " to check [oned, occi, rocci, econe], defaults to 'oned'") do |service| .service = service end opts.on("--check-network [ID'S]", Array, 'Comma separated list of network IDs to check') do |network| .network = network end opts.on("--check-storage [ID'S]", Array, 'Comma separated list of storage IDs to check') do |storage| .storage = storage end opts.on("--check-compute [ID'S]", Array, 'Comma separated list of VM IDs to check') do |compute| .compute = compute end opts.on('--createvm [TEMPLATE_UUID]', String, 'rOCCI template uuid') do |tmpl| .template_uuid = tmpl end opts.on('--name [NAME]', String, 'Name for VM instantiated from template') do |vmname| .vmname = vmname end opts.separator '' opts.separator 'X.509 options:' opts.on('--user-cred [PATH]', String, "Path to user's X.509 credentials, defaults to ~/.globus/usercred.pem'")\ do |ucred| .user_cred = ucred end opts.on('--ca-file [PATH]', String, 'Path to CA certificates bundle in a file') do |cafile| .ca_file = cafile end opts.on('--ca-path [PATH]', String, 'Path to CA certificates directory, defaults to "/etc/grid-security/certificates"')\ do |capath| .ca_path = capath end opts.on('--voms', '--[no-]voms', 'Enable VOMS credentials; modifies behavior of the X.509 authN module')\ do |voms| .voms = voms end opts.separator '' opts.separator 'Common options:' opts.on('--debuglevel [NUMBER]', Integer, "Run with debugging mode on certain level, defaults to '0'") do |debug| if !debug .debug_level = 1 else .debug_level = debug end # Param. correction - normalize debug level to max 2, minus sign interpreted as switch, no problem there .debug_level %= 3 end opts.on_tail('-h', '--help', 'Show this message') do puts opts exit! end opts.on_tail('--version', 'Show version') do puts VERSION exit! end end opts_.parse!(args) # Emphasize required fields mandatory = [:protocol, :hostname, :port, :path, :service, :password] mandatory << :username unless .user_cred = .marshal_dump # Bug here, i am not sure the mandatory params working missing = mandatory.select { |param| [param].nil? } fail StandardError, "Missing required arguments #{missing.join(', ')}" unless missing.empty? end |