diff options
Diffstat (limited to 'src/libs/zbxaudit/audit_graph.c')
-rw-r--r-- | src/libs/zbxaudit/audit_graph.c | 133 |
1 files changed, 85 insertions, 48 deletions
diff --git a/src/libs/zbxaudit/audit_graph.c b/src/libs/zbxaudit/audit_graph.c index 3d7d1efc232..b4971eda8b8 100644 --- a/src/libs/zbxaudit/audit_graph.c +++ b/src/libs/zbxaudit/audit_graph.c @@ -52,6 +52,7 @@ void zbx_audit_graph_create_entry(int audit_action, zbx_uint64_t graphid, const resource_type = graph_flag_to_resource_type(flags); local_audit_graph_entry.id = graphid; + local_audit_graph_entry.id_table = AUDIT_GRAPH_ID; found_audit_graph_entry = (zbx_audit_entry_t**)zbx_hashset_search(zbx_get_audit_hashset(), &(local_audit_graph_entry_x)); @@ -60,25 +61,26 @@ void zbx_audit_graph_create_entry(int audit_action, zbx_uint64_t graphid, const { zbx_audit_entry_t *local_audit_graph_entry_insert; - local_audit_graph_entry_insert = zbx_audit_entry_init(graphid, name, audit_action, resource_type); + local_audit_graph_entry_insert = zbx_audit_entry_init(graphid, AUDIT_GRAPH_ID, name, audit_action, + resource_type); zbx_hashset_insert(zbx_get_audit_hashset(), &local_audit_graph_entry_insert, sizeof(local_audit_graph_entry_insert)); if (AUDIT_ACTION_ADD == audit_action) { - zbx_audit_update_json_append_uint64(graphid, AUDIT_DETAILS_ACTION_ADD, GR_OR_GRP(graphid), - graphid); + zbx_audit_update_json_append_uint64(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, + GR_OR_GRP(graphid), graphid, "graphs", "graphid"); } } } -void zbx_audit_graph_update_json_add_data(zbx_uint64_t graphid, const char *graph_copy_name, int width, int height, +void zbx_audit_graph_update_json_add_data(zbx_uint64_t graphid, const char *name, int width, int height, double yaxismin, double yaxismax, zbx_uint64_t templateid, int show_work_period, int show_triggers, int graphtype, int show_legend, int show_3d, double percent_left, double percent_right, int ymin_type, int ymax_type, zbx_uint64_t ymin_itemid, zbx_uint64_t ymax_itemid, int flags, int discover) { - char audit_key[AUDIT_DETAILS_KEY_LEN], audit_key_graph_copy_name[AUDIT_DETAILS_KEY_LEN], + char audit_key[AUDIT_DETAILS_KEY_LEN], audit_key_name[AUDIT_DETAILS_KEY_LEN], audit_key_width[AUDIT_DETAILS_KEY_LEN], audit_key_height[AUDIT_DETAILS_KEY_LEN], audit_key_yaxismin[AUDIT_DETAILS_KEY_LEN], audit_key_yaxismax[AUDIT_DETAILS_KEY_LEN], audit_key_templateid[AUDIT_DETAILS_KEY_LEN], audit_key_show_work_period[AUDIT_DETAILS_KEY_LEN], @@ -97,7 +99,7 @@ void zbx_audit_graph_update_json_add_data(zbx_uint64_t graphid, const char *grap zbx_snprintf(audit_key, sizeof(audit_key), (AUDIT_RESOURCE_GRAPH == resource_type) ? "graph" : "graphprototype"); #define AUDIT_KEY_SNPRINTF(r) zbx_snprintf(audit_key_##r, sizeof(audit_key_##r), GR_OR_GRP(r)); - AUDIT_KEY_SNPRINTF(graph_copy_name) + AUDIT_KEY_SNPRINTF(name) AUDIT_KEY_SNPRINTF(width) AUDIT_KEY_SNPRINTF(height) AUDIT_KEY_SNPRINTF(yaxismin) @@ -117,43 +119,51 @@ void zbx_audit_graph_update_json_add_data(zbx_uint64_t graphid, const char *grap AUDIT_KEY_SNPRINTF(flags) AUDIT_KEY_SNPRINTF(discover) #undef AUDIT_KEY_SNPRINTF - zbx_audit_update_json_append_no_value(graphid, AUDIT_DETAILS_ACTION_ADD, audit_key); -#define ADD_STR(r) zbx_audit_update_json_append_string(graphid, AUDIT_DETAILS_ACTION_ADD, audit_key_##r, r); -#define ADD_UINT64(r) zbx_audit_update_json_append_uint64(graphid, AUDIT_DETAILS_ACTION_ADD, audit_key_##r, r); -#define ADD_INT(r) zbx_audit_update_json_append_int(graphid, AUDIT_DETAILS_ACTION_ADD, audit_key_##r, r); -#define ADD_DOUBLE(r) zbx_audit_update_json_append_double(graphid, AUDIT_DETAILS_ACTION_ADD, audit_key_##r, r); - ADD_STR(graph_copy_name) - ADD_INT(width) - ADD_INT(height) - ADD_DOUBLE(yaxismin) - ADD_DOUBLE(yaxismax) - ADD_UINT64(templateid) - ADD_INT(show_work_period) - ADD_INT(show_triggers) - ADD_INT(graphtype) - ADD_INT(show_legend) - ADD_INT(show_3d) - ADD_DOUBLE(percent_left) - ADD_DOUBLE(percent_right) - ADD_INT(ymin_type) - ADD_INT(ymax_type) - ADD_UINT64(ymin_itemid) - ADD_UINT64(ymax_itemid) - ADD_INT(flags) - ADD_INT(discover) + zbx_audit_update_json_append_no_value(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, audit_key); +#define ADD_STR(r, t, f) zbx_audit_update_json_append_string(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, \ + audit_key_##r, r, t, f); +#define ADD_UINT64(r, t, f) zbx_audit_update_json_append_uint64(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, \ + audit_key_##r, r, t, f); +#define ADD_INT(r, t, f) zbx_audit_update_json_append_int(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, \ + audit_key_##r, r, t, f); +#define ADD_DOUBLE(r, t, f) zbx_audit_update_json_append_double(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, \ + audit_key_##r, r, t, f); +#define AUDIT_TABLE_NAME "graphs" + ADD_STR(name, AUDIT_TABLE_NAME, "name") + ADD_INT(width, AUDIT_TABLE_NAME, "width") + ADD_INT(height, AUDIT_TABLE_NAME, "height") + ADD_DOUBLE(yaxismin, AUDIT_TABLE_NAME, "yaxismin") + ADD_DOUBLE(yaxismax, AUDIT_TABLE_NAME, "yaxismax") + ADD_UINT64(templateid, AUDIT_TABLE_NAME, "templateid") + ADD_INT(show_work_period, AUDIT_TABLE_NAME, "show_work_period") + ADD_INT(show_triggers, AUDIT_TABLE_NAME, "show_triggers") + ADD_INT(graphtype, AUDIT_TABLE_NAME, "graphtype") + ADD_INT(show_legend, AUDIT_TABLE_NAME, "show_legend") + ADD_INT(show_3d, AUDIT_TABLE_NAME, "show_3d") + ADD_DOUBLE(percent_left, AUDIT_TABLE_NAME, "percent_left") + ADD_DOUBLE(percent_right, AUDIT_TABLE_NAME, "percent_right") + ADD_INT(ymin_type, AUDIT_TABLE_NAME, "ymin_type") + ADD_INT(ymax_type, AUDIT_TABLE_NAME, "ymax_type") + ADD_UINT64(ymin_itemid, AUDIT_TABLE_NAME, "ymin_itemid") + ADD_UINT64(ymax_itemid, AUDIT_TABLE_NAME, "ymax_itemid") + ADD_INT(flags, AUDIT_TABLE_NAME, "flags") + if (AUDIT_RESOURCE_GRAPH_PROTOTYPE == resource_type) + ADD_INT(discover, AUDIT_TABLE_NAME, "discover") #undef ADD_STR #undef ADD_UINT64 #undef ADD_INT #undef ADD_DOUBLE +#undef AUDIT_TABLE_NAME } void zbx_audit_graph_update_json_add_gitems(zbx_uint64_t graphid, int flags, zbx_uint64_t gitemid, int drawtype, - int sortorder, const char *color, int yaxisside, int calc_fnc, int type) + int sortorder, const char *color, int yaxisside, int calc_fnc, int type, zbx_uint64_t itemid) { char audit_key_[AUDIT_DETAILS_KEY_LEN], audit_key_drawtype[AUDIT_DETAILS_KEY_LEN], audit_key_sortorder[AUDIT_DETAILS_KEY_LEN], audit_key_color[AUDIT_DETAILS_KEY_LEN], audit_key_yaxisside[AUDIT_DETAILS_KEY_LEN], - audit_key_calc_fnc[AUDIT_DETAILS_KEY_LEN], audit_key_type[AUDIT_DETAILS_KEY_LEN]; + audit_key_calc_fnc[AUDIT_DETAILS_KEY_LEN], audit_key_type[AUDIT_DETAILS_KEY_LEN], + audit_key_itemid[AUDIT_DETAILS_KEY_LEN]; int resource_type; RETURN_IF_AUDIT_OFF(); @@ -170,18 +180,26 @@ void zbx_audit_graph_update_json_add_gitems(zbx_uint64_t graphid, int flags, zbx AUDIT_KEY_GITEMS_SNPRINTF(yaxisside, .) AUDIT_KEY_GITEMS_SNPRINTF(calc_fnc, .) AUDIT_KEY_GITEMS_SNPRINTF(type, .) - - zbx_audit_update_json_append_no_value(graphid, AUDIT_DETAILS_ACTION_ADD, audit_key_); -#define ADD_STR(r) zbx_audit_update_json_append_string(graphid, AUDIT_DETAILS_ACTION_ADD, audit_key_##r, r); -#define ADD_INT(r) zbx_audit_update_json_append_int(graphid, AUDIT_DETAILS_ACTION_ADD, audit_key_##r, r); - ADD_INT(drawtype) - ADD_INT(sortorder) - ADD_STR(color); - ADD_INT(yaxisside) - ADD_INT(calc_fnc) - ADD_INT(type) + AUDIT_KEY_GITEMS_SNPRINTF(itemid, .) + + zbx_audit_update_json_append_no_value(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, audit_key_); +#define ADD_STR(r, t, f) zbx_audit_update_json_append_string(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, \ + audit_key_##r, r, t, f); +#define ADD_INT(r, t, f) zbx_audit_update_json_append_int(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, \ + audit_key_##r, r, t, f); +#define ADD_UINT64(r, t, f) zbx_audit_update_json_append_uint64(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_ADD, \ + audit_key_##r, r, t, f); +#define AUDIT_TABLE_NAME "graphs_items" + ADD_INT(drawtype, AUDIT_TABLE_NAME, "drawtype") + ADD_INT(sortorder, AUDIT_TABLE_NAME, "sortorder") + ADD_STR(color, AUDIT_TABLE_NAME, "color"); + ADD_INT(yaxisside, AUDIT_TABLE_NAME, "yaxisside") + ADD_INT(calc_fnc, AUDIT_TABLE_NAME, "calc_fnc") + ADD_INT(type, AUDIT_TABLE_NAME, "type") + ADD_UINT64(itemid, AUDIT_TABLE_NAME, "itemid") #undef ADD_STR #undef ADD_INT +#undef AUDIT_TABLE_NAME } #define PREPARE_AUDIT_GRAPH_UPDATE(resource, type1, type2) \ @@ -197,7 +215,7 @@ void zbx_audit_graph_update_json_update_##resource(zbx_uint64_t graphid, int fla \ zbx_snprintf(buf, sizeof(buf), GR_OR_GRP(resource)); \ \ - zbx_audit_update_json_update_##type2(graphid, buf, resource##_old, resource##_new); \ + zbx_audit_update_json_update_##type2(graphid, AUDIT_GRAPH_ID, buf, resource##_old, resource##_new); \ } PREPARE_AUDIT_GRAPH_UPDATE(name, const char*, string) @@ -214,10 +232,10 @@ PREPARE_AUDIT_GRAPH_UPDATE(percent_left, double, double) PREPARE_AUDIT_GRAPH_UPDATE(percent_right, double, double) PREPARE_AUDIT_GRAPH_UPDATE(ymin_type, int, int) PREPARE_AUDIT_GRAPH_UPDATE(ymax_type, int, int) -PREPARE_AUDIT_GRAPH_UPDATE(ymin_itemid, uint64_t, uint64) -PREPARE_AUDIT_GRAPH_UPDATE(ymax_itemid, uint64_t, uint64) +PREPARE_AUDIT_GRAPH_UPDATE(ymin_itemid, zbx_uint64_t, uint64) +PREPARE_AUDIT_GRAPH_UPDATE(ymax_itemid, zbx_uint64_t, uint64) PREPARE_AUDIT_GRAPH_UPDATE(discover, int, int) -PREPARE_AUDIT_GRAPH_UPDATE(templateid, uint64_t, uint64) +PREPARE_AUDIT_GRAPH_UPDATE(templateid, zbx_uint64_t, uint64) #undef PREPARE_AUDIT_GRAPH_UPDATE #undef GR_OR_GRP @@ -233,7 +251,7 @@ void zbx_audit_graph_update_json_update_gitem_create_entry(zbx_uint64_t graphid, AUDIT_KEY_GITEMS_SNPRINTF(,) - zbx_audit_update_json_append_no_value(graphid, AUDIT_DETAILS_ACTION_UPDATE, audit_key_); + zbx_audit_update_json_append_no_value(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_UPDATE, audit_key_); } #define PREPARE_AUDIT_GRAPH_UPDATE(resource, type1, type2) \ @@ -249,8 +267,10 @@ void zbx_audit_graph_update_json_update_gitem_update_##resource(zbx_uint64_t gra \ AUDIT_KEY_GITEMS_SNPRINTF(resource, .) \ \ - zbx_audit_update_json_update_##type2(graphid, audit_key_##resource, resource##_old, resource##_new); \ + zbx_audit_update_json_update_##type2(graphid, AUDIT_GRAPH_ID, audit_key_##resource, resource##_old, \ + resource##_new); \ } +PREPARE_AUDIT_GRAPH_UPDATE(itemid, zbx_uint64_t, uint64) PREPARE_AUDIT_GRAPH_UPDATE(drawtype,int, int) PREPARE_AUDIT_GRAPH_UPDATE(sortorder, int, int) PREPARE_AUDIT_GRAPH_UPDATE(color, const char*, string) @@ -261,6 +281,23 @@ PREPARE_AUDIT_GRAPH_UPDATE(type, int, int) #undef PREPARE_AUDIT_GRAPH_UPDATE #undef AUDIT_KEY_GITEMS_SNPRINTF +void zbx_audit_graph_update_json_delete_gitems(zbx_uint64_t graphid, int flags, zbx_uint64_t gitemid) +{ + char audit_key[AUDIT_DETAILS_KEY_LEN]; + int resource_type; + + RETURN_IF_AUDIT_OFF(); + + resource_type = graph_flag_to_resource_type(flags); + + if (AUDIT_RESOURCE_GRAPH == resource_type) + zbx_snprintf(audit_key, sizeof(audit_key), "graph.gitems[" ZBX_FS_UI64 "]", gitemid); + else + zbx_snprintf(audit_key, sizeof(audit_key), "graphprototype.gitems[" ZBX_FS_UI64 "]", gitemid); + + zbx_audit_update_json_append_no_value(graphid, AUDIT_GRAPH_ID, AUDIT_DETAILS_ACTION_DELETE, audit_key); +} + void zbx_audit_DBselect_delete_for_graph(const char *sql, zbx_vector_uint64_t *ids) { DB_RESULT result; |