def create_uptime_check_config(project_name, host_name=None, display_name=None): config = monitoring_v3.types.uptime_pb2.UptimeCheckConfig() config.display_name = display_name or 'New uptime check' config.monitored_resource.type = 'uptime_url' config.monitored_resource.labels.update( {'host': host_name or 'example.com'}) config.http_check.path = '/' config.http_check.port = 80 config.timeout.seconds = 10 config.period.seconds = 300 client = monitoring_v3.UptimeCheckServiceClient() new_config = client.create_uptime_check_config(project_name, config) pprint.pprint(new_config) return new_config
def test_delete_uptime_check_config(self): channel = ChannelStub() patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = monitoring_v3.UptimeCheckServiceClient() # Setup Request name = client.uptime_check_config_path("[PROJECT]", "[UPTIME_CHECK_CONFIG]") client.delete_uptime_check_config(name) assert len(channel.requests) == 1 expected_request = uptime_service_pb2.DeleteUptimeCheckConfigRequest( name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def create_uptime_check_config_get(project_name, host_name=None, display_name=None): config = monitoring_v3.UptimeCheckConfig() config.display_name = display_name or "New GET uptime check" config.monitored_resource = { "type": "uptime_url", "labels": {"host": host_name or "example.com"} } config.http_check = { "request_method": monitoring_v3.UptimeCheckConfig.HttpCheck.RequestMethod.GET, "path": "/", "port": 80 } config.timeout = {"seconds": 10} config.period = {"seconds": 300} client = monitoring_v3.UptimeCheckServiceClient() new_config = client.create_uptime_check_config(request={"parent": project_name, "uptime_check_config": config}) pprint.pprint(new_config) return new_config
def create_uptime_check_config_post(project_name, host_name=None, display_name=None): config = monitoring_v3.types.uptime_pb2.UptimeCheckConfig() config.display_name = display_name or "New POST uptime check" config.monitored_resource.type = "uptime_url" config.monitored_resource.labels.update({"host": host_name or "example.com"}) config.http_check.request_method = ( monitoring_v3.enums.UptimeCheckConfig.HttpCheck.RequestMethod.POST ) config.http_check.content_type = ( monitoring_v3.enums.UptimeCheckConfig.HttpCheck.ContentType.URL_ENCODED ) config.http_check.body = "foo=bar".encode("utf-8") config.http_check.path = "/" config.http_check.port = 80 config.timeout.seconds = 10 config.period.seconds = 300 client = monitoring_v3.UptimeCheckServiceClient() new_config = client.create_uptime_check_config(project_name, config) pprint.pprint(new_config) return new_config
def create_uptime_check_config_post(project_name, host_name=None, display_name=None): config = monitoring_v3.UptimeCheckConfig() config.display_name = display_name or "New POST uptime check" config.monitored_resource = { "type": "uptime_url", "labels": {"host": host_name or "example.com"} } config.http_check = { "request_method": monitoring_v3.UptimeCheckConfig.HttpCheck.RequestMethod.POST, "content_type": monitoring_v3.UptimeCheckConfig.HttpCheck.ContentType.URL_ENCODED, "body": "foo=bar".encode("utf-8"), "path": "/", "port": 80 } config.timeout = {"seconds": 10} config.period = {"seconds": 300} client = monitoring_v3.UptimeCheckServiceClient() new_config = client.create_uptime_check_config(request={"parent": project_name, "uptime_check_config": config}) pprint.pprint(new_config) return new_config
def test_update_uptime_check_config(self): # Setup Expected Response name = 'name3373707' display_name = 'displayName1615086568' expected_response = {'name': name, 'display_name': display_name} expected_response = uptime_pb2.UptimeCheckConfig(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = monitoring_v3.UptimeCheckServiceClient(channel=channel) # Setup Request uptime_check_config = {} response = client.update_uptime_check_config(uptime_check_config) assert expected_response == response assert len(channel.requests) == 1 expected_request = uptime_service_pb2.UpdateUptimeCheckConfigRequest( uptime_check_config=uptime_check_config) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_uptime_check_config(self): # Setup Expected Response name_2 = 'name2-1052831874' display_name = 'displayName1615086568' expected_response = {'name': name_2, 'display_name': display_name} expected_response = uptime_pb2.UptimeCheckConfig(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = monitoring_v3.UptimeCheckServiceClient(channel=channel) # Setup Request name = client.uptime_check_config_path('[PROJECT]', '[UPTIME_CHECK_CONFIG]') response = client.get_uptime_check_config(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = uptime_service_pb2.GetUptimeCheckConfigRequest( name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_uptime_check_configs(self): # Setup Expected Response next_page_token = "" total_size = 705419236 uptime_check_configs_element = {} uptime_check_configs = [uptime_check_configs_element] expected_response = { "next_page_token": next_page_token, "total_size": total_size, "uptime_check_configs": uptime_check_configs, } expected_response = uptime_service_pb2.ListUptimeCheckConfigsResponse( **expected_response ) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = monitoring_v3.UptimeCheckServiceClient() # Setup Request parent = client.project_path("[PROJECT]") paged_list_response = client.list_uptime_check_configs(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.uptime_check_configs[0] == resources[0] assert len(channel.requests) == 1 expected_request = uptime_service_pb2.ListUptimeCheckConfigsRequest( parent=parent ) actual_request = channel.requests[0][1] assert expected_request == actual_request
def delete_uptime_check_config(config_name): client = monitoring_v3.UptimeCheckServiceClient() client.delete_uptime_check_config(config_name) print('Deleted ', config_name)
def get_uptime_check_config(config_name): client = monitoring_v3.UptimeCheckServiceClient() config = client.get_uptime_check_config(config_name) pprint.pprint(config)
def list_uptime_check_configs(project_name): client = monitoring_v3.UptimeCheckServiceClient() configs = client.list_uptime_check_configs(project_name) for config in configs: pprint.pprint(config)
def __init__(self, test=False): if not test: self.client = monitoring_v3.UptimeCheckServiceClient() else: self.client = None
def __init__(self, bot_): self.bot = bot_ self.client = monitoring_v3.UptimeCheckServiceClient( os.getenv('GOOGLE_CRED')) self.project_name = 'projects/braincell-bot-dpy'
def ucc_client(): return monitoring_v3.UptimeCheckServiceClient()
def delete_uptime_check_config(config_name): client = monitoring_v3.UptimeCheckServiceClient() client.delete_uptime_check_config(request={"name": config_name}) print("Deleted ", config_name)