[ZBXNEXT-505] support hex and octal conversion to text/character/string Created: 2010 Sep 08 Updated: 2024 Apr 25 Resolved: 2024 Apr 25 |
|
Status: | Closed |
Project: | ZABBIX FEATURE REQUESTS |
Component/s: | None |
Affects Version/s: | 1.8.2, 1.8.3, 1.8.4 |
Fix Version/s: | None |
Type: | Change Request | Priority: | Major |
Reporter: | Ruud Boersma | Assignee: | Unassigned |
Resolution: | Duplicate | Votes: | 43 |
Labels: | hexadecimal, items, preprocessing | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified | ||
Environment: |
openSUSE appliance |
Attachments: |
![]() ![]() |
||||||||||||||||||||||||
Issue Links: |
|
Description |
Referring to this thread: Some oid have hexadecimal values with spaces. this is solved in the call mentionen above. |
Comments |
Comment by Alexei Vladishev [ 2012 Oct 11 ] |
It could done in scope of |
Comment by Raymond Kuiper [ 2013 Dec 05 ] |
I'm seeing the same sort of problem here (running 2.2.0). "0A 85 98 FF" Which translates to "10 133 152 255" (add the dots and you have an IP address). It would be nice if Zabbix could translate this numeric hex into a human-readable IP address. |
Comment by Pavel [ 2014 Jul 05 ] |
The same problem with Juniper. |
Comment by Alexander G. [ 2016 Mar 23 ] |
The same problem with some HP printers when retrieving the consumables (e.g. toners) using OID 1.3.6.1.2.1.43.11.1.1.6.1. The names of that consumables will be shown as hex string. This is annoying especially when using discovery rules since the items got that hex string names. You can reproduce that with Net-SNMPs snmpwalk as shown here for a HP printer model LaserJet 500 color M551: For snmpwalk a work around will help. Just add option -Oa: |
Comment by Daniil Pimonenko [ 2016 May 10 ] |
Is issue closed? |
Comment by Alexander G. [ 2016 May 11 ] |
For my opinion it is not closed yet. Did Zabbix provide any update, I didn't see yet? I'm currently running Zabbix 3.0.2. I stay in contact with HP. But I'm afraid that HP wont fix the firmware of their printers. HP says that some SNMP agents interpret the data as hex decimal value while the others interpret the data as octet string. If your SNMP agent does interpret the data as hex decimal value, you are not a lucky guy. The problem occurs with some HP printers, because they sent a trailing zero byte. See my last post. You can force the Net-SNMP command line tools, to interpret the data as octet string by using the -Oa option. Again see my last post. Since Zabbix using the Net-SNMP library as well, it must be a simple way, to tell Zabbix to force the Net-SNMP library to interpret the data as octet string instead of as hex decimal value. |
Comment by Joakim Plate [ 2016 May 16 ] |
I actually ran into the opposite issue with hrPrinterDetectedErrorState. It ends up being interpreted as string, and thus is incompatible with the numeric type it needs to be. Thus ut requires the -Ox option to work properly. $ snmpwalk -c public -v 1 segotppl001 hrPrinterDetectedErrorState $ snmpwalk -c public -v 1 -Ox segotppl001 hrPrinterDetectedErrorState |
Comment by Ryan Wagoner [ 2017 Nov 01 ] |
I upgraded from CentOS 6 to 7 and am running into this issue. snmpwalk on CentOS 7 returns Hex-STRING for printer supplies OID 1.3.6.1.2.1.43.11.1.1.6 where as CentOS 6 returned STRING. It would be great to have this option in Zabbix. It looks like my only option right now is to write a discovery script. |
Comment by Alexander G. [ 2017 Nov 07 ] |
Solving this issue would make Zabbix to a even better software. I use the following perl script as work around: use strict; # Configuration variables my $snmpwalk_command = "snmpwalk -On -Oa"; my $consumable_names_oid = ".1.3.6.1.2.1.43.11.1.1.6.1"; my $usage = "Error! Need at least 3 arguments: SNMP version, SNMP community and host name or ip address. \n E. g.: $0 2c public printer1"; # Get command line arguments. my $snmpversion = shift || die($usage); my $snmpcommunity = shift || die($usage); my $hostoraddress = shift || die($usage); # Print beginning of the JSON data string. print "{\n"; print "\t\"data\":[\n\n"; my $first_element = 1; foreach my $output (`$snmpwalk_command -v$snmpversion -c $snmpcommunity $hostoraddress $consumable_names_oid 2>&1`) { if ($output =~ /^$consumable_names_oid\.([0-9]+) = STRING: \"(.*)\"$/) { print "\t,\n" if not $first_element; $first_element = 0; print "\t{\n"; print "\t\t\"{#SNMPINDEX}\":\"$1\",\n"; print "\t\t\"{#SNMPVALUE}\":\"$2\"\n"; print "\t}\n"; } } # Print end of the JSON data string. print "\n\t]\n"; print "}\n"; |
Comment by Konstantin Ilyasov [ 2018 Mar 10 ] |
So the only option to convert hex-string values to string is using scripts? |
Comment by Dirk Bongard [ 2018 Mar 26 ] |
I have the same issue like Alexander G.. |
Comment by René de Groot [ 2018 Oct 08 ] |
Hi Alexander, Thanks for the script, although I still have some troubles getting the actual values. Would you be so kind to share your template? |
Comment by Alexander G. [ 2018 Oct 10 ] |
Here comes the template: SNMPv2c Printers use external script.xml You can also call the script from command line like this: ./discover_printer_consumables.pl 2c public printer Where 2c stands for SNMP Version 2c, public is the SNMP community string and printer is the ip address or name of the printer. Please make sure, that you copied the script in to the right location as cofigured in zabbix_server.conf by the parameter ExternalScripts (e. g. /usr/lib/zabbix/externalscripts). Hope that helps! |
Comment by René de Groot [ 2018 Oct 10 ] |
Hi Alexander, Thanks for your help! It works great! (Zabbix 4.0) |
Comment by Ildar Davletov [ 2019 Jan 30 ] |
I hope this bug will be fixed until we celebrate 10 years... really ashaming. |
Comment by omavel [ 2019 Jul 09 ] |
One moar 10 years old FR... Hope never dies.
updated |
Comment by Raymond Kuiper [ 2019 Jul 09 ] |
It's not a bug, i't's a feature request. As such it's open for sponsored development, send an email to [email protected] That being said, in Zabbix 4.2 it might be possible to use a pre-processing javascript to handle this conversion (although I haven't looked into that topic yet). Any confirmation from the Zabbix devs that this would be possible or not? |
Comment by Vladislavs Sokurenko [ 2019 Jul 09 ] |
Yes, it's possible, please try something like this: var out = ""; for (var i = 0, nums = value.split(" "); i < nums.length; i++) { out += String.fromCharCode(parseInt(nums[i], 16)); } return out; |
Comment by Vadim Chekirka [ 2019 Nov 11 ] |
Vladislav, thank you for you script, but in my case it working only in test mode, I added it to preprocessing and got error - "Invalid discovery rule value:" Also I found somewhere that use {} inside function Zabbix doesn't support. Any ideas? |
Comment by Vladislavs Sokurenko [ 2019 Nov 11 ] |
It should work the same way as during the test, can you please show the test output ? |
Comment by Vadim Chekirka [ 2019 Nov 13 ] |
discovery{#SERIALRWNAME},1.3.6.1.4.1.3212.7.1.3.4.1.1.1.2 Discovered name is - "22 53 6C 6F 74 20 54 68 72 65 00" When I run through the script I have expected name as - "Slot Thre
But today when I tested discovery I got new error - Invalid discovery rule value: cannot find pair with name "{#IFNAME}" when I remove preprocessing script discovering works. |
Comment by Michel van Son [ 2019 Nov 25 ] |
Vladislavs' scripts works fine for a single hex value. If you use that in an LLD, it'll only replace the first value found. I wrote this script to correct that: var out = ""; var regex = /{#SNMPVALUE}":"([0-9 A-F a-f ]*) "}/; var m; do { m = regex.exec(value) if (m) { var str = ""; for (var i = 0, nums = m[1].split(" "); i < nums.length; i++) { str += String.fromCharCode(parseInt(nums[i], 16)); } value = value.replace(m[1], str); } } while (m); return (value); You'll need to fiddle with the regex, watch for whitespaces etc. |
Comment by Eugene [ 2020 Sep 17 ] |
Hello everyone, and thanks to the unsubscribed above. There is a little problem with 0x00 symbol in the SNMP answer, so there is a little modified JS for converts HEX to String, for Zabbix data collectors prototypes and items. For discovery group: var regex = /"{#SNMPVALUE}":"([0-9 A-F ]*) "}/; var m; do { m = regex.exec(value) if (m) { var str = ''; hex = m[1]; hex = hex.replace(/ /g,''); for (var n = 0; n < hex.length; n += 2) { if (hex.substr(n, 2) != '00'){ str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)); } } value = value.replace(m[1], str); } } while (m); return (value); And for prototypes of items: var str1 = value; var hex = str1.toString(); if (! hex.match(/\b[0-9A-F ]{6}\b/gi)) { return str1; } else { hex = hex.replace(/ /g,""); var str = ''; for (var n = 0; n < hex.length; n += 2) { str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)); } return str; }
|
Comment by Ed Driesen [ 2021 Jul 07 ] |
@Eugene , thanks! Sorry for the noobish question, but where exactly do you put those snippets in (i'm using 5.0 lts) Is it in one place for all (where?), or somewhere more global? |
Comment by Alex Kalimulin [ 2023 Oct 23 ] |
For the most part, this should be solved by |
Comment by Vladislavs Sokurenko [ 2024 Apr 24 ] |
Please also see if |
Comment by Vladislavs Sokurenko [ 2024 Apr 25 ] |
The original issue from the report is completed under |