Details

      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 $@";
      }
      

      Specification

        Issue Links

          Activity

          Kester Allen created issue -
          richlv made changes -
          Field Original Value New Value
          Labels valuemapping
          Oleksiy Zagorskyi made changes -
          Fix Version/s 2.0.3 [ 11312 ]
          Oleksiy Zagorskyi made changes -
          Labels valuemapping api valuemapping
          Oleksiy Zagorskyi made changes -
          Link This issue is duplicated by VGL-1 [ VGL-1 ]
          Alexei Vladishev made changes -
          Zabbix ID NA NMR
          Alexander Vladishev made changes -
          Workflow ZBXNEXT workflow [ 26498 ] Zabbix workflow [ 31633 ]
          richlv made changes -
          Labels api valuemapping api missingapi valuemapping
          richlv made changes -
          Labels api missingapi valuemapping missingapi valuemapping
          Alexei Vladishev made changes -
          Workflow Zabbix workflow [ 31633 ] Zabbix workflow - new [ 38612 ]
          richlv made changes -
          Link This issue is duplicated by ZBXNEXT-2787 [ ZBXNEXT-2787 ]
          richlv made changes -
          Summary Zabbix API for adding new Value Mappings Zabbix API for Value Mappings
          Aleksandrs Saveljevs made changes -
          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 $@";
          }
          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:

          {code}
          #!/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 $@";
          }
          {code}
          Damien Vargas made changes -
          Link This issue is duplicated by ZBXNEXT-2789 [ ZBXNEXT-2789 ]
          Damien Vargas made changes -
          Attachment zabbixAPIValueMapping2.2.tar.gz [ 34028 ]
          Attachment zabbixAPIValueMapping2.4.tar.gz [ 34029 ]
          Aleksandrs Saveljevs made changes -
          Labels missingapi valuemapping missingapi patch valuemapping
          Alexander Vladishev made changes -
          Assignee Alexei Vladishev [ alexei ] Ivo Kurzemnieks [ iivs ]
          Alexander Vladishev made changes -
          Status Open [ 1 ] READY TO DEVELOP [ 10006 ]
          Fix Version/s 3.0.0alpha3 (trunk) [ 13103 ]
          Alexander Vladishev made changes -
          Zabbix ID NMR
          Ivo Kurzemnieks made changes -
          Status READY TO DEVELOP [ 10006 ] In Progress [ 3 ]
          Ivo Kurzemnieks made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Alexander Vladishev made changes -
          Status Resolved [ 5 ] IN TESTING [ 10007 ]
          Assignee Ivo Kurzemnieks [ iivs ] Alexander Vladishev [ sasha ]
          Alexander Vladishev made changes -
          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:

          {code}
          #!/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 $@";
          }
          {code}
          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:

          {code}
          #!/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 $@";
          }
          {code}

          [Specification|https://www.zabbix.org/wiki/Docs/specs/ZBXNEXT-1424]
          Alexander Vladishev made changes -
          Fix Version/s 3.0.0alpha4 (trunk) [ 13200 ]
          Fix Version/s 3.0.0alpha3 [ 13103 ]
          Alexander Vladishev made changes -
          Status IN TESTING [ 10007 ] READY TO DEVELOP [ 10006 ]
          Assignee Alexander Vladishev [ sasha ] Ivo Kurzemnieks [ iivs ]
          Ivo Kurzemnieks made changes -
          Status READY TO DEVELOP [ 10006 ] In Progress [ 3 ]
          Ivo Kurzemnieks made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Assignee Ivo Kurzemnieks [ iivs ] Alexander Vladishev [ sasha ]
          Alexander Vladishev made changes -
          Status Resolved [ 5 ] IN TESTING [ 10007 ]
          Alexander Vladishev made changes -
          Status IN TESTING [ 10007 ] Tested [ 10002 ]
          Assignee Alexander Vladishev [ sasha ] Ivo Kurzemnieks [ iivs ]
          Ivo Kurzemnieks made changes -
          Assignee Ivo Kurzemnieks [ iivs ]
          Status Tested [ 10002 ] Needs documenting [ 10004 ]
          Alexander Vladishev made changes -
          Assignee Ivo Kurzemnieks [ iivs ]
          Ivo Kurzemnieks made changes -
          Assignee Ivo Kurzemnieks [ iivs ] Martins Valkovskis [ martins-v ]
          Martins Valkovskis made changes -
          Status Needs documenting [ 10004 ] IN DOCUMENTING [ 10008 ]
          Martins Valkovskis made changes -
          Status IN DOCUMENTING [ 10008 ] Documented [ 10005 ]
          Martins Valkovskis made changes -
          Assignee Martins Valkovskis [ martins-v ] Alexander Vladishev [ sasha ]
          Alexander Vladishev made changes -
          Assignee Alexander Vladishev [ sasha ]
          Status Documented [ 10005 ] Done [ 10003 ]
          Alexander Vladishev made changes -
          Status Done [ 10003 ] Closed [ 6 ]
          Resolution Fixed [ 1 ]
          Alexander Vladishev made changes -
          Workflow Zabbix workflow - new [ 38612 ] Copy of Zabbix workflow - new [ 73670 ]
          Alexander Vladishev made changes -
          Workflow Copy of Zabbix workflow - new [ 73670 ] Zabbix workflow - new [ 88955 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Kester Allen
            • Votes:
              25 Vote for this issue
              Watchers:
              19 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: