diff options
author | Andrejs Kozlovs <andrejs.kozlovs@zabbix.com> | 2021-08-20 09:19:37 +0300 |
---|---|---|
committer | Andrejs Kozlovs <andrejs.kozlovs@zabbix.com> | 2021-08-20 09:19:37 +0300 |
commit | 3fa63a467fcac3c6ac184c92be72d2196c43dfc0 (patch) | |
tree | 41f7d2f9f314ca194657683215e387358879cf10 /src/libs/zbxaudit/audit_host.c | |
parent | c50a284449a01efea43a0b8a3a752ca99c22ad47 (diff) |
........S. [ZBXNEXT-6810] preliminary commit before merge
Diffstat (limited to 'src/libs/zbxaudit/audit_host.c')
-rw-r--r-- | src/libs/zbxaudit/audit_host.c | 153 |
1 files changed, 117 insertions, 36 deletions
diff --git a/src/libs/zbxaudit/audit_host.c b/src/libs/zbxaudit/audit_host.c index a3b97b94bf7..62c65e5d361 100644 --- a/src/libs/zbxaudit/audit_host.c +++ b/src/libs/zbxaudit/audit_host.c @@ -27,9 +27,13 @@ audit_key_securitylevel[AUDIT_DETAILS_KEY_LEN], \ audit_key_authpassphrase[AUDIT_DETAILS_KEY_LEN], \ audit_key_privpassphrase[AUDIT_DETAILS_KEY_LEN], audit_key_authprotocol[AUDIT_DETAILS_KEY_LEN], \ - audit_key_privprotocol[AUDIT_DETAILS_KEY_LEN], audit_key_contextname[AUDIT_DETAILS_KEY_LEN]; \ + audit_key_privprotocol[AUDIT_DETAILS_KEY_LEN], audit_key_contextname[AUDIT_DETAILS_KEY_LEN], \ + audit_key[AUDIT_DETAILS_KEY_LEN]; \ + \ RETURN_IF_AUDIT_OFF(); \ \ + zbx_snprintf(audit_key, sizeof(audit_key), #auditentry".interfaces[" ZBX_FS_UI64 \ + "].details", interfaceid); \ zbx_snprintf(audit_key_version, sizeof(audit_key_version), #auditentry".interfaces[" ZBX_FS_UI64 \ "].details.version", interfaceid); \ zbx_snprintf(audit_key_bulk, sizeof(audit_key_bulk), #auditentry".interfaces[" ZBX_FS_UI64 \ @@ -57,10 +61,8 @@ void zbx_audit_##funcname##_update_json_add_snmp_interface(zbx_uint64_t hostid, const char *authpassphrase, const char *privpassphrase, zbx_uint64_t authprotocol, \ zbx_uint64_t privprotocol, const char *contextname, zbx_uint64_t interfaceid) \ { \ - char audit_key[AUDIT_DETAILS_KEY_LEN]; \ PREPARE_UPDATE_JSON_SNMP_INTERFACE_OP(auditentry) \ - zbx_snprintf(audit_key, sizeof(audit_key), #auditentry".interfaces[" ZBX_FS_UI64 "]", interfaceid); \ - zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key); \ + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key); \ zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_version, version); \ zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_bulk, bulk); \ zbx_audit_update_json_append_string(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_community, community); \ @@ -90,6 +92,7 @@ void zbx_audit_##funcname##_update_json_update_snmp_interface(zbx_uint64_t hosti const char *contextname_new, zbx_uint64_t interfaceid) \ { \ PREPARE_UPDATE_JSON_SNMP_INTERFACE_OP(funcname) \ + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_UPDATE, audit_key); \ zbx_audit_update_json_update_uint64(hostid, audit_key_version, version_old, version_new); \ zbx_audit_update_json_update_uint64(hostid, audit_key_bulk, bulk_old, bulk_new); \ zbx_audit_update_json_update_string(hostid, audit_key_community, community_old, community_new); \ @@ -188,6 +191,12 @@ void zbx_audit_##funcname##_create_entry(int audit_action, zbx_uint64_t hostid, zbx_json_init(&(local_audit_host_entry_insert->details_json), ZBX_JSON_STAT_BUF_LEN); \ zbx_hashset_insert(zbx_get_audit_hashset(), &local_audit_host_entry_insert, \ sizeof(local_audit_host_entry_insert)); \ + \ + if (AUDIT_ACTION_ADD == audit_action) \ + { \ + zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, \ + #auditentry".hostid", hostid); \ + } \ } \ } \ \ @@ -333,24 +342,30 @@ void zbx_audit_host_update_json_delete_hostmacro(zbx_uint64_t hostid, zbx_uint64 zbx_audit_update_json_delete(hostid, AUDIT_DETAILS_ACTION_DELETE, buf); } -void zbx_audit_hostgroup_update_json_attach(zbx_uint64_t hostid, zbx_uint64_t hostgroupid, zbx_uint64_t groupid) +void zbx_audit_hostgroup_update_json_add_group(zbx_uint64_t hostid, zbx_uint64_t hostgroupid, zbx_uint64_t groupid) { - char buf[AUDIT_DETAILS_KEY_LEN]; + char audit_key[AUDIT_DETAILS_KEY_LEN], audit_key_hostid[AUDIT_DETAILS_KEY_LEN], + audit_key_groupid[AUDIT_DETAILS_KEY_LEN]; RETURN_IF_AUDIT_OFF(); - zbx_snprintf(buf, sizeof(buf), "host.groups[" ZBX_FS_UI64 "].groupid", hostgroupid); - zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ATTACH, buf, groupid); + zbx_snprintf(audit_key, sizeof(audit_key), "host.groups[" ZBX_FS_UI64 "]", hostgroupid); + zbx_snprintf(audit_key_hostid, sizeof(audit_key_hostid), "host.groups[" ZBX_FS_UI64 "].hostid", hostgroupid); + zbx_snprintf(audit_key_groupid, sizeof(audit_key_groupid), "host.groups[" ZBX_FS_UI64 "].groupid", hostgroupid); + + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key); + zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_hostid, hostid); + zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_groupid, groupid); } -void zbx_audit_hostgroup_update_json_detach(zbx_uint64_t hostid, zbx_uint64_t hostgroupid, zbx_uint64_t groupid) +void zbx_audit_hostgroup_update_json_delete_group(zbx_uint64_t hostid, zbx_uint64_t hostgroupid, zbx_uint64_t groupid) { char buf[AUDIT_DETAILS_KEY_LEN]; RETURN_IF_AUDIT_OFF(); zbx_snprintf(buf, sizeof(buf), "host.groups[" ZBX_FS_UI64 "]", hostgroupid); - zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_DETACH, buf, groupid); + zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_DELETE, buf, groupid); } void zbx_audit_host_hostgroup_delete(zbx_uint64_t hostid, const char* hostname, zbx_vector_uint64_t *hostgroupids, @@ -366,7 +381,7 @@ void zbx_audit_host_hostgroup_delete(zbx_uint64_t hostid, const char* hostname, for (i = 0; i < groupids->values_num; i++) { zbx_snprintf(buf, sizeof(buf), "host.groups[" ZBX_FS_UI64 "].groupid", hostgroupids->values[i]); - zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_DETACH, buf, + zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_DELETE, buf, groupids->values[i]); } } @@ -473,12 +488,12 @@ void zbx_audit_host_prototype_update_json_add_details(zbx_uint64_t hostid, zbx_u custom_interfaces); } -void zbx_audit_host_prototype_update_json_add_templateid(zbx_uint64_t hostid, zbx_uint64_t templateid) +void zbx_audit_host_prototype_update_json_update_templateid(zbx_uint64_t hostid, zbx_uint64_t templateid_orig, + zbx_uint64_t templateid) { RETURN_IF_AUDIT_OFF(); - zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, "hostprototype.templateid", - templateid); + zbx_audit_update_json_update_uint64(hostid, "hostprototype.templateid", templateid_orig, templateid); } #define PREPARE_AUDIT_HOST_PROTOTYPE_UPDATE(resource, type1, type2) \ @@ -499,59 +514,96 @@ PREPARE_AUDIT_HOST_PROTOTYPE_UPDATE(custom_interfaces, int, int) void zbx_audit_host_prototype_update_json_add_group_details(zbx_uint64_t hostid, zbx_uint64_t group_prototypeid, const char* name, zbx_uint64_t groupid, zbx_uint64_t templateid) { - char audit_key_name[AUDIT_DETAILS_KEY_LEN], audit_key_groupid[AUDIT_DETAILS_KEY_LEN], + char audit_key[AUDIT_DETAILS_KEY_LEN], audit_key_hostid[AUDIT_DETAILS_KEY_LEN], + audit_key_name[AUDIT_DETAILS_KEY_LEN], audit_key_groupid[AUDIT_DETAILS_KEY_LEN], audit_key_templateid[AUDIT_DETAILS_KEY_LEN]; RETURN_IF_AUDIT_OFF(); if (0 != strlen(name)) { + zbx_snprintf(audit_key, sizeof(audit_key), "hostprototype.groupPrototypes[" ZBX_FS_UI64 "]", + group_prototypeid); + zbx_snprintf(audit_key_hostid, sizeof(audit_key_hostid), "hostprototype.groupPrototypes[" + ZBX_FS_UI64 "].hostid", group_prototypeid); zbx_snprintf(audit_key_name, sizeof(audit_key_name), "hostprototype.groupPrototypes[" ZBX_FS_UI64 - "].name", group_prototypeid); + "].name", group_prototypeid); + zbx_snprintf(audit_key_templateid, sizeof(audit_key_templateid), "hostprototype.groupPrototypes[" + ZBX_FS_UI64 "].templateid", group_prototypeid); zbx_audit_update_json_append_string(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_name, name); } else if (0 != groupid) { + zbx_snprintf(audit_key, sizeof(audit_key), "hostprototype.groupLinks[" ZBX_FS_UI64 "]", + group_prototypeid); + zbx_snprintf(audit_key_hostid, sizeof(audit_key_hostid), "hostprototype.groupLinks[" ZBX_FS_UI64 + "].hostid", group_prototypeid); zbx_snprintf(audit_key_groupid, sizeof(audit_key_groupid), "hostprototype.groupLinks[" ZBX_FS_UI64 "].groupid", group_prototypeid); - zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ATTACH, audit_key_groupid, - groupid); + zbx_snprintf(audit_key_templateid, sizeof(audit_key_templateid), "hostprototype.groupLinks[" ZBX_FS_UI64 + "].templateid", group_prototypeid); + zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_groupid, groupid); } - zbx_snprintf(audit_key_templateid, sizeof(audit_key_templateid), "hostprototype.groupPrototypes[" ZBX_FS_UI64 - "].templateid", group_prototypeid); + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key); + zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_hostid, hostid); zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_templateid, templateid); } void zbx_audit_host_prototype_update_json_update_group_links(zbx_uint64_t hostid, zbx_uint64_t groupid, zbx_uint64_t templateid_old, zbx_uint64_t templateid_new) { - char buf[AUDIT_DETAILS_KEY_LEN]; + char audit_key[AUDIT_DETAILS_KEY_LEN], audit_key_groupid[AUDIT_DETAILS_KEY_LEN]; RETURN_IF_AUDIT_OFF(); - zbx_snprintf(buf, sizeof(buf), "hostprototype.groupLinks[" ZBX_FS_UI64 "].groupid", groupid); + zbx_snprintf(audit_key, sizeof(audit_key_groupid), "hostprototype.groupLinks[" ZBX_FS_UI64 "]", groupid); + zbx_snprintf(audit_key_groupid, sizeof(audit_key_groupid), "hostprototype.groupLinks[" ZBX_FS_UI64 "].groupid", + groupid); - zbx_audit_update_json_update_uint64(hostid, buf, templateid_old, templateid_new); + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_UPDATE, audit_key); + zbx_audit_update_json_update_uint64(hostid, audit_key_groupid, templateid_old, templateid_new); } -#define PREPARE_AUDIT_TEMPLATE_OP(funcname, auditentry, op1, op2) \ -void zbx_audit_##funcname##_update_json_##op1##_parent_template(zbx_uint64_t hostid, \ +#define PREPARE_AUDIT_TEMPLATE_ADD(funcname, auditentry) \ +void zbx_audit_##funcname##_update_json_add_parent_template(zbx_uint64_t hostid, \ zbx_uint64_t hosttemplateid, zbx_uint64_t templateid) \ { \ - char buf[AUDIT_DETAILS_KEY_LEN]; \ + char audit_key[AUDIT_DETAILS_KEY_LEN], audit_key_hostid[AUDIT_DETAILS_KEY_LEN], \ + audit_key_templateid[AUDIT_DETAILS_KEY_LEN]; \ + \ + RETURN_IF_AUDIT_OFF(); \ + \ + zbx_snprintf(audit_key, sizeof(audit_key), #auditentry".templates[" ZBX_FS_UI64 "]", hosttemplateid); \ + zbx_snprintf(audit_key_hostid, sizeof(audit_key), #auditentry".templates[" ZBX_FS_UI64 "].hostid", \ + hosttemplateid); \ + zbx_snprintf(audit_key_templateid, sizeof(audit_key_templateid), #auditentry".templates[" ZBX_FS_UI64 \ + "].templateid", hosttemplateid); \ + \ + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key); \ + zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_hostid, hostid); \ + zbx_audit_update_json_append_uint64(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_templateid, \ + templateid); \ +} \ + +#define PREPARE_AUDIT_TEMPLATE_DELETE(funcname, auditentry) \ +void zbx_audit_##funcname##_update_json_delete_parent_template(zbx_uint64_t hostid, \ + zbx_uint64_t hosttemplateid) \ +{ \ + char audit_key_templateid[AUDIT_DETAILS_KEY_LEN]; \ \ RETURN_IF_AUDIT_OFF(); \ \ - zbx_snprintf(buf, sizeof(buf), #auditentry".templates[" ZBX_FS_UI64 "].templateid", hosttemplateid); \ + zbx_snprintf(audit_key_templateid, sizeof(audit_key_templateid), #auditentry".templates[" ZBX_FS_UI64 \ + "]", hosttemplateid); \ \ - zbx_audit_update_json_append_uint64(hostid, op2, buf, templateid); \ + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_DELETE, audit_key_templateid); \ } \ -PREPARE_AUDIT_TEMPLATE_OP(host, host, attach, AUDIT_DETAILS_ACTION_ATTACH) -PREPARE_AUDIT_TEMPLATE_OP(host, host, detach, AUDIT_DETAILS_ACTION_DETACH) -PREPARE_AUDIT_TEMPLATE_OP(host_prototype, hostprototype, attach, AUDIT_DETAILS_ACTION_ATTACH) -PREPARE_AUDIT_TEMPLATE_OP(host_prototype, hostprototype, detach, AUDIT_DETAILS_ACTION_DETACH) +PREPARE_AUDIT_TEMPLATE_ADD(host, host) +PREPARE_AUDIT_TEMPLATE_DELETE(host, host) +PREPARE_AUDIT_TEMPLATE_ADD(host_prototype, hostprototype) +PREPARE_AUDIT_TEMPLATE_DELETE(host_prototype, hostprototype) void zbx_audit_host_prototype_update_json_delete_interface(zbx_uint64_t hostid, zbx_uint64_t interfaceid) { @@ -567,23 +619,38 @@ void zbx_audit_host_prototype_update_json_delete_interface(zbx_uint64_t hostid, void zbx_audit_host_prototype_update_json_add_hostmacro(zbx_uint64_t hostid, zbx_uint64_t macroid, const char *macro, const char *value, const char *description, int type) { - char audit_key_name[AUDIT_DETAILS_KEY_LEN], audit_key_value[AUDIT_DETAILS_KEY_LEN], - audit_key_description[AUDIT_DETAILS_KEY_LEN], audit_key_type[AUDIT_DETAILS_KEY_LEN]; + char audit_key[AUDIT_DETAILS_KEY_LEN], audit_key_name[AUDIT_DETAILS_KEY_LEN], + audit_key_value[AUDIT_DETAILS_KEY_LEN], audit_key_description[AUDIT_DETAILS_KEY_LEN], + audit_key_type[AUDIT_DETAILS_KEY_LEN]; RETURN_IF_AUDIT_OFF(); + zbx_snprintf(audit_key, sizeof(audit_key), "hostprototype.macros[" ZBX_FS_UI64 "]", macroid); zbx_snprintf(audit_key_name, sizeof(audit_key_name), "hostprototype.macros[" ZBX_FS_UI64 "].name", macroid); zbx_snprintf(audit_key_value, sizeof(audit_key_value), "hostprototype.macros[" ZBX_FS_UI64 "].value", macroid); zbx_snprintf(audit_key_description, sizeof(audit_key_value), "hostprototype.macros[" ZBX_FS_UI64 "].description", macroid); zbx_snprintf(audit_key_type, sizeof(audit_key_type), "hostprototype.macros[" ZBX_FS_UI64 "].type", macroid); + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key); zbx_audit_update_json_append_string(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_name, macro); zbx_audit_update_json_append_string(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_value, value); zbx_audit_update_json_append_string(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_description, description); zbx_audit_update_json_append_int(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_type, type); } +void zbx_audit_host_prototype_update_json_update_hostmacro_create_entry(zbx_uint64_t hostid, + zbx_uint64_t hostmacroid) +{ + char buf[AUDIT_DETAILS_KEY_LEN]; + + RETURN_IF_AUDIT_OFF(); + + zbx_snprintf(buf, sizeof(buf), "hostprototype.macros[" ZBX_FS_UI64 "]", hostmacroid); + + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_UPDATE, buf); +} + #define PREPARE_AUDIT_HOST_PROTOTYPE_UPDATE_HOSTMACRO(resource, type1, type2) \ void zbx_audit_host_prototype_update_json_update_hostmacro_##resource(zbx_uint64_t hostid, \ zbx_uint64_t hostmacroid, type1 old_##resource, type1 new_##resource) \ @@ -592,7 +659,7 @@ void zbx_audit_host_prototype_update_json_update_hostmacro_##resource(zbx_uint64 \ RETURN_IF_AUDIT_OFF(); \ \ - zbx_snprintf(buf, sizeof(buf), "hostprototype.macros[" ZBX_FS_UI64 "]."#resource, hostmacroid); \ + zbx_snprintf(buf, sizeof(buf), "hostprototype.macros[" ZBX_FS_UI64 "]."#resource, hostmacroid); \ \ zbx_audit_update_json_update_##type2(hostid, buf, old_##resource, new_##resource); \ } \ @@ -616,17 +683,31 @@ void zbx_audit_host_prototype_update_json_delete_hostmacro(zbx_uint64_t hostid, void zbx_audit_host_prototype_update_json_add_tag(zbx_uint64_t hostid, zbx_uint64_t tagid, const char* tag, const char* value) { - char audit_key_tag[AUDIT_DETAILS_KEY_LEN], audit_key_value[AUDIT_DETAILS_KEY_LEN]; + char audit_key[AUDIT_DETAILS_KEY_LEN], audit_key_tag[AUDIT_DETAILS_KEY_LEN], + audit_key_value[AUDIT_DETAILS_KEY_LEN]; RETURN_IF_AUDIT_OFF(); + zbx_snprintf(audit_key, sizeof(audit_key), "hostprototype.tags[" ZBX_FS_UI64 "]", tagid); zbx_snprintf(audit_key_tag, sizeof(audit_key_tag), "hostprototype.tags[" ZBX_FS_UI64 "].tag", tagid); zbx_snprintf(audit_key_value, sizeof(audit_key_value), "hostprototype.tags[" ZBX_FS_UI64 "].value", tagid); + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key); zbx_audit_update_json_append_string(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_tag, tag); zbx_audit_update_json_append_string(hostid, AUDIT_DETAILS_ACTION_ADD, audit_key_value, value); } +void zbx_audit_host_prototype_update_json_update_tag_create_entry(zbx_uint64_t hostid, zbx_uint64_t tagid) +{ + char buf[AUDIT_DETAILS_KEY_LEN]; + + RETURN_IF_AUDIT_OFF(); + + zbx_snprintf(buf, sizeof(buf), "hostprototype.tags[" ZBX_FS_UI64 "]", tagid); + + zbx_audit_update_json_append(hostid, AUDIT_DETAILS_ACTION_UPDATE, buf); +} + void zbx_audit_host_prototype_update_json_update_tag_tag(zbx_uint64_t hostid, zbx_uint64_t tagid, const char* tag_old, const char *tag_new) { |