-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxMCIUtils.xml
169 lines (135 loc) · 6.02 KB
/
xMCIUtils.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?xml version="1.0" encoding="UTF-8"?>
<unload unload_date="2017-04-03 18:48:38">
<sys_remote_update_set action="INSERT_OR_UPDATE">
<application display_value="Global">global</application>
<application_name>Global</application_name>
<application_scope>global</application_scope>
<application_version/>
<collisions/>
<commit_date/>
<deleted/>
<description>A wrapper script for use in the xMatters CI Support groups add-on. </description>
<inserted/>
<name>xMCIUtils</name>
<origin_sys_id/>
<release_date/>
<remote_sys_id>1851969fdbb57200a34fd421cf961961</remote_sys_id>
<state>loaded</state>
<summary/>
<sys_class_name>sys_remote_update_set</sys_class_name>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2017-04-03 18:48:38</sys_created_on>
<sys_id>ed81de1bdb397200a34fd421cf961945</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2017-04-03 18:48:38</sys_updated_on>
<update_set display_value=""/>
<update_source display_value=""/>
<updated/>
</sys_remote_update_set>
<sys_update_xml action="INSERT_OR_UPDATE">
<action>INSERT_OR_UPDATE</action>
<application display_value="Global">global</application>
<category>customer</category>
<comments/>
<name>sys_script_include_cb2d45d1db731200fc79f7fdbf9619b5</name>
<payload><?xml version="1.0" encoding="UTF-8"?><record_update table="sys_script_include"><sys_script_include action="INSERT_OR_UPDATE"><access>public</access><active>true</active><api_name>global.xMCIUtils</api_name><client_callable>false</client_callable><description> .</description><name>xMCIUtils</name><script><![CDATA[var xMCIUtils = Class.create();
xMCIUtils.prototype = {
initialize : function() {
this.maxDepth = gs.getProperty('glide.relationship.max_depth',10 ); // how deep to look
this.currentDepth = 0;
this.services = {}; // list of affected services
this.parents = {}; // already checked parents
this.children = {};
this.maxSize = gs.getProperty('glide.relationship.threshold',1000 ); // how many records to return
this.added = 0; // track how many added, since can't get size() for an Object
},
/**
* Determine which business services are related to a specific CI
*
* Inputs:
* id - is the sys_id of a configuration item ( cmdb_ci )
* relation - an array containing one or both of "child", "parent"
*
* Returns:
* an array of sys_id values for cmdb_ci_service records downstream of
* or upthe input item
*/
servicesRelatedToCI: function( id, relation ) {
var ci = new GlideRecord("cmdb_ci");
if( ci.get( id ) ) {
// Add myself if I am a service
if( ci.sys_class_name == "cmdb_ci_service" )
this._addService( id, this.services );
for( var k in relation ) {
this.currentDepth = 0;
this._addKinServices( id, {}, this.services, this.currentDepth, relation[k] );
for( var item in this.services )
gs.info( relation[k] + ' Services: ' + item );
}
}
var svcarr = []; // services is an Object, convert to Array for final query
for ( var item in this.services )
svcarr.push( item );
return svcarr; // list of affected services
},
_addKinServices : function( value, list, services, currentDepth, relation ) {
if( list[ value ] ) // already checked?
return;
else
list[ value ] = true;
if( this.added >= this.maxSize )
return;
else {
currentDepth++;
var al = SNC.CMDBUtil.getRelatedRecords( value, "", "cmdb_ci", "cmdb_ci", relation ); // returns ArrayList
if( al.size() > 0 ) {
// first add the unique services
var kids = new GlideRecord('cmdb_ci_service');
kids.addQuery('sys_id', al );
kids.query();
while( kids.next()) {
var str = kids.sys_id;
if( !services[ str ] ) {
this._addService( str, services );
if( this.added >= this.maxSize )
return;
if( currentDepth < this.maxDepth )
this._addKinServices( str, list, services, currentDepth, relation );
}
}
// now check parents of non-services
for( var i=0; i < al.size(); i++) {
var parent = al.get( i );
if( parent ) {
var str = parent + "";
if( !services[ str ] ) // if already in "services", we already checked its parents
if( currentDepth < this.maxDepth )
this._addKinServices( str, list, services, currentDepth, relation );
}
}
}
}
},
_addService: function( id, services ) {
services[ id ] = true;
this.added++;
},
type: 'xMCIUtils'
};]]></script><sys_class_name>sys_script_include</sys_class_name><sys_created_by>admin</sys_created_by><sys_created_on>2016-06-03 02:25:49</sys_created_on><sys_customer_update>true</sys_customer_update><sys_id>cb2d45d1db731200fc79f7fdbf9619b5</sys_id><sys_mod_count>7</sys_mod_count><sys_name>xMCIUtils</sys_name><sys_package display_value="Global" source="global">global</sys_package><sys_policy/><sys_replace_on_upgrade>false</sys_replace_on_upgrade><sys_scope display_value="Global">global</sys_scope><sys_update_name>sys_script_include_cb2d45d1db731200fc79f7fdbf9619b5</sys_update_name><sys_updated_by>admin</sys_updated_by><sys_updated_on>2017-04-03 18:48:21</sys_updated_on></sys_script_include></record_update></payload>
<remote_update_set display_value="xMCIUtils">ed81de1bdb397200a34fd421cf961945</remote_update_set>
<replace_on_upgrade>false</replace_on_upgrade>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2017-04-03 18:48:38</sys_created_on>
<sys_id>6181de1bdb397200a34fd421cf961946</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2017-04-03 18:48:38</sys_updated_on>
<table/>
<target_name>xMCIUtils</target_name>
<type>Script Include</type>
<update_domain>global</update_domain>
<update_set display_value=""/>
<view/>
</sys_update_xml>
</unload>