def test_args(): arg_parser = ArgumentParser(description="resoto metrics exporter", env_args_prefix="RESOTOMETRICS_") add_args(arg_parser) arg_parser.parse_args() assert resotocore.http_uri == "https://localhost:8900" assert resotocore.ws_uri == "wss://localhost:8900"
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--protect-snowflakes-config", help="Path to Protect Snowflakes Plugin Config", default=None, dest="protect_snowflakes_config", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--resotocore-uri", help="resotocore URI (default: https://localhost:8900)", default="https://localhost:8900", dest="resotocore_uri", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--cleanup-untagged-config", help="Path to Cleanup Untagged Plugin Config", default=None, dest="cleanup_untagged_config", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--resotocore-subscriber-id", help="resotocore actions subscriber identifier (default: worker)", default="worker", dest="resotocore_subscriber_id", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--psk", help="Pre-shared key", type=lambda x: x if len(x) > 0 else None, default=None, dest="psk", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--subscriber-id", help="Unique subscriber ID (default: resoto.worker)", default="resoto.worker", dest="subscriber_id", type=str, )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--event-timeout", help="Event Listener Timeout in seconds (default 900)", default=900, dest="event_timeout", type=int, )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--web-path", help="Web root in browser (default: /)", default="/", dest="web_path", type=str, )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--cleanup-expired", help="Cleanup expired resources (default: False)", dest="cleanup_expired", action="store_true", default=False, )
def test_args(): arg_parser = ArgumentParser( description="resoto worker", env_args_prefix="RESOTOWORKER_", ) add_args(arg_parser) core_add_args(arg_parser) arg_parser.parse_args() assert resotocore.http_uri == "https://localhost:8900"
def test_args(): arg_parser = ArgumentParser(description="resoto metrics exporter", env_args_prefix="RESOTOMETRICS_") add_args(arg_parser) arg_parser.parse_args() assert ArgumentParser.args.resotocore_uri == "http://localhost:8900" assert ArgumentParser.args.resotocore_ws_uri == "ws://localhost:8900" assert ArgumentParser.args.resotocore_graph == "resoto" assert ArgumentParser.args.timeout == 300
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--example-region", help="Example Region", dest="example_region", type=str, default=None, nargs="+", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--override", help="Override config attribute(s)", dest="config_override", type=str, default=[], nargs="+", )
def add_args(arg_parser: ArgumentParser) -> None: """Add args to the arg parser This adds the GraphContainer()'s own args. """ arg_parser.add_argument( "--tag-as-metrics-label", help="Tag to use as metrics label", dest="metrics_tag_as_label", type=str, default=None, nargs="+", )
def add_args(arg_parser: ArgumentParser) -> None: """Add args to the arg parser This adds the PluginLoader()'s own args. """ arg_parser.add_argument( "--collector", help="Collectors to load (default: all)", dest="collector", type=str, default=None, nargs="+", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--cleanup-aws-alarms", help="Cleanup AWS Cloudwatch Alarms (default: False)", dest="cleanup_aws_alarms", action="store_true", default=False, ) arg_parser.add_argument( "--cleanup-aws-alarms-config", help="Path to Cleanup AWS Cloudwatch Alarms Plugin Config", default=None, dest="cleanup_aws_alarms_config", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--debug-dump-json", help="Dump the generated json data (default: False)", dest="debug_dump_json", action="store_true", ) arg_parser.add_argument( "--tempdir", help="Directory to create temporary files in (default: system default)", default=None, dest="tempdir", type=str, )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--resotocore-uri", help="resotocore URI (default: http://localhost:8900)", default="http://localhost:8900", dest="resotocore_uri", ) arg_parser.add_argument( "--resotocore-ws-uri", help="resotocore Websocket URI (default: ws://localhost:8900)", default="ws://localhost:8900", dest="resotocore_ws_uri", ) arg_parser.add_argument( "--resotocore-graph", help="resotocore graph name (default: resoto)", default="resoto", dest="resotocore_graph", ) arg_parser.add_argument( "--timeout", help="Metrics generation timeout in seconds (default: 300)", default=300, dest="timeout", type=int, )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--cleanup-aws-vpcs", help="Cleanup AWS VPCs (default: False)", dest="cleanup_aws_vpcs", action="store_true", default=False, ) arg_parser.add_argument( "--cleanup-aws-vpcs-config", help="Path to Cleanup AWS VPCs Plugin Config", default=None, dest="cleanup_aws_vpcs_config", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--cleanup-aws-loadbalancers", help="Cleanup unused AWS Loadbalancers (default: False)", dest="cleanup_aws_loadbalancers", action="store_true", default=False, ) arg_parser.add_argument( "--cleanup-aws-loadbalancers-age", help="Cleanup unused AWS Loadbalancers Age (default: 7 days)", default="7 days", dest="cleanup_aws_loadbalancers_age", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--cleanup-volumes", help="Cleanup unused Volumes (default: False)", dest="cleanup_volumes", action="store_true", default=False, ) arg_parser.add_argument( "--cleanup-volumes-age", help="Cleanup unused Volumes Age (default: 14 days)", default="14 days", dest="cleanup_volumes_age", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--fork", help="Use forked process instead of threads (default: False)", dest="fork", action="store_true", ) arg_parser.add_argument( "--pool-size", help="Collector thread/process pool size (default: 5)", dest="pool_size", default=5, type=int, )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--tagvalidator-config", help="Path to Tag Validator Config", default=None, dest="tagvalidator_config", ) arg_parser.add_argument( "--tagvalidator-dry-run", help="Tag Validator Dry Run", dest="tagvalidator_dry_run", action="store_true", default=False, )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--web-port", help="Web Port (default 9955)", default=9955, dest="web_port", type=int, ) arg_parser.add_argument( "--web-host", help="IP to bind to (default: ::)", default="::", dest="web_host", type=str, )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--ignore-deferred-connections", help="Do not try to resolve deferred edges", dest="ignore_deferred_connections", action="store_true", default=False, ) arg_parser.add_argument( "--graph-merge-kind", help="Resource kind to merge graph at (default: cloud)", dest="graph_merge_kind", type=str, choices=["cloud", "account"], default="cloud", )
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--digitalocean-api-tokens", help="DigitalOcean API tokens for the teams to be collected", dest="digitalocean_api_tokens", type=str, default=[], nargs="+", ) arg_parser.add_argument( "--digitalocean-spaces-access-keys", help="DigitalOcean Spaces access keys for the teams to be collected, separated by colons", dest="digitalocean_spaces_access_keys", type=str, default=[], nargs="+", )
def main() -> None: setup_logger("resotometrics") signal(SIGINT, handler) signal(SIGTERM, handler) arg_parser = ArgumentParser(description="resoto metrics exporter", env_args_prefix="RESOTOMETRICS_") add_args(arg_parser) logging_add_args(arg_parser) jwt_add_args(arg_parser) WebServer.add_args(arg_parser) WebApp.add_args(arg_parser) arg_parser.parse_args() metrics = Metrics() graph_collector = GraphCollector(metrics) REGISTRY.register(graph_collector) base_uri = ArgumentParser.args.resotocore_uri.strip("/") resotocore_graph = ArgumentParser.args.resotocore_graph graph_uri = f"{base_uri}/graph/{resotocore_graph}" query_uri = f"{graph_uri}/query/aggregate?section=reported" message_processor = partial(core_actions_processor, metrics, query_uri) core_actions = CoreActions( identifier="resotometrics", resotocore_uri=ArgumentParser.args.resotocore_uri, resotocore_ws_uri=ArgumentParser.args.resotocore_ws_uri, actions={ "generate_metrics": { "timeout": ArgumentParser.args.timeout, "wait_for_completion": True, }, }, message_processor=message_processor, ) web_server = WebServer(WebApp()) web_server.daemon = True web_server.start() core_actions.start() shutdown_event.wait() web_server.shutdown() core_actions.shutdown() sys.exit(0)
def test_web(): arg_parser = ArgumentParser( description="resoto metrics exporter", env_args_prefix="RESOTOMETRICS_" ) WebServer.add_args(arg_parser) WebApp.add_args(arg_parser) arg_parser.parse_args() # Find a free local port to reuse when we bind the web server. # This is so that multiple builds/tests can run in parallel # on the same CI agent. tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcp.bind(("", 0)) _, free_port = tcp.getsockname() ArgumentParser.args.web_port = free_port tcp.close() # todo: race between closing socket and reusing free port in WebServer web_server = WebServer(WebApp()) web_server.daemon = True web_server.start() start_time = time.time() while not web_server.serving: if time.time() - start_time > 10: raise RuntimeError("timeout waiting for web server start") time.sleep(0.1) # We're statically using localhost in the endpoint url. # Other options would have been to set ArgumentParser.args.web_host # and then connect to that value. However we'd have to use an IP # address and then needed to decide if we use either # 127.0.0.1 or ::1. Which might fail on CI boxes without # IPv4 or IPv6 respectively. Instead we leave the default which # binds to all IPs and assume that localhost will resolve to # the appropriate v4 or v6 loopback address. A disadvantage # of this is that for a brief moment during the test we're # exposing the web server on all local IPs. endpoint = f"http://localhost:{ArgumentParser.args.web_port}" r = requests.get(f"{endpoint}/health") assert r.content == b"ok\r\n" web_server.shutdown()
def add_args(arg_parser: ArgumentParser) -> None: arg_parser.add_argument( "--vsphere-user", help="VSphere user name", dest="vsphere_user", type=str, default=None, ) arg_parser.add_argument( "--vsphere-password", help="VSphere user password", dest="vsphere_password", type=str, default=None, ) arg_parser.add_argument( "--vsphere-host", help="VSphere Host address", dest="vsphere_host", type=str, default=None, ) arg_parser.add_argument( "--vsphere-port", help="VSphere Region", dest="vsphere_port", type=int, default=443, ) arg_parser.add_argument( "--vsphere-insecure", help="VSphere insecure connection. Do not verify certificates", dest="vsphere_insecure", action="store_true", )