|
24 | 24 |
|
25 | 25 |
|
26 | 26 | import logging |
27 | | -from argparse import ArgumentParser, RawDescriptionHelpFormatter |
28 | 27 |
|
29 | 28 | from cr_module.classes.plugin import PluginData |
30 | 29 | from cr_module.system_chassi import get_system_info, get_chassi_data, get_system_data |
|
33 | 32 | from cr_module.bmc import get_bmc_info |
34 | 33 | from cr_module.firmware import get_firmware_info |
35 | 34 | from cr_module.event import get_event_log |
36 | | -from cr_module.classes.redfish import default_conn_max_retries, default_conn_timeout |
37 | | -from cr_module.classes.inventory import Fan, PowerSupply, Temperature, Memory, Processor |
38 | | - |
| 35 | +from cr_module.args import parse_command_line |
39 | 36 |
|
40 | | -def parse_command_line(): |
41 | | - """parse command line arguments |
42 | | - Also add current version and version date to description |
43 | | - """ |
44 | | - |
45 | | - # define command line options |
46 | | - parser = ArgumentParser( |
47 | | - description=f"{description}\nVersion: {__version__} ({__version_date__})", |
48 | | - formatter_class=RawDescriptionHelpFormatter, add_help=False) |
49 | | - |
50 | | - group = parser.add_argument_group(title="mandatory arguments") |
51 | | - group.add_argument("-H", "--host", |
52 | | - help="define the host to request. To change the port just add ':portnumber' to this parameter") |
53 | | - |
54 | | - group = parser.add_argument_group(title="authentication arguments") |
55 | | - group.add_argument("-u", "--username", help="the login user name") |
56 | | - group.add_argument("-p", "--password", help="the login password") |
57 | | - group.add_argument("-f", "--authfile", help="authentication file with user name and password") |
58 | | - group.add_argument("--sessionfile", help="define name of session file") |
59 | | - group.add_argument("--sessionfiledir", help="define directory where the plugin saves session files") |
60 | | - group.add_argument("--sessionlock", action='store_true', help="prevents multiple sessions and locks the session file when connecting") |
61 | | - group.add_argument("--nosession", action='store_true', |
62 | | - help="Don't establish a persistent session and log out after check is finished") |
63 | | - |
64 | | - group = parser.add_argument_group(title="optional arguments") |
65 | | - group.add_argument("-h", "--help", action='store_true', |
66 | | - help="show this help message and exit") |
67 | | - group.add_argument("-w", "--warning", default="", |
68 | | - help="set warning value") |
69 | | - group.add_argument("-c", "--critical", default="", |
70 | | - help="set critical value") |
71 | | - group.add_argument("-v", "--verbose", action='store_true', |
72 | | - help="this will add all https requests and responses to output, " |
73 | | - "also adds inventory source data to all inventory objects") |
74 | | - group.add_argument("-d", "--detailed", action='store_true', |
75 | | - help="always print detailed result") |
76 | | - group.add_argument("-m", "--max", type=int, |
77 | | - help="set maximum of returned items for --sel or --mel") |
78 | | - group.add_argument("-r", "--retries", type=int, default=default_conn_max_retries, |
79 | | - help=f"set number of maximum retries (default: {default_conn_max_retries})") |
80 | | - group.add_argument("-t", "--timeout", type=int, default=default_conn_timeout, |
81 | | - help=f"set number of request timeout per try/retry (default: {default_conn_timeout})") |
82 | | - group.add_argument("--log_exclude", |
83 | | - help="a comma separated list of log lines (regex) " |
84 | | - "to exclude from log status checks (--sel, --mel)") |
85 | | - group.add_argument("--ignore_missing_ps", action='store_true', |
86 | | - help="ignore the fact that no power supplies are present and report the status " |
87 | | - "of the power subsystem") |
88 | | - group.add_argument("--enable_bmc_security_warning", action='store_true', |
89 | | - help="return status WARNING if BMC security issues are detected (HPE iLO only)") |
90 | | - |
91 | | - # require at least one argument |
92 | | - group = parser.add_argument_group(title="query status/health information (at least one is required)") |
93 | | - group.add_argument("--storage", dest="requested_query", action='append_const', const="storage", |
94 | | - help="request storage health") |
95 | | - group.add_argument("--proc", dest="requested_query", action='append_const', const="proc", |
96 | | - help="request processor health") |
97 | | - group.add_argument("--memory", dest="requested_query", action='append_const', const="memory", |
98 | | - help="request memory health") |
99 | | - group.add_argument("--power", dest="requested_query", action='append_const', const="power", |
100 | | - help="request power supply health") |
101 | | - group.add_argument("--temp", dest="requested_query", action='append_const', const="temp", |
102 | | - help="request temperature sensors status") |
103 | | - group.add_argument("--fan", dest="requested_query", action='append_const', const="fan", |
104 | | - help="request fan status") |
105 | | - group.add_argument("--nic", dest="requested_query", action='append_const', const="nic", |
106 | | - help="request network interface status") |
107 | | - group.add_argument("--bmc", dest="requested_query", action='append_const', const="bmc", |
108 | | - help="request bmc info and status") |
109 | | - group.add_argument("--info", dest="requested_query", action='append_const', const="info", |
110 | | - help="request system information") |
111 | | - group.add_argument("--firmware", dest="requested_query", action='append_const', const="firmware", |
112 | | - help="request firmware information") |
113 | | - group.add_argument("--sel", dest="requested_query", action='append_const', const="sel", |
114 | | - help="request System Log status") |
115 | | - group.add_argument("--mel", dest="requested_query", action='append_const', const="mel", |
116 | | - help="request Management Processor Log status") |
117 | | - group.add_argument("--all", dest="requested_query", action='append_const', const="all", |
118 | | - help="request all of the above information at once") |
119 | | - |
120 | | - # inventory |
121 | | - group = parser.add_argument_group(title="query inventory information (no health check)") |
122 | | - group.add_argument("-i", "--inventory", action='store_true', |
123 | | - help="return inventory in json format instead of regular plugin output") |
124 | | - group.add_argument("--inventory_id", |
125 | | - help="set an ID which can be used to identify this host in the destination inventory") |
126 | | - group.add_argument("--inventory_name", |
127 | | - help="set a name which can be used to identify this host in the destination inventory") |
128 | | - group.add_argument("--inventory_file", |
129 | | - help="set file to write the inventory output to. Otherwise stdout will be used.") |
130 | | - |
131 | | - result = parser.parse_args() |
132 | | - |
133 | | - if result.help: |
134 | | - parser.print_help() |
135 | | - print("") |
136 | | - exit(0) |
137 | | - |
138 | | - if result.requested_query is None: |
139 | | - parser.error("You need to specify at least one query command.") |
140 | | - |
141 | | - # need to check this our self otherwise it's not |
142 | | - # possible to put the help command into an arguments group |
143 | | - if result.host is None: |
144 | | - parser.error("No remote host defined") |
145 | | - |
146 | | - return result |
| 37 | +from cr_module.classes.inventory import Fan, PowerSupply, Temperature, Memory, Processor |
147 | 38 |
|
148 | 39 |
|
149 | 40 | if __name__ == "__main__": |
150 | 41 | # start here |
151 | | - args = parse_command_line() |
| 42 | + args = parse_command_line(description, __version__, __version_date__) |
152 | 43 |
|
153 | 44 | if args.verbose: |
154 | 45 | # initialize logger |
|
0 commit comments