Exemplo n.º 1
0
def create_webhook(token, event_type):
    tableau_auth = TSC.PersonalAccessTokenAuth(token_name=TABLEAU_TOKEN_NAME,
                                               personal_access_token=token,
                                               site_id=TABLEAU_SITE_NAME)
    server = TSC.Server(TABLEAU_SERVER)

    # Set http options to disable verifying SSL
    server.add_http_options({'verify': False})
    server.use_server_version()
    with server.auth.sign_in_with_personal_access_token(tableau_auth):
        new_webhook = TSC.WebhookItem()
        new_webhook.name = "Webooks created from Heroku"
        new_webhook.url = HEROKU_URL
        new_webhook.event = event_type

        # Check if identical webhook is already created
        exists = False
        for existing_webhook in TSC.Pager(server.webhooks):
            exists = compare_webhook(new_webhook, existing_webhook)
            if exists:
                break

        if not exists:
            new_webhook = server.webhooks.create(new_webhook)
            print("Webhook created: {}".format(new_webhook))
            return True, new_webhook
        else:
            print("Webhook already exists: {}".format(new_webhook))
            return False, new_webhook
Exemplo n.º 2
0
def main():

    parser = argparse.ArgumentParser(description='Explore webhook functions supported by the Server API.')
    # Common options; please keep those in sync across all samples
    parser.add_argument('--server', '-s', required=True, help='server address')
    parser.add_argument('--site', '-S', help='site name')
    parser.add_argument('--token-name', '-p', required=True,
                        help='name of the personal access token used to sign into the server')
    parser.add_argument('--token-value', '-v', required=True,
                        help='value of the personal access token used to sign into the server')
    parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
                        help='desired logging level (set to error by default)')
    # Options specific to this sample
    parser.add_argument('--create', help='create a webhook')
    parser.add_argument('--delete', help='delete a webhook', action='store_true')

    args = parser.parse_args()

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    # SIGN IN
    tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
    server = TSC.Server(args.server, use_server_version=True)
    with server.auth.sign_in(tableau_auth):

        # Create webhook if create flag is set (-create, -c)
        if args.create:

            new_webhook = TSC.WebhookItem()
            new_webhook.name = args.create
            new_webhook.url = "https://ifttt.com/maker-url"
            new_webhook.event = "datasource-created"
            print(new_webhook)
            new_webhook = server.webhooks.create(new_webhook)
            print("Webhook created. ID: {}".format(new_webhook.id))

        # Gets all webhook items
        all_webhooks, pagination_item = server.webhooks.get()
        print("\nThere are {} webhooks on site: ".format(pagination_item.total_available))
        print([webhook.name for webhook in all_webhooks])

        if all_webhooks:
            # Pick one webhook from the list and delete it
            sample_webhook = all_webhooks[0]
            # sample_webhook.delete()
            print("+++"+sample_webhook.name)

            if (args.delete):
                print("Deleting webhook " + sample_webhook.name)
                server.webhooks.delete(sample_webhook.id)
Exemplo n.º 3
0
    def test_create(self):
        with open(CREATE_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.post(self.baseurl, text=response_xml)
            webhook_model = TSC.WebhookItem()
            webhook_model.name = "Test Webhook"
            webhook_model.url = "https://ifttt.com/maker-url"
            webhook_model.event = "datasource-created"

            new_webhook = self.server.webhooks.create(webhook_model)

            self.assertNotEqual(new_webhook.id, None)
Exemplo n.º 4
0
def create_webhook(server):
    webhook_name = input('Webhook name: ')
    webhook_event = input('Webhook event: ')
    destination_url = input('Destination URL: ')
    print('Creating a new webhook...')

    new_webhook = TSC.WebhookItem()
    new_webhook.name = webhook_name
    new_webhook.event = webhook_event
    new_webhook.url = destination_url

    new_webhook = server.webhooks.create(new_webhook)
    print('Successfully created a new webhook.')

    owner_name = get_owner_name(server, new_webhook.owner_id)
    print_webhook(new_webhook, owner_name)
print(
    "Spring cleaning: Deleting existing \"duplicate\" webhooks on Tableau Server, that have the same name."
)
ts_existing_webhooks, pagination_itom = tableau_server.webhooks.get()
for ts_existing_webhook in ts_existing_webhooks:
    if (ts_existing_webhook.name in [webhook["name"] for webhook in webhooks]):
        print("Deleting existing webhook " + ts_existing_webhook.name +
              " as we're recreating it.")
        tableau_server.webhooks.delete(ts_existing_webhook.id)

print("Creating webhooks on Tableau Server")

for webhook in webhooks:

    webhook_model = TSC.WebhookItem()
    webhook_model.name = webhook["name"]
    webhook_model.event = webhook["event_name"]
    webhook_model.url = config["Webhook Configuration"]["webhook_url"]

    try:
        ts_webhook = tableau_server.webhooks.create(webhook_model)
        print("Webhook created: \"" + ts_webhook.name + "\" with id " +
              ts_webhook._id)
        # Store ID so we can delete them later
        webhook["id"] = ts_webhook._id
    except Exception as e:
        print("Failed to create Webhook.")
        print(e)
        exit(1)
import tableauserverclient as TSC

server_url = 'https://10ax.online.tableau.com'
site = 'jharriscohdev372485'
pat = ''
pat_name = 'JeremyDevPAT'
tableau_auth = TSC.PersonalAccessTokenAuth(token_name=pat_name, personal_access_token=pat, site_id=site)
server = TSC.Server(server_url, use_server_version=True)

wbh = TSC.WebhookItem()
wbh.name = "ExtractFailedToTwitter"
wbh.url = "https://us-central1-datatest-270319.cloudfunctions.net/datasource-get-info"
wbh.event = "datasource-refresh-failed"

with server.auth.sign_in(tableau_auth):
    print(server.webhooks.create(wbh))