Пример #1
0
    def __init__(self, config):
        """Initialize the scanner."""
        import synology_srm

        self.client = synology_srm.Client(host=config[CONF_HOST],
                                          port=config[CONF_PORT],
                                          username=config[CONF_USERNAME],
                                          password=config[CONF_PASSWORD],
                                          https=config[CONF_SSL])

        if not config[CONF_VERIFY_SSL]:
            self.client.http.disable_https_verify()

        self.last_results = []
        self.success_init = self._update_info()

        _LOGGER.info("Synology SRM scanner initialized")
Пример #2
0
def main(args):
    """Main entry point allowing external calls

    Args:
      args ([str]): command line parameter list
    """
    args = parse_args(args)
    setup_logging(args.loglevel)
    _logger.debug("Starting crazy calculations...")

    # client connection information
    client = synology_srm.Client(host='192.168.1.1',
                                 port=8001,
                                 https=True,
                                 username='******',
                                 password="******")

    # to get to work without cert
    client.http.disable_https_verify()

    #web api base URL
    response = client.http._get_base_url()
    print(response)

    endpoints = client.base.query_info()

    # List all the API endpoints available
    # Note: Not all of these are implemented in the pyhon library
    # Will try to call directly with http.call(...) method
    for endpoint, config in endpoints.items():
        print("API endpoint {} (minVersion={}, maxVersion={})".format(
            endpoint,
            config['minVersion'],
            config['maxVersion'],
        ))

    # List certificate
    response = client.core.list_certificate()
    print(json.dumps(response, indent=4, sort_keys=True))

    # Get all the hosts, but filter for one specfic known host
    response = client.core.get_network_nsm_device(
        {"hostname": "DESKTOP-6AVJ2SV"})
    print(json.dumps(response, indent=4, sort_keys=True))

    #response = client.core.get_ngfw_traffic("day")
    #print(json.dumps(response, indent=4, sort_keys=True))

    # Test mannually passing in an api endpoint request

    # Already supported by synology_srm api
    response = client.http.call(
        endpoint='entry.cgi',
        api='SYNO.Core.DDNS.ExtIP',
        method='list',
        version=1,
    )
    print(json.dumps(response, indent=4, sort_keys=True))

    #response = client.http.call(
    #  endpoint='query.cgi',
    #  api='SYNO.API.Info',
    #  method='query',
    #  version=1,
    #)
    #print(json.dumps(response, indent=4, sort_keys=True))

    # This is what the API call looks like from the URL
    #https://192.168.1.1:8001/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=all

    response = api_call(client, 'SYNO.Core.DDNS.ExtIP', 'list')
    print(json.dumps(response, indent=4, sort_keys=True))

    response = api_call(client, 'SYNO.Core.System.Utilization', 'get')
    print(json.dumps(response, indent=4, sort_keys=True))

    # SYNO.Core.Network.Router.Topology
    response = api_call(client, 'SYNO.Core.Network.Router.Topology', 'get')
    print(json.dumps(response, indent=4, sort_keys=True))

    # SYNO.Core.Network.Wifi.Client
    response = api_call(client, 'SYNO.Core.Network.Wifi.Client', 'list')
    print(json.dumps(response, indent=4, sort_keys=True))

    _logger.info("Script ends here")