CMDBUtil - グローバル
CMDBUtil API は、構成管理データベース (CMDB) のテーブル関係を作成および管理し、CMDB ベースラインを管理するためのユーティリティメソッドを提供します。
CMDBUtilは、JavaScript でアクセス可能な ScriptableObject です。CMDBUtil API には動的メソッドと静的メソッドがあります。ダイナミックメソッドにアクセスするには、SNC.CMDBUtil オブジェクトを作成します。静的メソッドにアクセスするには、SNC.CMDBUtil グローバルオブジェクトを使用してメソッドを呼び出します。
var cu = new SNC.CMDBUtil();
cu.baselineProposedChangesGenDIFF(current, action.get('sysparm_changeset'));var output = SNC.CMDBUtil.getAllChildrenOfAsCommaList('cmdb_ci_computer');これらのメソッドを使用して、CMDB テーブル関係とベースラインを管理します。
CMDBUtil - baselineProposedChangesApplyChanges(GlideRecord proposedChanges)
タスクに関連付けられたすべての CI の更新セットを表す task_ci レコードに提案された変更を適用します。
これは動的なメソッドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| 提案された変更 | GlideRecord | 変更要求 (CHG) で提案された変更の集合 |
| タイプ | 説明 |
|---|---|
| なし |
//Where current is a GlideRecord and action is the current UI action
var base = new SNC.CMDBUtil();
base.baselineProposedChangesApplyChanges(current);
CMDBUtil - baselineProposedChangesGenDiff(GlideRecord current, 文字列 changeSet)
提案された変更差分の XML を生成し、それを対応する task_ci レコードに追加します。
これは動的なメソッドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| current | GlideRecord | 提案された変更のコレクションを含む GlideRecord |
| 変更セット ID | 文字列 | 使用する変更セットを表す task_ci レコードの sysid |
| タイプ | 説明 |
|---|---|
| なし |
//Where current is a GlideRecord and action is the current UI action
var base = new SNC.CMDBUtil();
base.baselineProposedChangesGenDIFF(current, action.get('sysparm_changeset'));
CMDBUtil - bootstrap(文字列 dictFile)
データベースを作成し、システムディクショナリーテーブルを作成し、システムディクショナリーテーブルを記述することによって、環境をブートストラップします。
これは静的メソッドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| dictFile | 文字列 | ロードするディクショナリーのパスを含むファイル名 |
| タイプ | 説明 |
|---|---|
| なし |
CMDBUtil - createCIRelationship(文字列 tableName, 文字列 parent, 文字列 child, 文字列 parentField, 文字列 childField)
フィールド間の CI 関係を作成します。
| 名前 | タイプ | 説明 |
|---|---|---|
| tableName | 文字列 | オプション。関係のターゲットテーブルの名前。 デフォルト:CI 関係 [cmdb_rel_ci] テーブル。 |
| 親 | 文字列 | 構成アイテム [cmdb_ci] テーブルの親 CI レコードの sys_id。 |
| 子 | 文字列 | 構成アイテム [cmdb_ci] テーブルの子 CI レコードの sys_id。 |
| parentField | 文字列 | CI 関係タイプ [cmdb_rel_type] テーブルにリストされている親関係ラベル。 |
| childField | 文字列 | CI 関係タイプ [cmdb_rel_type] テーブルにリストされている子関係ラベル。 |
| タイプ | 説明 |
|---|---|
| 文字列 | CI 関係 [cmdb_rel_ci] テーブルにリストされる新しいレコードの sys_id。 |
次の例は、親 CI の contains フィールドと子 CI の contains_by フィールド間の CI 関係を作成する方法を示しています。関係は CI 関係 [cmdb_rel_ci] テーブルにリストされます。
var base = new SNC.CMDBUtil();
base.createCIRelationship('<parent_ci_sys_id>', '<child_ci_sys_id>, 'Contains', 'Contained by');
CMDBUtil - getAllChildrenOfAsCommaList(文字列 baseTable)
指定したテーブルのすべての子テーブルをコンマ区切りのリストとして取得します。
これは静的メソッドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| ベーステーブル | 文字列 | ベーステーブル名 |
| タイプ | 説明 |
|---|---|
| 文字列 | ベーステーブルを拡張するテーブルの sys_id のコンマ区切りのリスト |
//Where cmdv_ci_computer is a table.
var output = SNC.CMDBUtil.getAllChildrenOfAsCommaList('cmdb_ci_computer');
gs.print(output);
CMDBUtil getCMDBViews()
CMDB View [cmdb_view] テーブル内のすべてのレコードを取得します。
このメソッドは動的です。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| アレイ | CMDB ビュー [cmdb_view] テーブル内のレコードリスト。 |
次の例は、CMDB ビューをリストする方法を示しています。
var util = new SNC.CMDBUtil();
var cmdbViews = util.getCMDBViews();
gs.info(cmdbViews);
// Note that the output in the example is type: java.util.ArrayList
// To convert to JS Array, use ArrayUtils (add these lines preceding gs.info):
// var arrUtil = new global.ArrayUtil();
// var arrViews = arrUtil.convertArray(cmdbViews);
出力:
[View 3, View 1, View 2, Another view]
CMDBUtil - getTables0(文字列 tableName)
テーブルのすべての親のリストを取得します。
このメソッドは静的メソッドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| tableName | 文字列 | テーブル名。 |
| タイプ | 説明 |
|---|---|
| アレイ | 指定された表の親である表のリスト。 |
次の例は、サーバー [cmdb_ci_server] テーブルの親テーブルをリストする方法を示しています。
var gr = new GlideRecord('incident');
// Querying the incident table
gr.addQuery('number','INC0000005');
gr.query();
if(gr.next()){
// Find the list of parent tables for Configuration item field of this Incident
var ciParent = SNC.CMDBUtil.getTables0(gr.cmdb_ci.sys_class_name);
gs.print("Parent Tables for the Configuration Item '" + gr.cmdb_ci.name + "' belonging to the CMDB Class '"+ gr.cmdb_ci.sys_class_name+ "' are: \n" + ciParent);
}
出力:
Parent Tables for the Configuration Item 'ApplicationServerPeopleSoft' belonging to the CMDB Class 'cmdb_ci_server' are:
[cmdb_ci_server, cmdb_ci_computer, cmdb_ci_hardware, cmdb_ci, cmdb]
CMDBUtil - isExcludedFromBR(文字列 className)
CI クラスがビジネス ルール除外リスト [cmdb_business_rule_exclusions] テーブルで定義されているかどうかを決定します。ビジネスルールが除外された CI クラスで実行されないようにするには、詳細条件でこのメソッドを使用します。
たとえば、ビジネス ルールを挿入するビジネス ルールの作成では、高度な条件でこのメソッドを使用して、cmdb_ci_qualifier、cmdb_ci_endpoint、cmdb_ci_storage_volume、およびcmdb_ci_vcenter_datastore_diskなどの CI クラスのアセットを作成しないようにします。ビジネス ルール除外リスト [cmdb_business_rule_exclusions] テーブルで除外クラスを定義します。
| 名前 | タイプ | 説明 |
|---|---|---|
| className | 文字列 | 除外を確認するクラスの名前 |
| タイプ | 説明 |
|---|---|
| ブーリアン | クラスがビジネス ルール除外リスト[cmdb_business_rule_exclusions]テーブルで定義されている場合は True です。それ以外の場合は false です。 |
//Returns true if the cmdb_ci_endpoint class is defined
//in the Business Rule Exclusion Lists table
var exclusion = SNC.CMDBUtil.isExcludedFromBR("cmdb_ci_endpoint");
//Advanced condition that prevents business rules from executing on
//classes in the Business Rule Exclusion Lists table
(!SNC.CMDBUtil.isExcludedFromBR(current.getTableName()))
CMDBUtil - processCIChange(GlideRecord event, GlideRecord target)
CI 関係の変更を処理する RelationshipEventProcessor() への呼び出しをラップします。
これは動的なメソッドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| イベント | GlideRecord | イベント レコード |
| target | GlideRecord | ターゲットレコード |
| タイプ | 説明 |
|---|---|
| なし |
CMDBUtil - processRelChange(GlideRecord event, GlideRecord current, String relType、String triplet)
指定されたタイプとトリプレットを使用して、CI 関係の変更を処理する RelationshipEventProcessor() への呼び出しをラップします。
これは動的なメソッドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| イベント | GlideRecord | イベントレコード |
| current | GlideRecord | 現在のレコード。これは、現在のプロセスが削除の場合は、関係レコードまたはユーザー レコードのいずれかです。 |
| relType | 文字列 | 変更された関係のタイプ |
| triplet | 文字列 | 変更された関係からの子、親、およびクラス名 |
| タイプ | 説明 |
|---|---|
| なし |
CMDBUtil - removeCIRelationship(String tableName, String parentField, String childField, String parentDesc, ObjectchildDesc)
指定された CI 関係を削除します。
これは動的なメソッドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| tableName | 文字列 | オプション。テーブル名 デフォルト:CI 関係 [cmdb_rel_ci] テーブル |
| parentField | 文字列 | 親フィールド |
| childField | 文字列 | 子フィールド |
| parentDesc | 文字列 | 親関係記述子 |
| childDesc | オブジェクト | 子関係記述子 |
| タイプ | 説明 |
|---|---|
| なし |
このコード例は、指定された親のすべての関係タイプ 'Depends on::Used by' を削除する方法を示しています。
var cu = new SNC.CMDBUtil();
var parentSysID = '27d18f6fc0a8000b00ad14d4929d1b45';
var parentDesc = 'Depends on';
var childDesc = 'Used by'
// Get records with parent equal parentSysID
var relation = new GlideRecord('cmdb_rel_ci');
relation.addQuery('parent', parentSysID);
relation.query();
while(relation.next()){
// Remove every relation of type: 'Depends on::Used by' for the parent
// If the relation type does not exist, it inserts this relation type into [cmdb_rel_type].
cu.removeCIRelationship('cmdb_rel_ci', parentSysID, relation.child.getValue('sys_id'), parentDesc, childDesc)
}
CMDBUtil - reParentTable(文字列 table, 文字列 oldParent, 文字列 newParent)
指定されたテーブルの親を新しい親に変更します。
このメソッドは静的メソッドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| テーブル | 文字列 | 親を再指定するためのテーブル。 |
| oldParent | 文字列 | 古い親。 |
| newParent | 文字列 | 新しい親。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | 親の変更が成功したかどうかを示すフラグ。 有効な値:
|
次の例を再作成するには、提供されたコードを使用してカスタムテーブルを作成します。次にレコードを作成し、タスクテーブルで確認します。作成されたカスタムテーブルはタスクテーブルから拡張されています。これは、親の再指定が正常に行われたことを意味します。このコードは、コピーアンドペーストで直接使用するためのものではありません。出力を表示するために、コードを実行する前にカスタムテーブルが作成されています。
/*
Before running the code in the background Script Make Sure 'Record For Rollback' is unchecked.
This API CMDBUtil.reParentTable changes the parent of the table but will not allow the OOB tables to change the parent it works only in the custom table. Hence this script contains the creation of the custom table.
API CMDBUtil.reParentTable has 3 parameters (Table, Old Parent , New Parent);
We can make the Parent as Null as well by using this (Table, Old Parent, '');
The code in this example shows how to create a custom table without any extension.
Then creating a record and then again creating a record and checking in the task table after it gets extended to the task table.
If the code returns false means the record is not present in the task table as it is not extended. It returns true only when the record is found in the task table after the table is extended.
*/
/* Run the following code to create the custom table without an extension
createCustomTable('u_custom_table','Custom Table'); // Creating a custom Table (don't create if you have one)
var CreatedRecord = CreateCustomRecord('u_custom_table'); // Creating a record in the custom table
gs.print(CheckRecord('u_custom_table')); // Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
var getParentTables = new SNC.CMDBUtil.reParentTable('u_custom_table','','task'); // Extending the custom table to task table . This Works only when the table is extendable
var CreatedRecordAfter = CreateCustomRecord('u_custom_table'); // Creating a record in the custom table
gs.print(CheckRecord('u_custom_table')); // Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
*/
// If the custom Table is already created, run this. (Do not run these 4 lines when creating the table)
gs.print(CheckRecord('u_custom_table')); //Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
var getParentTables = new SNC.CMDBUtil.reParentTable('u_custom_table','','task'); //Extending the custom table to task table . This Works only when the table is extendable
var CreatedRecordAfter = CreateCustomRecord('u_custom_table'); //Creating a record in the custom table
gs.print(CheckRecord('u_custom_table')); //Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
function createCustomTable(Name, Label)
{
var customTable = new GlideRecord('sys_db_object');
customTable.initialize();
customTable.name= Name ;
customTable.label= Label ;
customTable.is_extendable= true;
customTable.insert();
}
function CreateCustomRecord(customTableName)
{
var customTable = new GlideRecord(customTableName);
customTable.initialize();
return customTable.insert();
}
function CheckRecord(customTableName)
{
var task =new GlideRecord('task');
task.addQuery('sys_class_name', customTableName);
task.query();
if(task.next())
{
return true;
}
return false;
}
出力:
*** Script: true
*** Script: true