Community
    • Categories
    • Recent
    • Popular
    • Users
    • Search
    • Register
    • Login

    Auslesen Field title über Field Identifier mittels der API

    Scheduled Pinned Locked Moved Allgemein
    api
    3 Posts 2 Posters 326 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      RWalter
      last edited by

      Ausgangslage ich habe einige Custom Categories mit mehreren Feldern. Beim Speichern von Werten wird ein Event ausgelöst, welches ein Perl Script auslöst, dass je nach Art der Änderung bestimmte Jenkins Pipelines aufruft. Funktioniert auch alles soweit wie es soll. Jedoch konnte ich weder im Forum per Suche noch in der API Dokumentation einen Weg finden, wie ich aus dem Feld Identifier c_1581951179201 den Feld Title TESTFIELD bekommen kann. Ist dies über cmdb.objects.read oder cmdb.category.read möglich.

      Um das gesamte besser zu verstehen im Folgenden ein Auszug aus der Kategorie Definition und der Call vom Perl Script an den Jenkins mit den aktuell übergebenen Daten
      Constant C__CATG__CUSTOM_FIELDS_BISRTE_OPENSHIFT

      {
          "c_1581079476324": {
              "type": "f_text",
              "title": "COMMON_DIRECTORY",
              "visibility": "visible",
              "show_in_list": 1
          },
        [...]
          "c_1581951174769": {
              "type": "hr",
              "title": "",
              "show_in_list": 0
          },
          "c_1581951179201": {
              "type": "f_text",
              "title": "TESTFIELD",
              "visibility": "visible",
              "show_in_list": 1
          }
      }
      

      Antwort des Jenkins auf den Aufruf aus dem Perl Script mitsamt der übergebenen Daten (für diesen Aufruf würde ich gerne noch vorher den Title auslesen lassen und mitübergeben, damit der Jenkins ohne irgendwelche weiteren API calls arbeiten kann)

      $VAR1 = '201';
      $VAR1 = {
                'categoryType' => 'C__CMDB__CATEGORY__TYPE_CUSTOM',
                'success' => 0,
                'categoryID' => '40',
                'postData' => {
                                'C__CATG__CUSTOM__c_1581615540289' => '',
                                'C__CATG__CUSTOM__c_1581615556843' => '',
                                'C__CATG__CUSTOM__c_1581616476530' => 'hr',
                                'catg_custom_id' => '40',
                                'C__CATG__CUSTOM__c_1581615857266' => '',
                                'C__CATG__CUSTOM__c_1581615920674' => '',
                                 [...]
                                'C__CATG__CUSTOM__c_1581951179201' => 'new-val',
                                'C__CATG__CUSTOM__c_1581616648733' => 'hr'
                              },
                'data' => [],
                'categoryDataID' => '66317',
                'objectID' => '2188',
                'changes' => {
                               'isys_cmdb_dao_category_g_custom_fields::f_text_c_1581951179201::40' => {
                                                                                                         'from' => 'old-val',
                                                                                                         'to' => 'new-val'
                                                                                                       }
                             },
                'categoryConst' => 'C__CATG__CUSTOM_FIELDS_BISRTE_OPENSHIFT',
                'multivalue' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )
              };
      

      Bei Unklarheiten, werde ich natürlich sonst noch weiter Informationen nachliefern.

      1 Reply Last reply Reply Quote 0
      • F Offline
        franknagel
        last edited by

        Ich denke, der RPC Endpunkt cmdb.category_info.read mit dem Parameter {'category': insert_category_name_here} liefert die Informationen, die Sie suchen.

        1 Reply Last reply Reply Quote 0
        • R Offline
          RWalter
          last edited by

          Danke für den Hinweis auf cmdb.category_info.read, die ist in der aktuellen Dokumentation (nicht der als veraltet deklarierten PDF) nicht mehr aufgelistet. Den Title eines Feldes anhand des Identifier so auszulesen funktioniert zwar, jedoch muss dafür die komplette Kategorie abgerufen und dann über das Rückgabeobjekt iteriert werden, um auf den Title zu kommen, nicht wirklich die effizienteste Art und Weise.

          Weiterhin beim eingangs beschriebenen Beispiel bleibend würde es ungefähr folgendermaßen ablaufen, um bei bekanntem Feld Identifier c_1581951179201 und Category Constant C__CATG__CUSTOM_FIELDS_BISRTE_OPENSHIFT den Feld Title TESTFIELD auszulesen:

          Abfrage:

          {
                    'version' => '2.0',
                    'id' => '861877',
                    'params' => {
                                  'category' => 'C__CATG__CUSTOM_FIELDS_BISRTE_OPENSHIFT',
                                  'apikey' => '<apikey>'
                                },
                    'method' => 'cmdb.category_info.read'
                  }
          

          Rückgabeobjekt (3000 Zeilen, verkürzt zur besseren Lesbarkeit) :

          {
                    'f_text_c_1581615851723' => {
                                                  'check' => {
                                                               'mandatory' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' )
                                                             },
                                                  'info' => {
                                                              'type' => 'text',
                                                              'title' => 'W4B_URL',
                                                              'backward' => do{my $o},
                                                              'primary_field' => do{my $o},
                                                              'description' => 'f_text'
                                                            },
                                                  'title' => 'W4B_URL',
                                                  'ui' => {
                                                            'default' => undef,
                                                            'params' => {
                                                                          'visibility' => 'visible',
                                                                          'type' => 'f_text',
                                                                          'title' => 'W4B_URL',
                                                                          'p_nMaxLen' => 255,
                                                                          'show_in_list' => 1
                                                                        },
                                                            'id' => 'c_1581615851723',
                                                            'type' => 'text'
                                                          },
                                                  'data' => {
                                                              'field_alias' => 'f_text_c_1581615851723',
                                                              'readonly' => do{my $o},
                                                              'index' => do{my $o},
                                                              'type' => 'text',
                                                              'field' => 'isys_catg_custom_fields_list__field_content',
                                                              'select' => {}
                                                            }
                                                },
                                             [...]
                    'f_text_c_1581951179201' => {
                                                  'info' => {
                                                              'backward' => do{my $o},
                                                              'primary_field' => do{my $o},
                                                              'description' => 'f_text',
                                                              'type' => 'text',
                                                              'title' => 'TESTFIELD'
                                                            },
                                                  'title' => 'TESTFIELD',
                                                  'ui' => {
                                                            'id' => 'c_1581951179201',
                                                            'params' => {
                                                                          'type' => 'f_text',
                                                                          'visibility' => 'visible',
                                                                          'title' => 'TESTFIELD',
                                                                          'p_nMaxLen' => 255,
                                                                          'show_in_list' => 1
                                                                        },
                                                            'type' => 'text',
                                                            'default' => undef
                                                          },
                                                  'data' => {
                                                              'field' => 'isys_catg_custom_fields_list__field_content',
                                                              'select' => {},
                                                              'field_alias' => 'f_text_c_1581951179201',
                                                              'readonly' => do{my $o},
                                                              'index' => do{my $o},
                                                              'type' => 'text'
                                                            },
                                                  'check' => {
                                                               'mandatory' => do{my $o}
                                                             }
                                                },
                    'f_text_c_1581615920674' => {
                                                  'ui' => {
                                                            'params' => {
                                                                          'title' => 'NORM_HTTP_ACTIVE',
                                                                          'p_nMaxLen' => 255,
                                                                          'visibility' => 'visible',
                                                                          'type' => 'f_text',
                                                                          'show_in_list' => 1
                                                                        },
                                                            'id' => 'c_1581615920674',
                                                            'type' => 'text',
                                                            'default' => undef
                                                          },
                                                  'data' => {
                                                              'select' => {},
                                                              'field' => 'isys_catg_custom_fields_list__field_content',
                                                              'index' => do{my $o},
                                                              'readonly' => do{my $o},
                                                              'type' => 'text',
                                                              'field_alias' => 'f_text_c_1581615920674'
                                                            },
                                                  'info' => {
                                                              'type' => 'text',
                                                              'title' => 'NORM_HTTP_ACTIVE',
                                                              'backward' => do{my $o},
                                                              'primary_field' => do{my $o},
                                                              'description' => 'f_text'
                                                            },
                                                  'title' => 'NORM_HTTP_ACTIVE',
                                                  'check' => {
                                                               'mandatory' => do{my $o}
                                                             }
                                                },
                                                [...]
          }
          

          Perl Schleife zum Auslesen des Title Felds, welches zum Identifier gehört ($callobjectfieldname entspricht dem oben gezeigten Abfrage-Objekt):

           my $fields = $client->call($uri, $callobjfieldname);
            while(my($key, $value) = each (%{ $fields->result }))
            {
              if ($fieldconstname =~ m/$key/ ){
                return $value->{'title'};
              }
            }
          

          Sehr viel Aufwand, um ein Attribute für eine bekannten Category Constant, Field Identifier Kombination auszulesen, obwohl jede von diesen Kombinationen zwingend unique ist und somit eine Abfrage mit beiden als Parameter direkt das Feld ansteuern und eine Menge Arbeit vermeiden könnte. Gibt es da wirklich keinen anderen Weg als den hier aufgezeigten?

          1 Reply Last reply Reply Quote 0
          • First post
            Last post