class QNAPStatsAPI(object): """Class to interface with the API.""" def __init__(self, config): """Initialize the API wrapper.""" from qnapstats import QNAPStats protocol = "https" if config.get(CONF_SSL) else "http" self._api = QNAPStats( protocol + "://" + config.get(CONF_HOST), config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD)) self.data = {} # pylint: disable=bare-except @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Update API information and store locally.""" try: self.data["system_stats"] = self._api.get_system_stats() self.data["system_health"] = self._api.get_system_health() self.data["smart_drive_health"] = self._api.get_smart_disk_health() self.data["volumes"] = self._api.get_volumes() self.data["bandwidth"] = self._api.get_bandwidth() except: _LOGGER.exception("Failed to fetch QNAP stats from the NAS.")
class QNAPStatsAPI: """Class to interface with the API.""" def __init__(self, config): """Initialize the API wrapper.""" protocol = "https" if config[CONF_SSL] else "http" self._api = QNAPStats( f"{protocol}://{config.get(CONF_HOST)}", config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD), verify_ssl=config.get(CONF_VERIFY_SSL), timeout=config.get(CONF_TIMEOUT), ) self.data = {} @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Update API information and store locally.""" try: self.data["system_stats"] = self._api.get_system_stats() self.data["system_health"] = self._api.get_system_health() self.data["smart_drive_health"] = self._api.get_smart_disk_health() self.data["volumes"] = self._api.get_volumes() self.data["bandwidth"] = self._api.get_bandwidth() except: # noqa: E722 pylint: disable=bare-except _LOGGER.exception("Failed to fetch QNAP stats from the NAS")
class QNAPStatsAPI: """Class to interface with the API.""" def __init__(self, config): """Initialize the API wrapper.""" from qnapstats import QNAPStats protocol = "https" if config.get(CONF_SSL) else "http" self._api = QNAPStats( '{}://{}'.format(protocol, config.get(CONF_HOST)), config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD), verify_ssl=config.get(CONF_VERIFY_SSL), timeout=config.get(CONF_TIMEOUT), ) self.data = {} @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Update API information and store locally.""" try: self.data["system_stats"] = self._api.get_system_stats() self.data["system_health"] = self._api.get_system_health() self.data["smart_drive_health"] = self._api.get_smart_disk_health() self.data["volumes"] = self._api.get_volumes() self.data["bandwidth"] = self._api.get_bandwidth() except: # noqa: E722 pylint: disable=bare-except _LOGGER.exception("Failed to fetch QNAP stats from the NAS")
class QNAPStatsAPI(object): """Class to interface with the API.""" def __init__(self, config): """Initialize the API wrapper.""" from qnapstats import QNAPStats protocol = "https" if config.get(CONF_SSL) else "http" self._api = QNAPStats(protocol + "://" + config.get(CONF_HOST), config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD)) self.data = {} # pylint: disable=bare-except @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Update API information and store locally.""" try: self.data["system_stats"] = self._api.get_system_stats() self.data["system_health"] = self._api.get_system_health() self.data["smart_drive_health"] = self._api.get_smart_disk_health() self.data["volumes"] = self._api.get_volumes() self.data["bandwidth"] = self._api.get_bandwidth() except: _LOGGER.exception("Failed to fetch QNAP stats from the NAS.")
def __init__(self, ip=QNAP_IP2, port=QNAP_PORT, username=QNAP_USERNAME2, password=QNAP_PASSWORD2): self.qnap = QNAPStats(ip, 443, username, password, verify_ssl=False) self.qnap.get_volumes()
def __init__(self, config): """Initialize the API wrapper.""" from qnapstats import QNAPStats protocol = "https" if config.get(CONF_SSL) else "http" self._api = QNAPStats(protocol + "://" + config.get(CONF_HOST), config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD)) self.data = {}
def __init__(self, config): """Initialize the API wrapper.""" protocol = "https" if config[CONF_SSL] else "http" self._api = QNAPStats( f"{protocol}://{config.get(CONF_HOST)}", config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD), verify_ssl=config.get(CONF_VERIFY_SSL), timeout=config.get(CONF_TIMEOUT), ) self.data = {}
def __init__(self, config): """Initialize the API wrapper.""" from qnapstats import QNAPStats protocol = "https" if config.get(CONF_SSL) else "http" self._api = QNAPStats( "{}://{}".format(protocol, config.get(CONF_HOST)), config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD), verify_ssl=config.get(CONF_VERIFY_SSL), timeout=config.get(CONF_TIMEOUT), ) self.data = {}
def __init__(self, config): """Initialize the API wrapper.""" from qnapstats import QNAPStats protocol = "https" if config.get(CONF_SSL) else "http" self._api = QNAPStats( protocol + "://" + config.get(CONF_HOST), config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD)) self.data = {}
class QnapSummary: __qnap = None def __init__(self, config): self.__qnap = QNAPStats(config['qnap']['ip'], config['qnap']['port'], config['qnap']['user'], config['qnap']['pass']) def get_stats(self): system_status = self.__qnap.get_system_stats() hdd_health = self.__qnap.get_smart_disk_health() return { 'temperature': { 'cpu': system_status['cpu']['temp_c'], 'hdd1': hdd_health['0:1']['temp_c'], 'hdd2': hdd_health['0:2']['temp_c'], 'system:': system_status['system']['temp_c'] }, 'health': { 'system': self.__qnap.get_system_health(), 'hdd1': hdd_health['0:1']['health'], 'hdd2': hdd_health['0:2']['health'] }, 'usage': { 'cpu': system_status['cpu']['usage_percent'], 'memory': system_status['memory']['free'] / system_status['memory']['total'] * 100, 'hdd': self.__calculate_hdd_usage(hdd_health, self.__qnap.get_volumes()) } } def __calculate_hdd_usage(self, hdd_info, volumes): free_size = 0 for v in volumes.values(): free_size += v['free_size'] return self.__convert_bytes_to_tb(free_size) / float(hdd_info['0:1']['capacity'].split(' ')[0]) * 100 def __convert_bytes_to_tb(self, size): return size / 1024 / 1024 / 1024 / 1024;
def __init__(self, config): """Initialize the API wrapper.""" from qnapstats import QNAPStats protocol = "https" if config.get(CONF_SSL) else "http" self._api = QNAPStats( '{}://{}'.format(protocol, config.get(CONF_HOST)), config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD), verify_ssl=config.get(CONF_VERIFY_SSL), timeout=config.get(CONF_TIMEOUT), ) self.data = {}
def __init__(self, config): self.__qnap = QNAPStats(config['qnap']['ip'], config['qnap']['port'], config['qnap']['user'], config['qnap']['pass'])