示例#1
0
 def test_app_manager_doesnt_load_crap_queries(self):
     app_mgr = ApplicationQueryManager(self.fw_query)
     app_mgr.retrieve_all_queries_in_group(MAIN_GROUP_ID)
     self.assertEqual(len(app_mgr.app_queries), 2)
     self.assertTrue(120 not in app_mgr.app_queries.keys())
     self.assertTrue(101 in app_mgr.app_queries.keys())
     self.assertTrue(105 in app_mgr.app_queries.keys())
示例#2
0
 def test_app_manager_invalid_query_cannot_validate(self):
     app_mgr = ApplicationQueryManager(self.fw_query)
     self.assertFalse(
         app_mgr.is_query_valid(FakeQueryInterface.TEST_QUERY_DATA_INVALID))
     self.assertFalse(
         app_mgr.is_query_valid(
             FakeQueryInterface.TEST_QUERY_DATA_ALMOST_VALID1))
     self.assertFalse(
         app_mgr.is_query_valid(
             FakeQueryInterface.TEST_QUERY_DATA_ALMOST_VALID2))
示例#3
0
    def test_app_mgr_can_create_queries(self):
        loaded_data = []

        def test_query_load(json_data):
            nonlocal loaded_data
            loaded_data.append(json_data)

        my_query = FakeQueryInterface(test_query_load)
        app_mgr = ApplicationQueryManager(my_query)
        app_mgr.create_default_queries_in_group(MAIN_GROUP_ID)

        self.assertEqual(9, len(loaded_data))
示例#4
0
    def init_services(self):
        self.cfg = ExtraMetricsConfiguration()
        read_config_helper(self.cfg)

        self.fw_query = FWRestQuery(
            hostname=self.cfg.get_fw_api_server_hostname(),
            api_key=self.cfg.get_fw_api_key(),
            verify_tls=self.cfg.get_verify_tls())

        self.app_qm = ApplicationQueryManager(self.fw_query)
        self.software_patches = SoftwarePatchStatus(self.fw_query)
        self.per_device = PerDeviceStatus(self.fw_query)

        self.zmq_sub = ZMQConnector(
            self.cfg,
            lambda topic, payload: self.event_callback(topic, payload))
示例#5
0
    def test_app_manager_rolls_queries_and_populates_metrics(self):
        app_mgr = ApplicationQueryManager(self.fw_query)
        app_mgr.validate_query_definitions()
        app_mgr.collect_application_query_results()

        after = REGISTRY.get_sample_value('extra_metrics_application_version',
                                          labels={
                                              "query_name":
                                              "Adobe Acrobat Reader Win",
                                              "application_version": "12.1",
                                              "query_id": "101"
                                          })
        self.assertEqual(1, after)

        after = REGISTRY.get_sample_value('extra_metrics_application_version',
                                          labels={
                                              "query_name":
                                              "Adobe Acrobat Reader Win",
                                              "application_version":
                                              "20.009.20067",
                                              "query_id": "101"
                                          })
        self.assertEqual(2, after)

        after = REGISTRY.get_sample_value('extra_metrics_application_version',
                                          labels={
                                              "query_name": "Zoom Win",
                                              "application_version": "20.1",
                                              "query_id": "105"
                                          })
        self.assertEqual(1, after)
示例#6
0
    def test_app_manager_collecting_twice_doesnt_cause_totals_to_double(self):
        app_mgr = ApplicationQueryManager(self.fw_query)
        app_mgr.validate_query_definitions()

        app_mgr.collect_application_query_results()
        app_mgr.collect_application_query_results()

        after = REGISTRY.get_sample_value('extra_metrics_application_version',
                                          labels={
                                              "query_name":
                                              "Adobe Acrobat Reader Win",
                                              "application_version": "12.1",
                                              "query_id": "101"
                                          })
        self.assertEqual(1, after)
示例#7
0
class MainRuntime:
    def __init__(self, logger):
        self.cfg = None
        self.zmq_sub = None
        self.app_qm = None
        self.software_patches = None
        self.per_device = None
        self.logger = logger
        self.rerun_data_collection = True

    def init_services(self):
        self.cfg = ExtraMetricsConfiguration()
        read_config_helper(self.cfg)

        self.fw_query = FWRestQuery(
            hostname=self.cfg.get_fw_api_server_hostname(),
            api_key=self.cfg.get_fw_api_key(),
            verify_tls=self.cfg.get_verify_tls())

        self.app_qm = ApplicationQueryManager(self.fw_query)
        self.software_patches = SoftwarePatchStatus(self.fw_query)
        self.per_device = PerDeviceStatus(self.fw_query)

        self.zmq_sub = ZMQConnector(
            self.cfg,
            lambda topic, payload: self.event_callback(topic, payload))

    def event_callback(self, topic, payload):
        self.logger.info(f"event received: {topic}")

        interesting_topics = [
            "/server/update_model_finished",
            "/api/auditlog",
        ]

        debug_topics = interesting_topics + [
            "/inventory/inventory_query_changed", "/server/change_packets",
            "/client/"
        ]

        for test_topic in debug_topics:
            if topic.startswith(test_topic):
                pretty_print_json = json.dumps(payload, indent=4)
                logger.info(f"topic: {topic}")
                logger.info(f"payload: {pretty_print_json}")

        if topic in interesting_topics:
            if topic == "/api/auditlog" and "Report Created" not in payload[
                    "message"]:
                return

            # set a flag in state indicating that the data collection should run imminently
            logger.info(f"topic {topic} fired; will re-queue data collection")
            self.rerun_data_collection = True

    async def validate_and_collect_data(self):
        self.app_qm.validate_query_definitions()
        self.app_qm.collect_application_query_results()

        self.software_patches.collect_patch_data_status()
        # WARNING; the per_device class relies on data collected from software updates, keep
        # this order of execution.
        self.per_device.collect_client_data(self.software_patches)

        self.rerun_data_collection = False
示例#8
0
 def test_app_mgr_rejects_invalid_inventory_query(self):
     app_mgr = ApplicationQueryManager(self.fw_query)
     result = app_mgr.is_query_valid(66)
     self.assertFalse(result)
示例#9
0
 def test_app_mgr_accepts_valid_inventory_query(self):
     app_mgr = ApplicationQueryManager(self.fw_query)
     result = app_mgr.is_query_valid(55)
     self.assertTrue(result)
示例#10
0
 def test_app_manager_query_validation(self):
     app_mgr = ApplicationQueryManager(self.fw_query)
     self.assertEqual(len(app_mgr.app_queries), 0)
     app_mgr.validate_query_definitions()
     self.assertEqual(len(app_mgr.app_queries), 2)