def do_inventory_actions_during_checking_for( config_cache: config.ConfigCache, host_config: config.HostConfig, ipaddress: Optional[HostAddress], *, parsed_sections_broker: ParsedSectionsBroker, ) -> None: status_data_store = StructuredDataStore( Path(cmk.utils.paths.status_data_dir)) if not host_config.do_status_data_inventory: # includes cluster case status_data_store.remove_files(host_name=host_config.hostname) return # nothing to do here trees = _do_inv_for_realhost( host_config, ipaddress, parsed_sections_broker=parsed_sections_broker, run_plugin_names=EVERYTHING, retentions_tracker=RetentionsTracker([]), ) if trees.status_data and not trees.status_data.is_empty(): status_data_store.save(host_name=host_config.hostname, tree=trees.status_data)
def _save_inventory_tree( hostname: HostName, inventory_tree: StructuredDataNode, retentions: Retentions, ) -> Optional[StructuredDataNode]: inventory_store = StructuredDataStore(cmk.utils.paths.inventory_output_dir) if inventory_tree.is_empty(): # Remove empty inventory files. Important for host inventory icon inventory_store.remove_files(host_name=hostname) return None old_tree = inventory_store.load(host_name=hostname) update_result = retentions.may_update(int(time.time()), old_tree) if old_tree.is_empty(): console.verbose("New inventory tree.\n") elif not old_tree.is_equal(inventory_tree): console.verbose("Inventory tree has changed. Add history entry.\n") inventory_store.archive( host_name=hostname, archive_dir=cmk.utils.paths.inventory_archive_dir, ) elif update_result.save_tree: console.verbose( "Update inventory tree%s.\n" % (" (%s)" % update_result.reason if update_result.reason else "") ) else: console.verbose( "Inventory tree not updated%s.\n" % (" (%s)" % update_result.reason if update_result.reason else "") ) return None inventory_store.save(host_name=hostname, tree=inventory_tree) return old_tree