[ZBXNEXT-2070] LLD graphs name truncated Created: 2013 Dec 12  Updated: 2023 Jun 06

Status: Open
Project: ZABBIX FEATURE REQUESTS
Component/s: Installation (I)
Affects Version/s: 2.2.0
Fix Version/s: None

Type: Change Request Priority: Major
Reporter: Andrey Melnikov Assignee: Unassigned
Resolution: Unresolved Votes: 22
Labels: database, fieldlength, graphs, lld
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by ZBXNEXT-7751 Cannot create graph - value is too long Closed
is duplicated by ZBX-9212 Increase graph name from 128 characters Closed

 Description   

128 byte field for graph name in sql database is not enough.
When I use LLD with graphs prototype defined as 'Traffic on interface {#SNMPVALUE} {{HOST.HOST}:ifAlias{#SNMPVALUE}.last(0)}'
when server expand #SNMPVALUE to real value 'D-Link DGS-3120-24SC R1.02.013 Port 24 on Unit 1' - graph name truncated.
Expanding row to 255 bytes helps.



 Comments   
Comment by Chris Reynolds [ 2016 Jul 19 ]

Is this just a case of changing the schema file supplied so the type is varchar (255)?

Comment by Shriharsh Thanvi [ 2016 Sep 16 ]

Can we identify the area / impact of the change in question ?
It looks very quick fix on the face of it.

Comment by Shriharsh Thanvi [ 2016 Sep 21 ]

I attempted to change the DB schema, along with the schema file.
I was able to create a trigger prototype with max 255 characters.
But unfortunately, the change in graph prototype was not reflected when we push the values.
It looks like some more validation is also done at the backend c-libraries, created at the time of compilation.

Comment by Kirill H [ 2017 Oct 12 ]

Frankly, I'd say, that it should be 512 char. Just to be safe. ISP/DC level switchport descriptions are impacted by it.

Comment by sbindley [ 2018 Feb 23 ]

I think it's because of this https://support.zabbix.com/browse/ZBX-5687 issue that is closed and won't be fixed?

It would be good to go ahead and create the graph and truncate the name at 128 characters, then instead of showing in the info column in the discovery rule that a graph was not created because of the length, that it was created but the name truncated. That way you at least get the graph without having to go create it manually with a shorter name.

Changing the column length doesn't do anything, it's coded somewhere to check the length and reject it over 128 characters.

Comment by Billy Farrington [ 2020 Aug 31 ]

We're in the process of implementing Zabbix across our network. Currently we have 1000+ devices in Zabbix with 8000+ more planned, and we're running into this specific issue. Going through thousands of devices and renaming interfaces to fit within the 128 character limit is a hard stop for us for two reasons:

1. It would negatively impact several departments who use these interface names to identify circuits

2. It would be a massive undertaking to log into all of these devices and rename interfaces, which defeats the purpose of LLD.

 

Manually identifying missing graphs and creating them by hand is equally problematic. Ideally these graphs could be added with a truncated name, as suggested by sbindley. We will have to consider alternative solutions without it.

Having looked at the source briefly it appears this is limited by GRAPH_NAME_LEN within include/db.h as well as the name column width in the database table definition. For now I'm going to do some experimentation and see what kind of issues we run into with increasing these values, but an official solution would be perferred.

Comment by Andrey Melnikov [ 2020 Aug 31 ]

> GRAPH_NAME_LEN within include/db.h as well as the name column width in the database table definition
No, you find only half part of iceberg. You must also hack 128 byte limit in src/libs/zbxdbhigh/dbschema.c and include/schema.inc.php - enjoy real-time validation!

> official solution would be perferred.
Four years official solution is "not a problem for us" (C)

Comment by Billy Farrington [ 2020 Sep 01 ]

Thanks. I had found include/schema.inc.php already but not the other one. I decided instead that it might be easier to come at the problem before it gets there. It's an ugly hack, but I'm working on having it truncate the initial snmp query response for ifAlias before it gets passed in. That way it avoids the character limit issue.

Comment by Josh Rogers [ 2023 Jun 06 ]

@Billy, I'm interested in your stop-gap solution of truncating the ifalias.  Were you able to get that working, and can you provide patch files?

Comment by Billy Farrington [ 2023 Jun 06 ]

@Josh, yes and no. Yes I was able to get it working and it has been doing well ever since, but no I don't recall exactly what it was I had done to resolve this particular error. I've made a bunch of other changes and added new views and API extensions since then to better suit our needs, so it's a bit hard to tell what is original and what isn't at this point. I'll do some poking around in it and see if anything refreshes my memory.

Comment by Billy Farrington [ 2023 Jun 06 ]

Looks like what I ended up doing was in /src/libs/zbxdbhigh/host.c and /src/libs/zbxdbhigh/lld_graph.c I checked the length of the graph name and truncated it if necessary right before the insert and update queries are generated. Someone else could very likely do a better job of it than I have, and it should be using the value from dbschema.c instead of a hard-coded length. I simply cut off the end and added a '...' to indicate that it was truncated. Obviously use this info at your own risk.

/src/libs/zbxdbhigh/host.c:

 

                if (strlen(name_esc) > 127) {
                        char *nCpy = malloc(sizeof(char) * 124);
                        strncpy(nCpy, name_esc, 124);
                        strcat(nCpy, "...");
                        strcpy(name_esc, nCpy);
                }
                zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
                                "insert into graphs"
                                " (graphid,name,width,height,yaxismin,yaxismax,templateid,"
                                "show_work_period,show_triggers,graphtype,show_legend,"
                                "show_3d,percent_left,percent_right,ymin_type,ymax_type,"

 

                if (strlen(name_esc) > 127) {
                        char *nCpy = malloc(sizeof(char) * 124);
                        strncpy(nCpy, name_esc, 124);
                        strcat(nCpy, "...");
                        strcpy(name_esc, nCpy);
                }

                zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
                                "update graphs"
                                " set name='%s',"
                                        "width=%d,"
                                        "height=%d,"
                                        "yaxismin=" ZBX_FS_DBL ","

/src/libs/zbxdbhigh/lld_graph.c:

                        zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, "update graphs set ");
                        if (0 != (graph->flags & ZBX_FLAG_LLD_GRAPH_UPDATE_NAME))
                        {
                                name_esc = DBdyn_escape_string(graph->name);

                                if (strlen(name_esc) > 127) {
                                        char *nCpy = malloc(sizeof(char) * 124);
                                        strncpy(nCpy, name_esc, 124);
                                        strcat(nCpy, "...");
                                        strcpy(name_esc, nCpy);
                                }

                                zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "name='%s'", name_esc);
                                zbx_free(name_esc);
                                d = ",";
                        }
 

 

Generated at Thu Apr 25 08:18:15 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.