Esempio n. 1
0
    def get_status(self):
        data_status = self.request(SENCORE_URLS_ENUM.STATUS)

        for item in (SENCORE_DATA_PATH.STATUS_CPU_TEMP, SENCORE_DATA_PATH.STATUS_CPU_TEMP,
                     SENCORE_DATA_PATH.STATUS_FREE_MEM, SENCORE_DATA_PATH.STATUS_FREE_DISC, SENCORE_DATA_PATH.STATUS_TIME):
            self.data[item.ATTR] = deep_getitem(data_status, item.PATH)

        port_info = deep_getitem(data_status, SENCORE_DATA_PATH.STATUS_PORT)

        port_info = port_info.split(" ") if port_info else ("NO_DATA", "NO_DATA")
        port, bitrate = port_info[0], port_info[-1]
        if bitrate != "NO_DATA":
            bitrate = ''.join([x for x in bitrate if x.isdigit() or x == '.'])
            bitrate = int(round((float(bitrate))))
        self.data["port"] = port
        self.data["bitrate"] = unicode(bitrate)
Esempio n. 2
0
    def get_general(self):
        data_general = self.request(SENCORE_URLS_ENUM.GENERAL)
        self.data[SENCORE_DATA_PATH.GENERAL_VERSION.ATTR] = deep_getitem(
            data_general, SENCORE_DATA_PATH.GENERAL_VERSION.PATH)

        self.data[SENCORE_DATA_PATH.GENERAL_UPTIME.ATTR] = deep_getitem(
            data_general, SENCORE_DATA_PATH.GENERAL_UPTIME.PATH)

        mlerr_table = deep_getitem(data_general, SENCORE_DATA_PATH.GENERAL_MLERROR.PATH)
        mw_table = deep_getitem(data_general, SENCORE_DATA_PATH.GENERAL_MW.PATH)
        channel_table = deep_getitem(data_general, SENCORE_DATA_PATH.GENERAL_CHANNEL.PATH)

        for ts_name in self.data["tss"]:
            ts_nm = self.data["tss"][ts_name]["name"]
            for channel in channel_table:
                if ts_nm == channel["name"]:
                    channel_data = {
                        attr[0] if isinstance(attr, tuple) else attr:
                            channel.get(attr[1] if isinstance(attr, tuple) else attr)
                        for attr in SENCORE_DATA_PATH.GENERAL_CHANNEL.ATTR
                    }
                    self.data["tss"][ts_name].update(channel_data)
                    break

            ts_index = self.data["tss"][ts_name]["chindex"]

            for mlerr in mlerr_table:
                if ts_index == mlerr["chindex"]:
                    mlerr_data = {
                        attr[0] if isinstance(attr, tuple) else attr:
                            mlerr.get(attr[1] if isinstance(attr, tuple) else attr)
                        for attr in SENCORE_DATA_PATH.GENERAL_MLERROR.ATTR
                    }
                    self.data["tss"][ts_name].update(mlerr_data)
                    break

            for mwerr in mw_table:
                if ts_index == mwerr["chindex"]:
                    mwerr_data = {
                        attr[0] if isinstance(attr, tuple) else attr:
                            mwerr.get(attr[1] if isinstance(attr, tuple) else attr)
                        for attr in SENCORE_DATA_PATH.GENERAL_MW.ATTR
                    }
                    self.data["tss"][ts_name].update(mwerr_data)
                    break
Esempio n. 3
0
 def get_eth(self):
     """
     parse eth data from analyzer
     :return:
     """
     data_eth = self.request(SENCORE_URLS_ENUM.ETH)
     for ts_data in deep_getitem(data_eth, SENCORE_DATA_PATH.ETH_TSS.PATH):
         self.data["tss"][ts_data["name"]] = {
             attr: ts_data.get(attr) for attr in SENCORE_DATA_PATH.ETH_TSS.ATTR
         }
         self.data["tss"][ts_data["name"]]["services"] = {}
Esempio n. 4
0
 def get_time_eth(self):
     eth_time_data = self.request(SENCORE_URLS_ENUM.ETH_TIME)
     eth_time_datas = deep_getitem(eth_time_data, "tree,item")
     self.data["time_eth"] = 0
     if eth_time_datas:
         item = [o for o in eth_time_datas if o["id"] == "H_d_d_d_p20_t112_s0_x-1_a0_s24_e63_l1"][0]
         epoch = datetime.datetime(1970, 1, 1)
         ntp_client = ntplib.NTPClient()
         ntp_time = ntp_client.request(TIME_SERVER).tx_time
         dt = datetime.datetime.strptime(item["value"], "%Y.%m.%d %H:%M:%S")
         current_time = int((dt - epoch).total_seconds())
         self.data["time_eth"] = current_time
         self.data["time_eth_diff"] = current_time - ntp_time
Esempio n. 5
0
    def get_etr_qam(self):
        qam_data = self.data["qam"]
        qam_data["tss"] = {}
        qam_data_tss = qam_data["tss"]
        data_ert_qam = self.request(SENCORE_URLS_ENUM.ETR_ALL)
        ert_inputs = deep_getitem(data_ert_qam, SENCORE_DATA_PATH.ETR_INPUTS.PATH)
        ert_qam_inputs = [inp for inp in ert_inputs if inp["name"] == "QAM1"]
        if not ert_qam_inputs:
            return
        ert_qam_input = ert_qam_inputs[0]
        ert_qam_input_id = ert_qam_input.get("id")
        for ts_data in ert_qam_input["tuningSetup"]:
            qam_data_tss[ts_data["name"]] = {
                attr[0] if isinstance(attr, tuple) else attr:
                    ts_data.get(attr[1] if isinstance(attr, tuple) else attr)
                for attr in SENCORE_DATA_PATH.ETR_INPUTS.ATTR
            }
            qam_data_tss[ts_data["name"]]["services"] = {}
            services_raw = self.request(
                SENCORE_URLS_ENUM.ETR, input_id=ert_qam_input_id, ts_index=ts_data.get("id"))
            services = deep_getitem(services_raw, SENCORE_DATA_PATH.ETR_SERVICES.PATH)
            if not services:
                continue
            qam_data_tss_services = qam_data_tss[ts_data["name"]]["services"]
            for service in services:
                qam_data_tss_services[service["id"]] = {}
                qam_data_tss_services[service["id"]] = {
                    attr[0] if isinstance(attr, tuple) else attr:
                        ts_data.get(attr[1] if isinstance(attr, tuple) else attr)
                    for attr in SENCORE_DATA_PATH.GENERAL_MW.ATTR
                }
                qam_data_tss_services[service["id"]]["pid_count"] = len(service["pid"])
            check = [o for o in deep_getitem(
                services_raw,
                SENCORE_DATA_PATH.ETR_CHECKS.PATH
            ) if o["name"] == "Interface checks"][0]

            qam_data_tss[ts_data["name"]]["sid_count"] = len(qam_data_tss[ts_data["name"]]["services"])
Esempio n. 6
0
 def get_tdt_time(self):
     tdt_time_data = self.request(SENCORE_URLS_ENUM.TDT_TIME)
     tdt_time_datas = deep_getitem(tdt_time_data, "tree,item")
     if tdt_time_datas:
         item = [o for o in tdt_time_datas if o["id"] == "H_d_d_d_p20_t112_s0_x-1_a0_s24_e63_l1"][0]
         self.data["date"] = item["value"]
Esempio n. 7
0
    def get_etr(self):
        """
        parse etr data
        :return:
        """
        for ts_name in self.data["tss"]:
            ts_data = self.data["tss"][ts_name]
            ts_index = ts_data["index"]
            data_ert = self.request(SENCORE_URLS_ENUM.ETR, input_id=100, ts_index=ts_index)
            pids_raw = deep_getitem(data_ert, SENCORE_DATA_PATH.ETR_PIDS.PATH)

            if not pids_raw:
                continue
            if not isinstance(pids_raw, list):
                pids_raw = [pids_raw]
            pids_ids = set([p["id"] for p in pids_raw])

            services_raw = deep_getitem(data_ert, SENCORE_DATA_PATH.ETR_SERVICES.PATH)

            if not services_raw:
                continue

            if isinstance(services_raw, dict):
                services = [services_raw]
            else:
                services = services_raw

            for service in services:
                pmt_pid = [p for p in service["pid"] if p["type"] == "PMT"][0]["id"]
                service_data = {
                    attr: service.get(attr) for attr in SENCORE_DATA_PATH.ETR_SERVICES.ATTR
                }
                service_data["service_pids"] = [
                    p.get("id") for p in service["pid"]
                ]
                service_data["not_existed"] = []
                service_data["id"] = service.get("id")
                service_data["pids"] = {}
                for pid_raw in pids_raw:
                    pid_id = pid_raw["id"]
                    if pid_id in service_data.get("service_pids", {}):
                        pid_data = {
                            attr[0] if isinstance(attr, tuple) else attr:
                                pid_raw.get(attr[1] if isinstance(attr, tuple) else attr)
                            for attr in SENCORE_DATA_PATH.ETR_PIDS.ATTR
                        }
                        service_data["pids"][pid_data["id"]] = pid_data

                service_data["scrambled"] = any(map(lambda x: x["scrambled"], service_data["pids"].values()))

                for pid in SENCORE_ATTRS_ENUM.REQUIRED_PIDS:
                    if pid not in pids_ids:
                        service_data["not_existed"].append(pid)
                ts_data["services"][service_data["id"]] = service_data
                ts_data["services"]["count"] = len(services_raw)
            pid_empty = set(service_data["not_existed"])
            ts_data["not_existed"] = ",".join(pid_empty) if pid_empty else "OK"

            ts_data["scrambled"] = any(map(lambda x: x["scrambled"],
                                           [v for v in ts_data["services"].values() if not isinstance(v, int)]))

            ts_checks = {}
            ts_checks_raw = deep_getitem(data_ert, SENCORE_DATA_PATH.ETR_CHECKS.PATH)
            if not ts_checks_raw:
                continue

            for check_p in ts_checks_raw:
                priority_name = "_".join(
                    check_p["name"].replace(".", "").split(" ")
                ).lower()

                ts_checks[priority_name] = {}

                for check in check_p["check"]:
                    if not isinstance(check, dict):
                        continue
                    check_name = "_".join(check["name"].split(" ")).lower()
                    ts_checks[priority_name][check_name] = check.get("currentErrorCount")
                ts_checks[priority_name]["count"] = sum(map(lambda x: int(x), ts_checks[priority_name].values()))
            ts_data["checks"] = ts_checks