[ZBXNEXT-1424] Zabbix API for Value Mappings Created: 2012 Sep 13 Updated: 2015 Oct 21 Resolved: 2015 Oct 21 |
|
Status: | Closed |
Project: | ZABBIX FEATURE REQUESTS |
Component/s: | API (A) |
Affects Version/s: | 2.0.2 |
Fix Version/s: | 3.0.0alpha4 |
Type: | New Feature Request | Priority: | Major |
Reporter: | Kester Allen | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 25 |
Labels: | missingapi, patch, valuemapping | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified | ||
Environment: |
Ubuntu 12.04 |
Attachments: | zabbixAPIValueMapping2.2.tar.gz zabbixAPIValueMapping2.4.tar.gz | ||||||||||||
Issue Links: |
|
Description |
It would be very convenient to be add value mappings via the API. I currently have a script that does this via db insertions, but it is fragile with respect to the database schema changing. The script is below: #!/usr/bin/perl use warnings; use strict; my $usage = "$0 valueMapName number newvalue [number2 newvalue2 [...]] E.g.: makevaluemap.pl 'Alarm Status' 1 ok 2 unknown 3 stale 4 problem makevaluemap.pl 'Aliveness' 0 dead 1 alive "; my $valueMapName = shift() || die "No new valuemap name"; my @mapList = @ARGV; die "No mappings given. Usage: $usage\n" if scalar(@mapList) == 0; my $user = qx/whoami/; chomp($user); die "Must be run as the zabbix user" if $user ne 'zabbix'; my $isEvenNumber = scalar(@mapList) % 2 == 0; die "Must give mapping->value pairs. Usage: $usage\n" if not $isEvenNumber; my %mappings = @mapList; my $newValueMapId = 1 + int(qx/psql -t -c 'select max(valuemapid) from valuemaps'/); my $newMappingId = 1 + int(qx/psql -t -c 'select max(mappingid) from mappings'/); eval { my $valueMapCmd = qq/psql -t -c "insert into valuemaps (valuemapid, name) values ('$newValueMapId', '$valueMapName');"/; print "$valueMapCmd\n"; system $valueMapCmd; eval { for my $from (keys %mappings) { my $to = $mappings{$from}; my $mappingCmd= qq/psql -t -c "insert into mappings (mappingid, valuemapid, value, newvalue) values ('$newMappingId', '$newValueMapId', '$from', '$to');"/; print "$mappingCmd\n"; system $mappingCmd; $newMappingId++; } }; if ($@) { die "something went wrong inserting into mappings $@"; } }; if ($@) { die "something went wrong inserting into valuemaps $@"; } |
Comments |
Comment by Kester Allen [ 2012 Sep 21 ] |
------ |
Comment by Alexei Vladishev [ 2012 Oct 09 ] |
I agree, it must be supported by Zabbix out of the box. |
Comment by richlv [ 2013 Jun 06 ] |
|
Comment by Justin McNutt [ 2013 Jun 27 ] |
XML import/export would be nice as well, but that also requires user interaction via the GUI (unless there's an API method like xml.import, which would be amazing). Admittedly, this would go a long way, but would not resolve all cases where API access is needed. API access to the value mappings is not just about configuration. In fact, XML import is likely to be a better way to accomplish configuration. However, If I query Event history for an Item that uses a value mapping, there's no good way using the API to query that mapping for proper interpretation. The extra bit of labelling that gives context to the raw data is hidden. I would say that the request for API access to the value mappings is much more about reading what's there and proper interpretation of the Event data than anything else. Of course, once there's a "valuemap.*" set of methods, adding .create, .update, and .delete methods is probably not too much of a stretch. But the .get method is probably the most crucial. In my humble opinion... |
Comment by Chuck Dand [ 2013 Jun 28 ] |
I'd say that depends on massively on why your using the API in the first place. If implementing a configuration management of Zabbix using something like Puppet via the API, then the ability to create and update Value Mappings is essential, XML import just won't cut it in that circumstance. |
Comment by richlv [ 2013 Jun 28 ] |
offtopic, but xml import/export via the api is possible already : https://www.zabbix.com/documentation/2.0/manual/appendix/api/configuration |
Comment by Justin McNutt [ 2013 Jul 05 ] |
The configuration.import and configuration.export methods do not allow for import/export of valuemaps. If it did, this would be a crude, but effective substitute for a set of valuemap.X methods. |
Comment by richlv [ 2013 Jul 08 ] |
oh, sure - just noted that having xml import/export would indirectly expose partial functionality over the api, too |
Comment by Dimitri Bellini [ 2014 Sep 17 ] |
I think is also useful to have an API to query a Value Mapping for a specific Item. |
Comment by Jens Berthold [ 2015 Mar 26 ] |
This request is open for 2 1/2 years - is there any plan to implement this soon? |
Comment by richlv [ 2015 Mar 26 ] |
unfortunately, it is not on the roadmap yet. it likely will wait for ZBXNEXT-2519 |
Comment by richlv [ 2015 Apr 20 ] |
|
Comment by Damien Vargas [ 2015 Apr 20 ] |
|
Comment by Damien Vargas [ 2015 Apr 20 ] |
Frontend Class of API ValueMapping. Use README to install. |
Comment by Ivo Kurzemnieks [ 2015 Sep 30 ] |
(1)
Translation strings removed:
sasha Updated list of strings. Please check. iivs CLOSED |
Comment by Ivo Kurzemnieks [ 2015 Sep 30 ] |
RESOLVED in svn://svn.zabbix.com/branches/dev/ZBXNEXT-1424 |
Comment by Alexander Vladishev [ 2015 Oct 13 ] |
(2) it must be written easier if (self::$userData['type'] == USER_TYPE_SUPER_ADMIN) { } elseif ($options['editable'] === null && self::$userData['type'] == USER_TYPE_ZABBIX_ADMIN) { } elseif ($options['editable'] !== null || self::$userData['type'] != USER_TYPE_SUPER_ADMIN) { return []; } Maybe so: if ($options['editable'] !== null && self::$userData['type'] != USER_TYPE_SUPER_ADMIN) { return []; } iivs Indeed so. RESOLVED in r56239 sasha CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 14 ] |
(3) Take a look at my minor changes in r56131, r56132, r56141, r56142. iivs CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 14 ] |
(4) check for the duplicated names in validateCreate() is not effective sasha RESOLVED in r56143 iivs Thanks! |
Comment by Alexander Vladishev [ 2015 Oct 14 ] |
(5) SQL request must be removed from valuemap.create(). sasha RESOLVED in r56145 iivs Thanks! |
Comment by Alexander Vladishev [ 2015 Oct 14 ] |
(6) check for the duplicated names in validateUpdate() is not effective sasha RESOLVED in r56156 iivs Thanks! |
Comment by Alexander Vladishev [ 2015 Oct 14 ] |
(7) selectMappings option must support "count" iivs RESOLVED in r56236 sasha Custom SQL request should be created in this case: SELECT valuemapid,COUNT(*) AS cnt FROM mappings GROUP BY valuemapid REOPENED iivs RESOLVED in r56264 sasha Good! But take a look at my changes in r56269. iivs Thanks! |
Comment by Alexander Vladishev [ 2015 Oct 14 ] |
(8) Too many SQL requests with selectMappings option. SELECT t.mappingid,t.valuemapid FROM mappings t WHERE t.valuemapid IN ('24','25','26','27') SELECT m.* FROM mappings m WHERE m.mappingid BETWEEN '180' AND '187' Only one request will be enough to get mappings. SELECT m.* FROM mappings m WHERE m.valuemapid IN ('24','25','26','27') iivs RESOLVED in r56235 sasha Using of array_key_exists() in the filter options is useless. 'valuemapids' is always present in $options array. 'filter' => array_key_exists('valuemapids', $options) ? ... : ... REOPENED iivs RESOLVED in r56264 sasha CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 14 ] |
(9) valuemap.get() returns an empty array instead of number of the valuemaps for non super-admins
iivs For me this happened only for regular users. RESOLVED in r56239 sasha Still reproducible. REOPENED iivs RESOLVED in r56268 sasha CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 14 ] |
(10) Possible "Undefined index" in valuemap.update()
Undefined index: name [CFrontendApiWrapper->update() → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → call_user_func_array() → CValueMap->update() in include/classes/api/services/CValueMap.php:196] sasha RESOLVED in r56184 iivs Possibly fixed and then broken again. Found it again and fixed. sasha Thanks! Take a look at my changes in r56256. iivs CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 15 ] |
(11) valuemap.update() can be work faster sasha RESOLVED in r56184 iivs Thanks! |
Comment by Alexander Vladishev [ 2015 Oct 15 ] |
(12) valuemap.delete() can be work faster sasha RESOLVED in r56186 iivs Thanks! |
Comment by Alexander Vladishev [ 2015 Oct 15 ] |
(13) caching in function getMappedValue() is not effective getMappedValue('100', 17); SELECT vm.valuemapid FROM valuemaps vm WHERE vm.valuemapid='17' SELECT t.mappingid,t.valuemapid FROM mappings t WHERE t.valuemapid='17' SELECT m.mappingid,m.value,m.newvalue FROM mappings m WHERE m.mappingid BETWEEN '89' AND '165' <= here we can cache all mappings getMappedValue('101', 17); SELECT vm.valuemapid FROM valuemaps vm WHERE vm.valuemapid='17' SELECT t.mappingid,t.valuemapid FROM mappings t WHERE t.valuemapid='17' SELECT m.mappingid,m.value,m.newvalue FROM mappings m WHERE m.mappingid BETWEEN '89' AND '165' sasha RESOLVED in r56190. iivs Thanks! |
Comment by Alexander Vladishev [ 2015 Oct 16 ] |
(14) Confirmation messages must be located in the view frontends/php/adm.valuemapping.php:124:133 if ($valuemap_count['cnt'] == 0) { $data['confirmMessage'] = _('Delete selected value mapping?'); } else { $data['confirmMessage'] = _n( 'Delete selected value mapping? It is used for %d item!', 'Delete selected value mapping? It is used for %d items!', $valuemap_count['cnt'] ); } iivs RESOLVED in r56240 sasha CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 19 ] |
(15) nonexistent fields are used in the API calls frontends/php/adm.valuemapping.php:107,136 'selectMappings' => ['mappingid', 'value', 'newvalue'] sasha RESOLVED in r56253 iivs Thanks! |
Comment by Alexander Vladishev [ 2015 Oct 19 ] |
(16) Direct SQL requests must be replaced by API calls. frontends/php/adm.valuemapping.php:120 sasha RESOLVED in r56255 iivs Thanks! |
Comment by Alexander Vladishev [ 2015 Oct 19 ] |
(17) Templates must be written by using our html classes sasha RESOLVED in r56260. iivs Minor coding style fix in r56266, please review. sasha CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 19 ] |
(18) Added [Clone] button for value mappings. It will be more consistent with other forms. sasha RESOLVED in r56261. iivs Thanks! jQuery code simplified in r56267, please review. sasha Thanks! CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 19 ] |
(19) Unused form name "valuemap_form"; unused class "row_mappings" sasha RESOLVED in r56262. iivs RESOLVED in r56265 sasha Many thanks! CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 19 ] |
(20) "sortfield" argument must support "name". Specification is updated accordingly. iivs RESOLVED in r56263 sasha CLOSED |
Comment by Ivo Kurzemnieks [ 2015 Oct 20 ] |
Implemented in pre-3.0.0alpha4 (trunk) r56276 |
Comment by Ivo Kurzemnieks [ 2015 Oct 20 ] |
(21) API documentation updated:
sasha Very good! But, "mappings" property is not described on > Value map object REOPENED iivs RESOLVED sasha Many thanks! CLOSED |
Comment by Alexander Vladishev [ 2015 Oct 20 ] |
(22) User documentation:
martins-v Reviewed. looks good.
sasha Looks good. CLOSED |