This example shows how you can configure and test the forwarding of a vCenter Server syslog by using the API. The example is based on the log_forwarding.py sample.

Note: For a complete and up-to-date version of the sample code, see the vsphere-automation-sdk-python VMware repository at GitHub.
...

        self.log_forwarding_client = Forwarding(self.stub_config)

...

    def set_log_forwarding(self):
        log_forwarding_config = [Forwarding.Config(hostname=self.loghost,
                                                   port=self.port,
                                                   protocol=self.protocol)]
        self.log_forwarding_client.set(log_forwarding_config)

    def get_log_forwarding(self):
        configs = self.log_forwarding_client.get()

        print("\nLog forwarding configurations:")
        table = [[cfg.hostname, cfg.port, cfg.protocol] for cfg in configs]
        headers = ["Loghost", "Port", "Protocol"]
        print(tabulate(table, headers))

    def test_log_forwarding(self):
        test_response = self.log_forwarding_client.test(True)

        print("\nLog forwarding test response:")
        table = [[resp.hostname,
                  resp.state,
                  resp.message.default_message if resp.message else None]
                 for resp in test_response]
        headers = ["Loghost", "State", "Message"]
        print(tabulate(table, headers))

    def update_log_forwarding(self):
        # Read log forwarding configuration
        log_forwarding_config = self.log_forwarding_client.get()

        # Delete the newly added configuration
        log_forwarding_config = list(filter(
                                    lambda cfg: cfg.hostname != self.loghost,
                                    log_forwarding_config))

        # Apply the modified log forwarding configuration
        self.log_forwarding_client.set(log_forwarding_config)

...