def parse_args(): parser = dish_common.create_arg_parser(output_description="publish it to a MQTT broker", bulk_history=False) group = parser.add_argument_group(title="MQTT broker options") group.add_argument("-n", "--hostname", default=HOST_DEFAULT, help="Hostname of MQTT broker, default: " + HOST_DEFAULT) group.add_argument("-p", "--port", type=int, help="Port number to use on MQTT broker") group.add_argument("-P", "--password", help="Set password for username/password authentication") group.add_argument("-U", "--username", help="Set username for authentication") if ssl_ok: def wrap_ca_arg(arg): return {"ca_certs": arg} group.add_argument("-C", "--ca-cert", type=wrap_ca_arg, dest="tls", help="Enable SSL/TLS using specified CA cert to verify broker", metavar="FILENAME") group.add_argument("-I", "--insecure", action="store_const", const={"cert_reqs": ssl.CERT_NONE}, dest="tls", help="Enable SSL/TLS but disable certificate verification (INSECURE!)") group.add_argument("-S", "--secure", action="store_const", const={}, dest="tls", help="Enable SSL/TLS using default CA cert") else: parser.epilog += "\nSSL support options not available due to missing ssl module" opts = dish_common.run_arg_parser(parser, need_id=True) if opts.username is None and opts.password is not None: parser.error("Password authentication requires username to be set") opts.mqargs = {} for key in ["hostname", "port", "tls"]: val = getattr(opts, key) if val is not None: opts.mqargs[key] = val if opts.username is not None: opts.mqargs["auth"] = {"username": opts.username} if opts.password is not None: opts.mqargs["auth"]["password"] = opts.password return opts
def parse_args(): parser = dish_common.create_arg_parser( output_description= "print it to standard output in text format; by default, will print in CSV format") group = parser.add_argument_group(title="CSV output options") group.add_argument("-H", "--print-header", action="store_true", help="Print CSV header instead of parsing data") opts = dish_common.run_arg_parser(parser, no_stdout_errors=True) if (opts.history_stats_mode or opts.satus_mode) and opts.bulk_mode: parser.error("bulk_history cannot be combined with other modes for CSV output") return opts
def parse_args(): parser = dish_common.create_arg_parser(output_description="write it to a sqlite database") parser.add_argument("database", help="Database file to use") group = parser.add_argument_group(title="sqlite database options") group.add_argument("-f", "--force", action="store_true", help="Force schema conversion, even if it results in downgrade; may " "result in discarded data") group.add_argument("-k", "--skip-query", action="store_true", help="Skip querying for prior sample write point in bulk mode") opts = dish_common.run_arg_parser(parser, need_id=True) opts.skip_query |= opts.no_counter return opts
def parse_args(): parser = dish_common.create_arg_parser( output_description="write it to an InfluxDB database") group = parser.add_argument_group(title="InfluxDB database options") group.add_argument("-n", "--hostname", default=HOST_DEFAULT, dest="host", help="Hostname of MQTT broker, default: " + HOST_DEFAULT) group.add_argument("-p", "--port", type=int, help="Port number to use on MQTT broker") group.add_argument( "-P", "--password", help="Set password for username/password authentication") group.add_argument( "-U", "--username", help="Set username for username/password authentication") group.add_argument("-T", "--token", help="Set token for InfluxDB v2 authentication") group.add_argument("-u", "--url", help="Set url for InfluxDB v2 server") group.add_argument("-o", "--org", help="Set org for InfluxDB v2 bucket") group.add_argument("-D", "--database", default=DATABASE_DEFAULT, help="Database/Bucket name to use, default: " + DATABASE_DEFAULT) group.add_argument("-R", "--retention-policy", help="Retention policy name to use") group.add_argument( "-k", "--skip-query", action="store_true", help="Skip querying for prior sample write point in bulk mode") group.add_argument( "-C", "--ca-cert", dest="verify_ssl", help="Enable SSL/TLS using specified CA cert to verify broker", metavar="FILENAME") group.add_argument( "-I", "--insecure", action="store_false", dest="verify_ssl", help="Enable SSL/TLS but disable certificate verification (INSECURE!)") group.add_argument("-S", "--secure", action="store_true", dest="verify_ssl", help="Enable SSL/TLS using default CA cert") env_map = ( ("INFLUXDB_HOST", "host"), ("INFLUXDB_PORT", "port"), ("INFLUXDB_USER", "username"), ("INFLUXDB_PWD", "password"), ("INFLUXDB_TOKEN", "token"), ("INFLUXDB_ORG", "org"), ("INFLUXDB_URL", "url"), ("INFLUXDB_DB", "database"), ("INFLUXDB_RP", "retention-policy"), ("INFLUXDB_SSL", "verify_ssl"), ) env_defaults = {} for var, opt in env_map: # check both set and not empty string val = os.environ.get(var) if val: if var == "INFLUXDB_SSL" and val == "secure": env_defaults[opt] = True elif var == "INFLUXDB_SSL" and val == "insecure": env_defaults[opt] = False else: env_defaults[opt] = val parser.set_defaults(**env_defaults) opts = dish_common.run_arg_parser(parser, need_id=True) if opts.username is None and opts.password is not None: parser.error("Password authentication requires username to be set") opts.icargs = {"timeout": 5} for key in [ "port", "host", "url", "password", "username", "database", "org", "token", "verify_ssl" ]: val = getattr(opts, key) if val is not None: opts.icargs[key] = val if opts.verify_ssl is not None: opts.icargs["ssl"] = True return opts