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, String changeSet)
提案された変更差分の XML を生成し、対応する task_ci レコードに追加します。
これは動的な方法です。
| 名前 | タイプ | 説明 |
|---|---|---|
| current | GlideRecord | 提案された変更のコレクションを含む GlideRecord。 |
| 変更セット | 文字列 | 使用する変更セットを表す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(String 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] テーブルにリストされている親関係ラベル。 |
| 子フィールド | 文字列 | CI 関係性タイプ [cmdb_rel_type] テーブルにリストされている子関係ラベル。 |
| タイプ | 説明 |
|---|---|
| 文字列 | CI 関係 [cmdb_rel_ci] テーブルにリストされている新しいレコードのSys_id。 |
次の例は、親 CI の [包含] フィールドと子 CI の [contained_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)
指定されたテーブルのすべての子テーブルをカンマ区切りリストとして取得します。
これは静的な方法です。
| 名前 | タイプ | 説明 |
|---|---|---|
| baseTable | 文字列 | ベーステーブル名。 |
| タイプ | 説明 |
|---|---|
| 文字列 | ベーステーブルを拡張するテーブルのsys_idsのカンマ区切りリスト。 |
//Where cmdv_ci_computer is a table.
var output = SNC.CMDBUtil.getAllChildrenOfAsCommaList('cmdb_ci_computer');
gs.print(output);
CMDBUtil - getCMDBViews()
CMDB ビュー [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 イベント、GlideRecord ターゲット)
CI 関係への変更を処理する RelationshipEventProcessor() の呼び出しをラップします。
これは動的な方法です。
| 名前 | タイプ | 説明 |
|---|---|---|
| イベント | GlideRecord | イベントレコード。 |
| ターゲット | GlideRecord | ターゲットレコード。 |
| タイプ | 説明 |
|---|---|
| なし |
CMDBUtil - processRelChange(GlideRecord event, GlideRecord current, String relType, String triplet)
CI 関係への変更を処理する RelationshipEventProcessor() の呼び出しを、指定されたタイプとトリプレットでラップします。
これは動的な方法です。
| 名前 | タイプ | 説明 |
|---|---|---|
| イベント | GlideRecord | イベントレコード |
| current | GlideRecord | 現在のレコード。これは関係レコードか、現在のプロセスが削除の場合はユーザーレコードのいずれかです。 |
| relType | 文字列 | 変更された関係のタイプ。 |
| トリプレット | 文字列 | 変更された関係の子、親、およびクラス名。 |
| タイプ | 説明 |
|---|---|
| なし |
CMDBUtil - removeCIRelationship(文字列 tableName, 文字列 parentField, 文字列 childField, 文字列 parentDesc, オブジェクト childDesc)
指定された CI 関係を削除します。
これは動的な方法です。
| 名前 | タイプ | 説明 |
|---|---|---|
| tableName | 文字列 | オプション。テーブル名 デフォルト:CI 関係 [cmdb_rel_ci] テーブル |
| parentField | 文字列 | 親フィールド |
| 子フィールド | 文字列 | 子フィールド |
| 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(文字列テーブル, 文字列 oldParent, 文字列 newParent)
指定されたテーブルの親を新しい親に変更します。
| 名前 | タイプ | 説明 |
|---|---|---|
| テーブル | 文字列 | 再ペアレント化するテーブル。 |
| oldParent | 文字列 | 古い親。 |
| 新しい親 | 文字列 | 新しい親。 |
| タイプ | 説明 |
|---|---|
| ブール | 親変更が成功したかどうかを示すフラグ。 有効な値:
|
次の例を再作成するには、提供されているコードを使用してカスタムテーブルを作成します。次に、レコードを作成し、タスクテーブルでチェックします。作成されたカスタムテーブルはタスクテーブルから拡張されたため、正常に再ペアレント化されていることを意味します。このコードは、コピー アンド ペーストで直接使用することを意図したものではありません。出力を表示するために、コードを実行する前にカスタムテーブルが作成されています。
/*
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