Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete denied parameters from host interfaces #1356

Merged
merged 4 commits into from
Aug 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions plugins/modules/zabbix_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ def update_inventory_zabbix(self, host_id, inventory):


# Add all default values to all missing parameters for existing interfaces
def update_exist_interfaces_with_defaults(exist_interfaces):
def update_exist_interfaces_with_defaults(exist_interfaces, zabbix_version):

new_exist_interfaces = []
default_interface = {
Expand All @@ -966,9 +966,29 @@ def update_exist_interfaces_with_defaults(exist_interfaces):
"privprotocol": 0,
"privpassphrase": ""
}
allowed_fields = [
'hostid',
'type',
'ip',
'dns',
'port',
'useip',
'main',
'details',
'interface_ref',
'items',
'interfaceid'
]
for interface in exist_interfaces:
normalized_interface = interface
if LooseVersion("7.0") <= LooseVersion(zabbix_version):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be >= ? 6.4 and 6.0 were working fine before.

Copy link
Collaborator Author

@masa-orca masa-orca Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it wrong code? checking fields process will runs for 7.0 and higher.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now you're checking for <= 7.0. That means it won't run in the future for 7.2, but it will run today for 6.4. 6.4 is working fine (don't think it needs the fields, but the API handles them gracefully). Either it needs to be >= 7.0 or we just sanitize them for all versions (which I don't honestly think is necessarily wrong).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now you're checking for <= 7.0

Does this mean integration test target is 7.0 and lower?

if LooseVersion("7.0") <= LooseVersion(zabbix_version):

If 6.4 and 6.0, zabbix_host module's behavior is not chenged from current behavior. in addition, this effects on 7.0, 7.2 and higher.

Either it needs to be >= 7.0 or we just sanitize them for all versions (which I don't honestly think is necessarily wrong).

If you want to check for all version, I will remove version checking condition.

denied_fields = list(set(interface.keys()) - set(allowed_fields))
normalized_interface = zabbix_utils.helper_normalize_data(
interface, del_keys=denied_fields
)[0]

new_interface = default_interface.copy()
new_interface.update(interface)
new_interface.update(normalized_interface)
new_interface["details"] = default_interface_details.copy()
if "details" in interface:
new_interface["details"].update(interface["details"])
Expand Down Expand Up @@ -1195,7 +1215,7 @@ def main():
# get existing host's interfaces
exist_interfaces = host._zapi.hostinterface.get({"output": "extend", "hostids": host_id})
exist_interfaces.sort(key=lambda x: int(x["interfaceid"]))
exist_interfaces = update_exist_interfaces_with_defaults(exist_interfaces)
exist_interfaces = update_exist_interfaces_with_defaults(exist_interfaces, host._zbx_api_version)

# Convert integer parameters from strings to ints
for idx, interface in enumerate(copy.deepcopy(exist_interfaces)):
Expand Down
Loading