Beispiel #1
0
    def run(self, context):
        if not context.inventory_timer.is_it_time():
            return

        log.info("Syncing the inventory...")
        inventory_data = inventory.aggregate(
            settings.PATHS.inventory_scripts,
            settings.PATHS.device_type,
            settings.PATHS.artifact_info,
        )
        if inventory_data:
            log.debug(f"aggregated inventory data: {inventory_data}")
            if not client_inventory.request(
                    context.config.ServerURL,
                    context.JWT,
                    inventory_data,
                    context.config.ServerCertificate,
                    method="PUT",
            ):
                log.info(
                    "Falling back to to updating the inventory with PATCH")
                # Ignoring the returned error. It will only be logged
                if not client_inventory.request(
                        context.config.ServerURL,
                        context.JWT,
                        inventory_data,
                        context.config.ServerCertificate,
                        method="PATCH",
                ):
                    log.error("Failed to submit the inventory")
                    return None
        else:
            log.info("No inventory data found")
            return None
        log.info("Inventory submitted successfully")
Beispiel #2
0
 def test_no_jwt(self, caplog, server_url, method):
     inventory.request(
         server_url,
         "",
         {"this is inventory": "data"},
         "this is the server certificate",
         method,
     )
     assert "No JWT not provided, unable to upload the inventory" in caplog.text
Beispiel #3
0
 def test_server_url(self, caplog, test_input, expected, method):
     inventory.request(
         test_input,
         "this is the JWT",
         {"this is inventory": "data"},
         "this is the server certificate",
         method,
     )
     assert expected in caplog.text
Beispiel #4
0
 def test_all_parameters_are_correct(self, server_url, caplog, method):
     inventory.request(
         server_url,
         "this is the JWT",
         {"this is inventory": "data"},
         "this is the server certificate",
         method,
     )
     assert "inventory response" in caplog.text
Beispiel #5
0
 def test_no_inventory_data(self, caplog, server_url, method):
     inventory.request(
         server_url,
         "this is the JWT",
         {},
         "this is the server certificate",
         method,
     )
     assert "No inventory_data provided" in caplog.text
Beispiel #6
0
 def run(self, context):
     log.info("Syncing the inventory...")
     inventory_data = inventory.aggregate(
         settings.PATHS.inventory_scripts,
         settings.PATHS.device_type,
         settings.PATHS.artifact_info,
     )
     if inventory_data:
         log.debug(f"aggreated inventory data: {inventory_data}")
         client_inventory.request(
             context.config.ServerURL,
             context.JWT,
             inventory_data,
             context.config.ServerCertificate,
         )
     else:
         log.info("No inventory data found")
     time.sleep(1)
Beispiel #7
0
 def test_staus_codes(self, httpserver, caplog, method, status_code,
                      expected_log, return_value):
     httpserver.expect_request(
         "/testStatusCodes/api/devices/v1/inventory/device/attributes"
     ).respond_with_json({"foo": "bar"}, status=status_code)
     r = inventory.request(
         httpserver.url_for("testStatusCodes"),
         "this is the JWT",
         {"this is inventory": "data"},
         "this is the server certificate",
         method,
     )
     assert r == return_value
     assert expected_log in caplog.text