name
stringlengths 3
72
| description
stringlengths 141
229
| ci_type
stringlengths 11
38
| pattern_type
stringclasses 4
values | pattern
stringlengths 196
32k
| pattern_commented
stringlengths 393
48.2k
|
---|---|---|---|---|---|
ACL Tags | I would like for you to help me build a Pattern that helps achieve Discovery of ACL Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "ACL Tags"
id = "bafa8d37dbfac0109149f2131f96190c"
description = "ACL Tags"
step {
name = "Parse ACL Tags"
parse_var_to_var {
from_var_name = "acl_rest"
to_var_names = table {
name = "cmdb_key_value"
col_names = "object_id","key","value"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeNetworkAclsResponse"
fields {
field {
col_name = "object_id"
xpath = "/DescribeNetworkAclsResponse/networkAclSet/item/networkAclId/text()"
delimiters = ""
position = 1
}
field {
col_name = "key"
xpath = "/DescribeNetworkAclsResponse/networkAclSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeNetworkAclsResponse/networkAclSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "filter out tags without values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Create reference between Tag and ACL"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_network_acl"
key2_name = "object_id"
result_table_name = "tag_to_acl"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "ACL Tags"
id = "bafa8d37dbfac0109149f2131f96190c" // Unique identifier for the pattern
description = "ACL Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse ACL Tags"
parse_var_to_var {
from_var_name = "acl_rest"
to_var_names = table {
name = "cmdb_key_value"
col_names = "object_id","key","value"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeNetworkAclsResponse"
fields {
field {
col_name = "object_id"
xpath = "/DescribeNetworkAclsResponse/networkAclSet/item/networkAclId/text()"
delimiters = ""
position = 1
}
field {
col_name = "key"
xpath = "/DescribeNetworkAclsResponse/networkAclSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeNetworkAclsResponse/networkAclSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter out tags without values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference between Tag and ACL"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_network_acl"
key2_name = "object_id"
result_table_name = "tag_to_acl"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Get Catalogs info | I would like for you to help me build a Pattern that helps achieve Discovery of Get Catalogs info. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Get Catalogs info"
id = "bb5fab311b58985014bc63913d4bcb55"
description = "Get Catalogs info"
step {
name = "run SQL query for Win get catalogs"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
}
on_true = runcmd_to_var {
cmd = concat {
"echo set head off feed off pages 0 line 3000 && echo SELECT DISTINCT OWNER FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS'); |\""
get_attr {"ora_home_exe"}
"\\bin\\sqlplus\" -s "
"$$username$$/$$password$$@"
get_attr {"sid"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = " "
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "run SQL query for Unix get catalogs"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_not_empty {get_attr {"connect_sql[1].listener_port"}}
is_not_empty {get_attr {"connect_sql[1].service_name"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"ora_home_exe"}
"/network/admin;export ORACLE_HOME="
get_attr {"ora_home_exe"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
"\""
get_attr {"ora_home_exe"}
"/bin/sqlplus\" -s "
"'$$username$$'/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"connect_sql[1].listener_port"}
"/"
get_attr {"connect_sql[1].service_name"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "run SQL query for Unix get catalogs with SID"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"sid"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"ora_home_exe"}
"/network/admin;export ORACLE_HOME="
get_attr {"ora_home_exe"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
"\""
get_attr {"ora_home_exe"}
"/bin/sqlplus\" -s "
"'$$username$$'/'$$password$$'@"
get_attr {"sid"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "failover if catalog is empty run SQL query for Unix get catalogs with SID"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"sid"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export ORACLE_SID="
get_attr {"sid"}
"; export ORACLE_HOME="
get_attr {"ora_home_exe"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
get_attr {"ora_home_exe"}
"/bin/sqlplus -s '$$username$$'/'$$password$$'"
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "run SQL query for Unix get catalogs with SID 2"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"sid"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"'$$username$$'/'$$password$$'@"
get_attr {"sid"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "failover run SQL query for Unix get catalogs with service name"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"connect_sql[1].listener_port"}}
is_not_empty {get_attr {"connect_sql[1].service_name"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"'$$username$$'/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"connect_sql[1].listener_port"}
"/"
get_attr {"connect_sql[1].service_name"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "failover if catalog is empty run SQL query for Unix get catalogs with SID 2"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"sid"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export ORACLE_SID="
get_attr {"sid"}
"; export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
get_attr {"oracle_home"}
"/bin/sqlplus -s '$$username$$'/'$$password$$'"
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "filter empty rows"
if {
condition = is_not_empty {get_attr {"cmdb_ci_db_ora_catalog"}}
on_true = filter {
src_table_name = "cmdb_ci_db_ora_catalog"
target_table_name = "cmdb_ci_db_ora_catalog"
condition = is_not_empty {get_attr {"cmdb_ci_db_ora_catalog[].schema"}}
}
on_false = nop {}
}
}
step {
name = "remove duplicates"
if {
condition = is_not_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
on_true = set_attr {
"NotInuse"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_db_ora_catalog},[\"schema\"]);
CTX.setAttribute(\"cmdb_ci_db_ora_catalog\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "set name variable"
transform {
src_table_name = "cmdb_ci_db_ora_catalog"
target_table_name = "cmdb_ci_db_ora_catalog"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"cmdb_ci_db_ora_catalog[].schema"}
"@"
get_attr {"cmdb_ci_db_ora_instance[1].name"}
}
}
set_field {
field_name = "database_instance"
value = get_attr {"cmdb_ci_db_ora_instance[1].sid"}
}
}
}
}
step {
name = "create relation between cmdb_ci_db_ora_instance and cmdb_ci_db_ora_catalog"
if {
condition = is_not_empty {get_attr {"cmdb_ci_db_ora_catalog"}}
on_true = relation_reference {
table1_name = "cmdb_ci_db_ora_instance"
table2_name = "cmdb_ci_db_ora_catalog"
result_table_name = "oracle_inst"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = childToParent
ref_field_name = "database_instance"
}
on_false = nop {}
}
}
}
| library {
name = "Get Catalogs info"
id = "bb5fab311b58985014bc63913d4bcb55" // Unique identifier for the pattern
description = "Get Catalogs info" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "run SQL query for Win get catalogs"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
}
on_true = runcmd_to_var {
cmd = concat {
"echo set head off feed off pages 0 line 3000 && echo SELECT DISTINCT OWNER FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS'); |\""
get_attr {"ora_home_exe"}
"\\bin\\sqlplus\" -s "
"$$username$$/$$password$$@"
get_attr {"sid"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = " "
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "run SQL query for Unix get catalogs"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_not_empty {get_attr {"connect_sql[1].listener_port"}}
is_not_empty {get_attr {"connect_sql[1].service_name"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"ora_home_exe"}
"/network/admin;export ORACLE_HOME="
get_attr {"ora_home_exe"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
"\""
get_attr {"ora_home_exe"}
"/bin/sqlplus\" -s "
"'$$username$$'/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"connect_sql[1].listener_port"}
"/"
get_attr {"connect_sql[1].service_name"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "run SQL query for Unix get catalogs with SID"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"sid"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"ora_home_exe"}
"/network/admin;export ORACLE_HOME="
get_attr {"ora_home_exe"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
"\""
get_attr {"ora_home_exe"}
"/bin/sqlplus\" -s "
"'$$username$$'/'$$password$$'@"
get_attr {"sid"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover if catalog is empty run SQL query for Unix get catalogs with SID"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"sid"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export ORACLE_SID="
get_attr {"sid"}
"; export ORACLE_HOME="
get_attr {"ora_home_exe"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
get_attr {"ora_home_exe"}
"/bin/sqlplus -s '$$username$$'/'$$password$$'"
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "run SQL query for Unix get catalogs with SID 2"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"sid"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"'$$username$$'/'$$password$$'@"
get_attr {"sid"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover run SQL query for Unix get catalogs with service name"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"connect_sql[1].listener_port"}}
is_not_empty {get_attr {"connect_sql[1].service_name"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"'$$username$$'/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"connect_sql[1].listener_port"}
"/"
get_attr {"connect_sql[1].service_name"}
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover if catalog is empty run SQL query for Unix get catalogs with SID 2"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
eq {
get_attr {"discovery_type"}
"horizontal"
}
is_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
is_not_empty {get_attr {"sid"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export ORACLE_SID="
get_attr {"sid"}
"; export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"SELECT DISTINCT OWNER || '####' FROM ALL_TABLES WHERE TABLESPACE_NAME NOT IN ('SYSTEM', 'SYSAUX', 'TOOLS');\" |"
get_attr {"oracle_home"}
"/bin/sqlplus -s '$$username$$'/'$$password$$'"
}
credentials = credentials {ciTypeId = "cmdb_ci_db_ora_instance"}
var_names = table {
name = "cmdb_ci_db_ora_catalog"
col_names = "schema"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "####"
exclude_lines_pattern = "TABLE_NAME"," ------------"," no rows"," OWNER"," set head off"," rows"," ERROR"," expired"," password"," ORA-"," timeout"
delimiters = "####"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter empty rows"
if {
condition = is_not_empty {get_attr {"cmdb_ci_db_ora_catalog"}}
on_true = filter {
src_table_name = "cmdb_ci_db_ora_catalog"
target_table_name = "cmdb_ci_db_ora_catalog"
condition = is_not_empty {get_attr {"cmdb_ci_db_ora_catalog[].schema"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "remove duplicates"
if {
condition = is_not_empty {get_attr {"cmdb_ci_db_ora_catalog[1].schema"}}
on_true = set_attr {
"NotInuse"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_db_ora_catalog},[\"schema\"]);
CTX.setAttribute(\"cmdb_ci_db_ora_catalog\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set name variable"
transform {
src_table_name = "cmdb_ci_db_ora_catalog"
target_table_name = "cmdb_ci_db_ora_catalog"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"cmdb_ci_db_ora_catalog[].schema"}
"@"
get_attr {"cmdb_ci_db_ora_instance[1].name"}
}
}
set_field {
field_name = "database_instance"
value = get_attr {"cmdb_ci_db_ora_instance[1].sid"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create relation between cmdb_ci_db_ora_instance and cmdb_ci_db_ora_catalog"
if {
condition = is_not_empty {get_attr {"cmdb_ci_db_ora_catalog"}}
on_true = relation_reference {
table1_name = "cmdb_ci_db_ora_instance"
table2_name = "cmdb_ci_db_ora_catalog"
result_table_name = "oracle_inst"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = childToParent
ref_field_name = "database_instance"
}
on_false = nop {}
}
}
}
|
Azure - Get Resource Group LDC | I would like for you to help me build a Pattern that helps achieve Discovery of Azure - Get Resource Group LDC. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure - Get Resource Group LDC"
id = "bc49f6941b67ec109614c95e0d4bcb0d"
description = ""
step {
name = "Parse response columns"
ref {refid = "84ecd7b9db911010b2a1f962759619f2"}
}
step {
name = "Parse Resource Group"
custom_operation {
attributes {
attribute {
name = "source"
value = "resource_response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "cmdb_ci_resource_group"
}
attribute {
name = "target_columns"
value = concat {
"location:data.rows."
get_attr {"response_location"}
",object_id:data.rows."
get_attr {"response_id"}
}
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "Parse Resource Group LDC"
parse_var_to_var {
from_var_name = "cmdb_ci_resource_group[1].location"
to_var_names = table {
name = "resource_group_ldc"
col_names = "object_id"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step {
name = "Merge LDC tables"
merge {
table1_name = "cmdb_ci_azure_datacenter"
key1_name = "object_id"
table2_name = "resource_group_ldc"
key2_name = "object_id"
result_table_name = "cmdb_ci_azure_datacenter"
unmatched_lines = keep
}
}
step {
name = "Create relation between LDC and Resource Group"
relation_reference {
table1_name = "cmdb_ci_azure_datacenter"
key1_name = "object_id"
table2_name = "cmdb_ci_resource_group"
key2_name = "location"
result_table_name = "ldc_to_resource_group"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
}
}
| library {
name = "Azure - Get Resource Group LDC"
id = "bc49f6941b67ec109614c95e0d4bcb0d" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse response columns"
ref {refid = "84ecd7b9db911010b2a1f962759619f2"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Resource Group"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "resource_response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "cmdb_ci_resource_group"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = concat {
"location:data.rows."
get_attr {"response_location"}
",object_id:data.rows."
get_attr {"response_id"}
}
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Resource Group LDC"
parse_var_to_var {
from_var_name = "cmdb_ci_resource_group[1].location"
to_var_names = table {
name = "resource_group_ldc"
col_names = "object_id"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge LDC tables"
merge {
table1_name = "cmdb_ci_azure_datacenter"
key1_name = "object_id"
table2_name = "resource_group_ldc"
key2_name = "object_id"
result_table_name = "cmdb_ci_azure_datacenter"
unmatched_lines = keep
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between LDC and Resource Group"
relation_reference {
table1_name = "cmdb_ci_azure_datacenter"
key1_name = "object_id"
table2_name = "cmdb_ci_resource_group"
key2_name = "location"
result_table_name = "ldc_to_resource_group"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
}
}
|
Amazon AWS - Get Classic LB Pool Member (LP) | I would like for you to help me build a Pattern that helps achieve Discovery of Amazon AWS - Get Classic LB Pool Member (LP). \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Amazon AWS - Get Classic LB Pool Member (LP)"
id = "bec94d319d7842abbae699bf0825b5e3"
description = "null"
step {
name = "Parse the Pool Members (Instances) for Classic LBs"
comment = "We would create new table with just Load Balancer name and instanceID, where the name would be used for the relationship and the instanceID will be used to populate it the relevant table."
parse_var_to_var {
from_var_name = "rest_resp_elb_v1"
to_var_names = table {
name = "withduplicates"
col_names = "Name","value"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "Name"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/Instances/InstanceId/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/LoadBalancerName/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Transfer the data into the Pool Member table"
comment = "The \"nodupl\" table is created from the Script Library record and it contains the data from the \"withduplicates\" table where the duplicate rows based on the \"Name\" column were removed and \"value\" column rowsdata was merged.
The left data is transferred into a new table named \"pool_members\"."
transform {
src_table_name = "withduplicates"
target_table_name = "pool_members"
operation {set_field {
field_name = "loadbalancers"
value = get_attr {"withduplicates[].value"}
}}
}
}
step {
name = "Filter the Pool Members for empty names"
comment = "Filter the Pool Members table so that CIs with empty name would not be created in SNow."
if {
condition = is_not_empty {get_attr {"pool_members"}}
on_true = filter {
src_table_name = "pool_members"
target_table_name = "pool_members"
condition = is_not_empty {get_attr {"pool_members[].Name"}}
}
on_false = nop {}
}
}
step {
name = "Fill cmdb_ci_lb_pool_member table"
comment = "Fill the data in the actual Service Now\" Load Balancer Pool Member\" table."
if {
condition = is_not_empty {get_attr {"pool_members"}}
on_true = transform {
src_table_name = "pool_members"
target_table_name = "cmdb_ci_lb_pool_member"
operation {
set_field {
field_name = "name"
value = get_attr {"pool_members[].Name"}
}
set_field {
field_name = "object_id"
value = get_attr {"pool_members[].Name"}
}
}
}
on_false = nop {}
}
}
step {
name = "Fill cmdb_ci_lb_pool table"
comment = "Fill the LB Pool table with the LB name, as there is not attribute in the AWS API calls that shows target group name for Classic Load Balancers and this table is needed to make the relation between LB and Pool Members."
transform {
src_table_name = "ELB_v1"
target_table_name = "cmdb_ci_lb_pool"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"ELB_v1[].Name"}
"-Pool"
}
}
set_field {
field_name = "object_id"
value = get_attr {"ELB_v1[].Name"}
}
set_field {
field_name = "comments"
value = concat {
get_attr {"service_account[1].account_id"}
"_"
get_attr {"cmdb_ci_aws_datacenter[1].name"}
"_d0d3b880db8b04109149f2131f96194e"
}
}
}
}
}
}
| library {
name = "Amazon AWS - Get Classic LB Pool Member (LP)"
id = "bec94d319d7842abbae699bf0825b5e3" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Pool Members (Instances) for Classic LBs"
comment = "We would create new table with just Load Balancer name and instanceID, where the name would be used for the relationship and the instanceID will be used to populate it the relevant table." // Relationship mapping: Identifies and records relationships between CIs
parse_var_to_var {
from_var_name = "rest_resp_elb_v1"
to_var_names = table {
name = "withduplicates"
col_names = "Name","value"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "Name"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/Instances/InstanceId/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/LoadBalancerName/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Transfer the data into the Pool Member table"
comment = "The \"nodupl\" table is created from the Script Library record and it contains the data from the \"withduplicates\" table where the duplicate rows based on the \"Name\" column were removed and \"value\" column rowsdata was merged.
The left data is transferred into a new table named \"pool_members\"."
transform {
src_table_name = "withduplicates"
target_table_name = "pool_members"
operation {set_field {
field_name = "loadbalancers"
value = get_attr {"withduplicates[].value"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter the Pool Members for empty names"
comment = "Filter the Pool Members table so that CIs with empty name would not be created in SNow."
if {
condition = is_not_empty {get_attr {"pool_members"}}
on_true = filter {
src_table_name = "pool_members"
target_table_name = "pool_members"
condition = is_not_empty {get_attr {"pool_members[].Name"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill cmdb_ci_lb_pool_member table"
comment = "Fill the data in the actual Service Now\" Load Balancer Pool Member\" table."
if {
condition = is_not_empty {get_attr {"pool_members"}}
on_true = transform {
src_table_name = "pool_members"
target_table_name = "cmdb_ci_lb_pool_member"
operation {
set_field {
field_name = "name"
value = get_attr {"pool_members[].Name"}
}
set_field {
field_name = "object_id"
value = get_attr {"pool_members[].Name"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill cmdb_ci_lb_pool table"
comment = "Fill the LB Pool table with the LB name, as there is not attribute in the AWS API calls that shows target group name for Classic Load Balancers and this table is needed to make the relation between LB and Pool Members." // Attribute collection: Collects specific attributes from the discovered CI
transform {
src_table_name = "ELB_v1"
target_table_name = "cmdb_ci_lb_pool"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"ELB_v1[].Name"}
"-Pool"
}
}
set_field {
field_name = "object_id"
value = get_attr {"ELB_v1[].Name"}
}
set_field {
field_name = "comments"
value = concat {
get_attr {"service_account[1].account_id"}
"_"
get_attr {"cmdb_ci_aws_datacenter[1].name"}
"_d0d3b880db8b04109149f2131f96194e"
}
}
}
}
}
}
|
Azure - Populate Azure Database Infromation | I would like for you to help me build a Pattern that helps achieve Discovery of Azure - Populate Azure Database Infromation. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure - Populate Azure Database Infromation"
id = "bf0a97ed670c03008ec4a4db2685ef38"
description = ""
step {
name = "Populate instance name"
transform {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cmdb_ci_cloud_database"
operation {set_field {
field_name = "instance"
value = get_attr {"cmdb_ci_cloud_database[].name"}
}}
}
}
step {
name = "Filter region according to LDC"
comment = "Filter out all DataBases which are not in the same logical data center region as set in LDC table."
if {
condition = is_empty {get_attr {"input_object_id"}}
on_true = filter {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cmdb_ci_cloud_database"
condition = any {
eq {
get_attr {"cmdb_ci_cloud_database[].region"}
get_attr {"ldc[1].name"}
}
eq {
get_attr {"cmdb_ci_cloud_database[].region"}
get_attr {"ldc[1].region"}
}
}
}
on_false = nop {}
}
}
step {
name = "Get DB status and state"
comment = "Using the loop functionality of the \"Transform Table\" operation to set DataBases operational status.
State: \"healthy\", \"succeeded\" and \"running\" will be set as \"operational\" state.
All others will be set as \"non-operational\"."
transform {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cmdb_ci_cloud_database"
operation {
set_field {
field_name = "operational_status"
value = eval {"javascript: var state = ${cmdb_ci_cloud_database[].state};
if (state)
state = ${cmdb_ci_cloud_database[].state}.toLowerCase();
var status='';
if (state == \"ready\" || state == \"healthy\" || state == \"succeeded\")
{
status = \"1\";
}
else
{
status = \"2\";
}
rtrn = status;"}
}
set_field {
field_name = "state"
value = eval {"javascript: var state = ${cmdb_ci_cloud_database[].state};
if (state)
state = ${cmdb_ci_cloud_database[].state}.toLowerCase();
var status='';
if (state == \"ready\" || state == \"healthy\" || state == \"succeeded\")
{
status = \"available\";
}
else
{
status = \"terminated\";
}
rtrn = status;"}
}
}
}
}
step {
name = "Populate install status and vendor "
comment = "Populating install_status and vendor columns."
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_database"}}
on_true = transform {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cmdb_ci_cloud_database"
operation {
set_field {
field_name = "install_status"
value = "1"
}
set_field {
field_name = "vendor"
value = "Microsoft"
}
}
}
on_false = nop {}
}
}
step {
name = "Check that it's Azure"
comment = "If it's not an Azure DataBase, the cloud DataBase table will not be populated and the pattern will stop."
match {
is_not_empty {get_attr {"cmdb_ci_cloud_database"}}
terminate_op = graceful
terminate_msg = "No Database is found in the LDC (region)"
}
}
}
| library {
name = "Azure - Populate Azure Database Infromation"
id = "bf0a97ed670c03008ec4a4db2685ef38" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate instance name"
transform {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cmdb_ci_cloud_database"
operation {set_field {
field_name = "instance"
value = get_attr {"cmdb_ci_cloud_database[].name"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter region according to LDC"
comment = "Filter out all DataBases which are not in the same logical data center region as set in LDC table."
if {
condition = is_empty {get_attr {"input_object_id"}}
on_true = filter {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cmdb_ci_cloud_database"
condition = any {
eq {
get_attr {"cmdb_ci_cloud_database[].region"}
get_attr {"ldc[1].name"}
}
eq {
get_attr {"cmdb_ci_cloud_database[].region"}
get_attr {"ldc[1].region"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get DB status and state"
comment = "Using the loop functionality of the \"Transform Table\" operation to set DataBases operational status.
State: \"healthy\", \"succeeded\" and \"running\" will be set as \"operational\" state.
All others will be set as \"non-operational\"."
transform {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cmdb_ci_cloud_database"
operation {
set_field {
field_name = "operational_status"
value = eval {"javascript: var state = ${cmdb_ci_cloud_database[].state}; // Script execution: Custom script to perform a specific action or collect data
if (state)
state = ${cmdb_ci_cloud_database[].state}.toLowerCase();
var status='';
if (state == \"ready\" || state == \"healthy\" || state == \"succeeded\")
{
status = \"1\";
}
else
{
status = \"2\";
}
rtrn = status;"}
}
set_field {
field_name = "state"
value = eval {"javascript: var state = ${cmdb_ci_cloud_database[].state}; // Script execution: Custom script to perform a specific action or collect data
if (state)
state = ${cmdb_ci_cloud_database[].state}.toLowerCase();
var status='';
if (state == \"ready\" || state == \"healthy\" || state == \"succeeded\")
{
status = \"available\";
}
else
{
status = \"terminated\";
}
rtrn = status;"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate install status and vendor "
comment = "Populating install_status and vendor columns."
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_database"}}
on_true = transform {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cmdb_ci_cloud_database"
operation {
set_field {
field_name = "install_status"
value = "1"
}
set_field {
field_name = "vendor"
value = "Microsoft"
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check that it's Azure"
comment = "If it's not an Azure DataBase, the cloud DataBase table will not be populated and the pattern will stop."
match {
is_not_empty {get_attr {"cmdb_ci_cloud_database"}}
terminate_op = graceful
terminate_msg = "No Database is found in the LDC (region)"
}
}
}
|
HP-UX - Installed Software | I would like for you to help me build a Pattern that helps achieve Discovery of HP-UX - Installed Software. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "HP-UX - Installed Software"
id = "b8f938f79fa032001d753758442e7065"
description = ""
step {
name = "Get installed software"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = runcmd_to_var {
cmd = "swlist -l product 2>/dev/null | grep -v 'PH.._'"
var_names = table {
name = "SPKG"
col_names = "name","version","descr"
}
parsing_strategy = regex_parsing {regex = "^\\s*(\\S+)\\s+(\\S+)\\s+(.+?)\\s*$"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Filter addons"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = filter {
src_table_name = "SPKG"
target_table_name = "SPKG"
condition = neq {
get_attr {"SPKG[].name"}
"#"
}
}
on_false = nop {}
}
}
step {
name = "Remove duplicate software"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = set_attr {
"dump_var"
eval {"javascript:
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${SPKG},[\"name\",\"version\"]);
CTX.setAttribute(\"SPKG\", tableWithoutDuplicates);
"}
}
on_false = nop {}
}
}
step {
name = "Mark all apps that we should keep according to filter"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = transform {
src_table_name = "SPKG"
target_table_name = "SPKG"
operation {set_field {
field_name = "shouldKeep"
value = eval {"javascript:
var rtrn = '';
var isIncludeMethod = ${isSoftwareFilterMethodIsInclude};
var appName = ${SPKG[].name};
var regex = ${softwareKeywordsRegex};
var extractFirstMatchWithRegex = function(stringToMatch,regex){
var regexObject = new RegExp(regex);
var match = stringToMatch.match(regexObject);
return match ? match[1] : null;
};
var match = extractFirstMatchWithRegex(appName,regex);
var isMatchFound = (match != null) && (match != \"\");
if((isIncludeMethod==\"true\" && isMatchFound) || (isIncludeMethod==\"false\" && !isMatchFound)){rtrn = \"true\";}else{rtrn = \"false\";}
"}
}}
}
on_false = nop {}
}
}
step {
name = "Retain only apps chosen by user's filter"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = filter {
src_table_name = "SPKG"
target_table_name = "SPKG"
condition = eq {
get_attr {"SPKG[].shouldKeep"}
"true"
}
}
on_false = nop {}
}
}
step {
name = "Update cmdb_sam_sw_install"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"false"
}
}
on_true = transform {
src_table_name = "SPKG"
target_table_name = "cmdb_sam_sw_install"
operation {
set_field {
field_name = "display_name"
value = get_attr {"SPKG[].name"}
}
set_field {
field_name = "version"
value = get_attr {"SPKG[].version"}
}
}
}
on_false = nop {}
}
}
step {
name = "Update cmdb_ci_spkg"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = transform {
src_table_name = "SPKG"
target_table_name = "cmdb_ci_spkg"
operation {
set_field {
field_name = "name"
value = get_attr {"SPKG[].name"}
}
set_field {
field_name = "version"
value = get_attr {"SPKG[].version"}
}
set_field {
field_name = "short_description"
value = get_attr {"SPKG[].descr"}
}
set_field {
field_name = "key"
value = concat {eval {"javascript: rtrn = \"\";rtrn = ${SPKG[].name} + \"_:::_\" + (${SPKG[].version}||\"NULL\");"}}
}
}
}
on_false = nop {}
}
}
step {
name = "Update cmdb_software_instance"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = transform {
src_table_name = "SPKG"
target_table_name = "cmdb_software_instance"
operation {set_field {
field_name = "name"
value = get_attr {"SPKG[].name"}
}}
}
on_false = nop {}
}
}
step {
name = "Ref/Rel between cmdb_software_instance and cmdb_ci_spkg"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = relation_reference {
table1_name = "cmdb_software_instance"
table2_name = "cmdb_ci_spkg"
result_table_name = "software_instance_spkg"
unmatched_lines = remove
condition = all {
eq {
get_attr {"cmdb_software_instance[].name"}
get_attr {"cmdb_ci_spkg[].name"}
}
eq {
get_attr {"cmdb_software_instance[].version"}
get_attr {"cmdb_ci_spkg[].version"}
}
}
ref_direction = parentToChild
ref_field_name = "software"
}
on_false = nop {}
}
}
step {
name = "Ref/Rel between cmdb_sam_sw_install and HPUX CI"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"false"
}
}
on_true = relation_reference {
table1_name = "cmdb_sam_sw_install"
table2_name = "cmdb_ci_hpux_server"
result_table_name = "sam_to_HP"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
ref_direction = parentToChild
ref_field_name = "non_ci"
}
on_false = nop {}
}
}
}
| library {
name = "HP-UX - Installed Software"
id = "b8f938f79fa032001d753758442e7065" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get installed software"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = runcmd_to_var {
cmd = "swlist -l product 2>/dev/null | grep -v 'PH.._'"
var_names = table {
name = "SPKG"
col_names = "name","version","descr"
}
parsing_strategy = regex_parsing {regex = "^\\s*(\\S+)\\s+(\\S+)\\s+(.+?)\\s*$"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter addons"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = filter {
src_table_name = "SPKG"
target_table_name = "SPKG"
condition = neq {
get_attr {"SPKG[].name"}
"#"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate software"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = set_attr {
"dump_var"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${SPKG},[\"name\",\"version\"]);
CTX.setAttribute(\"SPKG\", tableWithoutDuplicates);
"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Mark all apps that we should keep according to filter"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = transform {
src_table_name = "SPKG"
target_table_name = "SPKG"
operation {set_field {
field_name = "shouldKeep"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
var isIncludeMethod = ${isSoftwareFilterMethodIsInclude};
var appName = ${SPKG[].name};
var regex = ${softwareKeywordsRegex};
var extractFirstMatchWithRegex = function(stringToMatch,regex){
var regexObject = new RegExp(regex);
var match = stringToMatch.match(regexObject);
return match ? match[1] : null;
};
var match = extractFirstMatchWithRegex(appName,regex);
var isMatchFound = (match != null) && (match != \"\");
if((isIncludeMethod==\"true\" && isMatchFound) || (isIncludeMethod==\"false\" && !isMatchFound)){rtrn = \"true\";}else{rtrn = \"false\";}
"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Retain only apps chosen by user's filter"
if {
condition = eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
on_true = filter {
src_table_name = "SPKG"
target_table_name = "SPKG"
condition = eq {
get_attr {"SPKG[].shouldKeep"}
"true"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_sam_sw_install"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"false"
}
}
on_true = transform {
src_table_name = "SPKG"
target_table_name = "cmdb_sam_sw_install"
operation {
set_field {
field_name = "display_name"
value = get_attr {"SPKG[].name"}
}
set_field {
field_name = "version"
value = get_attr {"SPKG[].version"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_spkg"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = transform {
src_table_name = "SPKG"
target_table_name = "cmdb_ci_spkg"
operation {
set_field {
field_name = "name"
value = get_attr {"SPKG[].name"}
}
set_field {
field_name = "version"
value = get_attr {"SPKG[].version"}
}
set_field {
field_name = "short_description" // Script execution: Custom script to perform a specific action or collect data
value = get_attr {"SPKG[].descr"}
}
set_field {
field_name = "key"
value = concat {eval {"javascript: rtrn = \"\";rtrn = ${SPKG[].name} + \"_:::_\" + (${SPKG[].version}||\"NULL\");"}} // Script execution: Custom script to perform a specific action or collect data
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_software_instance"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = transform {
src_table_name = "SPKG"
target_table_name = "cmdb_software_instance"
operation {set_field {
field_name = "name"
value = get_attr {"SPKG[].name"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between cmdb_software_instance and cmdb_ci_spkg"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = relation_reference {
table1_name = "cmdb_software_instance"
table2_name = "cmdb_ci_spkg"
result_table_name = "software_instance_spkg"
unmatched_lines = remove
condition = all {
eq {
get_attr {"cmdb_software_instance[].name"}
get_attr {"cmdb_ci_spkg[].name"}
}
eq {
get_attr {"cmdb_software_instance[].version"}
get_attr {"cmdb_ci_spkg[].version"}
}
}
ref_direction = parentToChild
ref_field_name = "software"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between cmdb_sam_sw_install and HPUX CI"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"false"
}
}
on_true = relation_reference {
table1_name = "cmdb_sam_sw_install"
table2_name = "cmdb_ci_hpux_server"
result_table_name = "sam_to_HP"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
ref_direction = parentToChild
ref_field_name = "non_ci"
}
on_false = nop {}
}
}
}
|
OpenStack Identity | I would like for you to help me build a Pattern that helps achieve Discovery of OpenStack Identity. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "OpenStack Identity"
id = "b8af978adbf00010bf2fe0a1ca961923"
description = "null"
step {
name = "Get Services"
set_attr {
"services_list_response"
eval {"javascript: //Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack Get Identity Resources pattern.\");
var rtrn;
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var serviceURL = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
var token = CTX.getAttribute('token');
var resource = \"services\";
serviceURL = serviceURL + \"/v\" + keystone_version;
if (token) {
var header = \"X-Auth-Token:\" + token;
serviceURL = serviceURL + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
rtrn = response;
}
"}
}
}
step {
name = "Parse the Services"
parse_var_to_var {
from_var_name = "services_list_response"
to_var_names = table {
name = "services"
col_names = "service_id","service_name","service_type","service_enabled"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "service_id"
xpath = "/root/services/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_name"
xpath = "/root/services/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_type"
xpath = "/root/services/type/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_enabled"
xpath = "/root/services/enabled/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Parse Services with description"
parse_var_to_var {
from_var_name = "services_list_response"
to_var_names = table {
name = "services_description"
col_names = "service_id","service_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "service_id"
xpath = "/root/services/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_description"
xpath = "/root/services/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Add the Description to the service table"
if {
condition = is_not_empty {get_attr {"services_description"}}
on_true = merge {
table1_name = "services"
key1_name = "service_id"
table2_name = "services_description"
key2_name = "service_id"
result_table_name = "services"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_cloud_openstack_service table"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = transform {
src_table_name = "services"
target_table_name = "cmdb_ci_cloud_openstack_service"
operation {
set_field {
field_name = "object_id"
value = get_attr {"services[].service_id"}
}
set_field {
field_name = "name"
value = get_attr {"services[].service_name"}
}
set_field {
field_name = "type"
value = get_attr {"services[].service_type"}
}
set_field {
field_name = "enabled"
value = get_attr {"services[].service_enabled"}
}
set_field {
field_name = "short_description"
value = get_attr {"services[].service_description"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create Relation between cmdb_ci_cloud_openstack_service and cmdb_ci_cloud_service_account"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_openstack_service"
table2_name = "cmdb_ci_cloud_service_account"
result_table_name = "service_to_account"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Get EndPoints"
set_attr {
"endpoints_list_response"
eval {"javascript: //Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack Get Identity Resources pattern.\");
var rtrn;
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var serviceURL = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
var token = CTX.getAttribute('token');
var resource = \"endpoints\";
serviceURL = serviceURL + \"/v\" + keystone_version;
if (token) {
var header = \"X-Auth-Token:\" + token;
serviceURL = serviceURL + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
rtrn = response;
}
"}
}
}
step {
name = "Parse the Endpoints"
parse_var_to_var {
from_var_name = "endpoints_list_response"
to_var_names = table {
name = "endpoints"
col_names = "url","service_id","endpoint_id","interface","enabled"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "url"
xpath = "/root/endpoints/url/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_id"
xpath = "/root/endpoints/service_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "endpoint_id"
xpath = "/root/endpoints/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "interface"
xpath = "/root/endpoints/interface/text()"
delimiters = ""
position = 1
}
field {
col_name = "enabled"
xpath = "/root/endpoints/enabled/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Parse the Endpoint regions prior to versnio 3.2"
parse_var_to_var {
from_var_name = "endpoints_list_response"
to_var_names = table {
name = "endpoints_region"
col_names = "endpoint_id","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "endpoint_id"
xpath = "/root/endpoints/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/endpoints/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Check if any regions are parsed"
if {
condition = is_not_empty {get_attr {"endpoints_region"}}
on_true = filter {
src_table_name = "endpoints_region"
target_table_name = "endpoints_region"
condition = is_not_empty {get_attr {"endpoints_region[].region"}}
}
on_false = nop {}
}
}
step {
name = "Parse the Endpoint regions since versnio 3.2"
if {
condition = is_empty {get_attr {"endpoints_region"}}
on_true = parse_var_to_var {
from_var_name = "endpoints_list_response"
to_var_names = table {
name = "endpoints_region"
col_names = "endpoint_id","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "endpoint_id"
xpath = "/root/endpoints/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/endpoints/region_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the region to the Endpoints table"
if {
condition = is_not_empty {get_attr {"endpoints"}}
on_true = merge {
table1_name = "endpoints"
key1_name = "endpoint_id"
table2_name = "endpoints_region"
key2_name = "endpoint_id"
result_table_name = "endpoints"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
is_not_empty {get_attr {"endpoints"}}
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
}
on_true = filter {
src_table_name = "endpoints"
target_table_name = "endpoints"
condition = eq {
get_attr {"endpoints[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray()
var length = ldc.length
var region = ${endpoints[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_cloud_openstack_endpoint table"
if {
condition = is_not_empty {get_attr {"endpoints"}}
on_true = transform {
src_table_name = "endpoints"
target_table_name = "cmdb_ci_cloud_openstack_endpoint"
operation {
set_field {
field_name = "object_id"
value = get_attr {"endpoints[].endpoint_id"}
}
set_field {
field_name = "name"
value = get_attr {"endpoints[].url"}
}
set_field {
field_name = "interface"
value = get_attr {"endpoints[].interface"}
}
set_field {
field_name = "enabled"
value = get_attr {"endpoints[].enabled"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create Relation between cmdb_ci_cloud_openstack_endpoint and cmdb_ci_cloud_openstack_service tables"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_cloud_openstack_endpoint"}}
is_not_empty {get_attr {"cmdb_ci_cloud_openstack_service"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_openstack_endpoint"
key1_name = "service_id"
table2_name = "cmdb_ci_cloud_openstack_service"
key2_name = "service_id"
result_table_name = "endpoint_to_service"
unmatched_lines = remove
relation_type = "Use End Point To::Use End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create Relation between cmdb_ci_cloud_openstack_endpoint and cmdb_ci_openstack_datacenter tables"
if {
condition = is_not_empty {get_attr {"endpoints"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_openstack_endpoint"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "endpoints_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Get Domains"
set_attr {
"domains_list_response"
eval {"javascript: //Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack Get Identity Resources pattern.\");
var rtrn;
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var serviceURL = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
var token = CTX.getAttribute('token');
var resource = \"domains\";
serviceURL = serviceURL + \"/v\" + keystone_version;
if (token) {
var header = \"X-Auth-Token:\" + token;
serviceURL = serviceURL + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
rtrn = response;
}
"}
}
}
step {
name = "Parse the Domains"
parse_var_to_var {
from_var_name = "domains_list_response"
to_var_names = table {
name = "domains"
col_names = "domain_id","domain_name","domain_enabled"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "domain_id"
xpath = "/root/domains/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "domain_name"
xpath = "/root/domains/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "domain_enabled"
xpath = "/root/domains/enabled/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Parse Domains with description"
if {
condition = is_not_empty {get_attr {"domains"}}
on_true = parse_var_to_var {
from_var_name = "domains_list_response"
to_var_names = table {
name = "domains_description"
col_names = "domain_id","domain_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "domain_id"
xpath = "/root/domains/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "domain_description"
xpath = "/root/domains/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the desscription to the domain table"
if {
condition = is_not_empty {get_attr {"domains_description"}}
on_true = merge {
table1_name = "domains"
key1_name = "domain_id"
table2_name = "domains_description"
key2_name = "domain_id"
result_table_name = "domains"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_cloud_openstack_domain table"
if {
condition = is_not_empty {get_attr {"domains"}}
on_true = transform {
src_table_name = "domains"
target_table_name = "cmdb_ci_cloud_openstack_domain"
operation {
set_field {
field_name = "object_id"
value = get_attr {"domains[].domain_id"}
}
set_field {
field_name = "name"
value = get_attr {"domains[].domain_name"}
}
set_field {
field_name = "short_description"
value = get_attr {"domains[].domain_description"}
}
set_field {
field_name = "enabled"
value = get_attr {"domains[].domain_enabled"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create Relation betweem cmdb_ci_cloud_openstack_domain and cmdb_ci_cloud_service_account tables"
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_openstack_domain"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_openstack_domain"
key1_name = "domain_id"
table2_name = "cmdb_ci_cloud_service_account"
key2_name = "domain_id"
result_table_name = "domain_to_account"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "OpenStack Identity"
id = "b8af978adbf00010bf2fe0a1ca961923" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Services"
set_attr {
"services_list_response"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack Get Identity Resources pattern.\");
var rtrn;
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var serviceURL = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
var token = CTX.getAttribute('token');
var resource = \"services\";
serviceURL = serviceURL + \"/v\" + keystone_version;
if (token) {
var header = \"X-Auth-Token:\" + token;
serviceURL = serviceURL + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
rtrn = response;
}
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Services"
parse_var_to_var {
from_var_name = "services_list_response"
to_var_names = table {
name = "services"
col_names = "service_id","service_name","service_type","service_enabled"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "service_id"
xpath = "/root/services/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_name"
xpath = "/root/services/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_type"
xpath = "/root/services/type/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_enabled"
xpath = "/root/services/enabled/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Services with description" // Script execution: Custom script to perform a specific action or collect data
parse_var_to_var {
from_var_name = "services_list_response"
to_var_names = table {
name = "services_description" // Script execution: Custom script to perform a specific action or collect data
col_names = "service_id","service_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "service_id"
xpath = "/root/services/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/services/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the Description to the service table" // Script execution: Custom script to perform a specific action or collect data
if {
condition = is_not_empty {get_attr {"services_description"}} // Script execution: Custom script to perform a specific action or collect data
on_true = merge {
table1_name = "services"
key1_name = "service_id"
table2_name = "services_description" // Script execution: Custom script to perform a specific action or collect data
key2_name = "service_id"
result_table_name = "services"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_cloud_openstack_service table"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = transform {
src_table_name = "services"
target_table_name = "cmdb_ci_cloud_openstack_service"
operation {
set_field {
field_name = "object_id"
value = get_attr {"services[].service_id"}
}
set_field {
field_name = "name"
value = get_attr {"services[].service_name"}
}
set_field {
field_name = "type"
value = get_attr {"services[].service_type"}
}
set_field {
field_name = "enabled"
value = get_attr {"services[].service_enabled"}
}
set_field {
field_name = "short_description" // Script execution: Custom script to perform a specific action or collect data
value = get_attr {"services[].service_description"} // Script execution: Custom script to perform a specific action or collect data
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Relation between cmdb_ci_cloud_openstack_service and cmdb_ci_cloud_service_account"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_openstack_service"
table2_name = "cmdb_ci_cloud_service_account"
result_table_name = "service_to_account"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get EndPoints"
set_attr {
"endpoints_list_response"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack Get Identity Resources pattern.\");
var rtrn;
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var serviceURL = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
var token = CTX.getAttribute('token');
var resource = \"endpoints\";
serviceURL = serviceURL + \"/v\" + keystone_version;
if (token) {
var header = \"X-Auth-Token:\" + token;
serviceURL = serviceURL + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
rtrn = response;
}
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Endpoints"
parse_var_to_var {
from_var_name = "endpoints_list_response"
to_var_names = table {
name = "endpoints"
col_names = "url","service_id","endpoint_id","interface","enabled"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "url"
xpath = "/root/endpoints/url/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_id"
xpath = "/root/endpoints/service_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "endpoint_id"
xpath = "/root/endpoints/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "interface"
xpath = "/root/endpoints/interface/text()"
delimiters = ""
position = 1
}
field {
col_name = "enabled"
xpath = "/root/endpoints/enabled/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Endpoint regions prior to versnio 3.2"
parse_var_to_var {
from_var_name = "endpoints_list_response"
to_var_names = table {
name = "endpoints_region"
col_names = "endpoint_id","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "endpoint_id"
xpath = "/root/endpoints/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/endpoints/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check if any regions are parsed"
if {
condition = is_not_empty {get_attr {"endpoints_region"}}
on_true = filter {
src_table_name = "endpoints_region"
target_table_name = "endpoints_region"
condition = is_not_empty {get_attr {"endpoints_region[].region"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Endpoint regions since versnio 3.2"
if {
condition = is_empty {get_attr {"endpoints_region"}}
on_true = parse_var_to_var {
from_var_name = "endpoints_list_response"
to_var_names = table {
name = "endpoints_region"
col_names = "endpoint_id","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "endpoint_id"
xpath = "/root/endpoints/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/endpoints/region_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the region to the Endpoints table"
if {
condition = is_not_empty {get_attr {"endpoints"}}
on_true = merge {
table1_name = "endpoints"
key1_name = "endpoint_id"
table2_name = "endpoints_region"
key2_name = "endpoint_id"
result_table_name = "endpoints"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
is_not_empty {get_attr {"endpoints"}}
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
}
on_true = filter {
src_table_name = "endpoints"
target_table_name = "endpoints"
condition = eq {
get_attr {"endpoints[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray() // Script execution: Custom script to perform a specific action or collect data
var length = ldc.length
var region = ${endpoints[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_cloud_openstack_endpoint table"
if {
condition = is_not_empty {get_attr {"endpoints"}}
on_true = transform {
src_table_name = "endpoints"
target_table_name = "cmdb_ci_cloud_openstack_endpoint"
operation {
set_field {
field_name = "object_id"
value = get_attr {"endpoints[].endpoint_id"}
}
set_field {
field_name = "name"
value = get_attr {"endpoints[].url"}
}
set_field {
field_name = "interface"
value = get_attr {"endpoints[].interface"}
}
set_field {
field_name = "enabled"
value = get_attr {"endpoints[].enabled"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Relation between cmdb_ci_cloud_openstack_endpoint and cmdb_ci_cloud_openstack_service tables"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_cloud_openstack_endpoint"}}
is_not_empty {get_attr {"cmdb_ci_cloud_openstack_service"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_openstack_endpoint"
key1_name = "service_id"
table2_name = "cmdb_ci_cloud_openstack_service"
key2_name = "service_id"
result_table_name = "endpoint_to_service"
unmatched_lines = remove
relation_type = "Use End Point To::Use End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Relation between cmdb_ci_cloud_openstack_endpoint and cmdb_ci_openstack_datacenter tables"
if {
condition = is_not_empty {get_attr {"endpoints"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_openstack_endpoint"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "endpoints_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Domains"
set_attr {
"domains_list_response"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack Get Identity Resources pattern.\");
var rtrn;
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var serviceURL = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
var token = CTX.getAttribute('token');
var resource = \"domains\";
serviceURL = serviceURL + \"/v\" + keystone_version;
if (token) {
var header = \"X-Auth-Token:\" + token;
serviceURL = serviceURL + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
rtrn = response;
}
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Domains"
parse_var_to_var {
from_var_name = "domains_list_response"
to_var_names = table {
name = "domains"
col_names = "domain_id","domain_name","domain_enabled"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "domain_id"
xpath = "/root/domains/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "domain_name"
xpath = "/root/domains/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "domain_enabled"
xpath = "/root/domains/enabled/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Domains with description" // Script execution: Custom script to perform a specific action or collect data
if {
condition = is_not_empty {get_attr {"domains"}}
on_true = parse_var_to_var {
from_var_name = "domains_list_response"
to_var_names = table {
name = "domains_description" // Script execution: Custom script to perform a specific action or collect data
col_names = "domain_id","domain_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "domain_id"
xpath = "/root/domains/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "domain_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/domains/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the desscription to the domain table" // Script execution: Custom script to perform a specific action or collect data
if {
condition = is_not_empty {get_attr {"domains_description"}} // Script execution: Custom script to perform a specific action or collect data
on_true = merge {
table1_name = "domains"
key1_name = "domain_id"
table2_name = "domains_description" // Script execution: Custom script to perform a specific action or collect data
key2_name = "domain_id"
result_table_name = "domains"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_cloud_openstack_domain table"
if {
condition = is_not_empty {get_attr {"domains"}}
on_true = transform {
src_table_name = "domains"
target_table_name = "cmdb_ci_cloud_openstack_domain"
operation {
set_field {
field_name = "object_id"
value = get_attr {"domains[].domain_id"}
}
set_field {
field_name = "name"
value = get_attr {"domains[].domain_name"}
}
set_field {
field_name = "short_description" // Script execution: Custom script to perform a specific action or collect data
value = get_attr {"domains[].domain_description"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "enabled"
value = get_attr {"domains[].domain_enabled"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Relation betweem cmdb_ci_cloud_openstack_domain and cmdb_ci_cloud_service_account tables"
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_openstack_domain"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_openstack_domain"
key1_name = "domain_id"
table2_name = "cmdb_ci_cloud_service_account"
key2_name = "domain_id"
result_table_name = "domain_to_account"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
Amazon AWS - Get Classic LB data | I would like for you to help me build a Pattern that helps achieve Discovery of Amazon AWS - Get Classic LB data. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Amazon AWS - Get Classic LB data"
id = "b6d223afdb1a9300d504788dbf961986"
description = "null"
step {
name = "Get Classic Load Balancer"
comment = "The API call describes the specified load balancers. If no load balancers are specified, the call describes all of the amazon account load balancers. The step also parses the classic LB rest response into variable so it can be used on later stages.
Note:
Using \"true\" to Formatted field means that the response has to be parsed with delimited text because otherwise the parsing of attributes from it is not possible."
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://elasticloadbalancing.{region}.amazonaws.com/?Action=DescribeLoadBalancers&LoadBalancerNames.member.1="
get_attr {"input_object_id"}
"&Version=2012-06-01"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "rest_resp_elb_v1"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "Verify if we have any valid response"
comment = "pg - the check whether actual resources is removed based on patterns review for all kind of resources."
match {
all {
not_contains {
get_attr {"rest_resp_elb_v1"}
"Cloud request failed"
}
is_not_empty {get_attr {"rest_resp_elb_v1"}}
}
terminate_op = terminate
terminate_msg = ""
}
}
step {
name = "Parsing the fields for LB table"
comment = "Parsing the main LB field values, so we minimize the chance of missing LBs if some of the API Call additional attributes are not present."
parse_var_to_var {
from_var_name = "rest_resp_elb_v1"
to_var_names = table {
name = "ELB_v1"
col_names = "CanonicalHostedZoneName","CanonicalHostedZoneId","DNSName","Name","datacenter","availability_zone"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "CanonicalHostedZoneName"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/CanonicalHostedZoneName/text()"
delimiters = ""
position = 1
}
field {
col_name = "CanonicalHostedZoneId"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/CanonicalHostedZoneNameID/text()"
delimiters = ""
position = 1
}
field {
col_name = "DNSName"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/DNSName/text()"
delimiters = ""
position = 1
}
field {
col_name = "Name"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/LoadBalancerName/text()"
delimiters = ""
position = 1
}
field {
col_name = "datacenter"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/added_sn_region/text()"
delimiters = ""
position = 1
}
field {
col_name = "availability_zone"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/AvailabilityZones/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Parsing additional Classic LB attribues "
comment = "Getting addition attributes for relationships inside ServiceNow tables. The SourceSecurityGroup does not capture all the security groups assigned to a LB, but only the main/first group, so we can parse it in the same step and not worry about duplication of LBs.
A few exceptions:
- policies, because they are seldom present, which means that too few LBs would be returned in this step
- instances and Subnets, as they may have multiple values per LB, which means they would create duplicate rows."
parse_var_to_var {
from_var_name = "rest_resp_elb_v1"
to_var_names = table {
name = "additional_ELB_v1"
col_names = "SourceSecurityGroup","VPCId","Name","security_group_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "SourceSecurityGroup"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/SourceSecurityGroup/GroupName/text()"
delimiters = ""
position = 1
}
field {
col_name = "VPCId"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/VPCId/text()"
delimiters = ""
position = 1
}
field {
col_name = "Name"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/LoadBalancerName/text()"
delimiters = ""
position = 1
}
field {
col_name = "security_group_id"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/SecurityGroups/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Merging the Classic LB attributes"
comment = "Merging the two tables so we can work only with the main table for future steps."
if {
condition = is_not_empty {get_attr {"additional_ELB_v1"}}
on_true = merge {
table1_name = "ELB_v1"
key1_name = "Name"
table2_name = "additional_ELB_v1"
key2_name = "Name"
result_table_name = "ELB_v1"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Create LBtoAZHashMap"
set_attr {
"tmp"
eval {"javascript: rtrn = '';
var lb_and_az = ${ELB_v1};
var LBtoAZHashMap = new Packages.java.util.HashMap();
for (var i=0 ; i < lb_and_az.size(); i++){
var key = lb_and_az.get(i).get('Name');
var value = lb_and_az.get(i).get('availability_zone');
if (LBtoAZHashMap.containsKey(key)){
(LBtoAZHashMap.get(key)).add(value);
}
else {
var LBtoAZSet = new Packages.java.util.HashSet();
LBtoAZSet.add(value);
LBtoAZHashMap.put(key,LBtoAZSet);
}
}
CTX.setAttribute(\"LBtoAZHashMap\", LBtoAZHashMap);"}
}
}
step {
name = "Create LBtoSGHashMap"
set_attr {
"tmp"
eval {"javascript: rtrn = '';
var lb_and_sg = ${ELB_v1};
var LBtoSGHashMap = new Packages.java.util.HashMap();
for (var i=0 ; i < lb_and_sg.size(); i++){
var key = lb_and_sg.get(i).get('Name');
var value = lb_and_sg.get(i).get('security_group_id');
if (LBtoSGHashMap.containsKey(key)){
(LBtoSGHashMap.get(key)).add(value);
}
else {
var LBtoSGSet = new Packages.java.util.HashSet();
LBtoSGSet.add(value);
LBtoSGHashMap.put(key,LBtoSGSet);
}
}
CTX.setAttribute(\"LBtoSGHashMap\", LBtoSGHashMap);"}
}
}
step {
name = "Remove duplicate LBs"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${ELB_v1},[\"Name\"]);
CTX.setAttribute(\"ELB_v1\", tableWithoutDuplicates);"}
}
}
step {
name = "Add availability_zone and security_group_id to ELB_v1 table"
transform {
src_table_name = "ELB_v1"
target_table_name = "ELB_v1"
operation {
set_field {
field_name = "availability_zone"
value = eval {"javascript: rtrn = '';
LBtoAZHashMap = ${LBtoAZHashMap};
var object_id = ${ELB_v1[].Name};
rtrn = LBtoAZHashMap.get(object_id);"}
}
set_field {
field_name = "security_group_id"
value = eval {"javascript: rtrn = '';
LBtoSGHashMap = ${LBtoSGHashMap};
var object_id = ${ELB_v1[].Name};
rtrn = LBtoSGHashMap.get(object_id);"}
}
}
}
}
step {
name = "Get IPs for DNS"
set_attr {
"tmp"
eval {"javascript: var ArrayList = Packages.java.util.ArrayList;
var IPUtil = new Packages.com.snc.cmp.connector.util.IPUtil();
var DNS = ${ELB_v1[*].DNSName};
var LB_name = ${ELB_v1[*].Name};
var dns_and_ips = new ArrayList();
for (var i = 0; i < DNS.size(); i++){
var IPs = IPUtil.resolveHostName(DNS.get(i));
for (var j = 0; j < IPs.size(); j++){
dns_and_ips.add(\"LB_NAME = \" + LB_name.get(i) + \" NAME = \" + DNS.get(i) + \" IP = \" + IPs.get(j));
}
}
CTX.setAttribute(\"dns_and_ips\",dns_and_ips);"}
}
}
step {
name = "Parse DNS and IPs"
parse_var_to_var {
from_var_name = "dns_and_ips"
to_var_names = table {
name = "dns_ip_table"
col_names = "Name","name","ip_address"
}
parsing_strategy = regex_parsing {regex = "^LB_NAME\\ =\\ (.*?)\\ NAME\\ =\\ (.*?)\\ IP\\ =\\ (.*?)$"}
if_not_found_do = nop {}
}
}
step {
name = "Fill cmdb_ci_cloud_load_balancer table"
if {
condition = is_not_empty {get_attr {"ELB_v1"}}
on_true = transform {
src_table_name = "ELB_v1"
target_table_name = "cmdb_ci_cloud_load_balancer"
operation {
set_field {
field_name = "name"
value = get_attr {"ELB_v1[].Name"}
}
set_field {
field_name = "object_id"
value = get_attr {"ELB_v1[].Name"}
}
set_field {
field_name = "dns_name"
value = get_attr {"ELB_v1[].DNSName"}
}
set_field {
field_name = "fqdn"
value = get_attr {"ELB_v1[].DNSName"}
}
set_field {
field_name = "canonical_hosted_zone_id"
value = get_attr {"ELB_v1[].CanonicalHostedZoneId"}
}
set_field {
field_name = "canonical_hosted_zone_name"
value = get_attr {"ELB_v1[].DNSName"}
}
set_field {
field_name = "state"
value = "available"
}
}
}
on_false = nop {}
}
}
step {
name = "Fill cmdb_ci_dns_name table"
transform {
src_table_name = "dns_ip_table"
target_table_name = "cmdb_ci_dns_name"
operation {
set_field {
field_name = "object_id"
value = get_attr {"dns_ip_table[].name"}
}
set_field {
field_name = "name"
value = get_attr {"dns_ip_table[].name"}
}
set_field {
field_name = "install_status"
value = "1"
}
set_field {
field_name = "operational_status"
value = "1"
}
}
}
}
step {
name = "Fill cmdb_ci_cloud_lb_ipaddress with DNS"
transform {
src_table_name = "dns_ip_table"
target_table_name = "cmdb_ci_cloud_lb_ipaddress"
operation {
set_field {
field_name = "name"
value = get_attr {"dns_ip_table[].ip_address"}
}
set_field {
field_name = "object_id"
value = get_attr {"dns_ip_table[].ip_address"}
}
set_field {
field_name = "ip_address"
value = get_attr {"dns_ip_table[].ip_address"}
}
}
}
}
}
| library {
name = "Amazon AWS - Get Classic LB data"
id = "b6d223afdb1a9300d504788dbf961986" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Classic Load Balancer"
comment = "The API call describes the specified load balancers. If no load balancers are specified, the call describes all of the amazon account load balancers. The step also parses the classic LB rest response into variable so it can be used on later stages. // Step definition: Represents a single action or set of actions in the pattern
Note:
Using \"true\" to Formatted field means that the response has to be parsed with delimited text because otherwise the parsing of attributes from it is not possible." // Attribute collection: Collects specific attributes from the discovered CI
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://elasticloadbalancing.{region}.amazonaws.com/?Action=DescribeLoadBalancers&LoadBalancerNames.member.1="
get_attr {"input_object_id"}
"&Version=2012-06-01"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "rest_resp_elb_v1"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Verify if we have any valid response"
comment = "pg - the check whether actual resources is removed based on patterns review for all kind of resources."
match {
all {
not_contains {
get_attr {"rest_resp_elb_v1"}
"Cloud request failed"
}
is_not_empty {get_attr {"rest_resp_elb_v1"}}
}
terminate_op = terminate
terminate_msg = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parsing the fields for LB table"
comment = "Parsing the main LB field values, so we minimize the chance of missing LBs if some of the API Call additional attributes are not present." // Attribute collection: Collects specific attributes from the discovered CI
parse_var_to_var {
from_var_name = "rest_resp_elb_v1"
to_var_names = table {
name = "ELB_v1"
col_names = "CanonicalHostedZoneName","CanonicalHostedZoneId","DNSName","Name","datacenter","availability_zone"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "CanonicalHostedZoneName"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/CanonicalHostedZoneName/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "CanonicalHostedZoneId"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/CanonicalHostedZoneNameID/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "DNSName"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/DNSName/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "Name"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/LoadBalancerName/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "datacenter"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/added_sn_region/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "availability_zone"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/AvailabilityZones/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parsing additional Classic LB attribues "
comment = "Getting addition attributes for relationships inside ServiceNow tables. The SourceSecurityGroup does not capture all the security groups assigned to a LB, but only the main/first group, so we can parse it in the same step and not worry about duplication of LBs. // Step definition: Represents a single action or set of actions in the pattern
A few exceptions:
- policies, because they are seldom present, which means that too few LBs would be returned in this step // Step definition: Represents a single action or set of actions in the pattern
- instances and Subnets, as they may have multiple values per LB, which means they would create duplicate rows."
parse_var_to_var {
from_var_name = "rest_resp_elb_v1"
to_var_names = table {
name = "additional_ELB_v1"
col_names = "SourceSecurityGroup","VPCId","Name","security_group_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "SourceSecurityGroup"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/SourceSecurityGroup/GroupName/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "VPCId"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/VPCId/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "Name"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/LoadBalancerName/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "security_group_id"
xpath = "/root/DescribeLoadBalancersResponse/DescribeLoadBalancersResult/LoadBalancerDescriptions/SecurityGroups/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merging the Classic LB attributes" // Attribute collection: Collects specific attributes from the discovered CI
comment = "Merging the two tables so we can work only with the main table for future steps." // Step definition: Represents a single action or set of actions in the pattern
if {
condition = is_not_empty {get_attr {"additional_ELB_v1"}}
on_true = merge {
table1_name = "ELB_v1"
key1_name = "Name"
table2_name = "additional_ELB_v1"
key2_name = "Name"
result_table_name = "ELB_v1"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create LBtoAZHashMap"
set_attr {
"tmp"
eval {"javascript: rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var lb_and_az = ${ELB_v1};
var LBtoAZHashMap = new Packages.java.util.HashMap();
for (var i=0 ; i < lb_and_az.size(); i++){
var key = lb_and_az.get(i).get('Name');
var value = lb_and_az.get(i).get('availability_zone');
if (LBtoAZHashMap.containsKey(key)){
(LBtoAZHashMap.get(key)).add(value);
}
else {
var LBtoAZSet = new Packages.java.util.HashSet();
LBtoAZSet.add(value);
LBtoAZHashMap.put(key,LBtoAZSet);
}
}
CTX.setAttribute(\"LBtoAZHashMap\", LBtoAZHashMap);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create LBtoSGHashMap"
set_attr {
"tmp"
eval {"javascript: rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var lb_and_sg = ${ELB_v1};
var LBtoSGHashMap = new Packages.java.util.HashMap();
for (var i=0 ; i < lb_and_sg.size(); i++){
var key = lb_and_sg.get(i).get('Name');
var value = lb_and_sg.get(i).get('security_group_id');
if (LBtoSGHashMap.containsKey(key)){
(LBtoSGHashMap.get(key)).add(value);
}
else {
var LBtoSGSet = new Packages.java.util.HashSet();
LBtoSGSet.add(value);
LBtoSGHashMap.put(key,LBtoSGSet);
}
}
CTX.setAttribute(\"LBtoSGHashMap\", LBtoSGHashMap);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate LBs"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${ELB_v1},[\"Name\"]);
CTX.setAttribute(\"ELB_v1\", tableWithoutDuplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add availability_zone and security_group_id to ELB_v1 table"
transform {
src_table_name = "ELB_v1"
target_table_name = "ELB_v1"
operation {
set_field {
field_name = "availability_zone"
value = eval {"javascript: rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
LBtoAZHashMap = ${LBtoAZHashMap};
var object_id = ${ELB_v1[].Name}; // Unique identifier for the pattern
rtrn = LBtoAZHashMap.get(object_id);"}
}
set_field {
field_name = "security_group_id"
value = eval {"javascript: rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
LBtoSGHashMap = ${LBtoSGHashMap};
var object_id = ${ELB_v1[].Name}; // Unique identifier for the pattern
rtrn = LBtoSGHashMap.get(object_id);"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get IPs for DNS"
set_attr {
"tmp"
eval {"javascript: var ArrayList = Packages.java.util.ArrayList; // Script execution: Custom script to perform a specific action or collect data
var IPUtil = new Packages.com.snc.cmp.connector.util.IPUtil();
var DNS = ${ELB_v1[*].DNSName};
var LB_name = ${ELB_v1[*].Name};
var dns_and_ips = new ArrayList();
for (var i = 0; i < DNS.size(); i++){
var IPs = IPUtil.resolveHostName(DNS.get(i));
for (var j = 0; j < IPs.size(); j++){
dns_and_ips.add(\"LB_NAME = \" + LB_name.get(i) + \" NAME = \" + DNS.get(i) + \" IP = \" + IPs.get(j));
}
}
CTX.setAttribute(\"dns_and_ips\",dns_and_ips);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse DNS and IPs"
parse_var_to_var {
from_var_name = "dns_and_ips"
to_var_names = table {
name = "dns_ip_table"
col_names = "Name","name","ip_address"
}
parsing_strategy = regex_parsing {regex = "^LB_NAME\\ =\\ (.*?)\\ NAME\\ =\\ (.*?)\\ IP\\ =\\ (.*?)$"}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill cmdb_ci_cloud_load_balancer table"
if {
condition = is_not_empty {get_attr {"ELB_v1"}}
on_true = transform {
src_table_name = "ELB_v1"
target_table_name = "cmdb_ci_cloud_load_balancer"
operation {
set_field {
field_name = "name"
value = get_attr {"ELB_v1[].Name"}
}
set_field {
field_name = "object_id"
value = get_attr {"ELB_v1[].Name"}
}
set_field {
field_name = "dns_name"
value = get_attr {"ELB_v1[].DNSName"}
}
set_field {
field_name = "fqdn"
value = get_attr {"ELB_v1[].DNSName"}
}
set_field {
field_name = "canonical_hosted_zone_id"
value = get_attr {"ELB_v1[].CanonicalHostedZoneId"}
}
set_field {
field_name = "canonical_hosted_zone_name"
value = get_attr {"ELB_v1[].DNSName"}
}
set_field {
field_name = "state"
value = "available"
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill cmdb_ci_dns_name table"
transform {
src_table_name = "dns_ip_table"
target_table_name = "cmdb_ci_dns_name"
operation {
set_field {
field_name = "object_id"
value = get_attr {"dns_ip_table[].name"}
}
set_field {
field_name = "name"
value = get_attr {"dns_ip_table[].name"}
}
set_field {
field_name = "install_status"
value = "1"
}
set_field {
field_name = "operational_status"
value = "1"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill cmdb_ci_cloud_lb_ipaddress with DNS"
transform {
src_table_name = "dns_ip_table"
target_table_name = "cmdb_ci_cloud_lb_ipaddress"
operation {
set_field {
field_name = "name"
value = get_attr {"dns_ip_table[].ip_address"}
}
set_field {
field_name = "object_id"
value = get_attr {"dns_ip_table[].ip_address"}
}
set_field {
field_name = "ip_address"
value = get_attr {"dns_ip_table[].ip_address"}
}
}
}
}
}
|
Kubernetes Namespace | I would like for you to help me build a Pattern that helps achieve Discovery of Kubernetes Namespace. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Kubernetes Namespace"
id = "b6ec26569f1213002b9b92ec757fcf72"
description = ""
step {
name = "get namespaces"
custom_operation {
attributes {attribute {
name = "resource"
value = "namespaces"
}}
sys_id_op = "354649149f7303002ae692ec757fcfac"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step {
name = "trying parsing single namespace"
custom_operation {
attributes {
attribute {
name = "source"
value = "response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "namespaces"
}
attribute {
name = "target_columns"
value = "name:metadata.name,k8s_uid:metadata.uid"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step {
name = "trying parsing multiple namespace"
comment = "if we pass comma separated namespaces, we load them directly in the context prior running the pattern in the namespaces table. So, in case of comma separated namespaces the precondition in this step is false."
if {
condition = is_empty {get_attr {"namespaces"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "namespaces"
}
attribute {
name = "target_columns"
value = "name:items.metadata.name,k8s_uid:items.metadata.uid,state:items.status.phase"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "extract the namespaces if not *"
if {
condition = neq {
get_attr {"namespace"}
"*"
}
on_true = parse_var_to_var {
from_var_name = "namespace"
to_var_names = table {
name = "ns"
col_names = "name"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
line_seperator = ","
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "merge tables to keep only required namespaces"
if {
condition = neq {
get_attr {"namespace"}
"*"
}
on_true = merge {
table1_name = "namespaces"
key1_name = "name"
table2_name = "ns"
key2_name = "name"
result_table_name = "namespaces"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "check namespace"
if {
condition = is_not_empty {get_attr {"namespaces"}}
on_true = set_attr {
"namespace_list"
eval {"javascript: var rtrn = '';
var namespaces = ${namespaces[*].name};
var beforeReturn = '';
var separator = '';
for (var i = 0; i < namespaces.size(); i++) {
beforeReturn += separator + namespaces.get(i);
separator = ',';
}
rtrn = beforeReturn;"}
}
on_false = nop {}
}
}
step {
name = "Parse Namespace Labels"
set_attr {
"tmp"
eval {"javascript: var ArrayList = Packages.java.util.ArrayList;
var HashMap = Packages.java.util.HashMap;
// Create the target table
var nsLabels = new ArrayList();
CTX.setAttribute('namespace_labels', nsLabels);
// Iterate over the response table
var response = CTX.getAttribute('response');
var responseIter = response.iterator();
var index = 0;
while (responseIter.hasNext()) {
var line = responseIter.next();
var nssObj = JSON.parse(line);
for (var nsIdx in nssObj.items) {
var ns = nssObj.items[nsIdx];
// Iterate over labels of the ns
if (!ns.metadata.labels)
continue;
for (var key in ns.metadata.labels) {
// Create new row in the target object
var nsRow = new HashMap();
nsRow.put('k8s_uid',ns.metadata.uid + \" - \" + ns.metadata.name);
nsRow.put('key',key);
nsRow.put('value',ns.metadata.labels[key]);
nsRow.put('sys_class_name','cmdb_ci_kubernetes_namespace');
nsLabels.add(nsRow);
}
}
index++;
}
rtrn = nsLabels.size();
"}
}
}
step {
name = "Parse Namespace Annotations"
if {
condition = eq {
get_attr {"collect_annotations"}
"true"
}
on_true = set_attr {
"tmp"
eval {"javascript: var ArrayList = Packages.java.util.ArrayList;
var HashMap = Packages.java.util.HashMap;
var annotations_contains_list = ${annotations_contains_list};
// Create the target table
var nsannotations = new ArrayList();
CTX.setAttribute('namespace_annotations', nsannotations);
// Iterate over the response table
var response = CTX.getAttribute('response');
var responseIter = response.iterator();
var index = 0;
while (responseIter.hasNext()) {
var line = responseIter.next();
var nssObj = JSON.parse(line);
for (var nsIdx in nssObj.items) {
var ns = nssObj.items[nsIdx];
// Iterate over annotations of the ns
if (!ns.metadata.annotations)
continue;
for (var key in ns.metadata.annotations) {
// Create new row in the target object
if (annotations_contains_list == \"*\" || annotations_contains_list.indexOf(key) > -1 ) {
var nsRow = new HashMap();
nsRow.put('k8s_uid',ns.metadata.uid + \" - \" + ns.metadata.name);
nsRow.put('key',key);
nsRow.put('value',ns.metadata.annotations[key]);
nsRow.put('sys_class_name','cmdb_ci_kubernetes_namespace');
nsannotations.add(nsRow);
}
}
}
index++;
}
rtrn = nsannotations.size();"}
}
on_false = nop {}
}
}
step {
name = "Filter Labels if the namespaces is not *"
if {
condition = neq {
get_attr {"namespace"}
"*"
}
on_true = merge {
table1_name = "namespace_labels"
key1_name = "k8s_uid"
table2_name = "namespaces"
key2_name = "k8s_uid"
result_table_name = "namespace_labels"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "Filter annotations if the namespace is not *"
if {
condition = all {
neq {
get_attr {"namespace"}
"*"
}
eq {
get_attr {"collect_annotations"}
"true"
}
}
on_true = merge {
table1_name = "namespace_annotations"
key1_name = "k8s_uid"
table2_name = "namespaces"
key2_name = "k8s_uid"
result_table_name = "namespace_annotations"
unmatched_lines = remove
}
on_false = nop {}
}
}
}
| library {
name = "Kubernetes Namespace"
id = "b6ec26569f1213002b9b92ec757fcf72" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "get namespaces"
custom_operation {
attributes {attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "resource"
value = "namespaces"
}}
sys_id_op = "354649149f7303002ae692ec757fcfac"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "trying parsing single namespace"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "namespaces"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "name:metadata.name,k8s_uid:metadata.uid" // Metadata section: Contains metadata information about the pattern
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "trying parsing multiple namespace"
comment = "if we pass comma separated namespaces, we load them directly in the context prior running the pattern in the namespaces table. So, in case of comma separated namespaces the precondition in this step is false." // Step definition: Represents a single action or set of actions in the pattern
if {
condition = is_empty {get_attr {"namespaces"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "namespaces"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "name:items.metadata.name,k8s_uid:items.metadata.uid,state:items.status.phase" // Metadata section: Contains metadata information about the pattern
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "extract the namespaces if not *"
if {
condition = neq {
get_attr {"namespace"}
"*"
}
on_true = parse_var_to_var {
from_var_name = "namespace"
to_var_names = table {
name = "ns"
col_names = "name"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
line_seperator = ","
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "merge tables to keep only required namespaces"
if {
condition = neq {
get_attr {"namespace"}
"*"
}
on_true = merge {
table1_name = "namespaces"
key1_name = "name"
table2_name = "ns"
key2_name = "name"
result_table_name = "namespaces"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "check namespace"
if {
condition = is_not_empty {get_attr {"namespaces"}}
on_true = set_attr {
"namespace_list"
eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var namespaces = ${namespaces[*].name};
var beforeReturn = '';
var separator = '';
for (var i = 0; i < namespaces.size(); i++) {
beforeReturn += separator + namespaces.get(i);
separator = ',';
}
rtrn = beforeReturn;"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Namespace Labels"
set_attr {
"tmp"
eval {"javascript: var ArrayList = Packages.java.util.ArrayList; // Script execution: Custom script to perform a specific action or collect data
var HashMap = Packages.java.util.HashMap;
// Create the target table
var nsLabels = new ArrayList();
CTX.setAttribute('namespace_labels', nsLabels);
// Iterate over the response table
var response = CTX.getAttribute('response');
var responseIter = response.iterator();
var index = 0;
while (responseIter.hasNext()) {
var line = responseIter.next();
var nssObj = JSON.parse(line);
for (var nsIdx in nssObj.items) {
var ns = nssObj.items[nsIdx];
// Iterate over labels of the ns
if (!ns.metadata.labels) // Metadata section: Contains metadata information about the pattern
continue;
for (var key in ns.metadata.labels) { // Metadata section: Contains metadata information about the pattern
// Create new row in the target object
var nsRow = new HashMap();
nsRow.put('k8s_uid',ns.metadata.uid + \" - \" + ns.metadata.name); // Metadata section: Contains metadata information about the pattern
nsRow.put('key',key);
nsRow.put('value',ns.metadata.labels[key]); // Metadata section: Contains metadata information about the pattern
nsRow.put('sys_class_name','cmdb_ci_kubernetes_namespace');
nsLabels.add(nsRow);
}
}
index++;
}
rtrn = nsLabels.size();
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Namespace Annotations"
if {
condition = eq {
get_attr {"collect_annotations"}
"true"
}
on_true = set_attr {
"tmp"
eval {"javascript: var ArrayList = Packages.java.util.ArrayList; // Script execution: Custom script to perform a specific action or collect data
var HashMap = Packages.java.util.HashMap;
var annotations_contains_list = ${annotations_contains_list};
// Create the target table
var nsannotations = new ArrayList();
CTX.setAttribute('namespace_annotations', nsannotations);
// Iterate over the response table
var response = CTX.getAttribute('response');
var responseIter = response.iterator();
var index = 0;
while (responseIter.hasNext()) {
var line = responseIter.next();
var nssObj = JSON.parse(line);
for (var nsIdx in nssObj.items) {
var ns = nssObj.items[nsIdx];
// Iterate over annotations of the ns
if (!ns.metadata.annotations) // Metadata section: Contains metadata information about the pattern
continue;
for (var key in ns.metadata.annotations) { // Metadata section: Contains metadata information about the pattern
// Create new row in the target object
if (annotations_contains_list == \"*\" || annotations_contains_list.indexOf(key) > -1 ) {
var nsRow = new HashMap();
nsRow.put('k8s_uid',ns.metadata.uid + \" - \" + ns.metadata.name); // Metadata section: Contains metadata information about the pattern
nsRow.put('key',key);
nsRow.put('value',ns.metadata.annotations[key]); // Metadata section: Contains metadata information about the pattern
nsRow.put('sys_class_name','cmdb_ci_kubernetes_namespace');
nsannotations.add(nsRow);
}
}
}
index++;
}
rtrn = nsannotations.size();"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter Labels if the namespaces is not *"
if {
condition = neq {
get_attr {"namespace"}
"*"
}
on_true = merge {
table1_name = "namespace_labels"
key1_name = "k8s_uid"
table2_name = "namespaces"
key2_name = "k8s_uid"
result_table_name = "namespace_labels"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter annotations if the namespace is not *"
if {
condition = all {
neq {
get_attr {"namespace"}
"*"
}
eq {
get_attr {"collect_annotations"}
"true"
}
}
on_true = merge {
table1_name = "namespace_annotations"
key1_name = "k8s_uid"
table2_name = "namespaces"
key2_name = "k8s_uid"
result_table_name = "namespace_annotations"
unmatched_lines = remove
}
on_false = nop {}
}
}
}
|
Azure Availability Set Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Azure Availability Set Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure Availability Set Tags"
id = "b74c1f61db9d1010b2a1f962759619b3"
description = "Azure Availability Set Tags"
step {
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Availability Set Tags\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id};
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step {
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Create relation between Tag and Availability Set"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_availability_set"
key2_name = "object_id"
result_table_name = "tag_to_availability_set"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Azure Availability Set Tags"
id = "b74c1f61db9d1010b2a1f962759619b3" // Unique identifier for the pattern
description = "Azure Availability Set Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Availability Set Tags\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id}; // Unique identifier for the pattern
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and Availability Set"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_availability_set"
key2_name = "object_id"
result_table_name = "tag_to_availability_set"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Hyper-V - Virtual Machines | I would like for you to help me build a Pattern that helps achieve Discovery of Hyper-V - Virtual Machines. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Hyper-V - Virtual Machines"
id = "b74e4c759f6032001d753758442e70e6"
description = "null"
step {
name = "Parse columns in Msvm_ComputerSystem"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_ComputerSystem"}}
}
on_true = transform {
src_table_name = "Msvm_ComputerSystem"
target_table_name = "Msvm_ComputerSystem"
operation {
set_field {
field_name = "EnabledState"
value = eval {"javascript:
var rtrn = \"\";var enabledState = ${Msvm_ComputerSystem[].EnabledState};var enabledStates = {
0:\"stuck\", //Unknown
2:\"on\", //Enabled (running)
3:\"off\", //Disabled (turned off)
32768:\"suspended\", //Paused
32769:\"suspended\", //Suspended (saved state)
32770:\"changing\", //Starting (transition: disabled/suspended -> enabled)
32771:\"changing\", //Snapshotting
32773:\"changing\", //Saving (transition: enabled -> suspended)
32774:\"changing\", //Stopping (transition: enabled -> disabled)
32776:\"changing\", //Pausing (transition: enabled -> paused)
32777:\"changing\" //Resuming (transition: paused -> enabled)
};
rtrn = enabledStates[enabledState];
"}
}
set_field {
field_name = "VmElementName"
value = get_attr {"Msvm_ComputerSystem[].ElementName"}
}
}
}
on_false = nop {}
}
}
step {
name = "Get virtual memory data from Msvm_MemorySettingData (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850176(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT AllocationUnits,InstanceID,VirtualQuantity FROM Msvm_MemorySettingData"
var_names = table {
name = "Msvm_MemorySettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get virtual memory data from Msvm_MemorySettingData"
comment = "https://msdn.microsoft.com/en-us/library/cc136856(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_MemorySettingData"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT AllocationUnits,InstanceID,VirtualQuantity FROM Msvm_MemorySettingData"
var_names = table {
name = "Msvm_MemorySettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Parse relevant columns in Msvm_MemorySettingData"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_MemorySettingData"}}
}
on_true = transform {
src_table_name = "Msvm_MemorySettingData"
target_table_name = "Msvm_MemorySettingData"
operation {
set_field {
field_name = "InstanceID"
value = eval {"javascript:var rtrn = '';rtrn = WindowsDiscoveryUtil.extractHyperVVmId(${Msvm_MemorySettingData[].InstanceID});"}
}
set_field {
field_name = "MemoryVirtualQuantity"
value = get_attr {"Msvm_MemorySettingData[].VirtualQuantity"}
}
}
}
on_false = nop {}
}
}
step {
name = "Keep only \"Microsoft Virtual Machine\" rows"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = filter {
src_table_name = "Msvm_ComputerSystem"
target_table_name = "Msvm_ComputerSystem"
condition = eq {
get_attr {"Msvm_ComputerSystem[].Description"}
"Microsoft Virtual Machine"
}
}
on_false = nop {}
}
}
step {
name = "Get virtual processor data from Msvm_ProcessorSettingData (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850190(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT InstanceID,VirtualQuantity FROM Msvm_ProcessorSettingData"
var_names = table {
name = "Msvm_ProcessorSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get virtual processor data from Msvm_ProcessorSettingData"
comment = "https://msdn.microsoft.com/en-us/library/cc136870(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_ProcessorSettingData"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT InstanceID,VirtualQuantity FROM Msvm_ProcessorSettingData"
var_names = table {
name = "Msvm_ProcessorSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Parse relevant columns in Msvm_ProcessorSettingData"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_ProcessorSettingData"}}
}
on_true = transform {
src_table_name = "Msvm_ProcessorSettingData"
target_table_name = "Msvm_ProcessorSettingData"
operation {
set_field {
field_name = "InstanceID"
value = eval {"javascript:var rtrn = '';rtrn = WindowsDiscoveryUtil.extractHyperVVmId(${Msvm_ProcessorSettingData[].InstanceID});"}
}
set_field {
field_name = "CpuVirtualQuantity"
value = get_attr {"Msvm_ProcessorSettingData[].VirtualQuantity"}
}
}
}
on_false = nop {}
}
}
step {
name = "Get virtual ethernet data from Msvm_SyntheticEthernetPortSettingData (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850226(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT InstanceID,ElementName FROM Msvm_SyntheticEthernetPortSettingData"
var_names = table {
name = "Msvm_SyntheticEthernetPortSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get virtual ethernet data from Msvm_SyntheticEthernetPortSettingData"
comment = "https://msdn.microsoft.com/en-us/library/cc136914(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_SyntheticEthernetPortSettingData"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT InstanceID,ElementName FROM Msvm_SyntheticEthernetPortSettingData"
var_names = table {
name = "Msvm_SyntheticEthernetPortSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Parse relevant columns in Msvm_SyntheticEthernetPortSettingData"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_SyntheticEthernetPortSettingData"}}
}
on_true = transform {
src_table_name = "Msvm_SyntheticEthernetPortSettingData"
target_table_name = "Msvm_SyntheticEthernetPortSettingData"
operation {
set_field {
field_name = "InstanceID"
value = eval {"javascript:
var rtrn = '';
rtrn = WindowsDiscoveryUtil.extractHyperVVmId(${Msvm_SyntheticEthernetPortSettingData[].InstanceID});
"}
}
set_field {
field_name = "NicElementName"
value = get_attr {"Msvm_SyntheticEthernetPortSettingData[].ElementName"}
}
}
}
on_false = nop {}
}
}
step {
name = "Keep only NIC elements"
comment = "Will keep only \u201CNetwork Adapter\u201D element type, and used to count NICs"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_SyntheticEthernetPortSettingData"}}
}
on_true = filter {
src_table_name = "Msvm_SyntheticEthernetPortSettingData"
target_table_name = "Msvm_SyntheticEthernetPortSettingData"
condition = eq {
get_attr {"Msvm_SyntheticEthernetPortSettingData[].ElementName"}
"Network Adapter"
}
}
on_false = nop {}
}
}
step {
name = "Get virtual logical disks data from Msvm_LogicalDisk (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850173(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT BlockSize,ElementName,NumberOfBlocks,SystemName FROM Msvm_LogicalDisk"
var_names = table {
name = "Msvm_LogicalDisk"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get virtual logical disks data from Msvm_LogicalDisk"
comment = "https://msdn.microsoft.com/en-us/library/cc136853(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_LogicalDisk"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT BlockSize,ElementName,NumberOfBlocks,SystemName FROM Msvm_LogicalDisk"
var_names = table {
name = "Msvm_LogicalDisk"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Parse relevant columns in Msvm_LogicalDisk"
comment = "Used to calculate number of disks and total size"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_LogicalDisk"}}
}
on_true = transform {
src_table_name = "Msvm_LogicalDisk"
target_table_name = "Msvm_LogicalDisk"
operation {
set_field {
field_name = "InstanceID"
value = get_attr {"Msvm_LogicalDisk[].SystemName"}
}
set_field {
field_name = "DiskElementName"
value = get_attr {"Msvm_LogicalDisk[].ElementName"}
}
}
}
on_false = nop {}
}
}
step {
name = "Keep disks of type \"Hard Disk Image\""
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_LogicalDisk"}}
}
on_true = filter {
src_table_name = "Msvm_LogicalDisk"
target_table_name = "Msvm_LogicalDisk"
condition = eq {
get_attr {"Msvm_LogicalDisk[].ElementName"}
"Hard Disk Image"
}
}
on_false = nop {}
}
}
step {
name = "Get virtual system settings data from Msvm_VirtualSystemSettingData (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850257(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT BaseBoardSerialNumber,BIOSGUID,BIOSSerialNumber,ChassisSerialNumber,InstanceID FROM Msvm_VirtualSystemSettingData"
var_names = table {
name = "Msvm_VirtualSystemSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get virtual system settings data from Msvm_VirtualSystemSettingData"
comment = "https://msdn.microsoft.com/en-us/library/cc136944(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_VirtualSystemSettingData"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT BaseBoardSerialNumber,BIOSGUID,BIOSSerialNumber,ChassisSerialNumber,InstanceID FROM Msvm_VirtualSystemSettingData"
var_names = table {
name = "Msvm_VirtualSystemSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Parse relevant columns in Msvm_VirtualSystemSettingData"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_VirtualSystemSettingData"}}
}
on_true = transform {
src_table_name = "Msvm_VirtualSystemSettingData"
target_table_name = "Msvm_VirtualSystemSettingData"
operation {set_field {
field_name = "InstanceID"
value = eval {"javascript:var rtrn = '';rtrn = WindowsDiscoveryUtil.extractHyperVVmId(${Msvm_VirtualSystemSettingData[].InstanceID});"}
}}
}
on_false = nop {}
}
}
step {
name = "Create virtual machine data table"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_MemorySettingData"}}
}
on_true = merge {
table1_name = "Msvm_ComputerSystem"
table2_name = "Msvm_MemorySettingData"
result_table_name = "HyperVVirtualMachines"
unmatched_lines = keep
condition = eq {
get_attr {"Msvm_ComputerSystem[].Name"}
get_attr {"Msvm_MemorySettingData[].InstanceID"}
}
}
on_false = nop {}
}
}
step {
name = "Keep only VMs rows"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = filter {
src_table_name = "HyperVVirtualMachines"
target_table_name = "HyperVVirtualMachines"
condition = eq {
get_attr {"HyperVVirtualMachines[].internal_classname"}
"Msvm_ComputerSystem"
}
}
on_false = nop {}
}
}
step {
name = "Add processor data to virtual machine table"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_ProcessorSettingData"}}
}
on_true = merge {
table1_name = "HyperVVirtualMachines"
table2_name = "Msvm_ProcessorSettingData"
result_table_name = "HyperVVirtualMachines"
unmatched_lines = keep
condition = eq {
get_attr {"HyperVVirtualMachines[].Name"}
get_attr {"Msvm_ProcessorSettingData[].InstanceID"}
}
}
on_false = nop {}
}
}
step {
name = "Keep only VMs rows"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = filter {
src_table_name = "HyperVVirtualMachines"
target_table_name = "HyperVVirtualMachines"
condition = eq {
get_attr {"HyperVVirtualMachines[].internal_classname"}
"Msvm_ComputerSystem"
}
}
on_false = nop {}
}
}
step {
name = "Add system settings data to virtual machine table"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_VirtualSystemSettingData"}}
}
on_true = merge {
table1_name = "HyperVVirtualMachines"
table2_name = "Msvm_VirtualSystemSettingData"
result_table_name = "HyperVVirtualMachines"
unmatched_lines = keep
condition = eq {
get_attr {"HyperVVirtualMachines[].Name"}
get_attr {"Msvm_VirtualSystemSettingData[].InstanceID"}
}
}
on_false = nop {}
}
}
step {
name = "Keep only VMs rows"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = filter {
src_table_name = "HyperVVirtualMachines"
target_table_name = "HyperVVirtualMachines"
condition = eq {
get_attr {"HyperVVirtualMachines[].internal_classname"}
"Msvm_ComputerSystem"
}
}
on_false = nop {}
}
}
step {
name = "Insert virtual machines data to cmdb_ci_hyper_v_instance"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = transform {
src_table_name = "HyperVVirtualMachines"
target_table_name = "cmdb_ci_hyper_v_instance"
operation {
set_field {
field_name = "object_id"
value = get_attr {"HyperVVirtualMachines[].Name"}
}
set_field {
field_name = "state"
value = get_attr {"HyperVVirtualMachines[].EnabledState"}
}
set_field {
field_name = "nics"
value = eval {"${Msvm_SyntheticEthernetPortSettingData[*].InstanceID}.findAll{ it == ${HyperVVirtualMachines[].InstanceID} }.size()"}
}
set_field {
field_name = "memory"
value = get_attr {"HyperVVirtualMachines[].MemoryVirtualQuantity"}
}
set_field {
field_name = "cpus"
value = get_attr {"HyperVVirtualMachines[].CpuVirtualQuantity"}
}
set_field {
field_name = "disks"
value = eval {"${Msvm_LogicalDisk[*].InstanceID}.findAll{ it == ${HyperVVirtualMachines[].InstanceID} }.size()"}
}
set_field {
field_name = "disks_size"
value = eval {"javascript: total = 0
length = ${Msvm_LogicalDisk[*].InstanceID}.size()
ids = ${Msvm_LogicalDisk[*].InstanceID}
num_blocks = ${Msvm_LogicalDisk[*].NumberOfBlocks}
block_size = ${Msvm_LogicalDisk[*].BlockSize}
for (i = 0 ; i<length; i++){
if (ids.get(i) == ${HyperVVirtualMachines[].InstanceID})
total += num_blocks.get(i) * block_size.get(i) / (1024*1024*1024)
}
total"}
}
set_field {
field_name = "baseboard_serial"
value = get_attr {"HyperVVirtualMachines[].BaseBoardSerialNumber"}
}
set_field {
field_name = "bios_serial"
value = get_attr {"HyperVVirtualMachines[].BIOSSerialNumber"}
}
set_field {
field_name = "chassis_serial"
value = get_attr {"HyperVVirtualMachines[].ChassisSerialNumber"}
}
set_field {
field_name = "bios_guid"
value = eval {"javascript:var rtrn = '';var biosGuid = ${HyperVVirtualMachines[].BIOSGUID};if(!JSUtil.nil(biosGuid)){ rtrn = biosGuid.replace(/[{}]/g, \"\");}"}
}
set_field {
field_name = "name"
value = get_attr {"HyperVVirtualMachines[].VmElementName"}
}
}
}
on_false = nop {}
}
}
step {
name = "Remove duplicate from Hyper-V"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_hyper_v_instance},['object_id']);
CTX.setAttribute(\"cmdb_ci_hyper_v_instance\", tableWithoutDuplicates);"}
}
}
step {
name = "Reference and relation between cmdb_ci_hyper_v_instance to cmdb_ci_hyper_v_server"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_ci_hyper_v_instance"
table2_name = "cmdb_ci_hyper_v_server"
result_table_name = "hyper_instance_hyper_server"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Registered on::Has registered"
ref_direction = parentToChild
ref_field_name = "server"
}
on_false = nop {}
}
}
}
| library {
name = "Hyper-V - Virtual Machines"
id = "b74e4c759f6032001d753758442e70e6" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse columns in Msvm_ComputerSystem"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_ComputerSystem"}}
}
on_true = transform {
src_table_name = "Msvm_ComputerSystem"
target_table_name = "Msvm_ComputerSystem"
operation {
set_field {
field_name = "EnabledState"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = \"\";var enabledState = ${Msvm_ComputerSystem[].EnabledState};var enabledStates = {
0:\"stuck\", //Unknown
2:\"on\", //Enabled (running)
3:\"off\", //Disabled (turned off)
32768:\"suspended\", //Paused
32769:\"suspended\", //Suspended (saved state)
32770:\"changing\", //Starting (transition: disabled/suspended -> enabled)
32771:\"changing\", //Snapshotting
32773:\"changing\", //Saving (transition: enabled -> suspended)
32774:\"changing\", //Stopping (transition: enabled -> disabled)
32776:\"changing\", //Pausing (transition: enabled -> paused)
32777:\"changing\" //Resuming (transition: paused -> enabled)
};
rtrn = enabledStates[enabledState];
"}
}
set_field {
field_name = "VmElementName"
value = get_attr {"Msvm_ComputerSystem[].ElementName"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual memory data from Msvm_MemorySettingData (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850176(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT AllocationUnits,InstanceID,VirtualQuantity FROM Msvm_MemorySettingData"
var_names = table {
name = "Msvm_MemorySettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual memory data from Msvm_MemorySettingData"
comment = "https://msdn.microsoft.com/en-us/library/cc136856(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_MemorySettingData"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT AllocationUnits,InstanceID,VirtualQuantity FROM Msvm_MemorySettingData"
var_names = table {
name = "Msvm_MemorySettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse relevant columns in Msvm_MemorySettingData"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_MemorySettingData"}}
}
on_true = transform {
src_table_name = "Msvm_MemorySettingData"
target_table_name = "Msvm_MemorySettingData"
operation {
set_field {
field_name = "InstanceID"
value = eval {"javascript:var rtrn = '';rtrn = WindowsDiscoveryUtil.extractHyperVVmId(${Msvm_MemorySettingData[].InstanceID});"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "MemoryVirtualQuantity"
value = get_attr {"Msvm_MemorySettingData[].VirtualQuantity"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Keep only \"Microsoft Virtual Machine\" rows"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = filter {
src_table_name = "Msvm_ComputerSystem"
target_table_name = "Msvm_ComputerSystem"
condition = eq {
get_attr {"Msvm_ComputerSystem[].Description"} // Script execution: Custom script to perform a specific action or collect data
"Microsoft Virtual Machine"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual processor data from Msvm_ProcessorSettingData (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850190(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT InstanceID,VirtualQuantity FROM Msvm_ProcessorSettingData"
var_names = table {
name = "Msvm_ProcessorSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual processor data from Msvm_ProcessorSettingData"
comment = "https://msdn.microsoft.com/en-us/library/cc136870(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_ProcessorSettingData"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT InstanceID,VirtualQuantity FROM Msvm_ProcessorSettingData"
var_names = table {
name = "Msvm_ProcessorSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse relevant columns in Msvm_ProcessorSettingData"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_ProcessorSettingData"}}
}
on_true = transform {
src_table_name = "Msvm_ProcessorSettingData"
target_table_name = "Msvm_ProcessorSettingData"
operation {
set_field {
field_name = "InstanceID"
value = eval {"javascript:var rtrn = '';rtrn = WindowsDiscoveryUtil.extractHyperVVmId(${Msvm_ProcessorSettingData[].InstanceID});"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "CpuVirtualQuantity"
value = get_attr {"Msvm_ProcessorSettingData[].VirtualQuantity"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual ethernet data from Msvm_SyntheticEthernetPortSettingData (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850226(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT InstanceID,ElementName FROM Msvm_SyntheticEthernetPortSettingData"
var_names = table {
name = "Msvm_SyntheticEthernetPortSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual ethernet data from Msvm_SyntheticEthernetPortSettingData"
comment = "https://msdn.microsoft.com/en-us/library/cc136914(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_SyntheticEthernetPortSettingData"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT InstanceID,ElementName FROM Msvm_SyntheticEthernetPortSettingData"
var_names = table {
name = "Msvm_SyntheticEthernetPortSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse relevant columns in Msvm_SyntheticEthernetPortSettingData"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_SyntheticEthernetPortSettingData"}}
}
on_true = transform {
src_table_name = "Msvm_SyntheticEthernetPortSettingData"
target_table_name = "Msvm_SyntheticEthernetPortSettingData"
operation {
set_field {
field_name = "InstanceID"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
rtrn = WindowsDiscoveryUtil.extractHyperVVmId(${Msvm_SyntheticEthernetPortSettingData[].InstanceID});
"}
}
set_field {
field_name = "NicElementName"
value = get_attr {"Msvm_SyntheticEthernetPortSettingData[].ElementName"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Keep only NIC elements"
comment = "Will keep only \u201CNetwork Adapter\u201D element type, and used to count NICs"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_SyntheticEthernetPortSettingData"}}
}
on_true = filter {
src_table_name = "Msvm_SyntheticEthernetPortSettingData"
target_table_name = "Msvm_SyntheticEthernetPortSettingData"
condition = eq {
get_attr {"Msvm_SyntheticEthernetPortSettingData[].ElementName"}
"Network Adapter"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual logical disks data from Msvm_LogicalDisk (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850173(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT BlockSize,ElementName,NumberOfBlocks,SystemName FROM Msvm_LogicalDisk"
var_names = table {
name = "Msvm_LogicalDisk"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual logical disks data from Msvm_LogicalDisk"
comment = "https://msdn.microsoft.com/en-us/library/cc136853(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_LogicalDisk"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT BlockSize,ElementName,NumberOfBlocks,SystemName FROM Msvm_LogicalDisk"
var_names = table {
name = "Msvm_LogicalDisk"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse relevant columns in Msvm_LogicalDisk"
comment = "Used to calculate number of disks and total size"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_LogicalDisk"}}
}
on_true = transform {
src_table_name = "Msvm_LogicalDisk"
target_table_name = "Msvm_LogicalDisk"
operation {
set_field {
field_name = "InstanceID"
value = get_attr {"Msvm_LogicalDisk[].SystemName"}
}
set_field {
field_name = "DiskElementName"
value = get_attr {"Msvm_LogicalDisk[].ElementName"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Keep disks of type \"Hard Disk Image\""
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_LogicalDisk"}}
}
on_true = filter {
src_table_name = "Msvm_LogicalDisk"
target_table_name = "Msvm_LogicalDisk"
condition = eq {
get_attr {"Msvm_LogicalDisk[].ElementName"}
"Hard Disk Image"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual system settings data from Msvm_VirtualSystemSettingData (v2 namespace)"
comment = "https://msdn.microsoft.com/en-us/library/hh850257(v=vs.85).aspx"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization\\v2"
query = "SELECT BaseBoardSerialNumber,BIOSGUID,BIOSSerialNumber,ChassisSerialNumber,InstanceID FROM Msvm_VirtualSystemSettingData"
var_names = table {
name = "Msvm_VirtualSystemSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get virtual system settings data from Msvm_VirtualSystemSettingData"
comment = "https://msdn.microsoft.com/en-us/library/cc136944(v=vs.85).aspx"
if {
condition = all {
is_empty {get_attr {"Msvm_VirtualSystemSettingData"}}
eq {
get_attr {"isHyperV"}
"true"
}
}
on_true = run_wmi_query_to_var {
namespace = "\\root\\virtualization"
query = "SELECT BaseBoardSerialNumber,BIOSGUID,BIOSSerialNumber,ChassisSerialNumber,InstanceID FROM Msvm_VirtualSystemSettingData"
var_names = table {
name = "Msvm_VirtualSystemSettingData"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse relevant columns in Msvm_VirtualSystemSettingData"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_VirtualSystemSettingData"}}
}
on_true = transform {
src_table_name = "Msvm_VirtualSystemSettingData"
target_table_name = "Msvm_VirtualSystemSettingData"
operation {set_field {
field_name = "InstanceID"
value = eval {"javascript:var rtrn = '';rtrn = WindowsDiscoveryUtil.extractHyperVVmId(${Msvm_VirtualSystemSettingData[].InstanceID});"} // Script execution: Custom script to perform a specific action or collect data
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create virtual machine data table"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_MemorySettingData"}}
}
on_true = merge {
table1_name = "Msvm_ComputerSystem"
table2_name = "Msvm_MemorySettingData"
result_table_name = "HyperVVirtualMachines"
unmatched_lines = keep
condition = eq {
get_attr {"Msvm_ComputerSystem[].Name"}
get_attr {"Msvm_MemorySettingData[].InstanceID"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Keep only VMs rows"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = filter {
src_table_name = "HyperVVirtualMachines"
target_table_name = "HyperVVirtualMachines"
condition = eq {
get_attr {"HyperVVirtualMachines[].internal_classname"}
"Msvm_ComputerSystem"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add processor data to virtual machine table"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_ProcessorSettingData"}}
}
on_true = merge {
table1_name = "HyperVVirtualMachines"
table2_name = "Msvm_ProcessorSettingData"
result_table_name = "HyperVVirtualMachines"
unmatched_lines = keep
condition = eq {
get_attr {"HyperVVirtualMachines[].Name"}
get_attr {"Msvm_ProcessorSettingData[].InstanceID"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Keep only VMs rows"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = filter {
src_table_name = "HyperVVirtualMachines"
target_table_name = "HyperVVirtualMachines"
condition = eq {
get_attr {"HyperVVirtualMachines[].internal_classname"}
"Msvm_ComputerSystem"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add system settings data to virtual machine table"
if {
condition = all {
eq {
get_attr {"isHyperV"}
"true"
}
is_not_empty {get_attr {"Msvm_VirtualSystemSettingData"}}
}
on_true = merge {
table1_name = "HyperVVirtualMachines"
table2_name = "Msvm_VirtualSystemSettingData"
result_table_name = "HyperVVirtualMachines"
unmatched_lines = keep
condition = eq {
get_attr {"HyperVVirtualMachines[].Name"}
get_attr {"Msvm_VirtualSystemSettingData[].InstanceID"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Keep only VMs rows"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = filter {
src_table_name = "HyperVVirtualMachines"
target_table_name = "HyperVVirtualMachines"
condition = eq {
get_attr {"HyperVVirtualMachines[].internal_classname"}
"Msvm_ComputerSystem"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert virtual machines data to cmdb_ci_hyper_v_instance"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = transform {
src_table_name = "HyperVVirtualMachines"
target_table_name = "cmdb_ci_hyper_v_instance"
operation {
set_field {
field_name = "object_id"
value = get_attr {"HyperVVirtualMachines[].Name"}
}
set_field {
field_name = "state"
value = get_attr {"HyperVVirtualMachines[].EnabledState"}
}
set_field {
field_name = "nics"
value = eval {"${Msvm_SyntheticEthernetPortSettingData[*].InstanceID}.findAll{ it == ${HyperVVirtualMachines[].InstanceID} }.size()"}
}
set_field {
field_name = "memory"
value = get_attr {"HyperVVirtualMachines[].MemoryVirtualQuantity"}
}
set_field {
field_name = "cpus"
value = get_attr {"HyperVVirtualMachines[].CpuVirtualQuantity"}
}
set_field {
field_name = "disks"
value = eval {"${Msvm_LogicalDisk[*].InstanceID}.findAll{ it == ${HyperVVirtualMachines[].InstanceID} }.size()"}
}
set_field {
field_name = "disks_size"
value = eval {"javascript: total = 0 // Script execution: Custom script to perform a specific action or collect data
length = ${Msvm_LogicalDisk[*].InstanceID}.size()
ids = ${Msvm_LogicalDisk[*].InstanceID}
num_blocks = ${Msvm_LogicalDisk[*].NumberOfBlocks}
block_size = ${Msvm_LogicalDisk[*].BlockSize}
for (i = 0 ; i<length; i++){
if (ids.get(i) == ${HyperVVirtualMachines[].InstanceID})
total += num_blocks.get(i) * block_size.get(i) / (1024*1024*1024)
}
total"}
}
set_field {
field_name = "baseboard_serial"
value = get_attr {"HyperVVirtualMachines[].BaseBoardSerialNumber"}
}
set_field {
field_name = "bios_serial"
value = get_attr {"HyperVVirtualMachines[].BIOSSerialNumber"}
}
set_field {
field_name = "chassis_serial"
value = get_attr {"HyperVVirtualMachines[].ChassisSerialNumber"}
}
set_field {
field_name = "bios_guid"
value = eval {"javascript:var rtrn = '';var biosGuid = ${HyperVVirtualMachines[].BIOSGUID};if(!JSUtil.nil(biosGuid)){ rtrn = biosGuid.replace(/[{}]/g, \"\");}"} // Unique identifier for the pattern
}
set_field {
field_name = "name"
value = get_attr {"HyperVVirtualMachines[].VmElementName"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate from Hyper-V"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_hyper_v_instance},['object_id']);
CTX.setAttribute(\"cmdb_ci_hyper_v_instance\", tableWithoutDuplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference and relation between cmdb_ci_hyper_v_instance to cmdb_ci_hyper_v_server"
if {
condition = eq {
get_attr {"isHyperV"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_ci_hyper_v_instance"
table2_name = "cmdb_ci_hyper_v_server"
result_table_name = "hyper_instance_hyper_server"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Registered on::Has registered"
ref_direction = parentToChild
ref_field_name = "server"
}
on_false = nop {}
}
}
}
|
OpenStack Neutron Networks | I would like for you to help me build a Pattern that helps achieve Discovery of OpenStack Neutron Networks. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "OpenStack Neutron Networks"
id = "b76312d4db810010bf2fe0a1ca961904"
description = "null"
step {
name = "Get Networks details"
comment = "https://<service:port>/v3.0/<project_id>/volumes/detail - throws error
https://<service:port>/v3/<project_id>/volumes/detail - works"
if {
condition = is_not_empty {get_attr {"links_neutron"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Network Resources pattern.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_neutron[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_neutron[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id');
if (!input_object_id) { var resource = \"networks\";}
else { var resource = \"networks/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var service_url = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, service_url, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
resultList.add(newJson);
}
}
CTX.setAttribute('network_details_response', resultList);"}
}
on_false = nop {}
}
}
step {
name = "HD: Parse the Networks"
if {
condition = all {
is_not_empty {get_attr {"network_details_response"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks"
col_names = "network_name","network_id","network_status","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "network_name"
xpath = "/root/networks/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/networks/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_status"
xpath = "/root/networks/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/networks/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse the Networks"
if {
condition = all {
is_not_empty {get_attr {"network_details_response"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks"
col_names = "network_name","network_id","network_status","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "network_name"
xpath = "/root/network/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/network/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_status"
xpath = "/root/network/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/network/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Filter out regions without networks"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = is_not_empty {get_attr {"networks"}}
on_true = filter {
src_table_name = "networks"
target_table_name = "networks"
condition = is_not_empty {get_attr {"networks[].network_id"}}
}
on_false = nop {}
}
}
step {
name = "HD: Parse Networks descriptions"
if {
condition = all {
is_not_empty {get_attr {"networks"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks_add"
col_names = "network_id","network_desription"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "network_id"
xpath = "/root/networks/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_desription"
xpath = "/root/networks/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Networks descriptions"
if {
condition = all {
is_not_empty {get_attr {"networks"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks_add"
col_names = "network_id","network_desription"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "network_id"
xpath = "/root/network/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_desription"
xpath = "/root/network/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the description to the networks table"
if {
condition = is_not_empty {get_attr {"networks_add"}}
on_true = merge {
table1_name = "networks"
key1_name = "network_id"
table2_name = "networks_add"
key2_name = "network_id"
result_table_name = "networks"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "HD: Parse Network Projects"
if {
condition = all {
is_not_empty {get_attr {"networks"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks_add"
col_names = "project_id","network_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "project_id"
xpath = "/root/networks/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/networks/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Network Projects"
if {
condition = all {
is_not_empty {get_attr {"networks"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks_add"
col_names = "project_id","network_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "project_id"
xpath = "/root/network/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/network/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the projects to the networks table"
if {
condition = is_not_empty {get_attr {"networks_add"}}
on_true = merge {
table1_name = "networks"
key1_name = "network_id"
table2_name = "networks_add"
key2_name = "network_id"
result_table_name = "networks"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"networks"}}
}
on_true = filter {
src_table_name = "networks"
target_table_name = "networks"
condition = eq {
get_attr {"networks[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray()
var length = ldc.length
var region = ${networks[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_network table"
if {
condition = is_not_empty {get_attr {"networks"}}
on_true = transform {
src_table_name = "networks"
target_table_name = "cmdb_ci_network"
operation {
set_field {
field_name = "object_id"
value = get_attr {"networks[].network_id"}
}
set_field {
field_name = "name"
value = get_attr {"networks[].network_name"}
}
set_field {
field_name = "operational_status"
value = get_attr {"networks[].network_status"}
}
set_field {
field_name = "short_description"
value = get_attr {"networks[].network_desription"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_network and cmdb_ci_openstack_datacenter table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_network"}}
on_true = relation_reference {
table1_name = "cmdb_ci_network"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "network_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "OpenStack Neutron Networks"
id = "b76312d4db810010bf2fe0a1ca961904" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Networks details"
comment = "https://<service:port>/v3.0/<project_id>/volumes/detail - throws error
https://<service:port>/v3/<project_id>/volumes/detail - works"
if {
condition = is_not_empty {get_attr {"links_neutron"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Network Resources pattern.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_neutron[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_neutron[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id'); // Unique identifier for the pattern
if (!input_object_id) { var resource = \"networks\";}
else { var resource = \"networks/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var service_url = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, service_url, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
resultList.add(newJson);
}
}
CTX.setAttribute('network_details_response', resultList);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse the Networks"
if {
condition = all {
is_not_empty {get_attr {"network_details_response"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks"
col_names = "network_name","network_id","network_status","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "network_name"
xpath = "/root/networks/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/networks/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_status"
xpath = "/root/networks/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/networks/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse the Networks"
if {
condition = all {
is_not_empty {get_attr {"network_details_response"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks"
col_names = "network_name","network_id","network_status","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "network_name"
xpath = "/root/network/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/network/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_status"
xpath = "/root/network/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/network/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out regions without networks"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = is_not_empty {get_attr {"networks"}}
on_true = filter {
src_table_name = "networks"
target_table_name = "networks"
condition = is_not_empty {get_attr {"networks[].network_id"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Networks descriptions" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"networks"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks_add"
col_names = "network_id","network_desription"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "network_id"
xpath = "/root/networks/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_desription"
xpath = "/root/networks/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Networks descriptions" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"networks"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks_add"
col_names = "network_id","network_desription"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "network_id"
xpath = "/root/network/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_desription"
xpath = "/root/network/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the description to the networks table" // Script execution: Custom script to perform a specific action or collect data
if {
condition = is_not_empty {get_attr {"networks_add"}}
on_true = merge {
table1_name = "networks"
key1_name = "network_id"
table2_name = "networks_add"
key2_name = "network_id"
result_table_name = "networks"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Network Projects"
if {
condition = all {
is_not_empty {get_attr {"networks"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks_add"
col_names = "project_id","network_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "project_id"
xpath = "/root/networks/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/networks/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Network Projects"
if {
condition = all {
is_not_empty {get_attr {"networks"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "network_details_response"
to_var_names = table {
name = "networks_add"
col_names = "project_id","network_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "project_id"
xpath = "/root/network/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/network/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the projects to the networks table"
if {
condition = is_not_empty {get_attr {"networks_add"}}
on_true = merge {
table1_name = "networks"
key1_name = "network_id"
table2_name = "networks_add"
key2_name = "network_id"
result_table_name = "networks"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"networks"}}
}
on_true = filter {
src_table_name = "networks"
target_table_name = "networks"
condition = eq {
get_attr {"networks[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray() // Script execution: Custom script to perform a specific action or collect data
var length = ldc.length
var region = ${networks[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_network table"
if {
condition = is_not_empty {get_attr {"networks"}}
on_true = transform {
src_table_name = "networks"
target_table_name = "cmdb_ci_network"
operation {
set_field {
field_name = "object_id"
value = get_attr {"networks[].network_id"}
}
set_field {
field_name = "name"
value = get_attr {"networks[].network_name"}
}
set_field {
field_name = "operational_status"
value = get_attr {"networks[].network_status"}
}
set_field {
field_name = "short_description" // Script execution: Custom script to perform a specific action or collect data
value = get_attr {"networks[].network_desription"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_network and cmdb_ci_openstack_datacenter table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_network"}}
on_true = relation_reference {
table1_name = "cmdb_ci_network"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "network_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
AIX - Identity | I would like for you to help me build a Pattern that helps achieve Discovery of AIX - Identity. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "AIX - Identity"
id = "b79f1d509ffc32001d753758442e70b6"
description = ""
step {
name = "AIX - Serial Number"
ref {refid = "cb4f55509ffc32001d753758442e703f"}
}
step {
name = "AIX - Network"
ref {refid = "2e7f55509ffc32001d753758442e708c"}
}
}
| library {
name = "AIX - Identity"
id = "b79f1d509ffc32001d753758442e70b6" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "AIX - Serial Number"
ref {refid = "cb4f55509ffc32001d753758442e703f"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "AIX - Network"
ref {refid = "2e7f55509ffc32001d753758442e708c"} // Unique identifier for the pattern
}
}
|
Oracle OCI - Image Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Oracle OCI - Image Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Oracle OCI - Image Tags"
id = "b7b41def1bdde8100735a9f36b4bcbd9"
description = "Oracle OCI - Image Tags"
step {
name = "Parse Tags"
ref {refid = "0ad0a5751be960500735a9f36b4bcba6"}
}
step {
name = "Parse definedTags Tags"
ref {refid = "b5b342b11bdf345009b2ed34b24bcba5"}
}
step {
name = "Create relation between Tag and Image"
if {
condition = neq {
get_attr {"isNewImageModel"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_os_template"
key2_name = "object_id"
result_table_name = "tag_to_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
step {
name = "Create relation between Tag and Cloud Image"
if {
condition = eq {
get_attr {"isNewImageModel"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_os_image"
key2_name = "object_id"
result_table_name = "tag_to_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "Oracle OCI - Image Tags"
id = "b7b41def1bdde8100735a9f36b4bcbd9" // Unique identifier for the pattern
description = "Oracle OCI - Image Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags"
ref {refid = "0ad0a5751be960500735a9f36b4bcba6"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse definedTags Tags"
ref {refid = "b5b342b11bdf345009b2ed34b24bcba5"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and Image"
if {
condition = neq {
get_attr {"isNewImageModel"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_os_template"
key2_name = "object_id"
result_table_name = "tag_to_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and Cloud Image"
if {
condition = eq {
get_attr {"isNewImageModel"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_os_image"
key2_name = "object_id"
result_table_name = "tag_to_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
Collect SNAT IP Pool - SNMP | I would like for you to help me build a Pattern that helps achieve Discovery of Collect SNAT IP Pool - SNMP. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Collect SNAT IP Pool - SNMP"
id = "b8557bf11b455d10243064a3604bcb2c"
description = "Collect SNAT IP Pool - SNMP"
step {
name = "get axIpNatPoolStatsEntry"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.22610.2.4.3.18.100.1.1"
col_names = "1","2","3","4","5","6","7"
}
var_names = table {
name = "axIpNatPoolStatsEntry"
col_names = "axIpNatPoolName","axIpNatPoolStartAddress","axIpNatPoolEndAddress","axIpNatPoolPortUsage","axIpNatPoolTotalUsed","axIpNatPoolTotalFree","axIpNatPoolFailed"
}
if_not_found_do = terminate {}
cache_flag = 0
}
}
step {
name = "Populate SNAT table"
transform {
src_table_name = "axIpNatPoolStatsEntry"
target_table_name = "cmdb_ci_snat_ip_pool"
operation {
set_field {
field_name = "name"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolName"}
}
set_field {
field_name = "nat_pool_port_usage"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolPortUsage"}
}
set_field {
field_name = "nat_pool_end_address"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolEndAddress"}
}
set_field {
field_name = "nat_pool_start_address"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolStartAddress"}
}
set_field {
field_name = "nat_pool_total_free"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolTotalFree"}
}
set_field {
field_name = "nat_pool_total_used"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolTotalUsed"}
}
set_field {
field_name = "nat_pool_failed"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolFailed"}
}
set_field {
field_name = "object_id"
value = get_attr {"axIpNatPoolStatsEntry[].instanceID"}
}
}
}
}
step {
name = "Create relation to A10 "
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "cmdb_ci_snat_ip_pool"
result_table_name = "snat_2_a10"
unmatched_lines = keep
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
}
| library {
name = "Collect SNAT IP Pool - SNMP"
id = "b8557bf11b455d10243064a3604bcb2c" // Unique identifier for the pattern
description = "Collect SNAT IP Pool - SNMP" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "get axIpNatPoolStatsEntry"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.22610.2.4.3.18.100.1.1"
col_names = "1","2","3","4","5","6","7"
}
var_names = table {
name = "axIpNatPoolStatsEntry"
col_names = "axIpNatPoolName","axIpNatPoolStartAddress","axIpNatPoolEndAddress","axIpNatPoolPortUsage","axIpNatPoolTotalUsed","axIpNatPoolTotalFree","axIpNatPoolFailed"
}
if_not_found_do = terminate {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate SNAT table"
transform {
src_table_name = "axIpNatPoolStatsEntry"
target_table_name = "cmdb_ci_snat_ip_pool"
operation {
set_field {
field_name = "name"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolName"}
}
set_field {
field_name = "nat_pool_port_usage"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolPortUsage"}
}
set_field {
field_name = "nat_pool_end_address"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolEndAddress"}
}
set_field {
field_name = "nat_pool_start_address"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolStartAddress"}
}
set_field {
field_name = "nat_pool_total_free"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolTotalFree"}
}
set_field {
field_name = "nat_pool_total_used"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolTotalUsed"}
}
set_field {
field_name = "nat_pool_failed"
value = get_attr {"axIpNatPoolStatsEntry[].axIpNatPoolFailed"}
}
set_field {
field_name = "object_id"
value = get_attr {"axIpNatPoolStatsEntry[].instanceID"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation to A10 "
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "cmdb_ci_snat_ip_pool"
result_table_name = "snat_2_a10"
unmatched_lines = keep
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
}
|
Windows - ARP and NDP Tables | I would like for you to help me build a Pattern that helps achieve Discovery of Windows - ARP and NDP Tables. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Windows - ARP and NDP Tables"
id = "b8abaeb41b205910a63bdc61ab4bcb14"
description = "null"
step {
name = "Windows - ARP Table"
ref {refid = "21f94ed6dbc12200c06776231f9619b2"}
}
step {
name = "Windows - NDP Table"
ref {refid = "dd3d55141b36811082cd642aab4bcb32"}
}
}
| library {
name = "Windows - ARP and NDP Tables"
id = "b8abaeb41b205910a63bdc61ab4bcb14" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Windows - ARP Table"
ref {refid = "21f94ed6dbc12200c06776231f9619b2"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Windows - NDP Table"
ref {refid = "dd3d55141b36811082cd642aab4bcb32"} // Unique identifier for the pattern
}
}
|
Amazon AWS Get ECS TaskDefinitions | I would like for you to help me build a Pattern that helps achieve Discovery of Amazon AWS Get ECS TaskDefinitions. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Amazon AWS Get ECS TaskDefinitions"
id = "bf89e095db67b300e52b5f135e961951"
description = "null"
step {
name = "List ECS TasksDefinitions"
comment = "The Describe APIs returns only the first/default resource data, so all the resource ARNs have to parsed first and then used as API query parameters."
custom_operation {
attributes {
attribute {
name = "url"
value = "https://ecs.{region}.amazonaws.com/"
}
attribute {
name = "method"
value = "POST"
}
attribute {
name = "body"
value = "{}"
}
attribute {
name = "headers"
value = "X-Amz-Target:AmazonEC2ContainerServiceV20141113.ListTaskDefinitions,Content-Type:application/x-amz-json-1.1"
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "list_tasksdefinition_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step {
name = "Parse the TaskDefinitions ARNs"
if {
condition = is_not_empty {get_attr {"list_tasksdefinition_response"}}
on_true = parse_var_to_var {
from_var_name = "list_tasksdefinition_response"
to_var_names = table {
name = "task_definitions"
col_names = "td_arn","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "td_arn"
xpath = "/root/taskDefinitionArns/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/added_sn_region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Filter out regions without TaskDefinitions"
if {
condition = contains {
get_attr {"task_definitions"}
""
}
on_true = filter {
src_table_name = "task_definitions"
target_table_name = "task_definitions"
condition = is_not_empty {get_attr {"task_definitions[].td_arn"}}
}
on_false = nop {}
}
}
step {
name = "Get the TaskDefinition details"
if {
condition = is_not_empty {get_attr {"task_definitions"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Amazon AWS - ECS pattern\");
var cloudcall = new CloudRestAPIClient();
var result = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var new_response = new Packages.java.util.ArrayList();
var resource_arn = ${task_definitions[*].td_arn}.toArray()
var resource_region = ${task_definitions[*].region}.toArray()
headersMap.put(\"x-amz-target\", \"AmazonEC2ContainerServiceV20141113.DescribeTaskDefinition\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
for (var index = 0; index < resource_arn.length; index++) {
var ecsurl = \"https://ecs.\" + resource_region[index] + \".amazonaws.com/\";
var requestBody = '{\"include\": [ \"TAGS\" ],\"taskDefinition\":\"' + resource_arn[index] + '\"}';
// CTX.setAttribute('api_body'+index, requestBody);
try{
result = cloudcall.arrayListExecute(${service_account},null, ecsurl, headersMap, 'POST', requestBody, 'true', CTX );
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
break;
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources result=\" + result);
for (var j = 0; j < result.size(); j++){
new_response.add(result.get(j));
}
}
CTX.setAttribute('describe_taskdefinitions_response', new_response);"}
}
on_false = nop {}
}
}
step {
name = "Parse the TaskDefinitions details"
if {
condition = is_not_empty {get_attr {"describe_taskdefinitions_response"}}
on_true = parse_var_to_var {
from_var_name = "describe_taskdefinitions_response"
to_var_names = table {
name = "td_details"
col_names = "td_arn","td_status","td_cpu","td_memory","td_network_mode","td_revision","family"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "td_arn"
xpath = "/root/taskDefinition/taskDefinitionArn/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_status"
xpath = "/root/taskDefinition/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_cpu"
xpath = "/root/taskDefinition/cpu/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_memory"
xpath = "/root/taskDefinition/memory/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_network_mode"
xpath = "/root/taskDefinition/networkMode/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_revision"
xpath = "/root/taskDefinition/revision/text()"
delimiters = ""
position = 1
}
field {
col_name = "family"
xpath = "/root/taskDefinition/family/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Merge the TaskDefinition data into 1 table"
if {
condition = is_not_empty {get_attr {"task_definitions"}}
on_true = merge {
table1_name = "task_definitions"
key1_name = "td_arn"
table2_name = "td_details"
key2_name = "td_arn"
result_table_name = "task_definitions"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Parse the TaskDefinition compatibilities"
if {
condition = is_not_empty {get_attr {"task_definitions"}}
on_true = parse_var_to_var {
from_var_name = "describe_taskdefinitions_response"
to_var_names = table {
name = "td_compatibilities"
col_names = "td_arn","td_compatibility"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "td_arn"
xpath = "/root/taskDefinition/taskDefinitionArn/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_compatibility"
xpath = "/root/taskDefinition/compatibilities/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the TaskDefinition compatibilities "
if {
condition = is_not_empty {get_attr {"td_compatibilities"}}
on_true = transform {
src_table_name = "task_definitions"
target_table_name = "task_definitions"
operation {set_field {
field_name = "compatibilities"
value = eval {"javascript: var rtrn = ''
var td_arn = ${task_definitions[].td_arn}
var td_compatibility_arn = ${td_compatibilities[*].td_arn}.toArray()
var td_compatibility = ${td_compatibilities[*].td_compatibility}.toArray()
var separator = ''
var length = td_compatibility_arn.length
for(i=0; i < length; i++){
if (td_arn==td_compatibility_arn[i]) {
rtrn += separator + td_compatibility[i]
separator = ','
}
}
rtrn "}
}}
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_cloud_ecs_task_definition table"
if {
condition = is_not_empty {get_attr {"task_definitions"}}
on_true = transform {
src_table_name = "task_definitions"
target_table_name = "cmdb_ci_cloud_ecs_task_definition"
operation {
set_field {
field_name = "object_id"
value = get_attr {"task_definitions[].td_arn"}
}
set_field {
field_name = "name"
value = get_attr {"task_definitions[].family"}
}
set_field {
field_name = "status"
value = get_attr {"task_definitions[].td_status"}
}
set_field {
field_name = "revision"
value = get_attr {"task_definitions[].td_revision"}
}
set_field {
field_name = "network_mode"
value = get_attr {"task_definitions[].td_network_mode"}
}
set_field {
field_name = "cpu"
value = get_attr {"task_definitions[].td_cpu"}
}
set_field {
field_name = "memory"
value = get_attr {"task_definitions[].td_memory"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_cloud_ecs_task_definition and cmdb_ci_aws_datacenter"
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_ecs_task_definition"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_ecs_task_definition"
key1_name = "region"
table2_name = "cmdb_ci_aws_datacenter"
key2_name = "region"
result_table_name = "td_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "Amazon AWS Get ECS TaskDefinitions"
id = "bf89e095db67b300e52b5f135e961951" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "List ECS TasksDefinitions"
comment = "The Describe APIs returns only the first/default resource data, so all the resource ARNs have to parsed first and then used as API query parameters."
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = "https://ecs.{region}.amazonaws.com/"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "POST"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = "{}"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = "X-Amz-Target:AmazonEC2ContainerServiceV20141113.ListTaskDefinitions,Content-Type:application/x-amz-json-1.1"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "list_tasksdefinition_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the TaskDefinitions ARNs"
if {
condition = is_not_empty {get_attr {"list_tasksdefinition_response"}}
on_true = parse_var_to_var {
from_var_name = "list_tasksdefinition_response"
to_var_names = table {
name = "task_definitions"
col_names = "td_arn","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "td_arn"
xpath = "/root/taskDefinitionArns/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/added_sn_region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out regions without TaskDefinitions"
if {
condition = contains {
get_attr {"task_definitions"}
""
}
on_true = filter {
src_table_name = "task_definitions"
target_table_name = "task_definitions"
condition = is_not_empty {get_attr {"task_definitions[].td_arn"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get the TaskDefinition details"
if {
condition = is_not_empty {get_attr {"task_definitions"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Amazon AWS - ECS pattern\"); // Script execution: Custom script to perform a specific action or collect data
var cloudcall = new CloudRestAPIClient();
var result = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var new_response = new Packages.java.util.ArrayList();
var resource_arn = ${task_definitions[*].td_arn}.toArray()
var resource_region = ${task_definitions[*].region}.toArray()
headersMap.put(\"x-amz-target\", \"AmazonEC2ContainerServiceV20141113.DescribeTaskDefinition\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
for (var index = 0; index < resource_arn.length; index++) {
var ecsurl = \"https://ecs.\" + resource_region[index] + \".amazonaws.com/\";
var requestBody = '{\"include\": [ \"TAGS\" ],\"taskDefinition\":\"' + resource_arn[index] + '\"}';
// CTX.setAttribute('api_body'+index, requestBody);
try{
result = cloudcall.arrayListExecute(${service_account},null, ecsurl, headersMap, 'POST', requestBody, 'true', CTX );
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
break;
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources result=\" + result);
for (var j = 0; j < result.size(); j++){
new_response.add(result.get(j));
}
}
CTX.setAttribute('describe_taskdefinitions_response', new_response);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the TaskDefinitions details"
if {
condition = is_not_empty {get_attr {"describe_taskdefinitions_response"}}
on_true = parse_var_to_var {
from_var_name = "describe_taskdefinitions_response"
to_var_names = table {
name = "td_details"
col_names = "td_arn","td_status","td_cpu","td_memory","td_network_mode","td_revision","family"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "td_arn"
xpath = "/root/taskDefinition/taskDefinitionArn/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_status"
xpath = "/root/taskDefinition/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_cpu"
xpath = "/root/taskDefinition/cpu/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_memory"
xpath = "/root/taskDefinition/memory/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_network_mode"
xpath = "/root/taskDefinition/networkMode/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_revision"
xpath = "/root/taskDefinition/revision/text()"
delimiters = ""
position = 1
}
field {
col_name = "family"
xpath = "/root/taskDefinition/family/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge the TaskDefinition data into 1 table"
if {
condition = is_not_empty {get_attr {"task_definitions"}}
on_true = merge {
table1_name = "task_definitions"
key1_name = "td_arn"
table2_name = "td_details"
key2_name = "td_arn"
result_table_name = "task_definitions"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the TaskDefinition compatibilities"
if {
condition = is_not_empty {get_attr {"task_definitions"}}
on_true = parse_var_to_var {
from_var_name = "describe_taskdefinitions_response"
to_var_names = table {
name = "td_compatibilities"
col_names = "td_arn","td_compatibility"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "td_arn"
xpath = "/root/taskDefinition/taskDefinitionArn/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_compatibility"
xpath = "/root/taskDefinition/compatibilities/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the TaskDefinition compatibilities "
if {
condition = is_not_empty {get_attr {"td_compatibilities"}}
on_true = transform {
src_table_name = "task_definitions"
target_table_name = "task_definitions"
operation {set_field {
field_name = "compatibilities"
value = eval {"javascript: var rtrn = '' // Script execution: Custom script to perform a specific action or collect data
var td_arn = ${task_definitions[].td_arn}
var td_compatibility_arn = ${td_compatibilities[*].td_arn}.toArray()
var td_compatibility = ${td_compatibilities[*].td_compatibility}.toArray()
var separator = ''
var length = td_compatibility_arn.length
for(i=0; i < length; i++){
if (td_arn==td_compatibility_arn[i]) {
rtrn += separator + td_compatibility[i]
separator = ','
}
}
rtrn "}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_cloud_ecs_task_definition table"
if {
condition = is_not_empty {get_attr {"task_definitions"}}
on_true = transform {
src_table_name = "task_definitions"
target_table_name = "cmdb_ci_cloud_ecs_task_definition"
operation {
set_field {
field_name = "object_id"
value = get_attr {"task_definitions[].td_arn"}
}
set_field {
field_name = "name"
value = get_attr {"task_definitions[].family"}
}
set_field {
field_name = "status"
value = get_attr {"task_definitions[].td_status"}
}
set_field {
field_name = "revision"
value = get_attr {"task_definitions[].td_revision"}
}
set_field {
field_name = "network_mode"
value = get_attr {"task_definitions[].td_network_mode"}
}
set_field {
field_name = "cpu"
value = get_attr {"task_definitions[].td_cpu"}
}
set_field {
field_name = "memory"
value = get_attr {"task_definitions[].td_memory"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_cloud_ecs_task_definition and cmdb_ci_aws_datacenter"
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_ecs_task_definition"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_ecs_task_definition"
key1_name = "region"
table2_name = "cmdb_ci_aws_datacenter"
key2_name = "region"
result_table_name = "td_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
Azure Storage Volume Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Azure Storage Volume Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure Storage Volume Tags"
id = "d5f61e21dbd51010b2a1f9627596194f"
description = "Azure Storage Volume Tags"
step {
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Storage Volume Tags\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id};
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step {
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Create relation between Tag and Storage Volume"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "tag_to_storage_volume"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Azure Storage Volume Tags"
id = "d5f61e21dbd51010b2a1f9627596194f" // Unique identifier for the pattern
description = "Azure Storage Volume Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Storage Volume Tags\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id}; // Unique identifier for the pattern
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and Storage Volume"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "tag_to_storage_volume"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Azure Host License | I would like for you to help me build a Pattern that helps achieve Discovery of Azure Host License. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure Host License"
id = "ea5b7a181bf2941410a6dce7cc4bcbe2"
description = "Azure Host License"
step {
name = "Parse License"
custom_operation {
attributes {
attribute {
name = "source"
value = "resource_response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "license_type"
}
attribute {
name = "target_columns"
value = concat {
"object_id:data.rows."
get_attr {"response_properties"}
".virtualMachines.id,value:data.rows."
get_attr {"response_properties"}
".licenseType"
}
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "Add attributes to License"
if {
condition = is_not_empty {get_attr {"license_type"}}
on_true = transform {
src_table_name = "license_type"
target_table_name = "license_type"
operation {
set_field {
field_name = "key"
value = "Windows_OS_License_Type_automatic"
}
set_field {
field_name = "value"
value = eval {"javascript: var value = ${license_type[].value};
if (value == \"Windows_Server_Hybrid\"){
value = \"BYOL\";
} else {
value = \"License Included\";
}
value;"}
}
}
}
on_false = nop {}
}
}
step {
name = "Filter cmdb_key_value table"
filter {
src_table_name = "license_type"
target_table_name = "license_type"
condition = is_not_empty {get_attr {"license_type[].object_id"}}
}
}
step {
name = "Union Tag and License tables"
if {
condition = is_not_empty {get_attr {"license_type"}}
on_true = union {
table1_name = "cmdb_key_value"
table2_name = "license_type"
result_table_name = "cmdb_key_value"
}
on_false = nop {}
}
}
step {
name = "Create relation between License and VM"
if {
condition = is_not_empty {get_attr {"license_type"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
table2_name = "cmdb_ci_vm_instance"
result_table_name = "license_to_vm"
unmatched_lines = remove
condition = eq {
"true"
eval {"javascript: var rtrn = \"false\";
var vm_id = ${cmdb_ci_vm_instance[].source_native_key};
var license_id = ${cmdb_key_value[].object_id};
var value = ${cmdb_key_value[].value};
var account_id = ${service_account[1].account_id};
if (value == \"License Included\" || value == \"BYOL\") {
if (vm_id == (account_id + \"_\" + license_id)){
rtrn = \"true\";
}
}
rtrn;"}
}
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "Azure Host License"
id = "ea5b7a181bf2941410a6dce7cc4bcbe2" // Unique identifier for the pattern
description = "Azure Host License" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse License"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "resource_response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "license_type"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = concat {
"object_id:data.rows."
get_attr {"response_properties"}
".virtualMachines.id,value:data.rows."
get_attr {"response_properties"}
".licenseType"
}
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add attributes to License" // Attribute collection: Collects specific attributes from the discovered CI
if {
condition = is_not_empty {get_attr {"license_type"}}
on_true = transform {
src_table_name = "license_type"
target_table_name = "license_type"
operation {
set_field {
field_name = "key"
value = "Windows_OS_License_Type_automatic"
}
set_field {
field_name = "value"
value = eval {"javascript: var value = ${license_type[].value}; // Script execution: Custom script to perform a specific action or collect data
if (value == \"Windows_Server_Hybrid\"){
value = \"BYOL\";
} else {
value = \"License Included\";
}
value;"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_value table"
filter {
src_table_name = "license_type"
target_table_name = "license_type"
condition = is_not_empty {get_attr {"license_type[].object_id"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union Tag and License tables"
if {
condition = is_not_empty {get_attr {"license_type"}}
on_true = union {
table1_name = "cmdb_key_value"
table2_name = "license_type"
result_table_name = "cmdb_key_value"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between License and VM"
if {
condition = is_not_empty {get_attr {"license_type"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
table2_name = "cmdb_ci_vm_instance"
result_table_name = "license_to_vm"
unmatched_lines = remove
condition = eq {
"true"
eval {"javascript: var rtrn = \"false\"; // Script execution: Custom script to perform a specific action or collect data
var vm_id = ${cmdb_ci_vm_instance[].source_native_key}; // Unique identifier for the pattern
var license_id = ${cmdb_key_value[].object_id}; // Unique identifier for the pattern
var value = ${cmdb_key_value[].value};
var account_id = ${service_account[1].account_id}; // Unique identifier for the pattern
if (value == \"License Included\" || value == \"BYOL\") {
if (vm_id == (account_id + \"_\" + license_id)){ // Unique identifier for the pattern
rtrn = \"true\";
}
}
rtrn;"}
}
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
SNMP - Routing | I would like for you to help me build a Pattern that helps achieve Discovery of SNMP - Routing. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "SNMP - Routing"
id = "f3046bcadba52200868a7c841f9619d4"
description = "null"
step {
name = "Get routing table from ipCidrRouteTable"
comment = "mgmt.mib-2.ip.ipForward.ipCidrRouteTable
Holds routing table.ipCidrRouteTable if not empty, ipRouteTable otherwise"
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.4.24.4.1"
col_names = "5","1","2","4","6"
}
var_names = table {
name = "routeTable"
col_names = "ipRouteIfIndex","ipRouteDest","ipRouteMask","ipRouteNextHop","ipRouteType"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "if no routing table found, try from ipRouteTable"
comment = "mgmt.mib-2.ip.ipRouteTable"
if {
condition = all {
is_empty {get_attr {"routeTable"}}
neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.4.21.1"
col_names = "2","1","11","7","8"
}
var_names = table {
name = "routeTable"
col_names = "ipRouteIfIndex","ipRouteDest","ipRouteMask","ipRouteNextHop","ipRouteType"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Filter routeTable: delete empty ipRouteDest and ipRouteMask"
comment = "This step will filter out data when ipRouteDest and ipRouteMask is empty."
if {
condition = is_not_empty {get_attr {"routeTable"}}
on_true = filter {
src_table_name = "routeTable"
target_table_name = "routeTable"
condition = all {
is_not_empty {get_attr {"routeTable[].ipRouteDest"}}
is_not_empty {get_attr {"routeTable[].ipRouteMask"}}
}
}
on_false = nop {}
}
}
step {
name = "Set destination network & convert network data for future calculations"
comment = "Add calculated attributes (CIDR, networkAsInt, maskAsInt) by using \u201CNetworkDiscoveryUtil\u201D MID script include
We're using the calculated fields to match next-hop rules to their exit rules"
if {
condition = is_not_empty {get_attr {"routeTable[1].ipRouteMask"}}
on_true = transform {
src_table_name = "routeTable"
target_table_name = "routeTable"
operation {
set_field {
field_name = "cidr"
value = eval {"javascript:var rtrn = '';var netmask = ${routeTable[].ipRouteMask};rtrn = NetworkDiscoveryUtil.netmaskToCidr(netmask);"}
}
set_field {
field_name = "dest_ip_network"
value = eval {"javascript: var rtrn;
var SncIPNetworkV4 = Packages.com.snc.commons.networks.IPNetworkV4;
var SncIPAddressV4 = Packages.com.snc.commons.networks.IPAddressV4;
var SncIPNetmaskV4 = Packages.com.snc.commons.networks.IPNetmaskV4;
var ip = SncIPAddressV4(${routeTable[].ipRouteDest});
var netmask = SncIPNetmaskV4(${routeTable[].ipRouteMask});
var network = SncIPNetworkV4(ip, netmask);
rtrn = network.getAddress() + \"/\" + network.getNetmask();
if (rtrn == \"0.0.0.0/0.0.0.0\") {
rtrn = \"0.0.0.0/0\"
}
rtrn;"}
}
set_field {
field_name = "networkAsInt"
value = eval {"javascript:var rtrn = '';var ip = ${routeTable[].ipRouteDest};var netmask = ${routeTable[].ipRouteMask};rtrn = NetworkDiscoveryUtil.getNetworkFromIpAndMask(ip,netmask)+'';"}
}
set_field {
field_name = "maskAsInt"
value = eval {"javascript:var rtrn = '';var netmask = ${routeTable[].ipRouteMask};rtrn = NetworkDiscoveryUtil.stringIpToInt(netmask)+'';"}
}
}
}
on_false = nop {}
}
}
step {
name = "Match each interface to it's ip address"
comment = "Keep is used because the sensor didn't remove interfaces with no IPsRepresents router interfaces entries for dscy_router_interface"
merge {
table1_name = "ipAddresses"
key1_name = "ipAdEntIfIndex"
table2_name = "ifTable"
key2_name = "ifIndex"
result_table_name = "routerInterfacesTable"
unmatched_lines = keep
}
}
step {
name = "Calculate network data for future calculations"
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = transform {
src_table_name = "routerInterfacesTable"
target_table_name = "routerInterfacesTable"
operation {
set_field {
field_name = "networkAsInt"
value = eval {"javascript:var rtrn = '';var ip = ${routerInterfacesTable[].ipAdEntAddr};var netmask = ${routerInterfacesTable[].ipAdEntNetMask};rtrn = NetworkDiscoveryUtil.getNetworkFromIpAndMask(ip,netmask)+'';"}
}
set_field {
field_name = "maskAsInt"
value = eval {"javascript:var rtrn = '';var netmask = ${routerInterfacesTable[].ipAdEntNetMask}rtrn = NetworkDiscoveryUtil.stringIpToInt(netmask)+'';"}
}
}
}
on_false = nop {}
}
}
step {
name = "*Remove duplicate router interfaces"
set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${routerInterfacesTable},\"ifIndex\");CTX.setAttribute(\"routerInterfacesTable\", tableWithoutDuplicates); "}
}
}
step {
name = "Insert routerInterfacesTable to dscy_router_interface"
comment = "Get the router interfaces but don't overwrite $dscy_router_interface"
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = transform {
src_table_name = "routerInterfacesTable"
target_table_name = "dscy_router_interface_1"
operation {
set_field {
field_name = "type"
value = get_attr {"routerInterfacesTable[].ifType"}
}
set_field {
field_name = "ip_address"
value = get_attr {"routerInterfacesTable[].ipAdEntAddr"}
}
set_field {
field_name = "mac_address"
value = get_attr {"routerInterfacesTable[].ifPhysAddress"}
}
set_field {
field_name = "number"
value = get_attr {"routerInterfacesTable[].ifIndex"}
}
set_field {
field_name = "name"
value = get_attr {"routerInterfacesTable[].ifDescr"}
}
}
}
on_false = nop {}
}
}
step {
name = "Union both interfaces tables"
if {
condition = is_not_empty {get_attr {"dscy_router_interface_1[1].number"}}
on_true = union {
table1_name = "dscy_router_interface_1"
table2_name = "dscy_router_interface"
result_table_name = "dscy_router_interface"
}
on_false = nop {}
}
}
step {
name = "Remove duplicate router interfaces after union"
set_attr {
"notInUse"
eval {"javascript:
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${dscy_router_interface},[\"name\", \"mac_address\"]);CTX.setAttribute(\"dscy_router_interface\", tableWithoutDuplicates); "}
}
}
step {
name = "Remove unrelated rows"
comment = "This attribute is a key attribute.Because we used \"Keep\" option in \"Match each interface to it's ip address\" step, we want to make sure that there no redundant rows"
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = filter {
src_table_name = "dscy_router_interface"
target_table_name = "dscy_router_interface"
condition = all {
is_not_empty {get_attr {"dscy_router_interface[].mac_address"}}
is_not_empty {get_attr {"dscy_router_interface[].name"}}
eq {
"True"
eval {"javascript: var MACAddressClass = Packages.com.snc.commons.networks.MACAddress;
var current_mac = ${dscy_router_interface[].mac_address};
var rtrn = \"False\";
try{
var tmp = new MACAddressClass(current_mac);
rtrn = \"True\";
} catch(e) {
ms.log(e);
}
rtrn;"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create routerExitInterfacesTable"
comment = "Represents exit rule interfaces entries for dscy_route_interface"
if {
condition = is_not_empty {get_attr {"routeTable[1].ipRouteMask"}}
on_true = filter {
src_table_name = "routeTable"
target_table_name = "routerExitInterfacesTable"
condition = eq {
get_attr {"routeTable[].ipRouteType"}
"3"
}
}
on_false = nop {}
}
}
step {
name = "Insert routerExitInterfacesTable to dscy_route_interface"
if {
condition = is_not_empty {get_attr {"routerExitInterfacesTable[1].ipRouteType"}}
on_true = transform {
src_table_name = "routerExitInterfacesTable"
target_table_name = "dscy_route_interface"
operation {
set_field {
field_name = "type"
value = get_attr {"routerExitInterfacesTable[].ipRouteType"}
}
set_field {
field_name = "dest_ip_network"
value = get_attr {"routerExitInterfacesTable[].dest_ip_network"}
}
set_field {
field_name = "name"
value = concat {
get_attr {"routerExitInterfacesTable[].dest_ip_network"}
"[Direct]"
}
}
}
}
on_false = nop {}
}
}
step {
name = "Merge ifTable and routerExitInterfacesTable"
comment = "Merge ifTable and routerExitInterfacesTable to match the ifIndex between the tables."
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = merge {
table1_name = "routerExitInterfacesTable"
key1_name = "ipRouteIfIndex"
table2_name = "ifTable"
key2_name = "ifIndex"
result_table_name = "routerExitInterfacesTable"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "Reference and relation between dscy_route_interface to dscy_router_interface"
relation_reference {
table1_name = "dscy_router_interface"
key1_name = "ifIndex"
table2_name = "dscy_route_interface"
key2_name = "ipRouteIfIndex"
result_table_name = "route_interface_router_interface"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "router_interface"
}
}
step {
name = "Create routerNextHopInterfacesTable"
comment = "Represents next-hop interfaces entries for dscy_route_next_hop"
if {
condition = is_not_empty {get_attr {"routeTable[1].ipRouteType"}}
on_true = filter {
src_table_name = "routeTable"
target_table_name = "routerNextHopInterfacesTable"
condition = eq {
get_attr {"routeTable[].ipRouteType"}
"4"
}
}
on_false = nop {}
}
}
step {
name = "Insert routerNextHopInterfacesTable to dscy_route_next_hop"
transform {
src_table_name = "routerNextHopInterfacesTable"
target_table_name = "dscy_route_next_hop"
operation {
set_field {
field_name = "dest_ip_network"
value = get_attr {"routerNextHopInterfacesTable[].dest_ip_network"}
}
set_field {
field_name = "type"
value = get_attr {"routerNextHopInterfacesTable[].ipRouteType"}
}
set_field {
field_name = "next_hop_ip_address"
value = get_attr {"routerNextHopInterfacesTable[].ipRouteNextHop"}
}
set_field {
field_name = "name"
value = get_attr {"routerNextHopInterfacesTable[].ipRouteNextHop"}
}
}
}
}
step {
name = "Remove duplicate dscy_route_next_hop"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${dscy_route_next_hop},[\"dest_ip_network\", \"next_hop_ip_address\"]);CTX.setAttribute(\"dscy_route_next_hop\", tableWithoutDuplicates);
"}
}
}
step {
name = "Match each next hop to its route interface"
transform {
src_table_name = "dscy_route_next_hop"
target_table_name = "dscy_route_next_hop"
operation {set_field {
field_name = "routeInterfaceId"
value = eval {"javascript: var rtrn = '';
var routeInterfaces = ${dscy_route_interface};
var nextHop= ${dscy_route_next_hop[].next_hop_ip_address};
var nextHopAsInt = NetworkDiscoveryUtil.stringIpToInt(nextHop);
var routeInterface;
var maskAsInt;
var networkAsInt;
var ipAsInt;
for(var i = 0; i < routeInterfaces.size(); i++){
routeInterface = routeInterfaces.get(i);
maskAsInt = routeInterface.get(\"maskAsInt\");
networkAsInt = routeInterface.get(\"networkAsInt\");
if(NetworkDiscoveryUtil.doesIpContainedInNetwork(nextHopAsInt, maskAsInt,networkAsInt) || NetworkDiscoveryUtil.isBroadcastAddress(nextHopAsInt,maskAsInt,networkAsInt)){
rtrn = routeInterface.get(\"dest_ip_network\");
break;
}
}"}
}}
}
}
step {
name = "Reference and relation between dscy_route_next_hop to dscy_router_interface"
relation_reference {
table1_name = "dscy_route_interface"
key1_name = "dest_ip_network"
table2_name = "dscy_route_next_hop"
key2_name = "routeInterfaceId"
result_table_name = "route_next_hop_route_interface"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "route_interface"
}
}
}
| library {
name = "SNMP - Routing"
id = "f3046bcadba52200868a7c841f9619d4" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get routing table from ipCidrRouteTable"
comment = "mgmt.mib-2.ip.ipForward.ipCidrRouteTable
Holds routing table.ipCidrRouteTable if not empty, ipRouteTable otherwise"
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.4.24.4.1"
col_names = "5","1","2","4","6"
}
var_names = table {
name = "routeTable"
col_names = "ipRouteIfIndex","ipRouteDest","ipRouteMask","ipRouteNextHop","ipRouteType"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "if no routing table found, try from ipRouteTable"
comment = "mgmt.mib-2.ip.ipRouteTable"
if {
condition = all {
is_empty {get_attr {"routeTable"}}
neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.4.21.1"
col_names = "2","1","11","7","8"
}
var_names = table {
name = "routeTable"
col_names = "ipRouteIfIndex","ipRouteDest","ipRouteMask","ipRouteNextHop","ipRouteType"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter routeTable: delete empty ipRouteDest and ipRouteMask"
comment = "This step will filter out data when ipRouteDest and ipRouteMask is empty." // Step definition: Represents a single action or set of actions in the pattern
if {
condition = is_not_empty {get_attr {"routeTable"}}
on_true = filter {
src_table_name = "routeTable"
target_table_name = "routeTable"
condition = all {
is_not_empty {get_attr {"routeTable[].ipRouteDest"}}
is_not_empty {get_attr {"routeTable[].ipRouteMask"}}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set destination network & convert network data for future calculations"
comment = "Add calculated attributes (CIDR, networkAsInt, maskAsInt) by using \u201CNetworkDiscoveryUtil\u201D MID script include // Attribute collection: Collects specific attributes from the discovered CI
We're using the calculated fields to match next-hop rules to their exit rules"
if {
condition = is_not_empty {get_attr {"routeTable[1].ipRouteMask"}}
on_true = transform {
src_table_name = "routeTable"
target_table_name = "routeTable"
operation {
set_field {
field_name = "cidr"
value = eval {"javascript:var rtrn = '';var netmask = ${routeTable[].ipRouteMask};rtrn = NetworkDiscoveryUtil.netmaskToCidr(netmask);"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "dest_ip_network"
value = eval {"javascript: var rtrn; // Script execution: Custom script to perform a specific action or collect data
var SncIPNetworkV4 = Packages.com.snc.commons.networks.IPNetworkV4;
var SncIPAddressV4 = Packages.com.snc.commons.networks.IPAddressV4;
var SncIPNetmaskV4 = Packages.com.snc.commons.networks.IPNetmaskV4;
var ip = SncIPAddressV4(${routeTable[].ipRouteDest});
var netmask = SncIPNetmaskV4(${routeTable[].ipRouteMask});
var network = SncIPNetworkV4(ip, netmask);
rtrn = network.getAddress() + \"/\" + network.getNetmask();
if (rtrn == \"0.0.0.0/0.0.0.0\") {
rtrn = \"0.0.0.0/0\"
}
rtrn;"}
}
set_field {
field_name = "networkAsInt"
value = eval {"javascript:var rtrn = '';var ip = ${routeTable[].ipRouteDest};var netmask = ${routeTable[].ipRouteMask};rtrn = NetworkDiscoveryUtil.getNetworkFromIpAndMask(ip,netmask)+'';"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "maskAsInt"
value = eval {"javascript:var rtrn = '';var netmask = ${routeTable[].ipRouteMask};rtrn = NetworkDiscoveryUtil.stringIpToInt(netmask)+'';"} // Script execution: Custom script to perform a specific action or collect data
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Match each interface to it's ip address"
comment = "Keep is used because the sensor didn't remove interfaces with no IPsRepresents router interfaces entries for dscy_router_interface"
merge {
table1_name = "ipAddresses"
key1_name = "ipAdEntIfIndex"
table2_name = "ifTable"
key2_name = "ifIndex"
result_table_name = "routerInterfacesTable"
unmatched_lines = keep
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Calculate network data for future calculations"
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = transform {
src_table_name = "routerInterfacesTable"
target_table_name = "routerInterfacesTable"
operation {
set_field {
field_name = "networkAsInt"
value = eval {"javascript:var rtrn = '';var ip = ${routerInterfacesTable[].ipAdEntAddr};var netmask = ${routerInterfacesTable[].ipAdEntNetMask};rtrn = NetworkDiscoveryUtil.getNetworkFromIpAndMask(ip,netmask)+'';"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "maskAsInt"
value = eval {"javascript:var rtrn = '';var netmask = ${routerInterfacesTable[].ipAdEntNetMask}rtrn = NetworkDiscoveryUtil.stringIpToInt(netmask)+'';"} // Script execution: Custom script to perform a specific action or collect data
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "*Remove duplicate router interfaces"
set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${routerInterfacesTable},\"ifIndex\");CTX.setAttribute(\"routerInterfacesTable\", tableWithoutDuplicates); "} // Script execution: Custom script to perform a specific action or collect data
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert routerInterfacesTable to dscy_router_interface"
comment = "Get the router interfaces but don't overwrite $dscy_router_interface"
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = transform {
src_table_name = "routerInterfacesTable"
target_table_name = "dscy_router_interface_1"
operation {
set_field {
field_name = "type"
value = get_attr {"routerInterfacesTable[].ifType"}
}
set_field {
field_name = "ip_address"
value = get_attr {"routerInterfacesTable[].ipAdEntAddr"}
}
set_field {
field_name = "mac_address"
value = get_attr {"routerInterfacesTable[].ifPhysAddress"}
}
set_field {
field_name = "number"
value = get_attr {"routerInterfacesTable[].ifIndex"}
}
set_field {
field_name = "name"
value = get_attr {"routerInterfacesTable[].ifDescr"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union both interfaces tables"
if {
condition = is_not_empty {get_attr {"dscy_router_interface_1[1].number"}}
on_true = union {
table1_name = "dscy_router_interface_1"
table2_name = "dscy_router_interface"
result_table_name = "dscy_router_interface"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate router interfaces after union"
set_attr {
"notInUse"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${dscy_router_interface},[\"name\", \"mac_address\"]);CTX.setAttribute(\"dscy_router_interface\", tableWithoutDuplicates); "}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove unrelated rows"
comment = "This attribute is a key attribute.Because we used \"Keep\" option in \"Match each interface to it's ip address\" step, we want to make sure that there no redundant rows" // Step definition: Represents a single action or set of actions in the pattern
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = filter {
src_table_name = "dscy_router_interface"
target_table_name = "dscy_router_interface"
condition = all {
is_not_empty {get_attr {"dscy_router_interface[].mac_address"}}
is_not_empty {get_attr {"dscy_router_interface[].name"}}
eq {
"True"
eval {"javascript: var MACAddressClass = Packages.com.snc.commons.networks.MACAddress; // Script execution: Custom script to perform a specific action or collect data
var current_mac = ${dscy_router_interface[].mac_address};
var rtrn = \"False\";
try{
var tmp = new MACAddressClass(current_mac);
rtrn = \"True\";
} catch(e) {
ms.log(e);
}
rtrn;"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create routerExitInterfacesTable"
comment = "Represents exit rule interfaces entries for dscy_route_interface"
if {
condition = is_not_empty {get_attr {"routeTable[1].ipRouteMask"}}
on_true = filter {
src_table_name = "routeTable"
target_table_name = "routerExitInterfacesTable"
condition = eq {
get_attr {"routeTable[].ipRouteType"}
"3"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert routerExitInterfacesTable to dscy_route_interface"
if {
condition = is_not_empty {get_attr {"routerExitInterfacesTable[1].ipRouteType"}}
on_true = transform {
src_table_name = "routerExitInterfacesTable"
target_table_name = "dscy_route_interface"
operation {
set_field {
field_name = "type"
value = get_attr {"routerExitInterfacesTable[].ipRouteType"}
}
set_field {
field_name = "dest_ip_network"
value = get_attr {"routerExitInterfacesTable[].dest_ip_network"}
}
set_field {
field_name = "name"
value = concat {
get_attr {"routerExitInterfacesTable[].dest_ip_network"}
"[Direct]"
}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge ifTable and routerExitInterfacesTable"
comment = "Merge ifTable and routerExitInterfacesTable to match the ifIndex between the tables."
if {
condition = neq {
get_attr {"shouldBlockBGPRouting"}
"true"
}
on_true = merge {
table1_name = "routerExitInterfacesTable"
key1_name = "ipRouteIfIndex"
table2_name = "ifTable"
key2_name = "ifIndex"
result_table_name = "routerExitInterfacesTable"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference and relation between dscy_route_interface to dscy_router_interface"
relation_reference {
table1_name = "dscy_router_interface"
key1_name = "ifIndex"
table2_name = "dscy_route_interface"
key2_name = "ipRouteIfIndex"
result_table_name = "route_interface_router_interface"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "router_interface"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create routerNextHopInterfacesTable"
comment = "Represents next-hop interfaces entries for dscy_route_next_hop"
if {
condition = is_not_empty {get_attr {"routeTable[1].ipRouteType"}}
on_true = filter {
src_table_name = "routeTable"
target_table_name = "routerNextHopInterfacesTable"
condition = eq {
get_attr {"routeTable[].ipRouteType"}
"4"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert routerNextHopInterfacesTable to dscy_route_next_hop"
transform {
src_table_name = "routerNextHopInterfacesTable"
target_table_name = "dscy_route_next_hop"
operation {
set_field {
field_name = "dest_ip_network"
value = get_attr {"routerNextHopInterfacesTable[].dest_ip_network"}
}
set_field {
field_name = "type"
value = get_attr {"routerNextHopInterfacesTable[].ipRouteType"}
}
set_field {
field_name = "next_hop_ip_address"
value = get_attr {"routerNextHopInterfacesTable[].ipRouteNextHop"}
}
set_field {
field_name = "name"
value = get_attr {"routerNextHopInterfacesTable[].ipRouteNextHop"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate dscy_route_next_hop"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${dscy_route_next_hop},[\"dest_ip_network\", \"next_hop_ip_address\"]);CTX.setAttribute(\"dscy_route_next_hop\", tableWithoutDuplicates); // Script execution: Custom script to perform a specific action or collect data
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Match each next hop to its route interface"
transform {
src_table_name = "dscy_route_next_hop"
target_table_name = "dscy_route_next_hop"
operation {set_field {
field_name = "routeInterfaceId"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var routeInterfaces = ${dscy_route_interface};
var nextHop= ${dscy_route_next_hop[].next_hop_ip_address};
var nextHopAsInt = NetworkDiscoveryUtil.stringIpToInt(nextHop);
var routeInterface;
var maskAsInt;
var networkAsInt;
var ipAsInt;
for(var i = 0; i < routeInterfaces.size(); i++){
routeInterface = routeInterfaces.get(i);
maskAsInt = routeInterface.get(\"maskAsInt\");
networkAsInt = routeInterface.get(\"networkAsInt\");
if(NetworkDiscoveryUtil.doesIpContainedInNetwork(nextHopAsInt, maskAsInt,networkAsInt) || NetworkDiscoveryUtil.isBroadcastAddress(nextHopAsInt,maskAsInt,networkAsInt)){
rtrn = routeInterface.get(\"dest_ip_network\");
break;
}
}"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference and relation between dscy_route_next_hop to dscy_router_interface"
relation_reference {
table1_name = "dscy_route_interface"
key1_name = "dest_ip_network"
table2_name = "dscy_route_next_hop"
key2_name = "routeInterfaceId"
result_table_name = "route_next_hop_route_interface"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "route_interface"
}
}
}
|
Amazon AWS - Get Application and Network LB Target Groups | I would like for you to help me build a Pattern that helps achieve Discovery of Amazon AWS - Get Application and Network LB Target Groups. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Amazon AWS - Get Application and Network LB Target Groups"
id = "f337c5814f5427006d0e1b818110c768"
description = "null"
step {
name = "Set filter initial value"
set_attr {
"filter"
""
}
}
step {
name = "Set the filter value to discover only event related item if the pattern is invoked by an event"
if {
condition = is_not_empty {get_attr {"input_object_id"}}
on_true = set_attr {
"filter"
concat {
"&LoadBalancerArn="
get_attr {"ELB_v2[1].LoadBalancerArn"}
}
}
on_false = nop {}
}
}
step {
name = "Get Target Groups"
comment = "Get all Target groups in the account and directly filter the results into a table, because currently the response would not be needed anywhere else."
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://elasticloadbalancing.{region}.amazonaws.com/?Action=DescribeTargetGroups"
get_attr {"filter"}
"&Version=2015-12-01"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "target_group_resp"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step {
name = "Parse Target Groups"
parse_var_to_var {
from_var_name = "target_group_resp"
to_var_names = table {
name = "targetgroup"
col_names = "Name","LoadBalancerArn","targetgroup_arn"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "Name"
xpath = "/root/DescribeTargetGroupsResponse/DescribeTargetGroupsResult/TargetGroups/TargetGroupName/text()"
delimiters = ""
position = 1
}
field {
col_name = "LoadBalancerArn"
xpath = "/root/DescribeTargetGroupsResponse/DescribeTargetGroupsResult/TargetGroups/LoadBalancerArns/text()"
delimiters = ""
position = 1
}
field {
col_name = "targetgroup_arn"
xpath = "/root/DescribeTargetGroupsResponse/DescribeTargetGroupsResult/TargetGroups/TargetGroupArn/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Filter the LB related Target Groups"
comment = "The SNow metadata rules require the Target Groups to have active relations to cmdb_ci_cloud_load_balancer or cmdb_ci_hardware and the Pattern would get only the LB, so the target groups needs to be filtered only to the ones that are related to LB, as otherwise the payload will not be processed."
if {
condition = is_not_empty {get_attr {"targetgroup"}}
on_true = filter {
src_table_name = "targetgroup"
target_table_name = "targetgroup"
condition = is_not_empty {get_attr {"targetgroup[].LoadBalancerArn"}}
}
on_false = nop {}
}
}
step {
name = "Fill cmdb_ci_lb_pool table"
comment = "Directly try to fill the SNow table for Cloud LB Pool if we have any results parsed in previous step."
if {
condition = is_not_empty {get_attr {"targetgroup"}}
on_true = transform {
src_table_name = "targetgroup"
target_table_name = "cmdb_ci_lb_pool"
operation {
set_field {
field_name = "name"
value = get_attr {"targetgroup[].Name"}
}
set_field {
field_name = "object_id"
value = get_attr {"targetgroup[]. targetgroup_arn"}
}
}
}
on_false = nop {}
}
}
}
| library {
name = "Amazon AWS - Get Application and Network LB Target Groups"
id = "f337c5814f5427006d0e1b818110c768" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set filter initial value"
set_attr {
"filter"
""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set the filter value to discover only event related item if the pattern is invoked by an event"
if {
condition = is_not_empty {get_attr {"input_object_id"}}
on_true = set_attr {
"filter"
concat {
"&LoadBalancerArn="
get_attr {"ELB_v2[1].LoadBalancerArn"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Target Groups"
comment = "Get all Target groups in the account and directly filter the results into a table, because currently the response would not be needed anywhere else."
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://elasticloadbalancing.{region}.amazonaws.com/?Action=DescribeTargetGroups"
get_attr {"filter"}
"&Version=2015-12-01"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "target_group_resp"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Target Groups"
parse_var_to_var {
from_var_name = "target_group_resp"
to_var_names = table {
name = "targetgroup"
col_names = "Name","LoadBalancerArn","targetgroup_arn"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "Name"
xpath = "/root/DescribeTargetGroupsResponse/DescribeTargetGroupsResult/TargetGroups/TargetGroupName/text()"
delimiters = ""
position = 1
}
field {
col_name = "LoadBalancerArn"
xpath = "/root/DescribeTargetGroupsResponse/DescribeTargetGroupsResult/TargetGroups/LoadBalancerArns/text()"
delimiters = ""
position = 1
}
field {
col_name = "targetgroup_arn"
xpath = "/root/DescribeTargetGroupsResponse/DescribeTargetGroupsResult/TargetGroups/TargetGroupArn/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter the LB related Target Groups"
comment = "The SNow metadata rules require the Target Groups to have active relations to cmdb_ci_cloud_load_balancer or cmdb_ci_hardware and the Pattern would get only the LB, so the target groups needs to be filtered only to the ones that are related to LB, as otherwise the payload will not be processed." // Metadata section: Contains metadata information about the pattern
if {
condition = is_not_empty {get_attr {"targetgroup"}}
on_true = filter {
src_table_name = "targetgroup"
target_table_name = "targetgroup"
condition = is_not_empty {get_attr {"targetgroup[].LoadBalancerArn"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill cmdb_ci_lb_pool table"
comment = "Directly try to fill the SNow table for Cloud LB Pool if we have any results parsed in previous step." // Step definition: Represents a single action or set of actions in the pattern
if {
condition = is_not_empty {get_attr {"targetgroup"}}
on_true = transform {
src_table_name = "targetgroup"
target_table_name = "cmdb_ci_lb_pool"
operation {
set_field {
field_name = "name"
value = get_attr {"targetgroup[].Name"}
}
set_field {
field_name = "object_id"
value = get_attr {"targetgroup[]. targetgroup_arn"}
}
}
}
on_false = nop {}
}
}
}
|
OpenStack Neutron Subnets | I would like for you to help me build a Pattern that helps achieve Discovery of OpenStack Neutron Subnets. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "OpenStack Neutron Subnets"
id = "f37312d4db810010bf2fe0a1ca96190b"
description = "null"
step {
name = "Get Subnets details"
comment = "https://<service:port>/v3.0/<project_id>/volumes/detail - throws error
https://<service:port>/v3/<project_id>/volumes/detail - works"
if {
condition = is_not_empty {get_attr {"links_neutron"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Network Resources pattern.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_neutron[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_neutron[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id');
if (!input_object_id) { var resource = \"subnets\";}
else { var resource = \"subnets/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var serviceURL = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
resultList.add(newJson);
}
}
CTX.setAttribute('subnets_details_response', resultList);"}
}
on_false = nop {}
}
}
step {
name = "HD: Parse the Subnets "
if {
condition = all {
is_not_empty {get_attr {"links_neutron"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "subnets_details_response"
to_var_names = table {
name = "subnets"
col_names = "subnet_id","subnet_name","network_id","project_id","enable_dhcp","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "subnet_id"
xpath = "/root/subnets/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "subnet_name"
xpath = "/root/subnets/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/subnets/network_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_id"
xpath = "/root/subnets/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "enable_dhcp"
xpath = "/root/subnets/enable_dhcp/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/subnets/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse the Subnets "
if {
condition = all {
is_not_empty {get_attr {"links_neutron"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "subnets_details_response"
to_var_names = table {
name = "subnets"
col_names = "subnet_id","subnet_name","network_id","project_id","enable_dhcp","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "subnet_id"
xpath = "/root/subnet/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "subnet_name"
xpath = "/root/subnet/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/subnet/network_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_id"
xpath = "/root/subnet/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "enable_dhcp"
xpath = "/root/subnet/enable_dhcp/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/subnet/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Filter out regions without subnets"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = is_not_empty {get_attr {"subnets"}}
on_true = filter {
src_table_name = "subnets"
target_table_name = "subnets"
condition = is_not_empty {get_attr {"subnets[].subnet_id"}}
}
on_false = nop {}
}
}
step {
name = "HD: Parse Subnets description"
if {
condition = all {
is_not_empty {get_attr {"subnets"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "subnets_details_response"
to_var_names = table {
name = "subnets_description"
col_names = "subnet_id","subnet_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "subnet_id"
xpath = "/root/subnets/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "subnet_description"
xpath = "/root/subnets/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Subnets description"
if {
condition = all {
is_not_empty {get_attr {"subnets"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "subnets_details_response"
to_var_names = table {
name = "subnets_description"
col_names = "subnet_id","subnet_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "subnet_id"
xpath = "/root/subnet/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "subnet_description"
xpath = "/root/subnet/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add Subnet description to the subnets table"
if {
condition = is_not_empty {get_attr {"subnets_description"}}
on_true = merge {
table1_name = "subnets"
key1_name = "subnet_id"
table2_name = "subnets_description"
key2_name = "subnet_id"
result_table_name = "subnets"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"subnets"}}
}
on_true = filter {
src_table_name = "subnets"
target_table_name = "subnets"
condition = eq {
get_attr {"subnets[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray()
var length = ldc.length
var region = ${subnets[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_cloud_subnet table"
if {
condition = is_not_empty {get_attr {"subnets"}}
on_true = transform {
src_table_name = "subnets"
target_table_name = "cmdb_ci_cloud_subnet"
operation {
set_field {
field_name = "object_id"
value = get_attr {"subnets[].subnet_id"}
}
set_field {
field_name = "name"
value = get_attr {"subnets[].subnet_name"}
}
set_field {
field_name = "short_description"
value = get_attr {"subnets_description[].subnet_description"}
}
set_field {
field_name = "is_dhcp_enabled"
value = get_attr {"subnets[].enable_dhcp"}
}
}
}
on_false = nop {}
}
}
step {
name = "Event: Populate cmdb_ci_network table"
comment = "populate only the network object_id, as this would be required for identification. The other network details will be updated by network pattern."
if {
condition = all {
is_not_empty {get_attr {"subnets"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = transform {
src_table_name = "subnets"
target_table_name = "cmdb_ci_network"
operation {set_field {
field_name = "object_id"
value = get_attr {"subnets[].subnet_id"}
}}
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_cloud_subnet and cmdb_ci_network table"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_cloud_subnet"}}
is_not_empty {get_attr {"cmdb_ci_network"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_network"
key1_name = "network_id"
table2_name = "cmdb_ci_cloud_subnet"
key2_name = "network_id"
result_table_name = "network_to_subnet"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "OpenStack Neutron Subnets"
id = "f37312d4db810010bf2fe0a1ca96190b" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Subnets details"
comment = "https://<service:port>/v3.0/<project_id>/volumes/detail - throws error
https://<service:port>/v3/<project_id>/volumes/detail - works"
if {
condition = is_not_empty {get_attr {"links_neutron"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Network Resources pattern.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_neutron[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_neutron[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id'); // Unique identifier for the pattern
if (!input_object_id) { var resource = \"subnets\";}
else { var resource = \"subnets/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var serviceURL = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
resultList.add(newJson);
}
}
CTX.setAttribute('subnets_details_response', resultList);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse the Subnets "
if {
condition = all {
is_not_empty {get_attr {"links_neutron"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "subnets_details_response"
to_var_names = table {
name = "subnets"
col_names = "subnet_id","subnet_name","network_id","project_id","enable_dhcp","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "subnet_id"
xpath = "/root/subnets/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "subnet_name"
xpath = "/root/subnets/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/subnets/network_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_id"
xpath = "/root/subnets/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "enable_dhcp"
xpath = "/root/subnets/enable_dhcp/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/subnets/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse the Subnets "
if {
condition = all {
is_not_empty {get_attr {"links_neutron"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "subnets_details_response"
to_var_names = table {
name = "subnets"
col_names = "subnet_id","subnet_name","network_id","project_id","enable_dhcp","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "subnet_id"
xpath = "/root/subnet/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "subnet_name"
xpath = "/root/subnet/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "network_id"
xpath = "/root/subnet/network_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_id"
xpath = "/root/subnet/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "enable_dhcp"
xpath = "/root/subnet/enable_dhcp/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/subnet/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out regions without subnets"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = is_not_empty {get_attr {"subnets"}}
on_true = filter {
src_table_name = "subnets"
target_table_name = "subnets"
condition = is_not_empty {get_attr {"subnets[].subnet_id"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Subnets description" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"subnets"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "subnets_details_response"
to_var_names = table {
name = "subnets_description" // Script execution: Custom script to perform a specific action or collect data
col_names = "subnet_id","subnet_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "subnet_id"
xpath = "/root/subnets/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "subnet_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/subnets/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Subnets description" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"subnets"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "subnets_details_response"
to_var_names = table {
name = "subnets_description" // Script execution: Custom script to perform a specific action or collect data
col_names = "subnet_id","subnet_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "subnet_id"
xpath = "/root/subnet/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "subnet_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/subnet/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add Subnet description to the subnets table" // Script execution: Custom script to perform a specific action or collect data
if {
condition = is_not_empty {get_attr {"subnets_description"}} // Script execution: Custom script to perform a specific action or collect data
on_true = merge {
table1_name = "subnets"
key1_name = "subnet_id"
table2_name = "subnets_description" // Script execution: Custom script to perform a specific action or collect data
key2_name = "subnet_id"
result_table_name = "subnets"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"subnets"}}
}
on_true = filter {
src_table_name = "subnets"
target_table_name = "subnets"
condition = eq {
get_attr {"subnets[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray() // Script execution: Custom script to perform a specific action or collect data
var length = ldc.length
var region = ${subnets[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_cloud_subnet table"
if {
condition = is_not_empty {get_attr {"subnets"}}
on_true = transform {
src_table_name = "subnets"
target_table_name = "cmdb_ci_cloud_subnet"
operation {
set_field {
field_name = "object_id"
value = get_attr {"subnets[].subnet_id"}
}
set_field {
field_name = "name"
value = get_attr {"subnets[].subnet_name"}
}
set_field {
field_name = "short_description" // Script execution: Custom script to perform a specific action or collect data
value = get_attr {"subnets_description[].subnet_description"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "is_dhcp_enabled"
value = get_attr {"subnets[].enable_dhcp"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Populate cmdb_ci_network table"
comment = "populate only the network object_id, as this would be required for identification. The other network details will be updated by network pattern."
if {
condition = all {
is_not_empty {get_attr {"subnets"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = transform {
src_table_name = "subnets"
target_table_name = "cmdb_ci_network"
operation {set_field {
field_name = "object_id"
value = get_attr {"subnets[].subnet_id"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_cloud_subnet and cmdb_ci_network table"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_cloud_subnet"}}
is_not_empty {get_attr {"cmdb_ci_network"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_network"
key1_name = "network_id"
table2_name = "cmdb_ci_cloud_subnet"
key2_name = "network_id"
result_table_name = "network_to_subnet"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
HP-UX - Network | I would like for you to help me build a Pattern that helps achieve Discovery of HP-UX - Network. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "HP-UX - Network"
id = "f4c270779fa032001d753758442e70fb"
description = ""
step {
name = "Get interfaces"
comment = "Excluding asterix, as the presents of it after name indicates that the interface is down. According to Vendor documentation."
runcmd_to_var {
cmd = "/usr/bin/netstat -in | grep -v Name | awk '{print $1}' | sort | uniq"
var_names = table {
name = "Interfaces"
col_names = "name"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "[*]"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Parse interfaces for easy extraction of IPs"
if {
condition = is_not_empty {get_attr {"Interfaces[1].name"}}
on_true = set_attr {
"IpAddress"
eval {"javascript: rtrn = \"\";
var table = ${Interfaces};
for (var i=0; i < table.size(); i++)
{
var row = table.get(i);
var unField = row.get(\"name\");
rtrn += \"ifconfig \" + unField + \"; \";
}"}
}
on_false = nop {}
}
}
step {
name = "Get IP addresses"
runcmd_to_var {
cmd = get_attr {"IpAddress"}
var_names = table {
name = "AdaptersIP"
col_names = "ip","netmask"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "inet"
delimiters = " "
selected_positions = 2,4
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Merge IPs and interfaces to create adapters"
set_attr {
"adaptersSheet"
concat {
get_attr {"Interfaces[*].name"}
";"
get_attr {"AdaptersIP[*].ip"}
";"
get_attr {"AdaptersIP[*].netmask"}
}
}
}
step {
name = "Parse relevant data for each adapter"
parse_var_to_var {
from_var_name = "adaptersSheet"
to_var_names = table {
name = "NetworkAdapters"
col_names = "name","ip","mask"
}
parsing_strategy = delimited_parsing {
delimiters = ";"
selected_positions = 1,2,3
}
if_not_found_do = nop {}
}
}
step {
name = "Get MAC"
runcmd_to_var {
cmd = "lanscan -ia"
var_names = table {
name = "Mac"
col_names = "mac","adapter"
}
parsing_strategy = delimited_parsing {
delimiters = " "
selected_positions = 1,2
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Set IpAddresses"
if {
condition = is_not_empty {get_attr {"NetworkAdapters"}}
on_true = filter {
src_table_name = "NetworkAdapters"
target_table_name = "IpAddresses"
condition = all {
neq {
get_attr {"NetworkAdapters[].ip"}
"127.0.0.1"
}
neq {
get_attr {"NetworkAdapters[].ip"}
"0.0.0.0"
}
neq {
get_attr {"NetworkAdapters[].ip"}
"255.255.255.255"
}
}
}
on_false = nop {}
}
}
step {
name = "Remove lines that doesn't represent an IP"
filter {
src_table_name = "IpAddresses"
target_table_name = "IpAddresses"
condition = all {
is_not_empty {get_attr {"IpAddresses[].ip"}}
is_not_empty {get_attr {"IpAddresses[].mask"}}
}
}
}
step {
name = "Update cmdb_ci_ip_address"
comment = "From HP documentation, a colon after the interface name delineates a logical interface. The documentation states that \"the TCP/IP protocol stack supports multiple logical interfaces per LAN interface. They are configured with the \"ifconfig\" command. For example:
ifconfig lan0:1 IPaddr1 netmask
ifconfig lan0:2 IPaddr2 netmask
In the above example 'lan0' is the interface name, whereas '1' indicates the first logical interface and '2' indicates the second logical interface associated with lan0.\" Therefore, this step will add all logical interfaces to the same adapter in order to avoid missing IP addresses."
transform {
src_table_name = "IpAddresses"
target_table_name = "cmdb_ci_ip_address"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"IpAddresses[].ip"}
}
set_field {
field_name = "netmask"
value = get_attr {"IpAddresses[].mask"}
}
set_field {
field_name = "ip_version"
value = "4"
}
set_field {
field_name = "name"
value = eval {"javascript: var name = ${IpAddresses[].name};
if(name){
name = name.split(\":\")[0];
}"}
}
}
}
}
step {
name = "Remove duplicate cmdb_ci_ip_address"
set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_ip_address},[\"ip_address\",\"netmask\"]);
CTX.setAttribute(\"cmdb_ci_ip_address\", tableWithoutDuplicates);"}
}
}
step {
name = "Merge adapters with MACs"
merge {
table1_name = "NetworkAdapters"
key1_name = "name"
table2_name = "Mac"
key2_name = "adapter"
result_table_name = "NetworkAdapters"
unmatched_lines = remove
}
}
step {
name = "Filter adapters table"
comment = "Filtering network adapters with empty identifying attributes."
filter {
src_table_name = "NetworkAdapters"
target_table_name = "NetworkAdapters"
condition = all {
is_not_empty {get_attr {"NetworkAdapters[].ip"}}
is_not_empty {get_attr {"NetworkAdapters[].mac"}}
is_not_empty {get_attr {"NetworkAdapters[].name"}}
}
}
}
step {
name = "Update cmdb_ci_network_adapter"
if {
condition = is_not_empty {get_attr {"NetworkAdapters"}}
on_true = transform {
src_table_name = "NetworkAdapters"
target_table_name = "cmdb_ci_network_adapter"
operation {
set_field {
field_name = "name"
value = get_attr {"NetworkAdapters[].name"}
}
set_field {
field_name = "ip_address"
value = get_attr {"NetworkAdapters[].ip"}
}
set_field {
field_name = "mac_address"
value = eval {"javascript: rtrn = \"\";
var mac = ${NetworkAdapters[].mac};
var macspl = mac.split('x');
var macStr = macspl[1].toString();
for (var i = 0; i < macStr.length; i += 2)
{
if (i == macStr.length - 2)
{
rtrn += macStr[i] + macStr[i+1];
}
else
{
rtrn += macStr[i] + macStr[i+1] + \":\";
}
}
"}
}
set_field {
field_name = "netmask"
value = get_attr {"NetworkAdapters[].mask"}
}
}
}
on_false = nop {}
}
}
step {
name = "Remove duplicate cmdb_ci_network_adapter"
set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_network_adapter},[\"name\",\"mac_address\"]);
CTX.setAttribute(\"cmdb_ci_network_adapter\", tableWithoutDuplicates);"}
}
}
step {
name = "Ref/Rel between cmdb_ci_ip_address and cmdb_ci_network_adapter"
relation_reference {
table1_name = "cmdb_ci_ip_address"
key1_name = "name"
table2_name = "cmdb_ci_network_adapter"
key2_name = "name"
result_table_name = "ip_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "nic"
}
}
step {
name = "Ref/Rel between cmdb_ci_network_adapter and HPUX CI"
relation_reference {
table1_name = "cmdb_ci_hpux_server"
table2_name = "cmdb_ci_network_adapter"
result_table_name = "ci_to_nic"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
step {
name = "Ref/Rel between cmdb_ci_ip_address and HPUX CI"
relation_reference {
table1_name = "cmdb_ci_hpux_server"
table2_name = "cmdb_ci_ip_address"
result_table_name = "lix_ip_rel"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = parentToChild
}
}
step {
name = "Update dscy_router_interface"
transform {
src_table_name = "cmdb_ci_network_adapter"
target_table_name = "dscy_router_interface"
operation {
set_field {
field_name = "name"
value = get_attr {"cmdb_ci_network_adapter[].name"}
}
set_field {
field_name = "ip_address"
value = get_attr {"cmdb_ci_network_adapter[].ip_address"}
}
set_field {
field_name = "mac_address"
value = get_attr {"cmdb_ci_network_adapter[].mac_address"}
}
}
}
}
step {
name = "Ref/Rel between dscy_router_interface and HPUX CI"
relation_reference {
table1_name = "cmdb_ci_hpux_server"
table2_name = "dscy_router_interface"
result_table_name = "aix_to_ri"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
}
| library {
name = "HP-UX - Network"
id = "f4c270779fa032001d753758442e70fb" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get interfaces"
comment = "Excluding asterix, as the presents of it after name indicates that the interface is down. According to Vendor documentation."
runcmd_to_var {
cmd = "/usr/bin/netstat -in | grep -v Name | awk '{print $1}' | sort | uniq"
var_names = table {
name = "Interfaces"
col_names = "name"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "[*]"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse interfaces for easy extraction of IPs"
if {
condition = is_not_empty {get_attr {"Interfaces[1].name"}}
on_true = set_attr {
"IpAddress"
eval {"javascript: rtrn = \"\"; // Script execution: Custom script to perform a specific action or collect data
var table = ${Interfaces};
for (var i=0; i < table.size(); i++)
{
var row = table.get(i);
var unField = row.get(\"name\");
rtrn += \"ifconfig \" + unField + \"; \";
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get IP addresses"
runcmd_to_var {
cmd = get_attr {"IpAddress"}
var_names = table {
name = "AdaptersIP"
col_names = "ip","netmask"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "inet"
delimiters = " "
selected_positions = 2,4
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge IPs and interfaces to create adapters"
set_attr {
"adaptersSheet"
concat {
get_attr {"Interfaces[*].name"}
";"
get_attr {"AdaptersIP[*].ip"}
";"
get_attr {"AdaptersIP[*].netmask"}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse relevant data for each adapter"
parse_var_to_var {
from_var_name = "adaptersSheet"
to_var_names = table {
name = "NetworkAdapters"
col_names = "name","ip","mask"
}
parsing_strategy = delimited_parsing {
delimiters = ";"
selected_positions = 1,2,3
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get MAC"
runcmd_to_var {
cmd = "lanscan -ia"
var_names = table {
name = "Mac"
col_names = "mac","adapter"
}
parsing_strategy = delimited_parsing {
delimiters = " "
selected_positions = 1,2
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set IpAddresses"
if {
condition = is_not_empty {get_attr {"NetworkAdapters"}}
on_true = filter {
src_table_name = "NetworkAdapters"
target_table_name = "IpAddresses"
condition = all {
neq {
get_attr {"NetworkAdapters[].ip"}
"127.0.0.1"
}
neq {
get_attr {"NetworkAdapters[].ip"}
"0.0.0.0"
}
neq {
get_attr {"NetworkAdapters[].ip"}
"255.255.255.255"
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove lines that doesn't represent an IP"
filter {
src_table_name = "IpAddresses"
target_table_name = "IpAddresses"
condition = all {
is_not_empty {get_attr {"IpAddresses[].ip"}}
is_not_empty {get_attr {"IpAddresses[].mask"}}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_ip_address"
comment = "From HP documentation, a colon after the interface name delineates a logical interface. The documentation states that \"the TCP/IP protocol stack supports multiple logical interfaces per LAN interface. They are configured with the \"ifconfig\" command. For example:
ifconfig lan0:1 IPaddr1 netmask
ifconfig lan0:2 IPaddr2 netmask
In the above example 'lan0' is the interface name, whereas '1' indicates the first logical interface and '2' indicates the second logical interface associated with lan0.\" Therefore, this step will add all logical interfaces to the same adapter in order to avoid missing IP addresses." // Step definition: Represents a single action or set of actions in the pattern
transform {
src_table_name = "IpAddresses"
target_table_name = "cmdb_ci_ip_address"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"IpAddresses[].ip"}
}
set_field {
field_name = "netmask"
value = get_attr {"IpAddresses[].mask"}
}
set_field {
field_name = "ip_version"
value = "4"
}
set_field {
field_name = "name"
value = eval {"javascript: var name = ${IpAddresses[].name}; // Script execution: Custom script to perform a specific action or collect data
if(name){
name = name.split(\":\")[0];
}"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate cmdb_ci_ip_address"
set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_ip_address},[\"ip_address\",\"netmask\"]);
CTX.setAttribute(\"cmdb_ci_ip_address\", tableWithoutDuplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge adapters with MACs"
merge {
table1_name = "NetworkAdapters"
key1_name = "name"
table2_name = "Mac"
key2_name = "adapter"
result_table_name = "NetworkAdapters"
unmatched_lines = remove
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter adapters table"
comment = "Filtering network adapters with empty identifying attributes." // Attribute collection: Collects specific attributes from the discovered CI
filter {
src_table_name = "NetworkAdapters"
target_table_name = "NetworkAdapters"
condition = all {
is_not_empty {get_attr {"NetworkAdapters[].ip"}}
is_not_empty {get_attr {"NetworkAdapters[].mac"}}
is_not_empty {get_attr {"NetworkAdapters[].name"}}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_network_adapter"
if {
condition = is_not_empty {get_attr {"NetworkAdapters"}}
on_true = transform {
src_table_name = "NetworkAdapters"
target_table_name = "cmdb_ci_network_adapter"
operation {
set_field {
field_name = "name"
value = get_attr {"NetworkAdapters[].name"}
}
set_field {
field_name = "ip_address"
value = get_attr {"NetworkAdapters[].ip"}
}
set_field {
field_name = "mac_address"
value = eval {"javascript: rtrn = \"\"; // Script execution: Custom script to perform a specific action or collect data
var mac = ${NetworkAdapters[].mac};
var macspl = mac.split('x');
var macStr = macspl[1].toString();
for (var i = 0; i < macStr.length; i += 2)
{
if (i == macStr.length - 2)
{
rtrn += macStr[i] + macStr[i+1];
}
else
{
rtrn += macStr[i] + macStr[i+1] + \":\";
}
}
"}
}
set_field {
field_name = "netmask"
value = get_attr {"NetworkAdapters[].mask"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate cmdb_ci_network_adapter"
set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_network_adapter},[\"name\",\"mac_address\"]);
CTX.setAttribute(\"cmdb_ci_network_adapter\", tableWithoutDuplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between cmdb_ci_ip_address and cmdb_ci_network_adapter"
relation_reference {
table1_name = "cmdb_ci_ip_address"
key1_name = "name"
table2_name = "cmdb_ci_network_adapter"
key2_name = "name"
result_table_name = "ip_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "nic"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between cmdb_ci_network_adapter and HPUX CI"
relation_reference {
table1_name = "cmdb_ci_hpux_server"
table2_name = "cmdb_ci_network_adapter"
result_table_name = "ci_to_nic"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between cmdb_ci_ip_address and HPUX CI"
relation_reference {
table1_name = "cmdb_ci_hpux_server"
table2_name = "cmdb_ci_ip_address"
result_table_name = "lix_ip_rel"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = parentToChild
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update dscy_router_interface"
transform {
src_table_name = "cmdb_ci_network_adapter"
target_table_name = "dscy_router_interface"
operation {
set_field {
field_name = "name"
value = get_attr {"cmdb_ci_network_adapter[].name"}
}
set_field {
field_name = "ip_address"
value = get_attr {"cmdb_ci_network_adapter[].ip_address"}
}
set_field {
field_name = "mac_address"
value = get_attr {"cmdb_ci_network_adapter[].mac_address"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between dscy_router_interface and HPUX CI"
relation_reference {
table1_name = "cmdb_ci_hpux_server"
table2_name = "dscy_router_interface"
result_table_name = "aix_to_ri"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
}
|
Gather the Network Information for A10 | I would like for you to help me build a Pattern that helps achieve Discovery of Gather the Network Information for A10. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Gather the Network Information for A10"
id = "f5a5b2160ba8030041490d2835673aa8"
description = "null"
step {
name = "Get IPv4 Table"
runcmd_to_var {
cmd = "show ip interfaces"
var_names = table {
name = "IPv4_table"
col_names = "port","ip_address","netmask","primaryIP","name"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = " IP Netmask PrimaryIP Name|--------------------------------"
delimiters = " ","
"
selected_positions = 1,2,3,4,5
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Get IPv6 Table"
runcmd_to_var {
cmd = "show ipv6 interfaces"
var_names = table {
name = "IPv6_table"
col_names = "port","ip_address","prefix_len","scope","type"
}
parsing_strategy = regex_parsing {regex = "(\\d+)\\s+(.*)\\/(\\d+)\\s*(\\w+)\\s*(\\w+)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Get eth_info_table from stats"
transform {
src_table_name = "IPv4_table"
target_table_name = "IPv4_table"
operation {set_field {
field_name = "eth_info_table"
value = eval {"javascript:
var port_num = CTX.getAttribute(\"IPv4_table[].port\");
var ip_address = CTX.getAttribute(\"IPv4_table[].ip_address\");
if (!isNaN(port_num)){
var command= \"show statistics interface ethernet \" + port_num +\" | include \" + ip_address
var response=CTX.getCommandManager().shellCommand(command, false, null, null, CTX);
rtrn = response
rtrn;
}"}
}}
}
}
step {
name = "Parse mac_address and link status"
parse_var_to_var {
from_var_name = "IPv4_table[*].eth_info_table"
to_var_names = table {
name = "macs_table"
col_names = "operational_status","mac_address"
}
parsing_strategy = regex_parsing {regex = ".*(Up|Down|Disabled).*([0-9a-fA-F]{4}\\.[0-9a-fA-F]{4}\\.[0-9a-fA-F]{4})"}
if_not_found_do = nop {}
}
}
step {
name = "Set mac_adderss at IPv4_table"
merge {
table1_name = "macs_table"
table2_name = "IPv4_table"
result_table_name = "IPv4_table"
unmatched_lines = keep
condition = contains {
get_attr {"IPv4_table[].eth_info_table"}
get_attr {"macs_table[].mac_address"}
}
}
}
step {
name = "Filter the IF table"
filter {
src_table_name = "IPv4_table"
target_table_name = "IPv4_table"
condition = any {
not_starts_with {
"127"
get_attr {"IPv4_table[].ip_address"}
}
not_starts_with {
"0"
get_attr {"IPv4_table[].ip_address"}
}
eq {
get_attr {"IPv4_table[].operational_status"}
"1"
}
}
}
}
step {
name = "Change the MAC address format"
comment = "A script which modify the mac address format from xxxx.xxxx.xxxx
to format of xx:xx:xx:xx:xx:xx."
transform {
src_table_name = "IPv4_table"
target_table_name = "IPv4_table"
operation {set_field {
field_name = "mac_address"
value = eval {"javascript:
var mac = ${IPv4_table[].mac_address};
var i;
var rtrn;
if (mac){
mac=mac.replace(/\\./g,\"\");
mac_array = mac.match(/../g);
rtrn=mac_array.join(\":\");
}"}
}}
}
}
step {
name = "Set Network Adapter"
transform {
src_table_name = "IPv4_table"
target_table_name = "cmdb_ci_network_adapter"
operation {
set_field {
field_name = "operational_status"
value = eval {"javascript:
var rtrn = '';
var oper_status = ${IPv4_table[].operational_status};
oper_status=(oper_status == 'Up' || !oper_status) ? 1 : 2; rtrn = oper_status; "}
}
set_field {
field_name = "mac_address"
value = get_attr {"IPv4_table[].mac_address"}
}
set_field {
field_name = "alias"
value = get_attr {"IPv4_table[].port"}
}
set_field {
field_name = "ip_address"
value = get_attr {"IPv4_table[].ip_address"}
}
set_field {
field_name = "name"
value = eval {"javascript:
var port=${IPv4_table[].port};
var rtrn;
if (!isNaN(port)){
rtrn=\"Ethernet \" + port;
}else{
rtrn=port;
}
"}
}
set_field {
field_name = "netmask"
value = get_attr {"IPv4_table[].netmask"}
}
set_field {
field_name = "primaryIP"
value = get_attr {"IPv4_table[].primaryIP"}
}
}
}
}
step {
name = "Set IP Address"
transform {
src_table_name = "IPv4_table"
target_table_name = "cmdb_ci_ip_address"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"IPv4_table[].ip_address"}
}
set_field {
field_name = "netmask"
value = get_attr {"IPv4_table[].netmask"}
}
set_field {
field_name = "version"
value = "4"
}
set_field {
field_name = "operational_status"
value = eval {"javascript:
var rtrn = '';
var oper_status = ${IPv4_table[].operational_status};
oper_status=(oper_status == 'Up' || !oper_status) ? 1 : 2; rtrn = oper_status; "}
}
}
}
}
step {
name = "Ref/Rel between IP and Nic"
relation_reference {
table1_name = "cmdb_ci_ip_address"
key1_name = "ip_address"
table2_name = "cmdb_ci_network_adapter"
key2_name = "ip_address"
result_table_name = "ip_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "nic"
}
}
step {
name = "Ref/Rel between NIC and A10"
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "cmdb_ci_network_adapter"
result_table_name = "A10_to_nic"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
step {
name = "Ref/Rel between IP and A10"
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "cmdb_ci_ip_address"
result_table_name = "ip_to_lb"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Owns::Owned by"
ref_direction = parentToChild
ref_field_name = ""
}
}
step {
name = "Ref/Rel between LB and RI"
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "dscy_router_interface"
result_table_name = "big_to_rout"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Uses::Used by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
step {
name = "Set LB Interface"
transform {
src_table_name = "IPv4_table"
target_table_name = "cmdb_ci_lb_interface"
operation {
set_field {
field_name = "name"
value = eval {"javascript:
var port=${IPv4_table[].port};
var rtrn;
if (!isNaN(port)){
rtrn=\"Ethernet \" + port;
}else{
rtrn=port;
}"}
}
set_field {
field_name = "mac_address"
value = get_attr {"IPv4_table[].mac_address"}
}
set_field {
field_name = "operational_status"
value = eval {"javascript:
var rtrn = '';
var oper_status = ${IPv4_table[].operational_status};
oper_status=(oper_status == 'Up' || !oper_status) ? 1 : 2;
rtrn = oper_status; "}
}
}
}
}
step {
name = "Ref/Rel between LB Interface and A10"
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "cmdb_ci_lb_interface"
result_table_name = "lbif_to_a10"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "load_balancer"
}
}
}
| library {
name = "Gather the Network Information for A10"
id = "f5a5b2160ba8030041490d2835673aa8" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get IPv4 Table"
runcmd_to_var {
cmd = "show ip interfaces"
var_names = table {
name = "IPv4_table"
col_names = "port","ip_address","netmask","primaryIP","name"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = " IP Netmask PrimaryIP Name|--------------------------------"
delimiters = " ","
"
selected_positions = 1,2,3,4,5
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get IPv6 Table"
runcmd_to_var {
cmd = "show ipv6 interfaces"
var_names = table {
name = "IPv6_table"
col_names = "port","ip_address","prefix_len","scope","type"
}
parsing_strategy = regex_parsing {regex = "(\\d+)\\s+(.*)\\/(\\d+)\\s*(\\w+)\\s*(\\w+)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get eth_info_table from stats"
transform {
src_table_name = "IPv4_table"
target_table_name = "IPv4_table"
operation {set_field {
field_name = "eth_info_table"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var port_num = CTX.getAttribute(\"IPv4_table[].port\");
var ip_address = CTX.getAttribute(\"IPv4_table[].ip_address\");
if (!isNaN(port_num)){
var command= \"show statistics interface ethernet \" + port_num +\" | include \" + ip_address
var response=CTX.getCommandManager().shellCommand(command, false, null, null, CTX);
rtrn = response
rtrn;
}"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse mac_address and link status"
parse_var_to_var {
from_var_name = "IPv4_table[*].eth_info_table"
to_var_names = table {
name = "macs_table"
col_names = "operational_status","mac_address"
}
parsing_strategy = regex_parsing {regex = ".*(Up|Down|Disabled).*([0-9a-fA-F]{4}\\.[0-9a-fA-F]{4}\\.[0-9a-fA-F]{4})"}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set mac_adderss at IPv4_table"
merge {
table1_name = "macs_table"
table2_name = "IPv4_table"
result_table_name = "IPv4_table"
unmatched_lines = keep
condition = contains {
get_attr {"IPv4_table[].eth_info_table"}
get_attr {"macs_table[].mac_address"}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter the IF table"
filter {
src_table_name = "IPv4_table"
target_table_name = "IPv4_table"
condition = any {
not_starts_with {
"127"
get_attr {"IPv4_table[].ip_address"}
}
not_starts_with {
"0"
get_attr {"IPv4_table[].ip_address"}
}
eq {
get_attr {"IPv4_table[].operational_status"}
"1"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Change the MAC address format"
comment = "A script which modify the mac address format from xxxx.xxxx.xxxx // Script execution: Custom script to perform a specific action or collect data
to format of xx:xx:xx:xx:xx:xx."
transform {
src_table_name = "IPv4_table"
target_table_name = "IPv4_table"
operation {set_field {
field_name = "mac_address"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var mac = ${IPv4_table[].mac_address};
var i;
var rtrn;
if (mac){
mac=mac.replace(/\\./g,\"\");
mac_array = mac.match(/../g);
rtrn=mac_array.join(\":\");
}"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set Network Adapter"
transform {
src_table_name = "IPv4_table"
target_table_name = "cmdb_ci_network_adapter"
operation {
set_field {
field_name = "operational_status"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
var oper_status = ${IPv4_table[].operational_status};
oper_status=(oper_status == 'Up' || !oper_status) ? 1 : 2; rtrn = oper_status; "}
}
set_field {
field_name = "mac_address"
value = get_attr {"IPv4_table[].mac_address"}
}
set_field {
field_name = "alias"
value = get_attr {"IPv4_table[].port"}
}
set_field {
field_name = "ip_address"
value = get_attr {"IPv4_table[].ip_address"}
}
set_field {
field_name = "name"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var port=${IPv4_table[].port};
var rtrn;
if (!isNaN(port)){
rtrn=\"Ethernet \" + port;
}else{
rtrn=port;
}
"}
}
set_field {
field_name = "netmask"
value = get_attr {"IPv4_table[].netmask"}
}
set_field {
field_name = "primaryIP"
value = get_attr {"IPv4_table[].primaryIP"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set IP Address"
transform {
src_table_name = "IPv4_table"
target_table_name = "cmdb_ci_ip_address"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"IPv4_table[].ip_address"}
}
set_field {
field_name = "netmask"
value = get_attr {"IPv4_table[].netmask"}
}
set_field {
field_name = "version"
value = "4"
}
set_field {
field_name = "operational_status"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
var oper_status = ${IPv4_table[].operational_status};
oper_status=(oper_status == 'Up' || !oper_status) ? 1 : 2; rtrn = oper_status; "}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between IP and Nic"
relation_reference {
table1_name = "cmdb_ci_ip_address"
key1_name = "ip_address"
table2_name = "cmdb_ci_network_adapter"
key2_name = "ip_address"
result_table_name = "ip_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "nic"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between NIC and A10"
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "cmdb_ci_network_adapter"
result_table_name = "A10_to_nic"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between IP and A10"
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "cmdb_ci_ip_address"
result_table_name = "ip_to_lb"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Owns::Owned by"
ref_direction = parentToChild
ref_field_name = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between LB and RI"
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "dscy_router_interface"
result_table_name = "big_to_rout"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Uses::Used by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set LB Interface"
transform {
src_table_name = "IPv4_table"
target_table_name = "cmdb_ci_lb_interface"
operation {
set_field {
field_name = "name"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var port=${IPv4_table[].port};
var rtrn;
if (!isNaN(port)){
rtrn=\"Ethernet \" + port;
}else{
rtrn=port;
}"}
}
set_field {
field_name = "mac_address"
value = get_attr {"IPv4_table[].mac_address"}
}
set_field {
field_name = "operational_status"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
var oper_status = ${IPv4_table[].operational_status};
oper_status=(oper_status == 'Up' || !oper_status) ? 1 : 2;
rtrn = oper_status; "}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between LB Interface and A10"
relation_reference {
table1_name = "cmdb_ci_lb_a10"
table2_name = "cmdb_ci_lb_interface"
result_table_name = "lbif_to_a10"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "load_balancer"
}
}
}
|
NIC Tags | I would like for you to help me build a Pattern that helps achieve Discovery of NIC Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "NIC Tags"
id = "f5d11713dbf280109149f2131f9619aa"
description = "NIC Tags"
step {
name = "parse tags"
parse_var_to_var {
from_var_name = "nic_resp"
to_var_names = table {
name = "cmdb_key_value"
col_names = "key","value","object_id"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeNetworkInterfacesResponse"
fields {
field {
col_name = "key"
xpath = "/DescribeNetworkInterfacesResponse/networkInterfaceSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeNetworkInterfacesResponse/networkInterfaceSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "object_id"
xpath = "/DescribeNetworkInterfacesResponse/networkInterfaceSet/item/networkInterfaceId/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "filter out tags without values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Create reference between NIC and Tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_nic"
key2_name = "object_id"
result_table_name = "key_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "NIC Tags"
id = "f5d11713dbf280109149f2131f9619aa" // Unique identifier for the pattern
description = "NIC Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "parse tags"
parse_var_to_var {
from_var_name = "nic_resp"
to_var_names = table {
name = "cmdb_key_value"
col_names = "key","value","object_id"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeNetworkInterfacesResponse"
fields {
field {
col_name = "key"
xpath = "/DescribeNetworkInterfacesResponse/networkInterfaceSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeNetworkInterfacesResponse/networkInterfaceSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "object_id"
xpath = "/DescribeNetworkInterfacesResponse/networkInterfaceSet/item/networkInterfaceId/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter out tags without values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference between NIC and Tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_nic"
key2_name = "object_id"
result_table_name = "key_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Get Object Id For GCP Linux Server | I would like for you to help me build a Pattern that helps achieve Discovery of Get Object Id For GCP Linux Server. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Get Object Id For GCP Linux Server"
id = "f601b0c087f37c1072a131173cbb3594"
description = "Get Object Id For GCP Linux Server"
step {
name = "Create isGCP variable"
if {
condition = contains {
get_attr {"cmdb_ci_linux_server[*].manufacturer"}
"Google"
}
on_true = set_attr {
"isGCP"
"true"
}
on_false = nop {}
}
}
step {
name = "Get Object ID"
if {
condition = eq {
get_attr {"isGCP"}
"true"
}
on_true = runcmd_to_var {
cmd = "curl \"http://metadata.google.internal/computeMetadata/v1/instance/id?alt=json\" -H \"Metadata-Flavor: Google\"; echo"
execution_mode = "DEFAULT"
var_names = "gcp_object_id"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Failover get Object ID with elevated permissions"
if {
condition = all {
eq {
get_attr {"isGCP"}
"true"
}
is_empty {get_attr {"gcp_object_id"}}
is_not_empty {get_attr {"sudo"}}
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"sudo"}
" curl \"http://metadata.google.internal/computeMetadata/v1/instance/id?alt=json\" -H \"Metadata-Flavor: Google\"; echo"
}
execution_mode = "DEFAULT"
var_names = "gcp_object_id"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Set server as virtual"
if {
condition = eq {
get_attr {"isGCP"}
"true"
}
on_true = set_attr {
"cmdb_ci_linux_server[*].virtual"
"true"
}
on_false = nop {}
}
}
step {
name = "Set server object_id"
if {
condition = is_not_empty {get_attr {"gcp_object_id"}}
on_true = set_attr {
"cmdb_ci_linux_server[*].object_id"
get_attr {"gcp_object_id"}
}
on_false = nop {}
}
}
}
| library {
name = "Get Object Id For GCP Linux Server"
id = "f601b0c087f37c1072a131173cbb3594" // Unique identifier for the pattern
description = "Get Object Id For GCP Linux Server" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create isGCP variable"
if {
condition = contains {
get_attr {"cmdb_ci_linux_server[*].manufacturer"}
"Google"
}
on_true = set_attr {
"isGCP"
"true"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Object ID"
if {
condition = eq {
get_attr {"isGCP"}
"true"
}
on_true = runcmd_to_var {
cmd = "curl \"http://metadata.google.internal/computeMetadata/v1/instance/id?alt=json\" -H \"Metadata-Flavor: Google\"; echo" // Metadata section: Contains metadata information about the pattern
execution_mode = "DEFAULT"
var_names = "gcp_object_id"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Failover get Object ID with elevated permissions"
if {
condition = all {
eq {
get_attr {"isGCP"}
"true"
}
is_empty {get_attr {"gcp_object_id"}}
is_not_empty {get_attr {"sudo"}}
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"sudo"}
" curl \"http://metadata.google.internal/computeMetadata/v1/instance/id?alt=json\" -H \"Metadata-Flavor: Google\"; echo" // Metadata section: Contains metadata information about the pattern
}
execution_mode = "DEFAULT"
var_names = "gcp_object_id"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set server as virtual"
if {
condition = eq {
get_attr {"isGCP"}
"true"
}
on_true = set_attr {
"cmdb_ci_linux_server[*].virtual"
"true"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set server object_id"
if {
condition = is_not_empty {get_attr {"gcp_object_id"}}
on_true = set_attr {
"cmdb_ci_linux_server[*].object_id"
get_attr {"gcp_object_id"}
}
on_false = nop {}
}
}
}
|
Weblogic Enrich attributes | I would like for you to help me build a Pattern that helps achieve Discovery of Weblogic Enrich attributes. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Weblogic Enrich attributes"
id = "f60cbc2383e5411dae866e4bbefc3f96"
description = ""
step {
name = "run command to retrieve all Weblogic parameters Win"
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = runcmd_to_var {
cmd = concat {
"set CLASSPATH="
get_attr {"process.environmentVariables.CLASSPATH.value"}
" && "
get_attr {"process.executablePath"}
" "
"weblogic.Admin -username "
"$$username$$"
" -password "
"'$$password$$'"
" -url t3://localhost:"
get_attr {"entry_point.port"}
" query -pretty -pattern \"*:*\""
}
credentials = credentials {ciTypeId = "cmdb_ci_app_server_weblogic"}
var_names = table {
name = "extended_attr"
col_names = "key"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "--------","MBeanName:","URL:no attributes have been specified"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "run command to retrieve all Weblogic parameters Win if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"extended_attr"}}
}
on_true = runcmd_to_var {
cmd = concat {
"set CLASSPATH="
get_attr {"process.environmentVariables.CLASSPATH.value"}
" && "
get_attr {"process.executablePath"}
" "
"weblogic.Admin -username "
"$$username$$"
" -password "
"'$$password$$'"
" -url t3://localhost:"
get_attr {"entry_point.port"}
" xquery -pretty -pattern \"*:*\""
}
credentials = credentials {ciTypeId = "cmdb_ci_app_server_weblogic"}
var_names = table {
name = "extended_attr"
col_names = "key"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "--------","MBeanName:","URL:no attributes have been specified"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "run command to retrieve all Weblogic parameters Unix"
if {
condition = neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = runcmd_to_var {
cmd = concat {
"export CLASSPATH="
get_attr {"process.environmentVariables.CLASSPATH.value"}
" ; "
get_attr {"process.executablePath"}
" "
"weblogic.Admin -username "
"$$username$$"
" -password "
"'$$password$$'"
" -url t3://localhost:"
get_attr {"entry_point.port"}
" query -pretty -pattern \"*:*\""
}
credentials = credentials {ciTypeId = "cmdb_ci_app_server_weblogic"}
var_names = table {
name = "extended_attr"
col_names = "key"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "--------"," MBeanName:"," URL:no attributes have been specified"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "run command to retrieve all Weblogic parameters Unix if empty"
if {
condition = all {
neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"extended_attr"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export CLASSPATH="
get_attr {"process.environmentVariables.CLASSPATH.value"}
" ; "
get_attr {"process.executablePath"}
" "
"weblogic.Admin -username "
"$$username$$"
" -password "
"'$$password$$'"
" -url t3://localhost:"
get_attr {"entry_point.port"}
" xquery -pretty -pattern \"*:*\""
}
credentials = credentials {ciTypeId = "cmdb_ci_app_server_weblogic"}
var_names = table {
name = "extended_attr"
col_names = "key"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "--------"," MBeanName:"," URL:no attributes have been specified"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "parse extended_attr"
if {
condition = is_not_empty {get_attr {"extended_attr"}}
on_true = parse_var_to_var {
from_var_name = "extended_attr[*].key"
to_var_names = table {
name = "extended_attr"
col_names = "key","value"
}
parsing_strategy = delimited_parsing {
delimiters = ":"
selected_positions = 1,2
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "add source field"
transform {
src_table_name = "extended_attr"
target_table_name = "extended_attr"
operation {set_field {
field_name = "source"
value = "Java_Command"
}}
}
}
}
| library {
name = "Weblogic Enrich attributes" // Attribute collection: Collects specific attributes from the discovered CI
id = "f60cbc2383e5411dae866e4bbefc3f96" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "run command to retrieve all Weblogic parameters Win"
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = runcmd_to_var {
cmd = concat {
"set CLASSPATH="
get_attr {"process.environmentVariables.CLASSPATH.value"}
" && "
get_attr {"process.executablePath"}
" "
"weblogic.Admin -username "
"$$username$$"
" -password "
"'$$password$$'"
" -url t3://localhost:"
get_attr {"entry_point.port"}
" query -pretty -pattern \"*:*\""
}
credentials = credentials {ciTypeId = "cmdb_ci_app_server_weblogic"}
var_names = table {
name = "extended_attr"
col_names = "key"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "--------","MBeanName:","URL:no attributes have been specified" // Attribute collection: Collects specific attributes from the discovered CI
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "run command to retrieve all Weblogic parameters Win if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"extended_attr"}}
}
on_true = runcmd_to_var {
cmd = concat {
"set CLASSPATH="
get_attr {"process.environmentVariables.CLASSPATH.value"}
" && "
get_attr {"process.executablePath"}
" "
"weblogic.Admin -username "
"$$username$$"
" -password "
"'$$password$$'"
" -url t3://localhost:"
get_attr {"entry_point.port"}
" xquery -pretty -pattern \"*:*\""
}
credentials = credentials {ciTypeId = "cmdb_ci_app_server_weblogic"}
var_names = table {
name = "extended_attr"
col_names = "key"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "--------","MBeanName:","URL:no attributes have been specified" // Attribute collection: Collects specific attributes from the discovered CI
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "run command to retrieve all Weblogic parameters Unix"
if {
condition = neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = runcmd_to_var {
cmd = concat {
"export CLASSPATH="
get_attr {"process.environmentVariables.CLASSPATH.value"}
" ; "
get_attr {"process.executablePath"}
" "
"weblogic.Admin -username "
"$$username$$"
" -password "
"'$$password$$'"
" -url t3://localhost:"
get_attr {"entry_point.port"}
" query -pretty -pattern \"*:*\""
}
credentials = credentials {ciTypeId = "cmdb_ci_app_server_weblogic"}
var_names = table {
name = "extended_attr"
col_names = "key"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "--------"," MBeanName:"," URL:no attributes have been specified" // Attribute collection: Collects specific attributes from the discovered CI
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "run command to retrieve all Weblogic parameters Unix if empty"
if {
condition = all {
neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"extended_attr"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export CLASSPATH="
get_attr {"process.environmentVariables.CLASSPATH.value"}
" ; "
get_attr {"process.executablePath"}
" "
"weblogic.Admin -username "
"$$username$$"
" -password "
"'$$password$$'"
" -url t3://localhost:"
get_attr {"entry_point.port"}
" xquery -pretty -pattern \"*:*\""
}
credentials = credentials {ciTypeId = "cmdb_ci_app_server_weblogic"}
var_names = table {
name = "extended_attr"
col_names = "key"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "--------"," MBeanName:"," URL:no attributes have been specified" // Attribute collection: Collects specific attributes from the discovered CI
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "parse extended_attr"
if {
condition = is_not_empty {get_attr {"extended_attr"}}
on_true = parse_var_to_var {
from_var_name = "extended_attr[*].key"
to_var_names = table {
name = "extended_attr"
col_names = "key","value"
}
parsing_strategy = delimited_parsing {
delimiters = ":"
selected_positions = 1,2
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "add source field"
transform {
src_table_name = "extended_attr"
target_table_name = "extended_attr"
operation {set_field {
field_name = "source"
value = "Java_Command"
}}
}
}
}
|
Subnet Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Subnet Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Subnet Tags"
id = "f61d54d573a333008c51d6dcb7f6a722"
description = "Subnet Tags"
step {
name = "Create cmdb_key_value table"
transform {
src_table_name = "subnet_tags"
target_table_name = "cmdb_key_value"
operation {
set_field {
field_name = "object_id"
value = get_attr {"subnet_tags[].subnetid"}
}
set_field {
field_name = "key"
value = get_attr {"subnet_tags[].tag_key"}
}
set_field {
field_name = "value"
value = get_attr {"subnet_tags[].subnet_name"}
}
}
}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Create reference between Subnet and Tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_subnet"
key2_name = "object_id"
result_table_name = "key_to_subnet"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Subnet Tags"
id = "f61d54d573a333008c51d6dcb7f6a722" // Unique identifier for the pattern
description = "Subnet Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create cmdb_key_value table"
transform {
src_table_name = "subnet_tags"
target_table_name = "cmdb_key_value"
operation {
set_field {
field_name = "object_id"
value = get_attr {"subnet_tags[].subnetid"}
}
set_field {
field_name = "key"
value = get_attr {"subnet_tags[].tag_key"}
}
set_field {
field_name = "value"
value = get_attr {"subnet_tags[].subnet_name"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference between Subnet and Tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_subnet"
key2_name = "object_id"
result_table_name = "key_to_subnet"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
OpenStack - Get Storage Resources Tags | I would like for you to help me build a Pattern that helps achieve Discovery of OpenStack - Get Storage Resources Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "OpenStack - Get Storage Resources Tags"
id = "f18bfa471bb14010f3540f28cc4bcb3e"
description = "OpenStack - Get Storage Resources Tags"
step {
name = "Parse the Volumes tags"
if {
condition = is_not_empty {get_attr {"volumes"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack Get Storage Resources pattern.\");
var json_array = ${volumes_details_response}.toArray()
var new_table = new Packages.java.util.ArrayList();
for (i=0; i < json_array.length; i++ ) {
var json_root =JSON.parse(json_array[i])
if (json_root.volumes.length) {
try {
for (j = 0; j < json_root.volumes.length; j++){
var row = new Packages.java.util.HashMap();
var volumes_id = JSON.stringify(json_root.volumes[j].id)
volumes_id = volumes_id.replace(/\"/g,'');
// remove the quotes from the parsed values
var full_tag_json = JSON.stringify(json_root.volumes[j].metadata)
var colon = full_tag_json.indexOf(\":\")
// get only resources with assigned Tags recognizable by the presense of character colon \":\"
if(colon ) {
full_tag_json = full_tag_json.replace(/\"/g,'');
full_tag_json = full_tag_json.substring(1, full_tag_json.length-1)
// remove the first and last character from the string as they are always curly brackets {}
row.put(\"volume_uuid\",volumes_id);
row.put(\"full_tag_json\",full_tag_json);
new_table.add(row)
}
}
}
catch (e) {
logger.debug(\"generic parse API REST response failed. exception=\" + e);
}
}
CTX.setAttribute('volumes_tags', new_table);
}"}
}
on_false = nop {}
}
}
step {
name = " Split the Volumes Tags into unique values"
if {
condition = is_not_empty {get_attr {"volumes_tags"}}
on_true = set_attr {
"tmp"
eval {"javascript: var new_table = new Packages.java.util.ArrayList();
var resource_tags = ${volumes_tags[*].full_tag_json}
var resource_id = ${volumes_tags[*].volume_uuid}
var resource_count = resource_id.size()
for (i=0; i < resource_count; i++){
var resource_tag = resource_tags.get(i).split(\",\")
var length = resource_tag.length;
for (j=0; j <length; j++){
var row = new Packages.java.util.HashMap();
row.put(\"volume_uuid\",resource_id.get(i));
row.put(\"value\",resource_tag[j]);
new_table.add(row)
}
}
CTX.setAttribute('volumes_tags', new_table); "}
}
on_false = nop {}
}
}
step {
name = "Separate the key and value out of the full tag"
if {
condition = is_not_empty {get_attr {"volumes_tags"}}
on_true = transform {
src_table_name = "volumes_tags"
target_table_name = "volumes_tags"
operation {
set_field {
field_name = "key"
value = eval {"javascript: var full_tag = ${volumes_tags[].value}.toString()
if (full_tag.indexOf(\":\") > 0) {full_tag = full_tag.substring(0,full_tag.indexOf(\":\"))}
full_tag"}
}
set_field {
field_name = "value"
value = eval {"javascript: var full_tag = ${volumes_tags[].value}.toString()
if (full_tag.indexOf(\":\") > 0) {
full_tag = full_tag.substring(full_tag.indexOf(\":\")+1,full_tag.lastIndex)
}
else {
full_tag = ''
}
full_tag"}
}
}
}
on_false = nop {}
}
}
step {
name = "Add the Volumes tags to the cmdb_key_value table"
if {
condition = is_not_empty {get_attr {"volumes_tags"}}
on_true = union {
table1_name = "volumes_tags"
table2_name = "cmdb_key_value"
result_table_name = "cmdb_key_value"
}
on_false = nop {}
}
}
step {
name = "Filter empty rows in case of no tags and specific cmdb_key_value table behavior"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
on_false = nop {}
}
}
step {
name = "Create reference between cmdb_key_value and cmdb_ci_storage_volume tables"
if {
condition = is_not_empty {get_attr {"volumes_tags"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "volume_uuid"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "tags_to_volumes"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "OpenStack - Get Storage Resources Tags"
id = "f18bfa471bb14010f3540f28cc4bcb3e" // Unique identifier for the pattern
description = "OpenStack - Get Storage Resources Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Volumes tags"
if {
condition = is_not_empty {get_attr {"volumes"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack Get Storage Resources pattern.\"); // Script execution: Custom script to perform a specific action or collect data
var json_array = ${volumes_details_response}.toArray()
var new_table = new Packages.java.util.ArrayList();
for (i=0; i < json_array.length; i++ ) {
var json_root =JSON.parse(json_array[i])
if (json_root.volumes.length) {
try {
for (j = 0; j < json_root.volumes.length; j++){
var row = new Packages.java.util.HashMap();
var volumes_id = JSON.stringify(json_root.volumes[j].id) // Unique identifier for the pattern
volumes_id = volumes_id.replace(/\"/g,''); // Unique identifier for the pattern
// remove the quotes from the parsed values
var full_tag_json = JSON.stringify(json_root.volumes[j].metadata) // Metadata section: Contains metadata information about the pattern
var colon = full_tag_json.indexOf(\":\")
// get only resources with assigned Tags recognizable by the presense of character colon \":\"
if(colon ) {
full_tag_json = full_tag_json.replace(/\"/g,'');
full_tag_json = full_tag_json.substring(1, full_tag_json.length-1)
// remove the first and last character from the string as they are always curly brackets {}
row.put(\"volume_uuid\",volumes_id);
row.put(\"full_tag_json\",full_tag_json);
new_table.add(row)
}
}
}
catch (e) {
logger.debug(\"generic parse API REST response failed. exception=\" + e);
}
}
CTX.setAttribute('volumes_tags', new_table);
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = " Split the Volumes Tags into unique values"
if {
condition = is_not_empty {get_attr {"volumes_tags"}}
on_true = set_attr {
"tmp"
eval {"javascript: var new_table = new Packages.java.util.ArrayList(); // Script execution: Custom script to perform a specific action or collect data
var resource_tags = ${volumes_tags[*].full_tag_json}
var resource_id = ${volumes_tags[*].volume_uuid} // Unique identifier for the pattern
var resource_count = resource_id.size()
for (i=0; i < resource_count; i++){
var resource_tag = resource_tags.get(i).split(\",\")
var length = resource_tag.length;
for (j=0; j <length; j++){
var row = new Packages.java.util.HashMap();
row.put(\"volume_uuid\",resource_id.get(i));
row.put(\"value\",resource_tag[j]);
new_table.add(row)
}
}
CTX.setAttribute('volumes_tags', new_table); "}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Separate the key and value out of the full tag"
if {
condition = is_not_empty {get_attr {"volumes_tags"}}
on_true = transform {
src_table_name = "volumes_tags"
target_table_name = "volumes_tags"
operation {
set_field {
field_name = "key"
value = eval {"javascript: var full_tag = ${volumes_tags[].value}.toString() // Script execution: Custom script to perform a specific action or collect data
if (full_tag.indexOf(\":\") > 0) {full_tag = full_tag.substring(0,full_tag.indexOf(\":\"))}
full_tag"}
}
set_field {
field_name = "value"
value = eval {"javascript: var full_tag = ${volumes_tags[].value}.toString() // Script execution: Custom script to perform a specific action or collect data
if (full_tag.indexOf(\":\") > 0) {
full_tag = full_tag.substring(full_tag.indexOf(\":\")+1,full_tag.lastIndex)
}
else {
full_tag = ''
}
full_tag"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the Volumes tags to the cmdb_key_value table"
if {
condition = is_not_empty {get_attr {"volumes_tags"}}
on_true = union {
table1_name = "volumes_tags"
table2_name = "cmdb_key_value"
result_table_name = "cmdb_key_value"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter empty rows in case of no tags and specific cmdb_key_value table behavior"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference between cmdb_key_value and cmdb_ci_storage_volume tables"
if {
condition = is_not_empty {get_attr {"volumes_tags"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "volume_uuid"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "tags_to_volumes"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
IBM Cloud Virtual Server Network Storage | I would like for you to help me build a Pattern that helps achieve Discovery of IBM Cloud Virtual Server Network Storage. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "IBM Cloud Virtual Server Network Storage"
id = "f189b50fdb0323002eeb0726ca9619e5"
description = "null"
step {
name = "Parsing Out Network Storage Info"
if {
condition = is_not_empty {get_attr {"cmdb_ci_vm_instance[1].object_id"}}
on_true = parse_var_to_var {
from_var_name = "vm_json"
to_var_names = table {
name = "network_storage_tbl"
col_names = "type","object_id","name","ipAddress","mount_point","avail_zone"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "type"
xpath = "/root/result/allowedNetworkStorage/nasType/text()"
delimiters = ""
position = 1
}
field {
col_name = "object_id"
xpath = "/root/result/allowedNetworkStorage/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "name"
xpath = "/root/result/allowedNetworkStorage/username/text()"
delimiters = ""
position = 1
}
field {
col_name = "ipAddress"
xpath = "/root/result/allowedNetworkStorage/serviceResourceBackendIpAddress/text()"
delimiters = ""
position = 1
}
field {
col_name = "mount_point"
xpath = "/root/result/allowedNetworkStorage/fileNetworkMountAddress/text()"
delimiters = ""
position = 1
}
field {
col_name = "avail_zone"
xpath = "/root/result/datacenter/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Filter Out Empty Rows from Network Storage Table"
filter {
src_table_name = "network_storage_tbl"
target_table_name = "network_storage_tbl"
condition = is_not_empty {get_attr {"network_storage_tbl[].object_id"}}
}
}
step {
name = "Remove Duplicates from Network Storage Table"
set_attr {
"tmp"
eval {"javascript: var table_no_duplicates = '';
table_no_duplicates = DuplicateRemover.removeDuplicates(${network_storage_tbl},[\"object_id\"]);
CTX.setAttribute(\"network_storage_tbl\", table_no_duplicates);"}
}
}
step {
name = "Find Network Storage Region"
if {
condition = all {
is_not_empty {get_attr {"network_storage_tbl[1].object_id"}}
contains {
get_attr {"is_ldc"}
"true"
}
}
on_true = transform {
src_table_name = "network_storage_tbl"
target_table_name = "network_storage_tbl"
operation {set_field {
field_name = "region"
value = eval {"javascript: var az = ${network_storage_tbl[].avail_zone};
var rtrn = '';
rtrn = IbmCloudDcToRegion.convertDctoRegion(az);"}
}}
}
on_false = nop {}
}
}
step {
name = "Filter Network Storage by Region"
if {
condition = all {
is_not_empty {get_attr {"network_storage_tbl[1].object_id"}}
is_not_empty {get_attr {"is_ldc"}}
}
on_true = filter {
src_table_name = "network_storage_tbl"
target_table_name = "network_storage_tbl"
condition = contains {
get_attr {"ldc_list"}
get_attr {"network_storage_tbl[].region"}
}
}
on_false = nop {}
}
}
step {
name = "Fill storage_volume Table"
if {
condition = is_not_empty {get_attr {"network_storage_tbl[1].object_id"}}
on_true = transform {
src_table_name = "network_storage_tbl"
target_table_name = "cmdb_ci_storage_volume"
operation {set_field {
field_name = "object_id"
value = get_attr {"network_storage_tbl[].object_id"}
}}
}
on_false = nop {}
}
}
step {
name = "Filtering NAS storage"
if {
condition = contains {
get_attr {"network_storage_tbl[*].type"}
"NAS"
}
on_true = filter {
src_table_name = "network_storage_tbl"
target_table_name = "nas_storage_tbl"
condition = contains {
get_attr {"network_storage_tbl[].type"}
"NAS"
}
}
on_false = nop {}
}
}
step {
name = "Fill endpoint_nfs Table"
if {
condition = is_not_empty {get_attr {"nas_storage_tbl[1].object_id"}}
on_true = transform {
src_table_name = "nas_storage_tbl"
target_table_name = "cmdb_ci_endpoint_nfs"
operation {
set_field {
field_name = "object_id"
value = get_attr {"nas_storage_tbl[].object_id"}
}
set_field {
field_name = "storage_server_ip"
value = get_attr {"nas_storage_tbl[].ipAddress"}
}
set_field {
field_name = "mount_point"
value = get_attr {"nas_storage_tbl[].mount_point"}
}
set_field {
field_name = "guest_id"
value = get_attr {"nas_storage_tbl[].guest_id"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create Relations Between NFS EP and Storage Volume"
if {
condition = is_not_empty {get_attr {"cmdb_ci_endpoint_nfs[1].object_id"}}
on_true = relation_reference {
table1_name = "cmdb_ci_endpoint_nfs"
key1_name = "object_id"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "nfs_ep_to_volume"
unmatched_lines = remove
relation_type = "Implement End Point To::Implement End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create Relations Between VM Instance and NFS EP"
if {
condition = is_not_empty {get_attr {"cmdb_ci_endpoint_nfs[1].object_id"}}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
table2_name = "cmdb_ci_endpoint_nfs"
result_table_name = "instance_to_nas_EP"
unmatched_lines = remove
condition = eq {
eval {"javascript: var rtrn = '';
var vm_id = ${cmdb_ci_vm_instance[].object_id};
var vol_id = ${cmdb_ci_endpoint_nfs[].object_id};
var vmHashSet = ${VMStorageCache}.get(vm_id);
if (vmHashSet){
rtrn = vmHashSet.contains(vol_id);
}
else {
rtrn = 'false'
}"}
"true"
}
relation_type = "Use End Point To::Use End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Filtering ISCSI Storage"
if {
condition = contains {
get_attr {"network_storage_tbl[*].type"}
"ISCSI"
}
on_true = filter {
src_table_name = "network_storage_tbl"
target_table_name = "iscsi_storage_tbl"
condition = contains {
get_attr {"network_storage_tbl[].type"}
"ISCSI"
}
}
on_false = nop {}
}
}
step {
name = "Fill endpoint_iscsi Table"
if {
condition = is_not_empty {get_attr {"iscsi_storage_tbl[1].object_id"}}
on_true = transform {
src_table_name = "iscsi_storage_tbl"
target_table_name = "cmdb_ci_endpoint_iscsi"
operation {
set_field {
field_name = "object_id"
value = get_attr {"iscsi_storage_tbl[].object_id"}
}
set_field {
field_name = "name"
value = get_attr {"iscsi_storage_tbl[].name"}
}
set_field {
field_name = "storage_server_ip"
value = get_attr {"iscsi_storage_tbl[].ipAddress"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create Relations Between ISCSI EP and Storage Volume"
if {
condition = is_not_empty {get_attr {"cmdb_ci_endpoint_iscsi[1].object_id"}}
on_true = relation_reference {
table1_name = "cmdb_ci_endpoint_iscsi"
key1_name = "object_id"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "iscsi_ep_to_volume"
unmatched_lines = keep
relation_type = "Implement End Point To::Implement End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create Relations Between VM Instance and NFS EP"
if {
condition = is_not_empty {get_attr {"cmdb_ci_endpoint_nfs[1].object_id"}}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
table2_name = "cmdb_ci_endpoint_iscsi"
result_table_name = "instance_to_iscsi_EP"
unmatched_lines = remove
condition = eq {
eval {"javascript: var rtrn = '';
var vm_id = ${cmdb_ci_vm_instance[].object_id};
var vol_id = ${cmdb_ci_endpoint_iscsi[].object_id};
var vmHashSet = ${VMStorageCache}.get(vm_id);
if (vmHashSet){
rtrn = vmHashSet.contains(vol_id);
}
else {
rtrn = 'false'
}"}
"true"
}
relation_type = "Use End Point To::Use End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Garbage Collection"
set_attr {
"tmp"
eval {"javascript: CTX.setAttribute(\"VMStorageCache\", '');
CTX.setAttribute(\"network_storage_tbl\", '');
CTX.setAttribute(\"nas_storage_tbl\", '');
CTX.setAttribute(\"iscsi_storage_tbl\", '');"}
}
}
}
| library {
name = "IBM Cloud Virtual Server Network Storage"
id = "f189b50fdb0323002eeb0726ca9619e5" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parsing Out Network Storage Info"
if {
condition = is_not_empty {get_attr {"cmdb_ci_vm_instance[1].object_id"}}
on_true = parse_var_to_var {
from_var_name = "vm_json"
to_var_names = table {
name = "network_storage_tbl"
col_names = "type","object_id","name","ipAddress","mount_point","avail_zone"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "type"
xpath = "/root/result/allowedNetworkStorage/nasType/text()"
delimiters = ""
position = 1
}
field {
col_name = "object_id"
xpath = "/root/result/allowedNetworkStorage/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "name"
xpath = "/root/result/allowedNetworkStorage/username/text()"
delimiters = ""
position = 1
}
field {
col_name = "ipAddress"
xpath = "/root/result/allowedNetworkStorage/serviceResourceBackendIpAddress/text()"
delimiters = ""
position = 1
}
field {
col_name = "mount_point"
xpath = "/root/result/allowedNetworkStorage/fileNetworkMountAddress/text()"
delimiters = ""
position = 1
}
field {
col_name = "avail_zone"
xpath = "/root/result/datacenter/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter Out Empty Rows from Network Storage Table"
filter {
src_table_name = "network_storage_tbl"
target_table_name = "network_storage_tbl"
condition = is_not_empty {get_attr {"network_storage_tbl[].object_id"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove Duplicates from Network Storage Table"
set_attr {
"tmp"
eval {"javascript: var table_no_duplicates = ''; // Script execution: Custom script to perform a specific action or collect data
table_no_duplicates = DuplicateRemover.removeDuplicates(${network_storage_tbl},[\"object_id\"]);
CTX.setAttribute(\"network_storage_tbl\", table_no_duplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Find Network Storage Region"
if {
condition = all {
is_not_empty {get_attr {"network_storage_tbl[1].object_id"}}
contains {
get_attr {"is_ldc"}
"true"
}
}
on_true = transform {
src_table_name = "network_storage_tbl"
target_table_name = "network_storage_tbl"
operation {set_field {
field_name = "region"
value = eval {"javascript: var az = ${network_storage_tbl[].avail_zone}; // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
rtrn = IbmCloudDcToRegion.convertDctoRegion(az);"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter Network Storage by Region"
if {
condition = all {
is_not_empty {get_attr {"network_storage_tbl[1].object_id"}}
is_not_empty {get_attr {"is_ldc"}}
}
on_true = filter {
src_table_name = "network_storage_tbl"
target_table_name = "network_storage_tbl"
condition = contains {
get_attr {"ldc_list"}
get_attr {"network_storage_tbl[].region"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill storage_volume Table"
if {
condition = is_not_empty {get_attr {"network_storage_tbl[1].object_id"}}
on_true = transform {
src_table_name = "network_storage_tbl"
target_table_name = "cmdb_ci_storage_volume"
operation {set_field {
field_name = "object_id"
value = get_attr {"network_storage_tbl[].object_id"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filtering NAS storage"
if {
condition = contains {
get_attr {"network_storage_tbl[*].type"}
"NAS"
}
on_true = filter {
src_table_name = "network_storage_tbl"
target_table_name = "nas_storage_tbl"
condition = contains {
get_attr {"network_storage_tbl[].type"}
"NAS"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill endpoint_nfs Table"
if {
condition = is_not_empty {get_attr {"nas_storage_tbl[1].object_id"}}
on_true = transform {
src_table_name = "nas_storage_tbl"
target_table_name = "cmdb_ci_endpoint_nfs"
operation {
set_field {
field_name = "object_id"
value = get_attr {"nas_storage_tbl[].object_id"}
}
set_field {
field_name = "storage_server_ip"
value = get_attr {"nas_storage_tbl[].ipAddress"}
}
set_field {
field_name = "mount_point"
value = get_attr {"nas_storage_tbl[].mount_point"}
}
set_field {
field_name = "guest_id"
value = get_attr {"nas_storage_tbl[].guest_id"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Relations Between NFS EP and Storage Volume"
if {
condition = is_not_empty {get_attr {"cmdb_ci_endpoint_nfs[1].object_id"}}
on_true = relation_reference {
table1_name = "cmdb_ci_endpoint_nfs"
key1_name = "object_id"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "nfs_ep_to_volume"
unmatched_lines = remove
relation_type = "Implement End Point To::Implement End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Relations Between VM Instance and NFS EP"
if {
condition = is_not_empty {get_attr {"cmdb_ci_endpoint_nfs[1].object_id"}}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
table2_name = "cmdb_ci_endpoint_nfs"
result_table_name = "instance_to_nas_EP"
unmatched_lines = remove
condition = eq {
eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var vm_id = ${cmdb_ci_vm_instance[].object_id}; // Unique identifier for the pattern
var vol_id = ${cmdb_ci_endpoint_nfs[].object_id}; // Unique identifier for the pattern
var vmHashSet = ${VMStorageCache}.get(vm_id);
if (vmHashSet){
rtrn = vmHashSet.contains(vol_id);
}
else {
rtrn = 'false'
}"}
"true"
}
relation_type = "Use End Point To::Use End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filtering ISCSI Storage"
if {
condition = contains {
get_attr {"network_storage_tbl[*].type"}
"ISCSI"
}
on_true = filter {
src_table_name = "network_storage_tbl"
target_table_name = "iscsi_storage_tbl"
condition = contains {
get_attr {"network_storage_tbl[].type"}
"ISCSI"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill endpoint_iscsi Table"
if {
condition = is_not_empty {get_attr {"iscsi_storage_tbl[1].object_id"}}
on_true = transform {
src_table_name = "iscsi_storage_tbl"
target_table_name = "cmdb_ci_endpoint_iscsi"
operation {
set_field {
field_name = "object_id"
value = get_attr {"iscsi_storage_tbl[].object_id"}
}
set_field {
field_name = "name"
value = get_attr {"iscsi_storage_tbl[].name"}
}
set_field {
field_name = "storage_server_ip"
value = get_attr {"iscsi_storage_tbl[].ipAddress"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Relations Between ISCSI EP and Storage Volume"
if {
condition = is_not_empty {get_attr {"cmdb_ci_endpoint_iscsi[1].object_id"}}
on_true = relation_reference {
table1_name = "cmdb_ci_endpoint_iscsi"
key1_name = "object_id"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "iscsi_ep_to_volume"
unmatched_lines = keep
relation_type = "Implement End Point To::Implement End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Relations Between VM Instance and NFS EP"
if {
condition = is_not_empty {get_attr {"cmdb_ci_endpoint_nfs[1].object_id"}}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
table2_name = "cmdb_ci_endpoint_iscsi"
result_table_name = "instance_to_iscsi_EP"
unmatched_lines = remove
condition = eq {
eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var vm_id = ${cmdb_ci_vm_instance[].object_id}; // Unique identifier for the pattern
var vol_id = ${cmdb_ci_endpoint_iscsi[].object_id}; // Unique identifier for the pattern
var vmHashSet = ${VMStorageCache}.get(vm_id);
if (vmHashSet){
rtrn = vmHashSet.contains(vol_id);
}
else {
rtrn = 'false'
}"}
"true"
}
relation_type = "Use End Point To::Use End Point From"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Garbage Collection"
set_attr {
"tmp"
eval {"javascript: CTX.setAttribute(\"VMStorageCache\", ''); // Script execution: Custom script to perform a specific action or collect data
CTX.setAttribute(\"network_storage_tbl\", '');
CTX.setAttribute(\"nas_storage_tbl\", '');
CTX.setAttribute(\"iscsi_storage_tbl\", '');"}
}
}
}
|
DynamoDB Tags | I would like for you to help me build a Pattern that helps achieve Discovery of DynamoDB Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "DynamoDB Tags"
id = "eacb1209db993300bbebf13bbf96199e"
description = "DynamoDB Tags"
step {
name = "Set resource type"
set_attr {
"resource_type"
"dynamodb"
}
}
step {
name = "Tags library"
ref {refid = "91986c05db0d3300bbebf13bbf961949"}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Reference between cmdb_ci_dynamodb_table and cmdb_key_value"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_dynamodb_table"
key2_name = "object_id"
result_table_name = "keyToDynamoDB"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "DynamoDB Tags"
id = "eacb1209db993300bbebf13bbf96199e" // Unique identifier for the pattern
description = "DynamoDB Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set resource type"
set_attr {
"resource_type"
"dynamodb"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Tags library"
ref {refid = "91986c05db0d3300bbebf13bbf961949"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference between cmdb_ci_dynamodb_table and cmdb_key_value"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_dynamodb_table"
key2_name = "object_id"
result_table_name = "keyToDynamoDB"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Azure Image Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Azure Image Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure Image Tags"
id = "ec719ba1db5d1010b2a1f96275961993"
description = "Azure Image Tags"
step {
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Image Tags\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id};
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step {
name = "Filter cmdb_key_pair table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Create relation between Tag and Image"
if {
condition = neq {
get_attr {"isNewImageModel"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_os_template"
key2_name = "object_id"
result_table_name = "tag_to_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
step {
name = "Create relation between Tag and Cloud Image"
if {
condition = eq {
get_attr {"isNewImageModel"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_os_image"
key2_name = "object_id"
result_table_name = "tag_to_cloud_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "Azure Image Tags"
id = "ec719ba1db5d1010b2a1f96275961993" // Unique identifier for the pattern
description = "Azure Image Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Image Tags\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id}; // Unique identifier for the pattern
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_pair table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and Image"
if {
condition = neq {
get_attr {"isNewImageModel"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_os_template"
key2_name = "object_id"
result_table_name = "tag_to_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and Cloud Image"
if {
condition = eq {
get_attr {"isNewImageModel"}
"true"
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_os_image"
key2_name = "object_id"
result_table_name = "tag_to_cloud_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
AIX - OS Revision | I would like for you to help me build a Pattern that helps achieve Discovery of AIX - OS Revision. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "AIX - OS Revision"
id = "ece2e9d09ffc32001d753758442e70ad"
description = ""
step {
name = "Parse revision"
runcmd_to_var {
cmd = "oslevel -s"
var_names = "os_service"
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "error"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Update service pack in AIX CI"
if {
condition = is_not_empty {get_attr {"os_service"}}
on_true = set_attr {
"cmdb_ci_aix_server[*].os_service_pack"
get_attr {"os_service"}
}
on_false = nop {}
}
}
}
| library {
name = "AIX - OS Revision"
id = "ece2e9d09ffc32001d753758442e70ad" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse revision"
runcmd_to_var {
cmd = "oslevel -s"
var_names = "os_service"
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "error"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update service pack in AIX CI"
if {
condition = is_not_empty {get_attr {"os_service"}}
on_true = set_attr {
"cmdb_ci_aix_server[*].os_service_pack"
get_attr {"os_service"}
}
on_false = nop {}
}
}
}
|
OpenStack Octavia Pools | I would like for you to help me build a Pattern that helps achieve Discovery of OpenStack Octavia Pools. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "OpenStack Octavia Pools"
id = "ed1afe6ddb810010bf2fe0a1ca961900"
description = "null"
step {
name = "Get Pools details"
comment = "https://<service:port>/v3.0/<project_id>/volumes/detail - throws error
https://<service:port>/v3/<project_id>/volumes/detail - works"
if {
condition = is_not_empty {get_attr {"links_lbaas"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Load Balancer Resources.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_lbaas[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_lbaas[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id');
if (!input_object_id) { var resource = \"lbaas/pools\";}
else { var resource = \"lbaas/pools/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var service_url = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, service_url, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
var newJson2 = parseUtil.addTagToResult(\"service_url\",servicesURL[i],newJson.toString());
resultList.add(newJson2);
}
}
CTX.setAttribute('pools_details_response', resultList);"}
}
on_false = nop {}
}
}
step {
name = "HD: Parse the Pools"
if {
condition = all {
is_not_empty {get_attr {"pools_details_response"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools"
col_names = "pool_provisioning_status","pool_id","pool_operating_status","pool_name","pool_lb_algorithm","region","service_url"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "pool_provisioning_status"
xpath = "/root/pools/provisioning_status/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_id"
xpath = "/root/pools/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_operating_status"
xpath = "/root/pools/operating_status/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_name"
xpath = "/root/pools/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_lb_algorithm"
xpath = "/root/pools/lb_algorithm/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/pools/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_url"
xpath = "/root/pools/service_url/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse the Pools"
if {
condition = all {
is_not_empty {get_attr {"pools_details_response"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools"
col_names = "pool_provisioning_status","pool_id","pool_operating_status","pool_name","pool_lb_algorithm","region","service_url"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "pool_provisioning_status"
xpath = "/root/pool/provisioning_status/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_id"
xpath = "/root/pool/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_operating_status"
xpath = "/root/pool/operating_status/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_name"
xpath = "/root/pool/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_lb_algorithm"
xpath = "/root/pool/lb_algorithm/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/pool/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_url"
xpath = "/root/pool/service_url/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Filter out regions without pools"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = is_not_empty {get_attr {"pools"}}
on_true = filter {
src_table_name = "pools"
target_table_name = "pools"
condition = is_not_empty {get_attr {"pools[].pool_id"}}
}
on_false = nop {}
}
}
step {
name = "HD: Parse Pools with description"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","pool_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pools/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_description"
xpath = "/root/pools/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Pools with description"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","pool_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pool/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_description"
xpath = "/root/pool/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add description to the pools table"
if {
condition = is_not_empty {get_attr {"pools_add"}}
on_true = merge {
table1_name = "pools"
key1_name = "pool_id"
table2_name = "pools_add"
key2_name = "pool_id"
result_table_name = "pools"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "HD: Parse Pools projects"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","project_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pools/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_id"
xpath = "/root/pools/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Pools projects"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","project_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pool/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_id"
xpath = "/root/pool/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add project info to the pools table"
if {
condition = is_not_empty {get_attr {"pools_add"}}
on_true = merge {
table1_name = "pools"
key1_name = "pool_id"
table2_name = "pools_add"
key2_name = "pool_id"
result_table_name = "pools"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "HD: Parse Pools Load Balancers"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","lb_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pools/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "lb_id"
xpath = "/root/pools/loadbalancers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Pools Load Balancers"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","lb_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pool/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "lb_id"
xpath = "/root/pool/loadbalancers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add Load Balancer info to the pools table"
comment = "pg - directly adding the LB info even though it is part of an array object in the JSON response, because even if there is more than 1 LB per Pool, they will be unique CIs inside SNOW, because the Pools are dependent CI Type and the relation to the LB will be part of the identification process."
if {
condition = is_not_empty {get_attr {"pools_add"}}
on_true = merge {
table1_name = "pools"
key1_name = "pool_id"
table2_name = "pools_add"
key2_name = "pool_id"
result_table_name = "pools"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"pools"}}
}
on_true = filter {
src_table_name = "pools"
target_table_name = "pools"
condition = eq {
get_attr {"pools[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray()
var length = ldc.length
var region = ${pools[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_lb_pool table"
if {
condition = is_not_empty {get_attr {"pools"}}
on_true = transform {
src_table_name = "pools"
target_table_name = "cmdb_ci_lb_pool"
operation {
set_field {
field_name = "object_id"
value = get_attr {"pools[].pool_id"}
}
set_field {
field_name = "name"
value = get_attr {"pools[].pool_name"}
}
set_field {
field_name = "install_status"
value = get_attr {"pools[].pool_provisioning_status"}
}
set_field {
field_name = "operational_status"
value = get_attr {"pools[].pool_operating_status"}
}
set_field {
field_name = "short_description"
value = get_attr {"pools[].pool_description"}
}
set_field {
field_name = "load_balancing_method"
value = get_attr {"pools[].pool_lb_algorithm"}
}
}
}
on_false = nop {}
}
}
step {
name = "Event: Populate cmdb_ci_cloud_load_balancer table"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = transform {
src_table_name = "pools"
target_table_name = "cmdb_ci_cloud_load_balancer"
operation {set_field {
field_name = "object_id"
value = get_attr {"pools[].lb_id"}
}}
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_lb_pool and cmdb_ci_cloud_load_balancer tables"
if {
condition = is_not_empty {get_attr {"cmdb_ci_lb_pool"}}
on_true = relation_reference {
table1_name = "cmdb_ci_lb_pool"
key1_name = "lb_id"
table2_name = "cmdb_ci_cloud_load_balancer"
key2_name = "lb_id"
result_table_name = "lb_pool_to_lb"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "OpenStack Octavia Pools"
id = "ed1afe6ddb810010bf2fe0a1ca961900" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Pools details"
comment = "https://<service:port>/v3.0/<project_id>/volumes/detail - throws error
https://<service:port>/v3/<project_id>/volumes/detail - works"
if {
condition = is_not_empty {get_attr {"links_lbaas"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Load Balancer Resources.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_lbaas[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_lbaas[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id'); // Unique identifier for the pattern
if (!input_object_id) { var resource = \"lbaas/pools\";}
else { var resource = \"lbaas/pools/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var service_url = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, service_url, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
var newJson2 = parseUtil.addTagToResult(\"service_url\",servicesURL[i],newJson.toString());
resultList.add(newJson2);
}
}
CTX.setAttribute('pools_details_response', resultList);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse the Pools"
if {
condition = all {
is_not_empty {get_attr {"pools_details_response"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools"
col_names = "pool_provisioning_status","pool_id","pool_operating_status","pool_name","pool_lb_algorithm","region","service_url"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "pool_provisioning_status"
xpath = "/root/pools/provisioning_status/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_id"
xpath = "/root/pools/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_operating_status"
xpath = "/root/pools/operating_status/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_name"
xpath = "/root/pools/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_lb_algorithm"
xpath = "/root/pools/lb_algorithm/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/pools/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_url"
xpath = "/root/pools/service_url/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse the Pools"
if {
condition = all {
is_not_empty {get_attr {"pools_details_response"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools"
col_names = "pool_provisioning_status","pool_id","pool_operating_status","pool_name","pool_lb_algorithm","region","service_url"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "pool_provisioning_status"
xpath = "/root/pool/provisioning_status/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_id"
xpath = "/root/pool/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_operating_status"
xpath = "/root/pool/operating_status/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_name"
xpath = "/root/pool/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_lb_algorithm"
xpath = "/root/pool/lb_algorithm/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/pool/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_url"
xpath = "/root/pool/service_url/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out regions without pools"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = is_not_empty {get_attr {"pools"}}
on_true = filter {
src_table_name = "pools"
target_table_name = "pools"
condition = is_not_empty {get_attr {"pools[].pool_id"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Pools with description" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","pool_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pools/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/pools/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Pools with description" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","pool_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pool/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "pool_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/pool/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add description to the pools table" // Script execution: Custom script to perform a specific action or collect data
if {
condition = is_not_empty {get_attr {"pools_add"}}
on_true = merge {
table1_name = "pools"
key1_name = "pool_id"
table2_name = "pools_add"
key2_name = "pool_id"
result_table_name = "pools"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Pools projects"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","project_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pools/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_id"
xpath = "/root/pools/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Pools projects"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","project_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pool/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_id"
xpath = "/root/pool/project_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add project info to the pools table"
if {
condition = is_not_empty {get_attr {"pools_add"}}
on_true = merge {
table1_name = "pools"
key1_name = "pool_id"
table2_name = "pools_add"
key2_name = "pool_id"
result_table_name = "pools"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Pools Load Balancers"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","lb_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pools/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "lb_id"
xpath = "/root/pools/loadbalancers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Pools Load Balancers"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "pools_details_response"
to_var_names = table {
name = "pools_add"
col_names = "pool_id","lb_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "pool_id"
xpath = "/root/pool/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "lb_id"
xpath = "/root/pool/loadbalancers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add Load Balancer info to the pools table"
comment = "pg - directly adding the LB info even though it is part of an array object in the JSON response, because even if there is more than 1 LB per Pool, they will be unique CIs inside SNOW, because the Pools are dependent CI Type and the relation to the LB will be part of the identification process."
if {
condition = is_not_empty {get_attr {"pools_add"}}
on_true = merge {
table1_name = "pools"
key1_name = "pool_id"
table2_name = "pools_add"
key2_name = "pool_id"
result_table_name = "pools"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"pools"}}
}
on_true = filter {
src_table_name = "pools"
target_table_name = "pools"
condition = eq {
get_attr {"pools[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray() // Script execution: Custom script to perform a specific action or collect data
var length = ldc.length
var region = ${pools[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_lb_pool table"
if {
condition = is_not_empty {get_attr {"pools"}}
on_true = transform {
src_table_name = "pools"
target_table_name = "cmdb_ci_lb_pool"
operation {
set_field {
field_name = "object_id"
value = get_attr {"pools[].pool_id"}
}
set_field {
field_name = "name"
value = get_attr {"pools[].pool_name"}
}
set_field {
field_name = "install_status"
value = get_attr {"pools[].pool_provisioning_status"}
}
set_field {
field_name = "operational_status"
value = get_attr {"pools[].pool_operating_status"}
}
set_field {
field_name = "short_description" // Script execution: Custom script to perform a specific action or collect data
value = get_attr {"pools[].pool_description"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "load_balancing_method"
value = get_attr {"pools[].pool_lb_algorithm"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Populate cmdb_ci_cloud_load_balancer table"
if {
condition = all {
is_not_empty {get_attr {"pools"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = transform {
src_table_name = "pools"
target_table_name = "cmdb_ci_cloud_load_balancer"
operation {set_field {
field_name = "object_id"
value = get_attr {"pools[].lb_id"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_lb_pool and cmdb_ci_cloud_load_balancer tables"
if {
condition = is_not_empty {get_attr {"cmdb_ci_lb_pool"}}
on_true = relation_reference {
table1_name = "cmdb_ci_lb_pool"
key1_name = "lb_id"
table2_name = "cmdb_ci_cloud_load_balancer"
key2_name = "lb_id"
result_table_name = "lb_pool_to_lb"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
Gather VIP information for identification | I would like for you to help me build a Pattern that helps achieve Discovery of Gather VIP information for identification. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Gather VIP information for identification"
id = "ed34125bfb363200a4e6710a51af8717"
description = "Library that gathers all the VIP information: name, IP address, port"
step {
name = "Set VIP name"
comment = "populate VIP name from pre_cmdb_ci_lb_service"
set_attr {
"name"
get_attr {"pre_cmdb_ci_lb_service[1].name"}
}
}
step {
name = "Set VIP IP"
comment = "populate VIP ip address from pre_cmdb_ci_lb_service"
set_attr {
"ip_address"
get_attr {"pre_cmdb_ci_lb_service[1].ip_address"}
}
}
step {
name = "Set VIP port"
comment = "populate VIP port from pre_cmdb_ci_lb_service"
set_attr {
"port"
get_attr {"pre_cmdb_ci_lb_service[1].port"}
}
}
}
| library {
name = "Gather VIP information for identification"
id = "ed34125bfb363200a4e6710a51af8717" // Unique identifier for the pattern
description = "Library that gathers all the VIP information: name, IP address, port" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set VIP name"
comment = "populate VIP name from pre_cmdb_ci_lb_service"
set_attr {
"name"
get_attr {"pre_cmdb_ci_lb_service[1].name"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set VIP IP"
comment = "populate VIP ip address from pre_cmdb_ci_lb_service"
set_attr {
"ip_address"
get_attr {"pre_cmdb_ci_lb_service[1].ip_address"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set VIP port"
comment = "populate VIP port from pre_cmdb_ci_lb_service"
set_attr {
"port"
get_attr {"pre_cmdb_ci_lb_service[1].port"}
}
}
}
|
DNS | I would like for you to help me build a Pattern that helps achieve Discovery of DNS. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "DNS"
id = "ede27fe5db652200868a7c841f961984"
description = "null"
step {
name = "Get DNS name - format 1"
comment = "The step precondition is selected to keep the current DNS functionality in any pattern that will not be modified with the DNS per IP change."
if {
condition = is_empty {get_attr {"cmdb_ci_ip_address[1].ip_address"}}
on_true = runcmd_to_var {
cmd = concat {
"nslookup "
get_attr {"computer_system.managementIP"}
}
execution_mode = "LOCAL_SCRIPT"
var_names = table {
name = "DnsTable"
col_names = "fqdn"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "Name:"
delimiters = " "
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get DNS name - format 2"
comment = "The step precondition is selected to keep the current DNS functionality in any pattern that will not be modified with the DNS per IP change."
if {
condition = all {
is_empty {get_attr {"DnsTable"}}
is_empty {get_attr {"cmdb_ci_ip_address[1].ip_address"}}
}
on_true = runcmd_to_var {
cmd = concat {
"nslookup "
get_attr {"computer_system.managementIP"}
}
execution_mode = "LOCAL_SCRIPT"
var_names = table {
name = "DnsTable"
col_names = "fqdn"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "name ="
delimiters = "name = "
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "nslookup all IP addresses"
if {
condition = is_not_empty {get_attr {"cmdb_ci_ip_address"}}
on_true = transform {
src_table_name = "cmdb_ci_ip_address"
target_table_name = "ip_addresses_dns"
operation {set_field {
field_name = "nslookup_response"
value = eval {"import com.snc.sw.kb.lang.commands.ExecutionMode;
def cmd = \"nslookup \"+${cmdb_ci_ip_address[].ip_address};
return ctx.getCommandManager().shellCommand(cmd, false, ExecutionMode.LOCAL_SCRIPT, null, ctx);
"}
}}
}
on_false = nop {}
}
}
step {
name = "Parse the IP DNS names in EVAL"
if {
condition = is_not_empty {get_attr {"ip_addresses_dns"}}
on_true = transform {
src_table_name = "ip_addresses_dns"
target_table_name = "ip_addresses_dns"
operation {set_field {
field_name = "fqdn"
value = eval {"javascript: var nslookup_response = ${ip_addresses_dns[].nslookup_response}.toString();
nslookup_response = nslookup_response.replace(/(\\r\\n|\\n|\\r)/gm, '').replace(/\\\\n/gm, '');
var rtrn = '';
var regex = /Name(?:=|:)\\s*(.*?)\\s*Address:/;
var temp = regex.exec(nslookup_response);
rtrn = temp && temp[1];
rtrn;"}
}}
}
on_false = nop {}
}
}
step {
name = "Filter out IPs without DNS"
if {
condition = is_not_empty {get_attr {"ip_addresses_dns"}}
on_true = filter {
src_table_name = "ip_addresses_dns"
target_table_name = "ip_addresses_dns"
condition = is_not_empty {get_attr {"ip_addresses_dns[].fqdn"}}
}
on_false = nop {}
}
}
step {
name = "Remove dupliucate DNS"
if {
condition = is_not_empty {get_attr {"ip_addresses_dns"}}
on_true = set_attr {
"tmp"
eval {"javascript:
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${ip_addresses_dns},[\"fqdn\"]);
CTX.setAttribute(\"ip_addresses_dns\", tableWithoutDuplicates);
"}
}
on_false = nop {}
}
}
step {
name = "Insert IP DNS data to cmdb_ci_dns_name"
if {
condition = is_not_empty {get_attr {"ip_addresses_dns"}}
on_true = transform {
src_table_name = "ip_addresses_dns"
target_table_name = "cmdb_ci_dns_name"
operation {set_field {
field_name = "name"
value = get_attr {"ip_addresses_dns[].fqdn"}
}}
}
on_false = nop {}
}
}
step {
name = "Insert DNS data to cmdb_ci_dns_name"
if {
condition = all {
is_empty {get_attr {"cmdb_ci_ip_address[1].ip_address"}}
is_not_empty {get_attr {"DnsTable"}}
}
on_true = transform {
src_table_name = "DnsTable"
target_table_name = "cmdb_ci_dns_name"
operation {
set_field {
field_name = "name"
value = get_attr {"DnsTable[].fqdn"}
}
set_field {
field_name = "ip_address"
value = get_attr {"computer_system.managementIP"}
}
}
}
on_false = nop {}
}
}
}
| library {
name = "DNS"
id = "ede27fe5db652200868a7c841f961984" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get DNS name - format 1"
comment = "The step precondition is selected to keep the current DNS functionality in any pattern that will not be modified with the DNS per IP change." // Step definition: Represents a single action or set of actions in the pattern
if {
condition = is_empty {get_attr {"cmdb_ci_ip_address[1].ip_address"}}
on_true = runcmd_to_var {
cmd = concat {
"nslookup "
get_attr {"computer_system.managementIP"}
}
execution_mode = "LOCAL_SCRIPT"
var_names = table {
name = "DnsTable"
col_names = "fqdn"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "Name:"
delimiters = " "
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get DNS name - format 2"
comment = "The step precondition is selected to keep the current DNS functionality in any pattern that will not be modified with the DNS per IP change." // Step definition: Represents a single action or set of actions in the pattern
if {
condition = all {
is_empty {get_attr {"DnsTable"}}
is_empty {get_attr {"cmdb_ci_ip_address[1].ip_address"}}
}
on_true = runcmd_to_var {
cmd = concat {
"nslookup "
get_attr {"computer_system.managementIP"}
}
execution_mode = "LOCAL_SCRIPT"
var_names = table {
name = "DnsTable"
col_names = "fqdn"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "name ="
delimiters = "name = "
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "nslookup all IP addresses"
if {
condition = is_not_empty {get_attr {"cmdb_ci_ip_address"}}
on_true = transform {
src_table_name = "cmdb_ci_ip_address"
target_table_name = "ip_addresses_dns"
operation {set_field {
field_name = "nslookup_response"
value = eval {"import com.snc.sw.kb.lang.commands.ExecutionMode;
def cmd = \"nslookup \"+${cmdb_ci_ip_address[].ip_address};
return ctx.getCommandManager().shellCommand(cmd, false, ExecutionMode.LOCAL_SCRIPT, null, ctx);
"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the IP DNS names in EVAL"
if {
condition = is_not_empty {get_attr {"ip_addresses_dns"}}
on_true = transform {
src_table_name = "ip_addresses_dns"
target_table_name = "ip_addresses_dns"
operation {set_field {
field_name = "fqdn"
value = eval {"javascript: var nslookup_response = ${ip_addresses_dns[].nslookup_response}.toString(); // Script execution: Custom script to perform a specific action or collect data
nslookup_response = nslookup_response.replace(/(\\r\\n|\\n|\\r)/gm, '').replace(/\\\\n/gm, '');
var rtrn = '';
var regex = /Name(?:=|:)\\s*(.*?)\\s*Address:/;
var temp = regex.exec(nslookup_response);
rtrn = temp && temp[1];
rtrn;"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out IPs without DNS"
if {
condition = is_not_empty {get_attr {"ip_addresses_dns"}}
on_true = filter {
src_table_name = "ip_addresses_dns"
target_table_name = "ip_addresses_dns"
condition = is_not_empty {get_attr {"ip_addresses_dns[].fqdn"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove dupliucate DNS"
if {
condition = is_not_empty {get_attr {"ip_addresses_dns"}}
on_true = set_attr {
"tmp"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${ip_addresses_dns},[\"fqdn\"]);
CTX.setAttribute(\"ip_addresses_dns\", tableWithoutDuplicates);
"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert IP DNS data to cmdb_ci_dns_name"
if {
condition = is_not_empty {get_attr {"ip_addresses_dns"}}
on_true = transform {
src_table_name = "ip_addresses_dns"
target_table_name = "cmdb_ci_dns_name"
operation {set_field {
field_name = "name"
value = get_attr {"ip_addresses_dns[].fqdn"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert DNS data to cmdb_ci_dns_name"
if {
condition = all {
is_empty {get_attr {"cmdb_ci_ip_address[1].ip_address"}}
is_not_empty {get_attr {"DnsTable"}}
}
on_true = transform {
src_table_name = "DnsTable"
target_table_name = "cmdb_ci_dns_name"
operation {
set_field {
field_name = "name"
value = get_attr {"DnsTable[].fqdn"}
}
set_field {
field_name = "ip_address"
value = get_attr {"computer_system.managementIP"}
}
}
}
on_false = nop {}
}
}
}
|
LoadBalancer Network Hardware | I would like for you to help me build a Pattern that helps achieve Discovery of LoadBalancer Network Hardware. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "LoadBalancer Network Hardware"
id = "ee0dde21dbe06600d8c976231f96196f"
description = "null"
step {
name = "Get IPv6 Table"
comment = "BT:
Collecting the IPv6 table information with the following SNMP OID:
mgmt.mib-2.ipv6MIB.ipv6MIBObjects.ipv6AddrTable"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.55.1.8.1"
col_names = "2","3","4","5"
}
var_names = table {
name = "ipv6"
col_names = "ipv6AddrPfxLength","ipv6AddrType","ipv6AddrAnycastFlag","ipv6AddrStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Get IPv4 Table"
comment = "BT:
Collecting the IPv4 table information with the following SNMP OID:
mgmt.mib-2.ip.ipAddrTable"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.4.20.1"
col_names = "1","2","3"
}
var_names = table {
name = "ipAddrTable"
col_names = "ipAdEntAddr","ipAdEntIfIndex","ipAdEntNetMask"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Get IF Table"
comment = "BT:
Collecting the Interface table information with the following SNMP OID:
mgmt.mib-2.interfaces.ifTable"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.2.2.1"
col_names = "1","2","3","6","7","8"
}
var_names = table {
name = "IfTable"
col_names = "ifIndex","ifDescr","ifType","ifPhysAddress","ifAdminStatus","ifOperStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Get Physical Table"
comment = "BT:
Collecting the Physical Address table information with the following SNMP OID: mgmt.mib-2.entityMIB.entityMIBObjects.entityPhysical.entPhysicalTable"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.47.1.1.1.1"
col_names = "4","11","2"
}
var_names = table {
name = "PhysicalTable"
col_names = "entPhysicalContainedIn","entPhysicalSerialNum","entPhysicalDescr"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Update the Serial Number Table"
transform {
src_table_name = "cmdb_serial_number"
target_table_name = "cmdb_serial_number"
operation {
set_field {
field_name = "serial_number"
value = get_attr {"serial_number"}
}
set_field {
field_name = "serial_number_type"
value = "chassis"
}
set_field {
field_name = "valid"
value = "true"
}
}
}
}
step {
name = "Combine IP with If"
comment = "BT:
Merging the Interfaces with the IP addresses using the common ifIndex to mach the rows."
merge {
table1_name = "IfTable"
key1_name = "instanceID"
table2_name = "ipAddrTable"
key2_name = "ipAdEntIfIndex"
result_table_name = "If_with_ip"
unmatched_lines = remove
}
}
step {
name = "Filter the IF table"
comment = "BT:
Filtering out the loopback and not operational Interfaces"
filter {
src_table_name = "If_with_ip"
target_table_name = "If_with_ip"
condition = all {
not_starts_with {
"127"
get_attr {"If_with_ip[].ipAdEntAddr"}
}
eq {
get_attr {"If_with_ip[].ifAdminStatus"}
"1"
}
not_starts_with {
"0"
get_attr {"If_with_ip[].ipAdEntAddr"}
}
}
}
}
step {
name = "Allow loopback discovery - if system property is true"
comment = "BT:
Filtering out the loopback and not operational Interfaces"
if {
condition = eq {
get_attr {"Allow_loopback_discovery"}
"false"
}
on_true = filter {
src_table_name = "If_with_ip"
target_table_name = "If_with_ip"
condition = neq {
get_attr {"If_with_ip[].ifType"}
"24"
}
}
on_false = nop {}
}
}
step {
name = "Make Empty Unique If table"
comment = "BT:
Creating an empty table that will hold the filtered network interfaces."
union {
table1_name = "IfUnique"
table2_name = "IfUnique"
result_table_name = "IfUnique"
}
}
step {
name = "Fill Unique If table"
comment = "BT:
Filtering the duplicated entries."
set_attr {
"temp_unique_If"
concat {eval {"javascript:var rtrn = \"\";var table = ${If_with_ip};var uniqueMap = {};for (var i=0; i < table.size(); i++) { var row = table.get(i); var unField = row.get(\"ifIndex\"); if (!uniqueMap[unField]) { uniqueMap[unField] = row; ${IfUnique}.add(row); }}rtrn = table;"}}
}
}
step {
name = "Set Network Adapter"
comment = "BT:
Updating the Network Adapter table with the coresponding values"
transform {
src_table_name = "IfUnique"
target_table_name = "cmdb_ci_network_adapter"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"IfUnique[].ipAdEntAddr"}
}
set_field {
field_name = "alias"
value = get_attr {"IfUnique[].ifIndex"}
}
set_field {
field_name = "netmask"
value = get_attr {"IfUnique[].ipAdEntNetMask"}
}
set_field {
field_name = "mac_address"
value = get_attr {"IfUnique[].ifPhysAddress"}
}
set_field {
field_name = "name"
value = get_attr {"IfUnique[].ifDescr"}
}
}
}
}
step {
name = "Set IP addresses"
comment = "BT:
Updating the IP addresses table with the coresponding values."
transform {
src_table_name = "ipAddrTable"
target_table_name = "cmdb_ci_ip_address"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"ipAddrTable[].ipAdEntAddr"}
}
set_field {
field_name = "netmask"
value = get_attr {"ipAddrTable[].ipAdEntNetMask"}
}
set_field {
field_name = "version"
value = "4"
}
}
}
}
step {
name = "Remove duplicates on cmdb_ci_ip_address"
set_attr {
"notInUse"
eval {"javascript:
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_ip_address},[\"netmask\",\"ip_address\"]);
CTX.setAttribute(\"cmdb_ci_ip_address\", tableWithoutDuplicates);
"}
}
}
step {
name = "Ref/Rel between IP and Nic"
comment = "BT:
Creating Reference from the ip address table to the network adapter using the ifIndex as common field on nic reference filed"
relation_reference {
table1_name = "cmdb_ci_ip_address"
key1_name = "ipAdEntIfIndex"
table2_name = "cmdb_ci_network_adapter"
key2_name = "ifIndex"
result_table_name = "ip_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "nic"
}
}
}
| library {
name = "LoadBalancer Network Hardware"
id = "ee0dde21dbe06600d8c976231f96196f" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get IPv6 Table"
comment = "BT:
Collecting the IPv6 table information with the following SNMP OID:
mgmt.mib-2.ipv6MIB.ipv6MIBObjects.ipv6AddrTable"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.55.1.8.1"
col_names = "2","3","4","5"
}
var_names = table {
name = "ipv6"
col_names = "ipv6AddrPfxLength","ipv6AddrType","ipv6AddrAnycastFlag","ipv6AddrStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get IPv4 Table"
comment = "BT:
Collecting the IPv4 table information with the following SNMP OID:
mgmt.mib-2.ip.ipAddrTable"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.4.20.1"
col_names = "1","2","3"
}
var_names = table {
name = "ipAddrTable"
col_names = "ipAdEntAddr","ipAdEntIfIndex","ipAdEntNetMask"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get IF Table"
comment = "BT:
Collecting the Interface table information with the following SNMP OID:
mgmt.mib-2.interfaces.ifTable"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.2.2.1"
col_names = "1","2","3","6","7","8"
}
var_names = table {
name = "IfTable"
col_names = "ifIndex","ifDescr","ifType","ifPhysAddress","ifAdminStatus","ifOperStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Physical Table"
comment = "BT:
Collecting the Physical Address table information with the following SNMP OID: mgmt.mib-2.entityMIB.entityMIBObjects.entityPhysical.entPhysicalTable"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.47.1.1.1.1"
col_names = "4","11","2"
}
var_names = table {
name = "PhysicalTable"
col_names = "entPhysicalContainedIn","entPhysicalSerialNum","entPhysicalDescr"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update the Serial Number Table"
transform {
src_table_name = "cmdb_serial_number"
target_table_name = "cmdb_serial_number"
operation {
set_field {
field_name = "serial_number"
value = get_attr {"serial_number"}
}
set_field {
field_name = "serial_number_type"
value = "chassis"
}
set_field {
field_name = "valid"
value = "true"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Combine IP with If"
comment = "BT:
Merging the Interfaces with the IP addresses using the common ifIndex to mach the rows."
merge {
table1_name = "IfTable"
key1_name = "instanceID"
table2_name = "ipAddrTable"
key2_name = "ipAdEntIfIndex"
result_table_name = "If_with_ip"
unmatched_lines = remove
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter the IF table"
comment = "BT:
Filtering out the loopback and not operational Interfaces"
filter {
src_table_name = "If_with_ip"
target_table_name = "If_with_ip"
condition = all {
not_starts_with {
"127"
get_attr {"If_with_ip[].ipAdEntAddr"}
}
eq {
get_attr {"If_with_ip[].ifAdminStatus"}
"1"
}
not_starts_with {
"0"
get_attr {"If_with_ip[].ipAdEntAddr"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Allow loopback discovery - if system property is true"
comment = "BT:
Filtering out the loopback and not operational Interfaces"
if {
condition = eq {
get_attr {"Allow_loopback_discovery"}
"false"
}
on_true = filter {
src_table_name = "If_with_ip"
target_table_name = "If_with_ip"
condition = neq {
get_attr {"If_with_ip[].ifType"}
"24"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Make Empty Unique If table"
comment = "BT:
Creating an empty table that will hold the filtered network interfaces."
union {
table1_name = "IfUnique"
table2_name = "IfUnique"
result_table_name = "IfUnique"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill Unique If table"
comment = "BT:
Filtering the duplicated entries."
set_attr {
"temp_unique_If"
concat {eval {"javascript:var rtrn = \"\";var table = ${If_with_ip};var uniqueMap = {};for (var i=0; i < table.size(); i++) { var row = table.get(i); var unField = row.get(\"ifIndex\"); if (!uniqueMap[unField]) { uniqueMap[unField] = row; ${IfUnique}.add(row); }}rtrn = table;"}} // Script execution: Custom script to perform a specific action or collect data
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set Network Adapter"
comment = "BT:
Updating the Network Adapter table with the coresponding values"
transform {
src_table_name = "IfUnique"
target_table_name = "cmdb_ci_network_adapter"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"IfUnique[].ipAdEntAddr"}
}
set_field {
field_name = "alias"
value = get_attr {"IfUnique[].ifIndex"}
}
set_field {
field_name = "netmask"
value = get_attr {"IfUnique[].ipAdEntNetMask"}
}
set_field {
field_name = "mac_address"
value = get_attr {"IfUnique[].ifPhysAddress"}
}
set_field {
field_name = "name"
value = get_attr {"IfUnique[].ifDescr"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set IP addresses"
comment = "BT:
Updating the IP addresses table with the coresponding values."
transform {
src_table_name = "ipAddrTable"
target_table_name = "cmdb_ci_ip_address"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"ipAddrTable[].ipAdEntAddr"}
}
set_field {
field_name = "netmask"
value = get_attr {"ipAddrTable[].ipAdEntNetMask"}
}
set_field {
field_name = "version"
value = "4"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicates on cmdb_ci_ip_address"
set_attr {
"notInUse"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_ip_address},[\"netmask\",\"ip_address\"]);
CTX.setAttribute(\"cmdb_ci_ip_address\", tableWithoutDuplicates);
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between IP and Nic"
comment = "BT:
Creating Reference from the ip address table to the network adapter using the ifIndex as common field on nic reference filed"
relation_reference {
table1_name = "cmdb_ci_ip_address"
key1_name = "ipAdEntIfIndex"
table2_name = "cmdb_ci_network_adapter"
key2_name = "ifIndex"
result_table_name = "ip_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "nic"
}
}
}
|
Collect Azure WebSite Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Collect Azure WebSite Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Collect Azure WebSite Tags"
id = "ef150ecb1b172c90113131de034bcb9e"
description = "Collect Azure WebSite Tags"
step {
name = "verify HD mode"
match {
eq {
get_attr {"pattern_runtime_mode"}
"horizontal"
}
terminate_op = terminate
terminate_msg = ""
}
}
step {
name = "Collect tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure WebSite Tags Extension\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id};
var rtrn = \"\";
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try
{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags])
{
var key = tag;
var value = json.data.rows[row][response_tags][tag];
logger.debug(\"Parsing tags. object_id=\" + resource_id);
logger.debug(\"Parsing tags: key=\" + key);
logger.debug(\"Parsing tags: value=\" + value);
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
/* Concatenation is done as a workaround to the case, in which Azure Resource Graph returns uninitialized values
when the tag value is left empty by the user (probably a defect in Azure).
These uninitialized values (if not treated) might cause errors in payload parsing/processing.
*/
resource_line.put(\"value\", value + \"\");
resource_table.add(resource_line);
}
}
catch(ex) {
logger.error(\"Generic resource JSON parse failed with exception =\" + ex);
logger.error(\"Generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
rtrn = resource_table;
CTX.setAttribute(\"cmdb_key_value\", resource_table);
rtrn;"}
}
}
step {
name = "keep tags with values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "verify we have tags"
match {
is_not_empty {get_attr {"cmdb_key_value[*].key"}}
terminate_op = graceful
terminate_msg = "No tags found for web sites."
}
}
step {
name = "Remove duplicates from cmdb_key_value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"object_id\",\"key\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "create reference to tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_webserver"
key2_name = "object_id"
result_table_name = "keyToWeb"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Collect Azure WebSite Tags"
id = "ef150ecb1b172c90113131de034bcb9e" // Unique identifier for the pattern
description = "Collect Azure WebSite Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "verify HD mode"
match {
eq {
get_attr {"pattern_runtime_mode"}
"horizontal"
}
terminate_op = terminate
terminate_msg = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Collect tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure WebSite Tags Extension\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id}; // Unique identifier for the pattern
var rtrn = \"\";
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try
{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags])
{
var key = tag;
var value = json.data.rows[row][response_tags][tag];
logger.debug(\"Parsing tags. object_id=\" + resource_id);
logger.debug(\"Parsing tags: key=\" + key);
logger.debug(\"Parsing tags: value=\" + value);
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
/* Concatenation is done as a workaround to the case, in which Azure Resource Graph returns uninitialized values
when the tag value is left empty by the user (probably a defect in Azure).
These uninitialized values (if not treated) might cause errors in payload parsing/processing.
*/
resource_line.put(\"value\", value + \"\");
resource_table.add(resource_line);
}
}
catch(ex) {
logger.error(\"Generic resource JSON parse failed with exception =\" + ex);
logger.error(\"Generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
rtrn = resource_table;
CTX.setAttribute(\"cmdb_key_value\", resource_table);
rtrn;"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "keep tags with values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "verify we have tags"
match {
is_not_empty {get_attr {"cmdb_key_value[*].key"}}
terminate_op = graceful
terminate_msg = "No tags found for web sites."
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicates from cmdb_key_value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"object_id\",\"key\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create reference to tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_webserver"
key2_name = "object_id"
result_table_name = "keyToWeb"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Kubernetes Leader | I would like for you to help me build a Pattern that helps achieve Discovery of Kubernetes Leader. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Kubernetes Leader"
id = "f03eee569f1213002b9b92ec757fcf61"
description = ""
step {
name = "get primary_node_name"
custom_operation {
attributes {attribute {
name = "resource"
value = "namespaces/kube-system/endpoints/kube-controller-manager"
}}
sys_id_op = "354649149f7303002ae692ec757fcfac"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "trying parsing primary_node_name_delimeted"
parse_var_to_var {
from_var_name = "response"
to_var_names = "master_node_name"
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "master_node_name"
xpath = "/root/metadata/annotations/control-plane.alpha.kubernetes.ioSlashleader/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "process primary_node_name from call result"
comment = "need to use EVAL for parsing the name as because the JSON parser does not support an array value highlighting. So converting the the whole array into a new JSON object and get the needed info."
if {
condition = is_not_empty {get_attr {"master_node_name"}}
on_true = set_attr {
"master_node_name"
eval {"javascript: var rtrn = '';
var masterName = ${master_node_name[1]};
masterName = masterName + \"\";
var beforeReturn;
if(masterName !== ''){
var masterNameJson = JSON.parse(masterName);
beforeReturn = masterNameJson.holderIdentity;
}else{
beforeReturn = '';
}
rtrn = beforeReturn;"}
}
on_false = nop {}
}
}
step {
name = "set primary_node_name and port manually "
if {
condition = all {
is_empty {get_attr {"master_node_name"}}
neq {
get_attr {"port"}
"-1"
}
}
on_true = set_attr {
"master_node_name"
concat {
"Kubernetes Cluster "
get_attr {"host"}
":"
get_attr {"port"}
}
}
on_false = nop {}
}
}
step {
name = "set primary_node_name manually"
if {
condition = is_empty {get_attr {"master_node_name"}}
on_true = set_attr {
"master_node_name"
concat {
"Kubernetes Cluster "
get_attr {"host"}
}
}
on_false = nop {}
}
}
step {
name = "Check if IP Address"
set_attr {
"is_host_ip_address"
eval {"javascript: var rslt;
var rtrn;
var init = ${host};
var ip_rgx = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
rslt = \"0\";
try {
if (init && init.match(ip_rgx)) {
rslt = \"1\";
}
} catch(e) {
e.getMessage();
}
rtrn = rslt;"}
}
}
step {
name = "Copy existing IP from host variable"
if {
condition = eq {
get_attr {"is_host_ip_address"}
"1"
}
on_true = set_attr {
"host_ip"
get_attr {"host"}
}
on_false = nop {}
}
}
step {
name = "Resolve primary_node_name"
if {
condition = all {
contains {
get_attr {"is_host_ip_address"}
"0"
}
is_empty {get_attr {"host_ip"}}
}
on_true = set_attr {
"host_ip"
eval {"javascript: var rtrn;
var ips;
var rslt;
var init = ${host};
// var ipsTable = new Packages.java.util.ArrayList()
try {
ipsRaw = Packages.com.snc.sw.util.DNSUtils.resolveHostName(init);
if(ipsRaw != null) {
// ipsTable.add(ipsRaw.get(0))
rslt = ipsRaw.get(0)
}
}
catch(e) {
logger.error(\" DNSUtils.resolveHostName failed: \" + e.getMessage() );
}
rtrn = rslt + \"\";"}
}
on_false = nop {}
}
}
step {
name = "Mid In cluster discovery resolve primary_node_name"
if {
condition = all {
contains {
get_attr {"is_host_ip_address"}
"0"
}
eq {
get_attr {"host_ip"}
"undefined"
}
}
on_true = set_attr {
"host_ip"
eval {"javascript: var host =${host};
var rtrn;
if(host == 'kubernetes.default.svc' || host == 'cluster'){
rtrn = ''
}"}
}
on_false = nop {}
}
}
step {
name = "Check if IP address is empty and log warning"
if {
condition = is_empty {get_attr {"host_ip"}}
on_true = set_attr {
"ignore_me"
eval {"javascript: if(host != 'kubernetes.default.svc' || host != 'cluster')
{
//Do not display this warning in case containerized mid in cluster Kubernetes discovery
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger('Kubernetes Leader');
logger.debugex('DNS does not resolve Kubernetes cluster hostname! ServiceNow will merge Kubernetes Cluster CIs if their IP addresses and ports match');
}"}
}
on_false = nop {}
}
}
}
| library {
name = "Kubernetes Leader"
id = "f03eee569f1213002b9b92ec757fcf61" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "get primary_node_name"
custom_operation {
attributes {attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "resource"
value = "namespaces/kube-system/endpoints/kube-controller-manager"
}}
sys_id_op = "354649149f7303002ae692ec757fcfac"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "trying parsing primary_node_name_delimeted"
parse_var_to_var {
from_var_name = "response"
to_var_names = "master_node_name"
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "master_node_name"
xpath = "/root/metadata/annotations/control-plane.alpha.kubernetes.ioSlashleader/text()" // Metadata section: Contains metadata information about the pattern
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "process primary_node_name from call result"
comment = "need to use EVAL for parsing the name as because the JSON parser does not support an array value highlighting. So converting the the whole array into a new JSON object and get the needed info."
if {
condition = is_not_empty {get_attr {"master_node_name"}}
on_true = set_attr {
"master_node_name"
eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var masterName = ${master_node_name[1]};
masterName = masterName + \"\";
var beforeReturn;
if(masterName !== ''){
var masterNameJson = JSON.parse(masterName);
beforeReturn = masterNameJson.holderIdentity;
}else{
beforeReturn = '';
}
rtrn = beforeReturn;"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set primary_node_name and port manually "
if {
condition = all {
is_empty {get_attr {"master_node_name"}}
neq {
get_attr {"port"}
"-1"
}
}
on_true = set_attr {
"master_node_name"
concat {
"Kubernetes Cluster "
get_attr {"host"}
":"
get_attr {"port"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set primary_node_name manually"
if {
condition = is_empty {get_attr {"master_node_name"}}
on_true = set_attr {
"master_node_name"
concat {
"Kubernetes Cluster "
get_attr {"host"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check if IP Address"
set_attr {
"is_host_ip_address"
eval {"javascript: var rslt; // Script execution: Custom script to perform a specific action or collect data
var rtrn;
var init = ${host};
var ip_rgx = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
rslt = \"0\";
try {
if (init && init.match(ip_rgx)) {
rslt = \"1\";
}
} catch(e) {
e.getMessage();
}
rtrn = rslt;"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Copy existing IP from host variable"
if {
condition = eq {
get_attr {"is_host_ip_address"}
"1"
}
on_true = set_attr {
"host_ip"
get_attr {"host"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Resolve primary_node_name"
if {
condition = all {
contains {
get_attr {"is_host_ip_address"}
"0"
}
is_empty {get_attr {"host_ip"}}
}
on_true = set_attr {
"host_ip"
eval {"javascript: var rtrn; // Script execution: Custom script to perform a specific action or collect data
var ips;
var rslt;
var init = ${host};
// var ipsTable = new Packages.java.util.ArrayList()
try {
ipsRaw = Packages.com.snc.sw.util.DNSUtils.resolveHostName(init);
if(ipsRaw != null) {
// ipsTable.add(ipsRaw.get(0))
rslt = ipsRaw.get(0)
}
}
catch(e) {
logger.error(\" DNSUtils.resolveHostName failed: \" + e.getMessage() );
}
rtrn = rslt + \"\";"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Mid In cluster discovery resolve primary_node_name"
if {
condition = all {
contains {
get_attr {"is_host_ip_address"}
"0"
}
eq {
get_attr {"host_ip"}
"undefined"
}
}
on_true = set_attr {
"host_ip"
eval {"javascript: var host =${host}; // Script execution: Custom script to perform a specific action or collect data
var rtrn;
if(host == 'kubernetes.default.svc' || host == 'cluster'){
rtrn = ''
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check if IP address is empty and log warning"
if {
condition = is_empty {get_attr {"host_ip"}}
on_true = set_attr {
"ignore_me"
eval {"javascript: if(host != 'kubernetes.default.svc' || host != 'cluster') // Script execution: Custom script to perform a specific action or collect data
{
//Do not display this warning in case containerized mid in cluster Kubernetes discovery
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger('Kubernetes Leader');
logger.debugex('DNS does not resolve Kubernetes cluster hostname! ServiceNow will merge Kubernetes Cluster CIs if their IP addresses and ports match');
}"}
}
on_false = nop {}
}
}
}
|
Azure Application LB Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Azure Application LB Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure Application LB Tags"
id = "f63cdb61db9d1010b2a1f9627596197e"
description = "Azure Application LB Tags"
step {
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Application LB Tags\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id};
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step {
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Create relation between Tag and LB"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_load_balancer"
key2_name = "object_id"
result_table_name = "tag_to_lb"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Azure Application LB Tags"
id = "f63cdb61db9d1010b2a1f9627596197e" // Unique identifier for the pattern
description = "Azure Application LB Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Application LB Tags\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id}; // Unique identifier for the pattern
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and LB"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_load_balancer"
key2_name = "object_id"
result_table_name = "tag_to_lb"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
OpenStack Nova Servers | I would like for you to help me build a Pattern that helps achieve Discovery of OpenStack Nova Servers. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "OpenStack Nova Servers"
id = "f6768a94db410010bf2fe0a1ca9619e8"
description = "null"
step {
name = "Get servers details"
if {
condition = is_not_empty {get_attr {"links_compute"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Compute Resources.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_compute[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_compute[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id');
if (!input_object_id) { var resource = \"servers/detail\";}
else { var resource = \"servers/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var serviceURL = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
resultList.add(newJson);
}
}
CTX.setAttribute('servers_details', resultList);"}
}
on_false = nop {}
}
}
step {
name = "HD: Parse servers"
if {
condition = is_empty {get_attr {"input_object_id"}}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers"
col_names = "host_id","server_name","status","tenant_id","server_uuid","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "host_id"
xpath = "/root/servers/hostId/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_name"
xpath = "/root/servers/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "status"
xpath = "/root/servers/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "tenant_id"
xpath = "/root/servers/tenant_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_uuid"
xpath = "/root/servers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/servers/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse servers"
if {
condition = is_not_empty {get_attr {"input_object_id"}}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers"
col_names = "host_id","server_name","status","tenant_id","server_uuid","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "host_id"
xpath = "/root/server/hostId/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_name"
xpath = "/root/server/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "status"
xpath = "/root/server/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "tenant_id"
xpath = "/root/server/tenant_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_uuid"
xpath = "/root/server/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/server/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Filter out regions without servers"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_not_empty {get_attr {"token_project_authorization"}}
}
on_true = filter {
src_table_name = "servers"
target_table_name = "servers"
condition = is_not_empty {get_attr {"servers[].server_uuid"}}
}
on_false = nop {}
}
}
step {
name = "HD: Parse Servers with Image"
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers_add"
col_names = "server_uuid","image_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "server_uuid"
xpath = "/root/servers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "image_id"
xpath = "/root/servers/image/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Servers with Image"
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers_add"
col_names = "server_uuid","image_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "server_uuid"
xpath = "/root/server/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "image_id"
xpath = "/root/server/image/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the Image information to the server table"
if {
condition = is_not_empty {get_attr {"servers_add"}}
on_true = merge {
table1_name = "servers"
key1_name = "server_uuid"
table2_name = "servers_add"
key2_name = "server_uuid"
result_table_name = "servers"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "HD: Parse Servers with Descriptions"
comment = "This field is new in version 2.19.
The description of the server. Before microversion 2.19 this was set to the server name."
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers_add"
col_names = "server_uuid","server_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "server_uuid"
xpath = "/root/servers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_description"
xpath = "/root/servers/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Servers with Descriptions"
comment = "This field is new in version 2.19.
The description of the server. Before microversion 2.19 this was set to the server name."
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers_add"
col_names = "server_uuid","server_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "server_uuid"
xpath = "/root/server/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_description"
xpath = "/root/server/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the Description information to the server table"
if {
condition = is_not_empty {get_attr {"servers_add"}}
on_true = merge {
table1_name = "servers"
key1_name = "server_uuid"
table2_name = "servers_add"
key2_name = "server_uuid"
result_table_name = "servers"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Populate the description prior to microversion 2.19"
if {
condition = all {
is_not_empty {get_attr {"servers"}}
eq {
eval {"javascript: var rtrn = \"false\"
var version = ${versions[1].id}
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Compute Resources.\");
try {
version = version.replace(\"v\",\"\")
version = parseInt(version)
if (version < 2.19) {
rtrn = \"true\"
}}
catch (e) {
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic parse version failure. exception=\" + e);
}
rtrn"}
"true"
}
}
on_true = transform {
src_table_name = "servers"
target_table_name = "servers"
operation {set_field {
field_name = "description"
value = eval {"javascript: var description = ${servers[].description}
var name = ${servers[].server_name}
if (!description) {description = name}
description"}
}}
}
on_false = nop {}
}
}
step {
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"servers"}}
}
on_true = filter {
src_table_name = "servers"
target_table_name = "servers"
condition = eq {
get_attr {"servers[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray()
var length = ldc.length
var region = ${servers[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step {
name = "Poplate cmdb_ci_vm_instance table"
if {
condition = is_not_empty {get_attr {"servers"}}
on_true = transform {
src_table_name = "servers"
target_table_name = "cmdb_ci_vm_instance"
operation {
set_field {
field_name = "object_id"
value = get_attr {"servers[].server_uuid"}
}
set_field {
field_name = "name"
value = get_attr {"servers[].server_name"}
}
set_field {
field_name = "status"
value = get_attr {"servers[].status"}
}
set_field {
field_name = "short_description"
value = get_attr {"servers[].description"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_vm_instance and cmdb_ci_openstack_datacenter tables"
if {
condition = is_not_empty {get_attr {"cmdb_ci_vm_instance"}}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "instance_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "OpenStack Nova Servers"
id = "f6768a94db410010bf2fe0a1ca9619e8" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get servers details"
if {
condition = is_not_empty {get_attr {"links_compute"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Compute Resources.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_compute[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_compute[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id'); // Unique identifier for the pattern
if (!input_object_id) { var resource = \"servers/detail\";}
else { var resource = \"servers/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var serviceURL = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
resultList.add(newJson);
}
}
CTX.setAttribute('servers_details', resultList);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse servers"
if {
condition = is_empty {get_attr {"input_object_id"}}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers"
col_names = "host_id","server_name","status","tenant_id","server_uuid","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "host_id"
xpath = "/root/servers/hostId/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_name"
xpath = "/root/servers/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "status"
xpath = "/root/servers/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "tenant_id"
xpath = "/root/servers/tenant_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_uuid"
xpath = "/root/servers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/servers/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse servers"
if {
condition = is_not_empty {get_attr {"input_object_id"}}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers"
col_names = "host_id","server_name","status","tenant_id","server_uuid","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "host_id"
xpath = "/root/server/hostId/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_name"
xpath = "/root/server/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "status"
xpath = "/root/server/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "tenant_id"
xpath = "/root/server/tenant_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_uuid"
xpath = "/root/server/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/server/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out regions without servers"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_not_empty {get_attr {"token_project_authorization"}}
}
on_true = filter {
src_table_name = "servers"
target_table_name = "servers"
condition = is_not_empty {get_attr {"servers[].server_uuid"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Servers with Image"
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers_add"
col_names = "server_uuid","image_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "server_uuid"
xpath = "/root/servers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "image_id"
xpath = "/root/servers/image/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Servers with Image"
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers_add"
col_names = "server_uuid","image_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "server_uuid"
xpath = "/root/server/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "image_id"
xpath = "/root/server/image/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the Image information to the server table"
if {
condition = is_not_empty {get_attr {"servers_add"}}
on_true = merge {
table1_name = "servers"
key1_name = "server_uuid"
table2_name = "servers_add"
key2_name = "server_uuid"
result_table_name = "servers"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Servers with Descriptions" // Script execution: Custom script to perform a specific action or collect data
comment = "This field is new in version 2.19.
The description of the server. Before microversion 2.19 this was set to the server name." // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers_add"
col_names = "server_uuid","server_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "server_uuid"
xpath = "/root/servers/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/servers/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Servers with Descriptions" // Script execution: Custom script to perform a specific action or collect data
comment = "This field is new in version 2.19.
The description of the server. Before microversion 2.19 this was set to the server name." // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"servers"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "servers_details"
to_var_names = table {
name = "servers_add"
col_names = "server_uuid","server_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "server_uuid"
xpath = "/root/server/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/server/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the Description information to the server table" // Script execution: Custom script to perform a specific action or collect data
if {
condition = is_not_empty {get_attr {"servers_add"}}
on_true = merge {
table1_name = "servers"
key1_name = "server_uuid"
table2_name = "servers_add"
key2_name = "server_uuid"
result_table_name = "servers"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate the description prior to microversion 2.19" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"servers"}}
eq {
eval {"javascript: var rtrn = \"false\" // Script execution: Custom script to perform a specific action or collect data
var version = ${versions[1].id}
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Compute Resources.\");
try {
version = version.replace(\"v\",\"\")
version = parseInt(version)
if (version < 2.19) {
rtrn = \"true\"
}}
catch (e) {
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic parse version failure. exception=\" + e);
}
rtrn"}
"true"
}
}
on_true = transform {
src_table_name = "servers"
target_table_name = "servers"
operation {set_field {
field_name = "description" // Script execution: Custom script to perform a specific action or collect data
value = eval {"javascript: var description = ${servers[].description} // Script execution: Custom script to perform a specific action or collect data
var name = ${servers[].server_name}
if (!description) {description = name} // Script execution: Custom script to perform a specific action or collect data
description"} // Script execution: Custom script to perform a specific action or collect data
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"servers"}}
}
on_true = filter {
src_table_name = "servers"
target_table_name = "servers"
condition = eq {
get_attr {"servers[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray() // Script execution: Custom script to perform a specific action or collect data
var length = ldc.length
var region = ${servers[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Poplate cmdb_ci_vm_instance table"
if {
condition = is_not_empty {get_attr {"servers"}}
on_true = transform {
src_table_name = "servers"
target_table_name = "cmdb_ci_vm_instance"
operation {
set_field {
field_name = "object_id"
value = get_attr {"servers[].server_uuid"}
}
set_field {
field_name = "name"
value = get_attr {"servers[].server_name"}
}
set_field {
field_name = "status"
value = get_attr {"servers[].status"}
}
set_field {
field_name = "short_description" // Script execution: Custom script to perform a specific action or collect data
value = get_attr {"servers[].description"} // Script execution: Custom script to perform a specific action or collect data
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_vm_instance and cmdb_ci_openstack_datacenter tables"
if {
condition = is_not_empty {get_attr {"cmdb_ci_vm_instance"}}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "instance_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
Create JBoss related app and service | I would like for you to help me build a Pattern that helps achieve Discovery of Create JBoss related app and service. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Create JBoss related app and service"
id = "fc05b76f67b77200e089027e2685ef23"
description = "null"
step {
name = "get discovery run mode"
set_attr {
"RunMode"
eval {"ctx.getWork().getDiscoveryType();"}
}
}
step {
name = "set web services config file path prefix - unix"
if {
condition = all {
neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
}
on_true = parse_var_to_var {
from_var_name = "process.commandLine"
to_var_names = "service_conf_file_path"
parsing_strategy = regex_parsing {regex = "-classpath\\s+(.*)\\/bin"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "set web services config file path prefix - win"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
}
on_true = set_attr {
"service_conf_file_path"
get_attr {"top_jboss_path"}
}
on_false = nop {}
}
}
step {
name = "set web services config file path"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"service_conf_file_path"}}
}
on_true = set_attr {
"service_conf_file_path"
concat {
get_attr {"service_conf_file_path"}
get_attr {"path_delimiter"}
"server"
get_attr {"path_delimiter"}
"default"
get_attr {"path_delimiter"}
"conf"
get_attr {"path_delimiter"}
"jboss-service.xml"
}
}
on_false = nop {}
}
}
step {
name = "retrieve web services config file content"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"service_conf_file_path"}}
}
on_true = parse_text_file_to_var {
file_path = get_files_by_filter {
expression = get_attr {"service_conf_file_path"}
foreach_attribute_name = "forEach"
}
var_names = table {
name = "jboss_services_table"
col_names = "name"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/server"
fields {
field {
col_name = "name"
xpath = "/server/mbean/@name"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "failover - retrieve web services config file content"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"jboss_services_table[1].name"}}
}
on_true = runcmd_to_var {
cmd = concat {
"ls -1 -d "
get_attr {"base_dir"}
"/deployments/*.deployed 2> /dev/null"
}
execution_mode = "DEFAULT"
var_names = table {
name = "jboss_services_table"
col_names = "name"
}
parsing_strategy = regex_parsing {regex = "deployments\\/(.*)\\.war.deployed"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "set list of web.xml web app path - win"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
}
on_true = runcmd_to_var {
cmd = concat {
"dir /s/b "
get_attr {"install_directory"}
"\\deploy\\web.xml"
}
var_names = table {
name = "web_xml_app_files"
col_names = "path"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "set list of web.xml web app path - unix"
if {
condition = all {
neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
}
on_true = runcmd_to_var {
cmd = concat {
"find "
get_attr {"install_directory"}
"/deploy -name web.xml -print"
}
var_names = table {
name = "web_xml_app_files"
col_names = "path"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = " failover set list of web.xml web app path - unix"
if {
condition = all {
neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"web_xml_app_files[1].path"}}
}
on_true = parse_var_to_var {
from_var_name = "web_files[*].file"
to_var_names = table {
name = "web_xml_app_files"
col_names = "path"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "remove non-war paths from list of web.xml paths"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = filter {
src_table_name = "web_xml_app_files"
target_table_name = "web_xml_app_files"
condition = contains {
get_attr {"web_xml_app_files[].path"}
".war"
}
}
on_false = nop {}
}
}
step {
name = "set web app name"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"web_xml_app_files[1].path"}}
}
on_true = parse_var_to_var {
from_var_name = "web_xml_app_files[*].path"
to_var_names = table {
name = "web_xml_app_info"
col_names = "name"
}
parsing_strategy = regex_parsing {regex = "([^\\/\\\\]+)\\.war"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "failover set web app name"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"web_xml_app_files[1].path"}}
is_empty {get_attr {"web_xml_app_info[1].name"}}
}
on_true = parse_var_to_var {
from_var_name = "war[*].path"
to_var_names = table {
name = "web_xml_app_info"
col_names = "name"
}
parsing_strategy = regex_parsing {regex = "([^\\/\\\\]+)\\.war"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "failover2 set web app name"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"web_xml_app_files[1].path"}}
is_empty {get_attr {"web_xml_app_info[1].name"}}
}
on_true = parse_var_to_var {
from_var_name = "defaults[*].uri"
to_var_names = table {
name = "web_xml_app_info"
col_names = "name"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "set web app doc base"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"war[1].path"}}
}
on_true = parse_var_to_var {
from_var_name = "war[*].path"
to_var_names = table {
name = "web_xml_app_doc_info"
col_names = "document_base"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "deployments",".war"
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = " failover set web app doc base"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"web_xml_app_files[1].path"}}
is_empty {get_attr {"web_xml_app_doc_info[1].document_base"}}
}
on_true = parse_var_to_var {
from_var_name = "web_xml_app_files[*].path"
to_var_names = table {
name = "web_xml_app_doc_info"
col_names = "document_base"
}
parsing_strategy = regex_parsing {regex = "deploy([\\/\\\\].*\\.war)[\\/\\\\]WEB.*|web.*"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = " failover 2 set web app doc base"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"web_xml_app_files[1].path"}}
is_empty {get_attr {"web_xml_app_doc_info[1].document_base"}}
}
on_true = parse_var_to_var {
from_var_name = "web_xml_app_files[*].path"
to_var_names = table {
name = "web_xml_app_doc_info"
col_names = "document_base"
}
parsing_strategy = regex_parsing {regex = "vfs([\\/\\\\].*\\.war)"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "adjust doc base - win"
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = transform {
src_table_name = "web_xml_app_doc_info"
target_table_name = "web_xml_app_doc_info"
operation {set_field {
field_name = "document_base"
value = concat {
get_attr {"home_dir"}
"\\deploy"
get_attr {"web_xml_app_doc_info[].document_base"}
}
}}
}
on_false = nop {}
}
}
step {
name = "parse web.xml for app data"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = parse_text_file_to_var {
file_path = get_files_by_filter {
expression = get_attr {"web_xml_app_files[*].path"}
foreach_attribute_name = "forEach"
}
var_names = table {
name = "web_xml_app_desc"
col_names = "desc"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/web-app"
fields {
field {
col_name = "desc"
xpath = "/web-app/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "failover parse web.xml for app data"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"web_xml_app_desc[1].desc"}}
is_not_empty {get_attr {"web_files[1].file"}}
}
on_true = parse_text_file_to_var {
file_path = get_files_by_filter {
expression = get_attr {"web_files[*].file"}
foreach_attribute_name = "forEach"
}
var_names = table {
name = "web_xml_app_desc"
col_names = "desc"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/web-app"
fields {
field {
col_name = "desc"
xpath = "/web-app/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "populate main web server CI "
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = transform {
src_table_name = "cmdb_ci_app_server_jboss"
target_table_name = "cmdb_ci_app_server_jboss"
operation {
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "install_directory"
value = eval {"javascript: rtrn = ${install_directory};
try{
var conf = ${conf_mode};
if(conf.contains(\"standalone\")){
rtrn = ${top_jboss_path} + ${path_delimiter} + \"standalone\";
}
}
catch(e){
//rtrn remains as initialized
}"}
}
set_field {
field_name = "running_process_command"
value = get_attr {"process.executable"}
}
set_field {
field_name = "running_process_key_parameters"
value = get_attr {"process.commandLine"}
}
}
}
on_false = nop {}
}
}
step {
name = "create web service CIs "
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = transform {
src_table_name = "jboss_services_table"
target_table_name = "cmdb_ci_web_service"
operation {set_field {
field_name = "name"
value = get_attr {"jboss_services_table[].name"}
}}
}
on_false = nop {}
}
}
step {
name = "create web app CIs"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = merge {
table1_name = "web_xml_app_doc_info"
table2_name = "web_xml_app_info"
result_table_name = "cmdb_ci_web_application"
unmatched_lines = remove
condition = contains {
get_attr {"web_xml_app_doc_info[].document_base"}
get_attr {"web_xml_app_info[].name"}
}
}
on_false = nop {}
}
}
step {
name = "relate web service CIs to main jboss server"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = relation_reference {
table1_name = "cmdb_ci_web_service"
table2_name = "cmdb_ci_app_server_jboss"
result_table_name = "result1"
unmatched_lines = keep
relation_type = "Runs on::Runs"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "relate web app CIs to main jboss server"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = relation_reference {
table1_name = "cmdb_ci_web_application"
table2_name = "cmdb_ci_app_server_jboss"
result_table_name = "result2"
unmatched_lines = keep
relation_type = "Runs on::Runs"
ref_direction = parentToChild
ref_field_name = "app_server"
}
on_false = nop {}
}
}
}
| library {
name = "Create JBoss related app and service"
id = "fc05b76f67b77200e089027e2685ef23" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "get discovery run mode"
set_attr {
"RunMode"
eval {"ctx.getWork().getDiscoveryType();"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set web services config file path prefix - unix"
if {
condition = all {
neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
}
on_true = parse_var_to_var {
from_var_name = "process.commandLine"
to_var_names = "service_conf_file_path"
parsing_strategy = regex_parsing {regex = "-classpath\\s+(.*)\\/bin"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set web services config file path prefix - win"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
}
on_true = set_attr {
"service_conf_file_path"
get_attr {"top_jboss_path"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set web services config file path"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"service_conf_file_path"}}
}
on_true = set_attr {
"service_conf_file_path"
concat {
get_attr {"service_conf_file_path"}
get_attr {"path_delimiter"}
"server"
get_attr {"path_delimiter"}
"default"
get_attr {"path_delimiter"}
"conf"
get_attr {"path_delimiter"}
"jboss-service.xml"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "retrieve web services config file content"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"service_conf_file_path"}}
}
on_true = parse_text_file_to_var {
file_path = get_files_by_filter {
expression = get_attr {"service_conf_file_path"}
foreach_attribute_name = "forEach" // Attribute collection: Collects specific attributes from the discovered CI
}
var_names = table {
name = "jboss_services_table"
col_names = "name"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/server"
fields {
field {
col_name = "name"
xpath = "/server/mbean/@name"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover - retrieve web services config file content"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"jboss_services_table[1].name"}}
}
on_true = runcmd_to_var {
cmd = concat {
"ls -1 -d "
get_attr {"base_dir"}
"/deployments/*.deployed 2> /dev/null"
}
execution_mode = "DEFAULT"
var_names = table {
name = "jboss_services_table"
col_names = "name"
}
parsing_strategy = regex_parsing {regex = "deployments\\/(.*)\\.war.deployed"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set list of web.xml web app path - win"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
}
on_true = runcmd_to_var {
cmd = concat {
"dir /s/b "
get_attr {"install_directory"}
"\\deploy\\web.xml"
}
var_names = table {
name = "web_xml_app_files"
col_names = "path"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set list of web.xml web app path - unix"
if {
condition = all {
neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
}
on_true = runcmd_to_var {
cmd = concat {
"find "
get_attr {"install_directory"}
"/deploy -name web.xml -print"
}
var_names = table {
name = "web_xml_app_files"
col_names = "path"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = " failover set list of web.xml web app path - unix"
if {
condition = all {
neq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"web_xml_app_files[1].path"}}
}
on_true = parse_var_to_var {
from_var_name = "web_files[*].file"
to_var_names = table {
name = "web_xml_app_files"
col_names = "path"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "remove non-war paths from list of web.xml paths"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = filter {
src_table_name = "web_xml_app_files"
target_table_name = "web_xml_app_files"
condition = contains {
get_attr {"web_xml_app_files[].path"}
".war"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set web app name"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"web_xml_app_files[1].path"}}
}
on_true = parse_var_to_var {
from_var_name = "web_xml_app_files[*].path"
to_var_names = table {
name = "web_xml_app_info"
col_names = "name"
}
parsing_strategy = regex_parsing {regex = "([^\\/\\\\]+)\\.war"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover set web app name"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"web_xml_app_files[1].path"}}
is_empty {get_attr {"web_xml_app_info[1].name"}}
}
on_true = parse_var_to_var {
from_var_name = "war[*].path"
to_var_names = table {
name = "web_xml_app_info"
col_names = "name"
}
parsing_strategy = regex_parsing {regex = "([^\\/\\\\]+)\\.war"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover2 set web app name"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"web_xml_app_files[1].path"}}
is_empty {get_attr {"web_xml_app_info[1].name"}}
}
on_true = parse_var_to_var {
from_var_name = "defaults[*].uri"
to_var_names = table {
name = "web_xml_app_info"
col_names = "name"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set web app doc base"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"war[1].path"}}
}
on_true = parse_var_to_var {
from_var_name = "war[*].path"
to_var_names = table {
name = "web_xml_app_doc_info"
col_names = "document_base"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "deployments",".war"
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = " failover set web app doc base"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"web_xml_app_files[1].path"}}
is_empty {get_attr {"web_xml_app_doc_info[1].document_base"}}
}
on_true = parse_var_to_var {
from_var_name = "web_xml_app_files[*].path"
to_var_names = table {
name = "web_xml_app_doc_info"
col_names = "document_base"
}
parsing_strategy = regex_parsing {regex = "deploy([\\/\\\\].*\\.war)[\\/\\\\]WEB.*|web.*"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = " failover 2 set web app doc base"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_not_empty {get_attr {"web_xml_app_files[1].path"}}
is_empty {get_attr {"web_xml_app_doc_info[1].document_base"}}
}
on_true = parse_var_to_var {
from_var_name = "web_xml_app_files[*].path"
to_var_names = table {
name = "web_xml_app_doc_info"
col_names = "document_base"
}
parsing_strategy = regex_parsing {regex = "vfs([\\/\\\\].*\\.war)"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "adjust doc base - win"
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = transform {
src_table_name = "web_xml_app_doc_info"
target_table_name = "web_xml_app_doc_info"
operation {set_field {
field_name = "document_base"
value = concat {
get_attr {"home_dir"}
"\\deploy"
get_attr {"web_xml_app_doc_info[].document_base"}
}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "parse web.xml for app data"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = parse_text_file_to_var {
file_path = get_files_by_filter {
expression = get_attr {"web_xml_app_files[*].path"}
foreach_attribute_name = "forEach" // Attribute collection: Collects specific attributes from the discovered CI
}
var_names = table {
name = "web_xml_app_desc"
col_names = "desc"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/web-app"
fields {
field {
col_name = "desc"
xpath = "/web-app/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover parse web.xml for app data"
if {
condition = all {
eq {
get_attr {"RunMode"}
"horizontal"
}
is_empty {get_attr {"web_xml_app_desc[1].desc"}}
is_not_empty {get_attr {"web_files[1].file"}}
}
on_true = parse_text_file_to_var {
file_path = get_files_by_filter {
expression = get_attr {"web_files[*].file"}
foreach_attribute_name = "forEach" // Attribute collection: Collects specific attributes from the discovered CI
}
var_names = table {
name = "web_xml_app_desc"
col_names = "desc"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/web-app"
fields {
field {
col_name = "desc"
xpath = "/web-app/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "populate main web server CI "
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = transform {
src_table_name = "cmdb_ci_app_server_jboss"
target_table_name = "cmdb_ci_app_server_jboss"
operation {
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "install_directory"
value = eval {"javascript: rtrn = ${install_directory}; // Script execution: Custom script to perform a specific action or collect data
try{
var conf = ${conf_mode};
if(conf.contains(\"standalone\")){
rtrn = ${top_jboss_path} + ${path_delimiter} + \"standalone\";
}
}
catch(e){
//rtrn remains as initialized
}"}
}
set_field {
field_name = "running_process_command"
value = get_attr {"process.executable"}
}
set_field {
field_name = "running_process_key_parameters"
value = get_attr {"process.commandLine"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create web service CIs "
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = transform {
src_table_name = "jboss_services_table"
target_table_name = "cmdb_ci_web_service"
operation {set_field {
field_name = "name"
value = get_attr {"jboss_services_table[].name"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create web app CIs"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = merge {
table1_name = "web_xml_app_doc_info"
table2_name = "web_xml_app_info"
result_table_name = "cmdb_ci_web_application"
unmatched_lines = remove
condition = contains {
get_attr {"web_xml_app_doc_info[].document_base"}
get_attr {"web_xml_app_info[].name"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "relate web service CIs to main jboss server"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = relation_reference {
table1_name = "cmdb_ci_web_service"
table2_name = "cmdb_ci_app_server_jboss"
result_table_name = "result1"
unmatched_lines = keep
relation_type = "Runs on::Runs"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "relate web app CIs to main jboss server"
if {
condition = eq {
get_attr {"RunMode"}
"horizontal"
}
on_true = relation_reference {
table1_name = "cmdb_ci_web_application"
table2_name = "cmdb_ci_app_server_jboss"
result_table_name = "result2"
unmatched_lines = keep
relation_type = "Runs on::Runs"
ref_direction = parentToChild
ref_field_name = "app_server"
}
on_false = nop {}
}
}
}
|
OpenStack Cinder Volumes | I would like for you to help me build a Pattern that helps achieve Discovery of OpenStack Cinder Volumes. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "OpenStack Cinder Volumes"
id = "fc501e26db810010bf2fe0a1ca9619d9"
description = "null"
step {
name = "Get volumes details"
comment = "https://<service:port>/v3.0/<project_id>/volumes/detail - throws error
https://<service:port>/v3/<project_id>/volumes/detail - works"
if {
condition = is_not_empty {get_attr {"cinder_base_url"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Storage Resources.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_cinder[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_cinder[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id');
if (!input_object_id) { var resource = \"volumes/detail\";}
else { var resource = \"volumes/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var serviceURL = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
resultList.add(newJson);
}
}
CTX.setAttribute('volumes_details_response', resultList);"}
}
on_false = nop {}
}
}
step {
name = "HD: Parse the Volumes "
if {
condition = all {
is_empty {get_attr {"input_object_id"}}
is_not_empty {get_attr {"cinder_base_url"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes"
col_names = "volume_uuid","volume_size","volume_name","volume_status","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volumes/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_size"
xpath = "/root/volumes/size/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_name"
xpath = "/root/volumes/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_status"
xpath = "/root/volumes/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/volumes/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse the Volumes"
if {
condition = is_not_empty {get_attr {"input_object_id"}}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes"
col_names = "volume_uuid","volume_size","volume_name","volume_status","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volume/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_size"
xpath = "/root/volume/size/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_name"
xpath = "/root/volume/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_status"
xpath = "/root/volume/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/volume/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Filter out regions without volumes"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = is_not_empty {get_attr {"volumes"}}
on_true = filter {
src_table_name = "volumes"
target_table_name = "volumes"
condition = is_not_empty {get_attr {"volumes[].volume_uuid"}}
}
on_false = nop {}
}
}
step {
name = "HD: Parse Volumes with Description"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","volume_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volumes/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_description"
xpath = "/root/volumes/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Volumes with Description"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","volume_description"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volume/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_description"
xpath = "/root/volume/description/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the Description information to the volumes table"
if {
condition = is_not_empty {get_attr {"volumes_add"}}
on_true = merge {
table1_name = "volumes"
key1_name = "volume_uuid"
table2_name = "volumes_add"
key2_name = "volume_uuid"
result_table_name = "volumes"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "HD: Parse Volumes types"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","volume_type"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volumes/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_type"
xpath = "/root/volumes/volume_type/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Volumes types"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","volume_type"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volume/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_type"
xpath = "/root/volume/volume_type/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the Volume type information to the volumes table"
if {
condition = is_not_empty {get_attr {"volumes_add"}}
on_true = merge {
table1_name = "volumes"
key1_name = "volume_uuid"
table2_name = "volumes_add"
key2_name = "volume_uuid"
result_table_name = "volumes"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "HD: Parse Volumes attached to Instances"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","server_uuid"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volumes/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_uuid"
xpath = "/root/volumes/attachments/server_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Event: Parse Volumes attached to Instances"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","server_uuid"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volume/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_uuid"
xpath = "/root/volume/attachments/server_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add the Volume attached Instance information to the volumes table"
if {
condition = is_not_empty {get_attr {"volumes_add"}}
on_true = merge {
table1_name = "volumes"
key1_name = "volume_uuid"
table2_name = "volumes_add"
key2_name = "volume_uuid"
result_table_name = "volumes"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"volumes"}}
}
on_true = filter {
src_table_name = "volumes"
target_table_name = "volumes"
condition = eq {
get_attr {"volumes[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray()
var length = ldc.length
var region = ${volumes[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step {
name = "Put the volume ID as name if the name is blank"
if {
condition = is_not_empty {get_attr {"volumes"}}
on_true = transform {
src_table_name = "volumes"
target_table_name = "volumes"
operation {set_field {
field_name = "volume_name"
value = eval {"javascript: var resource_id = ${volumes[].volume_uuid}
var resource_name = ${volumes[].volume_name}
var rtrn = '';
if (!resource_name) {rtrn = resource_id}
else {rtrn = resource_name}"}
}}
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_storage_volume table"
if {
condition = is_not_empty {get_attr {"volumes"}}
on_true = transform {
src_table_name = "volumes"
target_table_name = "cmdb_ci_storage_volume"
operation {
set_field {
field_name = "object_id"
value = get_attr {"volumes[].volume_uuid"}
}
set_field {
field_name = "name"
value = get_attr {"volumes[].volume_name"}
}
set_field {
field_name = "status"
value = get_attr {"volumes[].volume_status"}
}
set_field {
field_name = "short_description"
value = get_attr {"volumes[].volume_description"}
}
set_field {
field_name = "storage_type"
value = get_attr {"volumes[].volume_type"}
}
}
}
on_false = nop {}
}
}
step {
name = "Parse the unique instances out of the Volumes table"
set_attr {
"tmp"
eval {"javascript:
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${volumes},[\"server_uuid\"]);
CTX.setAttribute(\"vm_instance\", tableWithoutDuplicates);
"}
}
}
step {
name = "Filter out empty server_uuid coming from unattached volumes"
if {
condition = contains {
get_attr {"vm_instance"}
""
}
on_true = filter {
src_table_name = "vm_instance"
target_table_name = "vm_instance"
condition = is_not_empty {get_attr {"vm_instance[].server_uuid"}}
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_vm_instance table"
comment = "Populate only the instance_id which is required for unique identification and leave the rest of the details to be discovered by the OpenStack Compute pattern."
if {
condition = is_not_empty {get_attr {"vm_instance"}}
on_true = transform {
src_table_name = "vm_instance"
target_table_name = "cmdb_ci_vm_instance"
operation {set_field {
field_name = "object_id"
value = get_attr {"vm_instance[].server_uuid"}
}}
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_vm_instance and cmdb_ci_openstack_datacenter"
if {
condition = is_not_empty {get_attr {"cmdb_ci_vm_instance"}}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "instance_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_storage_volume and cmdb_ci_openstack_datacenter"
if {
condition = is_not_empty {get_attr {"cmdb_ci_storage_volume"}}
on_true = relation_reference {
table1_name = "cmdb_ci_storage_volume"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "volume_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_storage_volume and cmdb_ci_vm_instance table"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_storage_volume"}}
is_not_empty {get_attr {"cmdb_ci_vm_instance"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
key1_name = "server_uuid"
table2_name = "cmdb_ci_storage_volume"
key2_name = "server_uuid"
result_table_name = "volume_to_instance"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "OpenStack Cinder Volumes"
id = "fc501e26db810010bf2fe0a1ca9619d9" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get volumes details"
comment = "https://<service:port>/v3.0/<project_id>/volumes/detail - throws error
https://<service:port>/v3/<project_id>/volumes/detail - works"
if {
condition = is_not_empty {get_attr {"cinder_base_url"}}
on_true = set_attr {
"tmp"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var resultList = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"OpenStack - Get Storage Resources.\");
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var servicesURL = CTX.getAttribute('links_cinder[*].url').toArray(); //get all services in the different regions
var region = CTX.getAttribute('links_cinder[*].region').toArray();
var table_size = servicesURL.length
var token = CTX.getAttribute('token');
var input_object_id = CTX.getAttribute('input_object_id'); // Unique identifier for the pattern
if (!input_object_id) { var resource = \"volumes/detail\";}
else { var resource = \"volumes/\" + input_object_id;}
if (token) {
var header = \"X-Auth-Token:\" + token;
for (i=0; i < table_size; i++) {
var serviceURL = servicesURL[i] + \"/\" + resource ;
try{
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
}
catch (e){
logger.error(\">>>>>>>>>>>>>>>>>>>>> generic resource REST request failed. exception=\" + e);
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources request=\" + response);
// 1 question left is how Packages.com.snc.sw.commands.HttpCallHandler handles pagination. If the response has pages, the bellow code needs to be modified.
var newJson = parseUtil.addTagToResult(\"region\",region[i],response.toString());
resultList.add(newJson);
}
}
CTX.setAttribute('volumes_details_response', resultList);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse the Volumes "
if {
condition = all {
is_empty {get_attr {"input_object_id"}}
is_not_empty {get_attr {"cinder_base_url"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes"
col_names = "volume_uuid","volume_size","volume_name","volume_status","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volumes/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_size"
xpath = "/root/volumes/size/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_name"
xpath = "/root/volumes/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_status"
xpath = "/root/volumes/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/volumes/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse the Volumes"
if {
condition = is_not_empty {get_attr {"input_object_id"}}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes"
col_names = "volume_uuid","volume_size","volume_name","volume_status","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volume/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_size"
xpath = "/root/volume/size/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_name"
xpath = "/root/volume/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_status"
xpath = "/root/volume/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/volume/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out regions without volumes"
comment = "If present, which should not be the case, but being overprotective."
if {
condition = is_not_empty {get_attr {"volumes"}}
on_true = filter {
src_table_name = "volumes"
target_table_name = "volumes"
condition = is_not_empty {get_attr {"volumes[].volume_uuid"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Volumes with Description" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","volume_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volumes/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/volumes/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Volumes with Description" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","volume_description" // Script execution: Custom script to perform a specific action or collect data
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volume/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_description" // Script execution: Custom script to perform a specific action or collect data
xpath = "/root/volume/description/text()" // Script execution: Custom script to perform a specific action or collect data
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the Description information to the volumes table" // Script execution: Custom script to perform a specific action or collect data
if {
condition = is_not_empty {get_attr {"volumes_add"}}
on_true = merge {
table1_name = "volumes"
key1_name = "volume_uuid"
table2_name = "volumes_add"
key2_name = "volume_uuid"
result_table_name = "volumes"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Volumes types"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","volume_type"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volumes/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_type"
xpath = "/root/volumes/volume_type/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Volumes types"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","volume_type"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volume/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "volume_type"
xpath = "/root/volume/volume_type/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the Volume type information to the volumes table"
if {
condition = is_not_empty {get_attr {"volumes_add"}}
on_true = merge {
table1_name = "volumes"
key1_name = "volume_uuid"
table2_name = "volumes_add"
key2_name = "volume_uuid"
result_table_name = "volumes"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "HD: Parse Volumes attached to Instances"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","server_uuid"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volumes/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_uuid"
xpath = "/root/volumes/attachments/server_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Event: Parse Volumes attached to Instances"
if {
condition = all {
is_not_empty {get_attr {"volumes"}}
is_not_empty {get_attr {"input_object_id"}}
}
on_true = parse_var_to_var {
from_var_name = "volumes_details_response"
to_var_names = table {
name = "volumes_add"
col_names = "volume_uuid","server_uuid"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "volume_uuid"
xpath = "/root/volume/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "server_uuid"
xpath = "/root/volume/attachments/server_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add the Volume attached Instance information to the volumes table"
if {
condition = is_not_empty {get_attr {"volumes_add"}}
on_true = merge {
table1_name = "volumes"
key1_name = "volume_uuid"
table2_name = "volumes_add"
key2_name = "volume_uuid"
result_table_name = "volumes"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"volumes"}}
}
on_true = filter {
src_table_name = "volumes"
target_table_name = "volumes"
condition = eq {
get_attr {"volumes[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray() // Script execution: Custom script to perform a specific action or collect data
var length = ldc.length
var region = ${volumes[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Put the volume ID as name if the name is blank"
if {
condition = is_not_empty {get_attr {"volumes"}}
on_true = transform {
src_table_name = "volumes"
target_table_name = "volumes"
operation {set_field {
field_name = "volume_name"
value = eval {"javascript: var resource_id = ${volumes[].volume_uuid} // Unique identifier for the pattern
var resource_name = ${volumes[].volume_name}
var rtrn = '';
if (!resource_name) {rtrn = resource_id}
else {rtrn = resource_name}"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_storage_volume table"
if {
condition = is_not_empty {get_attr {"volumes"}}
on_true = transform {
src_table_name = "volumes"
target_table_name = "cmdb_ci_storage_volume"
operation {
set_field {
field_name = "object_id"
value = get_attr {"volumes[].volume_uuid"}
}
set_field {
field_name = "name"
value = get_attr {"volumes[].volume_name"}
}
set_field {
field_name = "status"
value = get_attr {"volumes[].volume_status"}
}
set_field {
field_name = "short_description" // Script execution: Custom script to perform a specific action or collect data
value = get_attr {"volumes[].volume_description"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "storage_type"
value = get_attr {"volumes[].volume_type"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the unique instances out of the Volumes table"
set_attr {
"tmp"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${volumes},[\"server_uuid\"]);
CTX.setAttribute(\"vm_instance\", tableWithoutDuplicates);
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out empty server_uuid coming from unattached volumes"
if {
condition = contains {
get_attr {"vm_instance"}
""
}
on_true = filter {
src_table_name = "vm_instance"
target_table_name = "vm_instance"
condition = is_not_empty {get_attr {"vm_instance[].server_uuid"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_vm_instance table"
comment = "Populate only the instance_id which is required for unique identification and leave the rest of the details to be discovered by the OpenStack Compute pattern."
if {
condition = is_not_empty {get_attr {"vm_instance"}}
on_true = transform {
src_table_name = "vm_instance"
target_table_name = "cmdb_ci_vm_instance"
operation {set_field {
field_name = "object_id"
value = get_attr {"vm_instance[].server_uuid"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_vm_instance and cmdb_ci_openstack_datacenter"
if {
condition = is_not_empty {get_attr {"cmdb_ci_vm_instance"}}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "instance_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_storage_volume and cmdb_ci_openstack_datacenter"
if {
condition = is_not_empty {get_attr {"cmdb_ci_storage_volume"}}
on_true = relation_reference {
table1_name = "cmdb_ci_storage_volume"
key1_name = "region"
table2_name = "cmdb_ci_openstack_datacenter"
key2_name = "region"
result_table_name = "volume_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_storage_volume and cmdb_ci_vm_instance table"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_storage_volume"}}
is_not_empty {get_attr {"cmdb_ci_vm_instance"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_instance"
key1_name = "server_uuid"
table2_name = "cmdb_ci_storage_volume"
key2_name = "server_uuid"
result_table_name = "volume_to_instance"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
SNMP - Switch - Vlan | I would like for you to help me build a Pattern that helps achieve Discovery of SNMP - Switch - Vlan. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "SNMP - Switch - Vlan"
id = "fc811e29db352200868a7c841f961951"
description = "null"
step {
name = "Create isCisco variable"
comment = "Indicates whether it is a Cisco deviceValue determined by sysDescrDefault is \u201Cfalse\u201D"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = set_attr {
"isCisco"
"false"
}
on_false = nop {}
}
}
step {
name = "Create shouldRunSSHCommands variable"
comment = "Indicates whether we should block routing parts.Default value is true"
set_attr {
"shouldRunSSHCommands"
eval {"javascript: var test = Packages.com.service_now.mid.services.Config.get().getProperty(\"mid.run.ssh.command.snmp\", 'true');
test"}
}
}
step {
name = "Create isNexus variable"
comment = "Indicates whether it is a Cisco NexusValue determined by sysDescrDefault is \u201Cfalse\u201D"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = set_attr {
"isNexus"
"false"
}
on_false = nop {}
}
}
step {
name = "Get vtpVlanTable if not already polled"
comment = "iso.org.dod.internet.private.enterprises.cisco.ciscoMgmt.ciscoVtpMIB.vtpMIBObjects.vlanInfo.vtpVlanTable"
if {
condition = all {
is_empty {get_attr {"vtpVlanTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.9.9.46.1.3.1.1"
col_names = "3","2"
}
var_names = table {
name = "vtpVlanTable"
col_names = "vtpVlanType","vtpVlanState"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Juniper - Get jnxExVlanTable"
comment = "iso.org.dod.internet.private.enterprises.juniperMIB.jnxMibs.jnxExMibRoot.jnxExSwitching.jnxExVlan.jnxVlanMIBObjects.jnxExVlanTable
http://oidref.com/1.3.6.1.4.1.2636.3.40.1.5.1.5"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.2636.3.40.1.5.1.5.1"
col_names = "5"
}
var_names = table {
name = "jnxExVlanTable"
col_names = "jnxExVlanTag"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get vmMembershipSummaryTable"
comment = "iso.org.dod.internet.private.enterprises.cisco.ciscoMgmt.ciscoVlanMembershipMIB.ciscoVlanMembershipMIBObjects.vmMembership.vmMembershipSummaryTable
http://iphostmonitor.com/mib/oids/CISCO-VLAN-MEMBERSHIP-MIB/vmMembershipSummaryTable.html"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.9.9.68.1.2.1.1"
col_names = "1","2","3"
}
var_names = table {
name = "vmMembershipSummaryTable"
col_names = "vmMembershipSummaryVlanIndex","vmMembershipSummaryMemberPorts","vmMembershipSummaryMember2kPorts"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get dot1dStpPortTable"
comment = "iso.org.dod.internet.mgmt.mib-2.dot1dBridge.dot1dStp.dot1dStpPortTable
http://iphostmonitor.com/mib/oids/BRIDGE-MIB/dot1dStpPortTable.htmlRepresents STP entries for discovery_switch_spanning_tree_table"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.17.2.15.1"
col_names = "1","3","4","6","8"
}
var_names = table {
name = "dot1dStpPortTable"
col_names = "dot1dStpPort","dot1dStpPortState","dot1dStpPortEnable","dot1dStpPortDesignatedRoot","dot1dStpPortDesignatedBridge"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get dot1dBasePortTable if not already polled"
comment = "iso.org.dod.internet.mgmt.mib-2.dot1dBridge.dot1dBase.dot1dBasePortTable"
if {
condition = all {
is_empty {get_attr {"dot1dBasePortTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.17.1.4.1"
col_names = "1","2"
}
var_names = table {
name = "dot1dBasePortTable"
col_names = "dot1dBasePort","dot1dBasePortIfIndex"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get dot1dTpFdbTable if not already polled"
comment = "iso.org.dod.internet.mgmt.mib-2.dot1dBridge.dot1dBase.dot1dBasePortTable"
if {
condition = all {
is_empty {get_attr {"dot1dTpFdbTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.17.4.3.1"
col_names = "1","2","3"
}
var_names = table {
name = "dot1dTpFdbTable"
col_names = "dot1dTpFdbAddress","dot1dTpFdbPort","dot1dTpFdbStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Get sysDescr if not already polled"
comment = "iso.org.dod.internet.mgmt.mib-2.system.sysDescr"
if {
condition = all {
is_not_empty {get_attr {"sysDescr"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = "1.3.6.1.2.1.1.1"
var_names = "sysDescr"
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Set isCisco variable"
if {
condition = all {
contains {
get_attr {"sysDescr"}
"cisco"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"isCisco"
"true"
}
on_false = nop {}
}
}
step {
name = "Set isNexus variable"
if {
condition = all {
contains {
get_attr {"sysDescr"}
"nx-os"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"isNexus"
"true"
}
on_false = nop {}
}
}
step {
name = "Extract VLAN id"
if {
condition = all {
is_not_empty {get_attr {"vtpVlanTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = transform {
src_table_name = "vtpVlanTable"
target_table_name = "vtpVlanTable"
operation {set_field {
field_name = "vlanId"
value = eval {"javascript:var rtrn = '';rtrn = NetworkDiscoveryUtil.extractFirstMatchWithRegex(${vtpVlanTable[].instanceID},/.*\\.([0-9]+)$/);"}
}}
}
on_false = nop {}
}
}
step {
name = "Create vlanList"
comment = "Contains vlan list. Depends the vendor, it can be composed out of the following sources:vtpVlanTable, vmMembershipSummaryTable or jnxExVlanTable"
if {
condition = all {
is_not_empty {get_attr {"vtpVlanTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"vlanList"
get_attr {"vtpVlanTable[*].vlanId"}
}
on_false = nop {}
}
}
step {
name = "If vtpVlanTable not available, try vmMembershipSummaryTable"
if {
condition = all {
is_empty {get_attr {"vtpVlanTable"}}
is_not_empty {get_attr {"vmMembershipSummaryTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = transform {
src_table_name = "vmMembershipSummaryTable"
target_table_name = "vmMembershipSummaryTable"
operation {set_field {
field_name = "vlanId"
value = eval {"javascript: var rtrn = '';
rtrn = ${vmMembershipSummaryTable[].instanceID}.replace(/\\./,'');"}
}}
}
on_false = nop {}
}
}
step {
name = "Create vlanList"
if {
condition = all {
is_empty {get_attr {"vtpVlanTable"}}
is_not_empty {get_attr {"vmMembershipSummaryTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"vlanList"
get_attr {"vmMembershipSummaryTable[*].vlanId"}
}
on_false = nop {}
}
}
step {
name = "Juniper - If vmMembershipSummaryTable not available, try jnxExVlanTable"
if {
condition = all {
is_empty {get_attr {"vtpVlanTable"}}
is_empty {get_attr {"vmMembershipSummaryTable"}}
is_not_empty {get_attr {"jnxExVlanTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"vlanList"
get_attr {"jnxExVlanTable[*].instanceID"}
}
on_false = nop {}
}
}
step {
name = "Handle FDB for Cisco"
comment = "In this step we\u2019re using EVAL clause to create forwarding table for Cisco.In Cisco, in order to get FDB, you must poll the table with the vlan id. Because we don\u2019t have loop mechanism, we must use EVAL to loop through all vlans, and poll the table separately for each vlan.In this EVAL we walk through vlans, and use Neebula's method on the context variable to fetch the data.We\u2019re using \u201CCTX.getCommandManager().snmpTableQueryWithContext\u201D method to poll the device & \u201CNetworkDiscoveryUtil.buildTableAttribute\u201D to create a table from the results. We join all results together to create a one table with all FDBs"
if {
condition = all {
eq {
get_attr {"isCisco"}
"true"
}
is_not_empty {get_attr {"vlanList"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"notInUse"
eval {"javascript: try{
var rtrn = '';var vlanList = ${vlanList};var snmpQueryResult;var debuggerFormattedTable;var forwardingTableName = \"dot1dTpFdbTable\";var finalForwardingTable = new Packages.java.util.ArrayList();
var joinTables = function(tabletoAddTo, tableToAdd){tabletoAddTo.addAll(tableToAdd);};
var addTableToContext = function(tableToAdd){
CTX.setAttribute(forwardingTableName, tableToAdd);
};
for(var i = 0; i < vlanList.size(); i++){
snmpQueryResult = CTX.getCommandManager().snmpTableQueryWithContext(\"1.3.6.1.2.1.17.4.3.1\", [\"1\", \"2\", \"3\"], \"@\" + vlanList.get(i), \"vlan-\" + vlanList.get(i), CTX);debuggerFormattedTable = NetworkDiscoveryUtil.buildTableAttribute([\"dot1dTpFdbAddress\", \"dot1dTpFdbPort\", \"dot1dTpFdbStatus\"], [\"1\", \"2\", \"3\"], [\"dot1dTpFdbAddress\"], snmpQueryResult,vlanList.get(i));joinTables(finalForwardingTable,debuggerFormattedTable);}
addTableToContext(finalForwardingTable);rtrn = '';
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Step Failed - Handle FDB for Cisco\").info(e.message);
}"}
}
on_false = nop {}
}
}
step {
name = "If isNexus and forwardingTable is empty, use SSH"
if {
condition = all {
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
eq {
get_attr {"shouldRunSSHCommands"}
"true"
}
eq {
get_attr {"isCisco"}
"true"
}
eq {
get_attr {"isNexus"}
"true"
}
is_empty {get_attr {"dot1dTpFdbTable"}}
}
on_true = runcmd_to_var {
cmd = "show mac address-table"
var_names = table {
name = "dot1dTpFdbTable"
col_names = "vlan_id","dot1dTpFdbAddress","dot1dTpFdbStatus","dot1dTpFdbPort"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "(^\\s*VLAN)|(^Legend)|(^\\s*\\* - primary)|(^\\s*age)|(^----)|(^\\s*\\(T\\))"
delimiters = " "
selected_positions = 2,3,4,8
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Normalize MAC on nexus results"
if {
condition = all {
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
eq {
get_attr {"shouldRunSSHCommands"}
"true"
}
eq {
get_attr {"isCisco"}
"true"
}
eq {
get_attr {"isNexus"}
"true"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
operation {set_field {
field_name = "dot1dTpFdbAddress"
value = eval {"javascript: try{
var rtrn = '';
var currentMAC = ${dot1dTpFdbTable[].dot1dTpFdbAddress};
rtrn = currentMAC.replace(/\\./g,'');
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Normalize MAC on nexus results\").info(e.message);
}"}
}}
}
on_false = nop {}
}
}
step {
name = "Handle FDB Using Q-Bridge-MIB"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.17.7.1.2.2.1"
col_names = "1","2","3"
}
var_names = table {
name = "dot1dTpFdbTable"
col_names = "dot1dTpFdbAddress","dot1dTpFdbPort","dot1dTpFdbStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "If we have results from Q-Brigde-MIB, extract VLAN ID"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
operation {set_field {
field_name = "vlan_id"
value = eval {"javascript: var rtrn = '',
instanceID = ${dot1dTpFdbTable[].instanceID},
tableKeyParts = instanceID.split('.');
/*
* The key should contain 7 numbers. 1 for dot1qFdbId (we used dot1dTpFdbTable as the name to be consistent! we are using Q-BRIDGE-MIB here) & 6 more for mac address.
* If we don't have 7 parts, return an empty value so we can filter empty FdbIds
*/
rtrn = ((tableKeyParts.length == 7) ? instanceID.split('.')[0] : '');"}
}}
}
on_false = nop {}
}
}
step {
name = "Remove rows with empty vlan, since this value is required for discovery_switch_fwd_table"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
}
on_true = filter {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
condition = is_not_empty {get_attr {"dot1dTpFdbTable[].vlan_id"}}
}
on_false = nop {}
}
}
step {
name = "Juniper - Create vlan column for jnxExVlanTable"
comment = "jnxExVlanTable instanceID is the internal VLAN used by the device
This step is used in order not to override instanceID of dot1dTpFdbTable while merging both tables next step"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"jnxExVlanTable"}}
}
on_true = transform {
src_table_name = "jnxExVlanTable"
target_table_name = "jnxExVlanTable"
operation {set_field {
field_name = "vlan_id"
value = get_attr {"jnxExVlanTable[].instanceID"}
}}
}
on_false = nop {}
}
}
step {
name = "Juniper - Match generic VLAN to jnx VLAN"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
is_not_empty {get_attr {"jnxExVlanTable"}}
}
on_true = merge {
table1_name = "dot1dTpFdbTable"
key1_name = "vlan_id"
table2_name = "jnxExVlanTable"
key2_name = "vlan_id"
result_table_name = "dot1dTpFdbTable"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "Juniper - Use jnx Vlan tag if found"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
is_not_empty {get_attr {"dot1dTpFdbTable[].jnxExVlanTag"}}
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
operation {set_field {
field_name = "vlan_id"
value = get_attr {"dot1dTpFdbTable[].jnxExVlanTag"}
}}
}
on_false = nop {}
}
}
step {
name = "Normalize mac & status in FDB if needed"
comment = "Normalize MACs and statuses on forwarding table
MACs normalized using \u201CconvertMac\u201D method in \u201CSNMP - Switch \u2013 ForwardingTable\u201D probe, and statuses normalized using hashmap
Added Try/cach Shay H."
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
operation {
set_field {
field_name = "dot1dTpFdbAddress"
value = eval {"javascript: //Added Try/Cach After dot1dTpFdbTable[].instanceID Had Problematic Data
//Like - unauthorized perssonel will be .......
var rtrn = '';
var instanceID = ${dot1dTpFdbTable[].instanceID};
try{
if (instanceID) {
var convertMac = function(mac) {var hex;var h;for (var x=0; x<mac.length; x++) {h = (+mac[x]).toString(16);if (x == 0) {hex = (h.length < 2? '0' : '') + h + ':';}else if (x == mac.length - 1) {hex += (h.length < 2? '0' : '') + h;}else {hex += (h.length < 2? '0' : '') + h + ':';}}return hex;};rtrn = convertMac(instanceID.split('.').slice(-6));
}
else {
var fdbAddress = ${dot1dTpFdbTable[].dot1dTpFdbAddress};
if (fdbAddress) {
var strTemp = new Packages.java.lang.String(fdbAddress);
if (strTemp.length() >= 12)
rtrn = strTemp.replaceAll(\"(.{2})\", \"$1:\").substring(0,17);
else
rtrn = fdbAddress;
}
}
}
//In Case Of Error Display In Log
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger (\" Step Failure - Normalize mac & status...\").error(e);
}"}
}
set_field {
field_name = "dot1dTpFdbStatus"
value = eval {"javascript: try{
var rtrn = '';var currentstatus = ${dot1dTpFdbTable[].dot1dTpFdbStatus};var statusMap = {1:'other',2:'invalid',3:'learned',4:'self',5:'mgmt'};rtrn = statusMap[currentstatus] || 'unknown';
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Step Failed - Normalize mac & status in FDB if needed\").info(e.message);
}"}
}
}
}
on_false = nop {}
}
}
step {
name = "Remove zeroed mac addresses"
comment = "Normalize MACs and statuses on forwarding table
MACs normalized using \u201CconvertMac\u201D method in \u201CSNMP - Switch \u2013 ForwardingTable\u201D probe, and statuses normalized using hashmap"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = filter {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
condition = neq {
get_attr {"dot1dTpFdbTable[].dot1dTpFdbAddress"}
"00:00:00:00:00:00"
}
}
on_false = nop {}
}
}
step {
name = "Insert data to discovery_switch_fwd_table"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "discovery_switch_fwd_table"
operation {
set_field {
field_name = "mac_address"
value = get_attr {"dot1dTpFdbTable[].dot1dTpFdbAddress"}
}
set_field {
field_name = "port"
value = get_attr {"dot1dTpFdbTable[].dot1dTpFdbPort"}
}
set_field {
field_name = "status"
value = get_attr {"dot1dTpFdbTable[].dot1dTpFdbStatus"}
}
set_field {
field_name = "vlan_id"
value = get_attr {"dot1dTpFdbTable[].vlan_id"}
}
}
}
on_false = nop {}
}
}
step {
name = "Remove duplicate forwarding rules"
if {
condition = eq {
get_attr {"shouldRunSwitchLogic"}
"true"
}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${discovery_switch_fwd_table},['mac_address','vlan_id']);CTX.setAttribute(\"discovery_switch_fwd_table\", tableWithoutDuplicates); "}
}
on_false = nop {}
}
}
step {
name = "Handle bridge ports for Cisco"
comment = "Same step as \"Handle FDB for Cisco\" but on bridge portsThe reason why there is no step like \"Handle FDB for Juniper\" for this table is that non-Cisco devices give this information correctly, with no need for vlan id."
if {
condition = all {
eq {
get_attr {"isCisco"}
"true"
}
is_not_empty {get_attr {"vlanList"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"notInUse"
eval {"javascript: try{
var rtrn = '';var vlanList = ${vlanList};var snmpQueryResult;var debuggerFormattedTable;var bridgePortTableName = \"dot1dBasePortTable\";var finalBridgePortTable = new Packages.java.util.ArrayList();var joinTables = function(tabletoAddTo, tableToAdd){tabletoAddTo.addAll(tableToAdd);};var addTableToContext = function(tableToAdd){CTX.setAttribute(bridgePortTableName, tableToAdd);};for(var i = 0; i < vlanList.size(); i++){snmpQueryResult = CTX.getCommandManager().snmpTableQueryWithContext(\"1.3.6.1.2.1.17.1.4.1\", [\"1\", \"2\"], \"@\" + vlanList.get(i), \"vlan-\" + vlanList.get(i), CTX);debuggerFormattedTable = NetworkDiscoveryUtil.buildTableAttribute([\"dot1dBasePort\", \"dot1dBasePortIfIndex\"], [\"1\", \"2\"], null, snmpQueryResult,vlanList.get(i));joinTables(finalBridgePortTable,debuggerFormattedTable);}addTableToContext(finalBridgePortTable);rtrn = '';
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Step failed - Handle bridge ports for Cisco\").info(e.message);
}"}
}
on_false = nop {}
}
}
step {
name = "Remove bridge ports without ifIndex"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = filter {
src_table_name = "dot1dBasePortTable"
target_table_name = "dot1dBasePortTable"
condition = is_not_empty {get_attr {"dot1dBasePortTable[].dot1dBasePortIfIndex"}}
}
on_false = nop {}
}
}
step {
name = "Insert data to discovery_switch_bridge_port_table"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = transform {
src_table_name = "dot1dBasePortTable"
target_table_name = "discovery_switch_bridge_port_table"
operation {
set_field {
field_name = "port"
value = get_attr {"dot1dBasePortTable[].dot1dBasePort"}
}
set_field {
field_name = "interface_index"
value = get_attr {"dot1dBasePortTable[].dot1dBasePortIfIndex"}
}
}
}
on_false = nop {}
}
}
step {
name = "Remove duplicate bridge ports"
if {
condition = eq {
get_attr {"shouldRunSwitchLogic"}
"true"
}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${discovery_switch_bridge_port_table},['interface_index','port']);CTX.setAttribute(\"discovery_switch_bridge_port_table\", tableWithoutDuplicates); "}
}
on_false = nop {}
}
}
step {
name = "Handle STP for Cisco"
comment = "Same step as \"Handle FDB for Cisco\" but on STP"
if {
condition = all {
eq {
get_attr {"isCisco"}
"true"
}
is_not_empty {get_attr {"vlanList"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"notInUse"
eval {"javascript: try{
var rtrn = '';var vlanList = ${vlanList};var snmpQueryResult;var debuggerFormattedTable;var stpTableName = \"dot1dStpPortTable\";var finalStpTable = new Packages.java.util.ArrayList();var joinTables = function(tabletoAddTo, tableToAdd){tabletoAddTo.addAll(tableToAdd);};var addTableToContext = function(tableToAdd){CTX.setAttribute(stpTableName, tableToAdd);};for(var i = 0; i < vlanList.size(); i++){snmpQueryResult = CTX.getCommandManager().snmpTableQueryWithContext(\"1.3.6.1.2.1.17.2.15.1\", [\"1\", \"3\", \"4\", \"6\", \"8\"], \"@\" + vlanList.get(i), \"vlan-\" + vlanList.get(i), CTX);debuggerFormattedTable = NetworkDiscoveryUtil.buildTableAttribute([\"dot1dStpPort\", \"dot1dStpPortState\", \"dot1dStpPortEnable\", \"dot1dStpPortDesignatedRoot\", \"dot1dStpPortDesignatedBridge\"], [\"1\", \"3\", \"4\", \"6\", \"8\"], null, snmpQueryResult,vlanList.get(i));joinTables(finalStpTable,debuggerFormattedTable);}addTableToContext(finalStpTable);rtrn = '';
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Step Failed - Handle STP for Cisco\").info(e.message);
}"}
}
on_false = nop {}
}
}
step {
name = "Insert data to discovery_switch_spanning_tree_table"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = transform {
src_table_name = "dot1dStpPortTable"
target_table_name = "discovery_switch_spanning_tree_table"
operation {
set_field {
field_name = "designated_root"
value = eval {"javascript:
try{
var rtrn = '';var currentMacAddress = ${dot1dStpPortTable[].dot1dStpPortDesignatedRoot};rtrn = currentMacAddress.replace(/-/g, ':').slice(6).toLowerCase();
}
//In Case Of Error Display In Log
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger (\" Step Failure -Insert data to discovery_switch_spanning_tree_table...\").error(e);
}
"}
}
set_field {
field_name = "designated_bridge_mac"
value = eval {"javascript:var rtrn = '';var currentMacAddress = ${dot1dStpPortTable[].dot1dStpPortDesignatedBridge};rtrn = currentMacAddress.replace(/-/g, ':').slice(6).toLowerCase();"}
}
set_field {
field_name = "port_enable"
value = eval {"javascript:var rtrn = '';var enableMap = {1:'enabled',2:'disabled'};var currentEnableStatus = ${dot1dStpPortTable[].dot1dStpPortEnable};rtrn = enableMap[currentEnableStatus];"}
}
set_field {
field_name = "port_state"
value = eval {"javascript:var rtrn = '';var statusMap = {1:'disabled',2:'blocking',3:'listening',4:'learning',5:'forwarding',6:'broken'};var currentState = ${dot1dStpPortTable[].dot1dStpPortState};rtrn = statusMap[currentState];"}
}
set_field {
field_name = "port"
value = get_attr {"dot1dStpPortTable[].dot1dStpPort"}
}
}
}
on_false = nop {}
}
}
step {
name = "Remove duplicate spanning tree entries"
if {
condition = eq {
get_attr {"shouldRunSwitchLogic"}
"true"
}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${discovery_switch_spanning_tree_table},\"port\");CTX.setAttribute(\"discovery_switch_spanning_tree_table\", tableWithoutDuplicates); "}
}
on_false = nop {}
}
}
}
| library {
name = "SNMP - Switch - Vlan"
id = "fc811e29db352200868a7c841f961951" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create isCisco variable"
comment = "Indicates whether it is a Cisco deviceValue determined by sysDescrDefault is \u201Cfalse\u201D"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = set_attr {
"isCisco"
"false"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create shouldRunSSHCommands variable"
comment = "Indicates whether we should block routing parts.Default value is true"
set_attr {
"shouldRunSSHCommands"
eval {"javascript: var test = Packages.com.service_now.mid.services.Config.get().getProperty(\"mid.run.ssh.command.snmp\", 'true'); // Script execution: Custom script to perform a specific action or collect data
test"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create isNexus variable"
comment = "Indicates whether it is a Cisco NexusValue determined by sysDescrDefault is \u201Cfalse\u201D"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = set_attr {
"isNexus"
"false"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get vtpVlanTable if not already polled"
comment = "iso.org.dod.internet.private.enterprises.cisco.ciscoMgmt.ciscoVtpMIB.vtpMIBObjects.vlanInfo.vtpVlanTable"
if {
condition = all {
is_empty {get_attr {"vtpVlanTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.9.9.46.1.3.1.1"
col_names = "3","2"
}
var_names = table {
name = "vtpVlanTable"
col_names = "vtpVlanType","vtpVlanState"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Juniper - Get jnxExVlanTable"
comment = "iso.org.dod.internet.private.enterprises.juniperMIB.jnxMibs.jnxExMibRoot.jnxExSwitching.jnxExVlan.jnxVlanMIBObjects.jnxExVlanTable
http://oidref.com/1.3.6.1.4.1.2636.3.40.1.5.1.5"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.2636.3.40.1.5.1.5.1"
col_names = "5"
}
var_names = table {
name = "jnxExVlanTable"
col_names = "jnxExVlanTag"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get vmMembershipSummaryTable"
comment = "iso.org.dod.internet.private.enterprises.cisco.ciscoMgmt.ciscoVlanMembershipMIB.ciscoVlanMembershipMIBObjects.vmMembership.vmMembershipSummaryTable
http://iphostmonitor.com/mib/oids/CISCO-VLAN-MEMBERSHIP-MIB/vmMembershipSummaryTable.html"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.9.9.68.1.2.1.1"
col_names = "1","2","3"
}
var_names = table {
name = "vmMembershipSummaryTable"
col_names = "vmMembershipSummaryVlanIndex","vmMembershipSummaryMemberPorts","vmMembershipSummaryMember2kPorts"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get dot1dStpPortTable"
comment = "iso.org.dod.internet.mgmt.mib-2.dot1dBridge.dot1dStp.dot1dStpPortTable
http://iphostmonitor.com/mib/oids/BRIDGE-MIB/dot1dStpPortTable.htmlRepresents STP entries for discovery_switch_spanning_tree_table"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.17.2.15.1"
col_names = "1","3","4","6","8"
}
var_names = table {
name = "dot1dStpPortTable"
col_names = "dot1dStpPort","dot1dStpPortState","dot1dStpPortEnable","dot1dStpPortDesignatedRoot","dot1dStpPortDesignatedBridge"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get dot1dBasePortTable if not already polled"
comment = "iso.org.dod.internet.mgmt.mib-2.dot1dBridge.dot1dBase.dot1dBasePortTable"
if {
condition = all {
is_empty {get_attr {"dot1dBasePortTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.17.1.4.1"
col_names = "1","2"
}
var_names = table {
name = "dot1dBasePortTable"
col_names = "dot1dBasePort","dot1dBasePortIfIndex"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get dot1dTpFdbTable if not already polled"
comment = "iso.org.dod.internet.mgmt.mib-2.dot1dBridge.dot1dBase.dot1dBasePortTable"
if {
condition = all {
is_empty {get_attr {"dot1dTpFdbTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.17.4.3.1"
col_names = "1","2","3"
}
var_names = table {
name = "dot1dTpFdbTable"
col_names = "dot1dTpFdbAddress","dot1dTpFdbPort","dot1dTpFdbStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get sysDescr if not already polled"
comment = "iso.org.dod.internet.mgmt.mib-2.system.sysDescr"
if {
condition = all {
is_not_empty {get_attr {"sysDescr"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = "1.3.6.1.2.1.1.1"
var_names = "sysDescr"
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set isCisco variable"
if {
condition = all {
contains {
get_attr {"sysDescr"}
"cisco"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"isCisco"
"true"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set isNexus variable"
if {
condition = all {
contains {
get_attr {"sysDescr"}
"nx-os"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"isNexus"
"true"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Extract VLAN id"
if {
condition = all {
is_not_empty {get_attr {"vtpVlanTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = transform {
src_table_name = "vtpVlanTable"
target_table_name = "vtpVlanTable"
operation {set_field {
field_name = "vlanId"
value = eval {"javascript:var rtrn = '';rtrn = NetworkDiscoveryUtil.extractFirstMatchWithRegex(${vtpVlanTable[].instanceID},/.*\\.([0-9]+)$/);"} // Script execution: Custom script to perform a specific action or collect data
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create vlanList"
comment = "Contains vlan list. Depends the vendor, it can be composed out of the following sources:vtpVlanTable, vmMembershipSummaryTable or jnxExVlanTable"
if {
condition = all {
is_not_empty {get_attr {"vtpVlanTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"vlanList"
get_attr {"vtpVlanTable[*].vlanId"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If vtpVlanTable not available, try vmMembershipSummaryTable"
if {
condition = all {
is_empty {get_attr {"vtpVlanTable"}}
is_not_empty {get_attr {"vmMembershipSummaryTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = transform {
src_table_name = "vmMembershipSummaryTable"
target_table_name = "vmMembershipSummaryTable"
operation {set_field {
field_name = "vlanId"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
rtrn = ${vmMembershipSummaryTable[].instanceID}.replace(/\\./,'');"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create vlanList"
if {
condition = all {
is_empty {get_attr {"vtpVlanTable"}}
is_not_empty {get_attr {"vmMembershipSummaryTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"vlanList"
get_attr {"vmMembershipSummaryTable[*].vlanId"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Juniper - If vmMembershipSummaryTable not available, try jnxExVlanTable"
if {
condition = all {
is_empty {get_attr {"vtpVlanTable"}}
is_empty {get_attr {"vmMembershipSummaryTable"}}
is_not_empty {get_attr {"jnxExVlanTable"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"vlanList"
get_attr {"jnxExVlanTable[*].instanceID"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Handle FDB for Cisco"
comment = "In this step we\u2019re using EVAL clause to create forwarding table for Cisco.In Cisco, in order to get FDB, you must poll the table with the vlan id. Because we don\u2019t have loop mechanism, we must use EVAL to loop through all vlans, and poll the table separately for each vlan.In this EVAL we walk through vlans, and use Neebula's method on the context variable to fetch the data.We\u2019re using \u201CCTX.getCommandManager().snmpTableQueryWithContext\u201D method to poll the device & \u201CNetworkDiscoveryUtil.buildTableAttribute\u201D to create a table from the results. We join all results together to create a one table with all FDBs" // Step definition: Represents a single action or set of actions in the pattern
if {
condition = all {
eq {
get_attr {"isCisco"}
"true"
}
is_not_empty {get_attr {"vlanList"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"notInUse"
eval {"javascript: try{ // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';var vlanList = ${vlanList};var snmpQueryResult;var debuggerFormattedTable;var forwardingTableName = \"dot1dTpFdbTable\";var finalForwardingTable = new Packages.java.util.ArrayList();
var joinTables = function(tabletoAddTo, tableToAdd){tabletoAddTo.addAll(tableToAdd);};
var addTableToContext = function(tableToAdd){
CTX.setAttribute(forwardingTableName, tableToAdd);
};
for(var i = 0; i < vlanList.size(); i++){
snmpQueryResult = CTX.getCommandManager().snmpTableQueryWithContext(\"1.3.6.1.2.1.17.4.3.1\", [\"1\", \"2\", \"3\"], \"@\" + vlanList.get(i), \"vlan-\" + vlanList.get(i), CTX);debuggerFormattedTable = NetworkDiscoveryUtil.buildTableAttribute([\"dot1dTpFdbAddress\", \"dot1dTpFdbPort\", \"dot1dTpFdbStatus\"], [\"1\", \"2\", \"3\"], [\"dot1dTpFdbAddress\"], snmpQueryResult,vlanList.get(i));joinTables(finalForwardingTable,debuggerFormattedTable);}
addTableToContext(finalForwardingTable);rtrn = '';
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Step Failed - Handle FDB for Cisco\").info(e.message);
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If isNexus and forwardingTable is empty, use SSH"
if {
condition = all {
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
eq {
get_attr {"shouldRunSSHCommands"}
"true"
}
eq {
get_attr {"isCisco"}
"true"
}
eq {
get_attr {"isNexus"}
"true"
}
is_empty {get_attr {"dot1dTpFdbTable"}}
}
on_true = runcmd_to_var {
cmd = "show mac address-table"
var_names = table {
name = "dot1dTpFdbTable"
col_names = "vlan_id","dot1dTpFdbAddress","dot1dTpFdbStatus","dot1dTpFdbPort"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "(^\\s*VLAN)|(^Legend)|(^\\s*\\* - primary)|(^\\s*age)|(^----)|(^\\s*\\(T\\))"
delimiters = " "
selected_positions = 2,3,4,8
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Normalize MAC on nexus results"
if {
condition = all {
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
eq {
get_attr {"shouldRunSSHCommands"}
"true"
}
eq {
get_attr {"isCisco"}
"true"
}
eq {
get_attr {"isNexus"}
"true"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
operation {set_field {
field_name = "dot1dTpFdbAddress"
value = eval {"javascript: try{ // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
var currentMAC = ${dot1dTpFdbTable[].dot1dTpFdbAddress};
rtrn = currentMAC.replace(/\\./g,'');
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Normalize MAC on nexus results\").info(e.message);
}"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Handle FDB Using Q-Bridge-MIB"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.2.1.17.7.1.2.2.1"
col_names = "1","2","3"
}
var_names = table {
name = "dot1dTpFdbTable"
col_names = "dot1dTpFdbAddress","dot1dTpFdbPort","dot1dTpFdbStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If we have results from Q-Brigde-MIB, extract VLAN ID"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
operation {set_field {
field_name = "vlan_id"
value = eval {"javascript: var rtrn = '', // Script execution: Custom script to perform a specific action or collect data
instanceID = ${dot1dTpFdbTable[].instanceID},
tableKeyParts = instanceID.split('.');
/*
* The key should contain 7 numbers. 1 for dot1qFdbId (we used dot1dTpFdbTable as the name to be consistent! we are using Q-BRIDGE-MIB here) & 6 more for mac address.
* If we don't have 7 parts, return an empty value so we can filter empty FdbIds
*/
rtrn = ((tableKeyParts.length == 7) ? instanceID.split('.')[0] : '');"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove rows with empty vlan, since this value is required for discovery_switch_fwd_table"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
}
on_true = filter {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
condition = is_not_empty {get_attr {"dot1dTpFdbTable[].vlan_id"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Juniper - Create vlan column for jnxExVlanTable"
comment = "jnxExVlanTable instanceID is the internal VLAN used by the device
This step is used in order not to override instanceID of dot1dTpFdbTable while merging both tables next step" // Step definition: Represents a single action or set of actions in the pattern
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"jnxExVlanTable"}}
}
on_true = transform {
src_table_name = "jnxExVlanTable"
target_table_name = "jnxExVlanTable"
operation {set_field {
field_name = "vlan_id"
value = get_attr {"jnxExVlanTable[].instanceID"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Juniper - Match generic VLAN to jnx VLAN"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
is_not_empty {get_attr {"jnxExVlanTable"}}
}
on_true = merge {
table1_name = "dot1dTpFdbTable"
key1_name = "vlan_id"
table2_name = "jnxExVlanTable"
key2_name = "vlan_id"
result_table_name = "dot1dTpFdbTable"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Juniper - Use jnx Vlan tag if found"
if {
condition = all {
eq {
get_attr {"isCisco"}
"false"
}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
is_not_empty {get_attr {"dot1dTpFdbTable"}}
is_not_empty {get_attr {"dot1dTpFdbTable[].jnxExVlanTag"}}
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
operation {set_field {
field_name = "vlan_id"
value = get_attr {"dot1dTpFdbTable[].jnxExVlanTag"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Normalize mac & status in FDB if needed"
comment = "Normalize MACs and statuses on forwarding table
MACs normalized using \u201CconvertMac\u201D method in \u201CSNMP - Switch \u2013 ForwardingTable\u201D probe, and statuses normalized using hashmap
Added Try/cach Shay H."
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
operation {
set_field {
field_name = "dot1dTpFdbAddress"
value = eval {"javascript: //Added Try/Cach After dot1dTpFdbTable[].instanceID Had Problematic Data // Script execution: Custom script to perform a specific action or collect data
//Like - unauthorized perssonel will be .......
var rtrn = '';
var instanceID = ${dot1dTpFdbTable[].instanceID};
try{
if (instanceID) {
var convertMac = function(mac) {var hex;var h;for (var x=0; x<mac.length; x++) {h = (+mac[x]).toString(16);if (x == 0) {hex = (h.length < 2? '0' : '') + h + ':';}else if (x == mac.length - 1) {hex += (h.length < 2? '0' : '') + h;}else {hex += (h.length < 2? '0' : '') + h + ':';}}return hex;};rtrn = convertMac(instanceID.split('.').slice(-6));
}
else {
var fdbAddress = ${dot1dTpFdbTable[].dot1dTpFdbAddress};
if (fdbAddress) {
var strTemp = new Packages.java.lang.String(fdbAddress);
if (strTemp.length() >= 12)
rtrn = strTemp.replaceAll(\"(.{2})\", \"$1:\").substring(0,17);
else
rtrn = fdbAddress;
}
}
}
//In Case Of Error Display In Log
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger (\" Step Failure - Normalize mac & status...\").error(e);
}"}
}
set_field {
field_name = "dot1dTpFdbStatus"
value = eval {"javascript: try{ // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';var currentstatus = ${dot1dTpFdbTable[].dot1dTpFdbStatus};var statusMap = {1:'other',2:'invalid',3:'learned',4:'self',5:'mgmt'};rtrn = statusMap[currentstatus] || 'unknown';
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Step Failed - Normalize mac & status in FDB if needed\").info(e.message);
}"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove zeroed mac addresses"
comment = "Normalize MACs and statuses on forwarding table
MACs normalized using \u201CconvertMac\u201D method in \u201CSNMP - Switch \u2013 ForwardingTable\u201D probe, and statuses normalized using hashmap"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = filter {
src_table_name = "dot1dTpFdbTable"
target_table_name = "dot1dTpFdbTable"
condition = neq {
get_attr {"dot1dTpFdbTable[].dot1dTpFdbAddress"}
"00:00:00:00:00:00"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert data to discovery_switch_fwd_table"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = transform {
src_table_name = "dot1dTpFdbTable"
target_table_name = "discovery_switch_fwd_table"
operation {
set_field {
field_name = "mac_address"
value = get_attr {"dot1dTpFdbTable[].dot1dTpFdbAddress"}
}
set_field {
field_name = "port"
value = get_attr {"dot1dTpFdbTable[].dot1dTpFdbPort"}
}
set_field {
field_name = "status"
value = get_attr {"dot1dTpFdbTable[].dot1dTpFdbStatus"}
}
set_field {
field_name = "vlan_id"
value = get_attr {"dot1dTpFdbTable[].vlan_id"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate forwarding rules"
if {
condition = eq {
get_attr {"shouldRunSwitchLogic"}
"true"
}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${discovery_switch_fwd_table},['mac_address','vlan_id']);CTX.setAttribute(\"discovery_switch_fwd_table\", tableWithoutDuplicates); "} // Script execution: Custom script to perform a specific action or collect data
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Handle bridge ports for Cisco"
comment = "Same step as \"Handle FDB for Cisco\" but on bridge portsThe reason why there is no step like \"Handle FDB for Juniper\" for this table is that non-Cisco devices give this information correctly, with no need for vlan id." // Step definition: Represents a single action or set of actions in the pattern
if {
condition = all {
eq {
get_attr {"isCisco"}
"true"
}
is_not_empty {get_attr {"vlanList"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"notInUse"
eval {"javascript: try{ // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';var vlanList = ${vlanList};var snmpQueryResult;var debuggerFormattedTable;var bridgePortTableName = \"dot1dBasePortTable\";var finalBridgePortTable = new Packages.java.util.ArrayList();var joinTables = function(tabletoAddTo, tableToAdd){tabletoAddTo.addAll(tableToAdd);};var addTableToContext = function(tableToAdd){CTX.setAttribute(bridgePortTableName, tableToAdd);};for(var i = 0; i < vlanList.size(); i++){snmpQueryResult = CTX.getCommandManager().snmpTableQueryWithContext(\"1.3.6.1.2.1.17.1.4.1\", [\"1\", \"2\"], \"@\" + vlanList.get(i), \"vlan-\" + vlanList.get(i), CTX);debuggerFormattedTable = NetworkDiscoveryUtil.buildTableAttribute([\"dot1dBasePort\", \"dot1dBasePortIfIndex\"], [\"1\", \"2\"], null, snmpQueryResult,vlanList.get(i));joinTables(finalBridgePortTable,debuggerFormattedTable);}addTableToContext(finalBridgePortTable);rtrn = '';
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Step failed - Handle bridge ports for Cisco\").info(e.message);
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove bridge ports without ifIndex"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = filter {
src_table_name = "dot1dBasePortTable"
target_table_name = "dot1dBasePortTable"
condition = is_not_empty {get_attr {"dot1dBasePortTable[].dot1dBasePortIfIndex"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert data to discovery_switch_bridge_port_table"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = transform {
src_table_name = "dot1dBasePortTable"
target_table_name = "discovery_switch_bridge_port_table"
operation {
set_field {
field_name = "port"
value = get_attr {"dot1dBasePortTable[].dot1dBasePort"}
}
set_field {
field_name = "interface_index"
value = get_attr {"dot1dBasePortTable[].dot1dBasePortIfIndex"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate bridge ports"
if {
condition = eq {
get_attr {"shouldRunSwitchLogic"}
"true"
}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${discovery_switch_bridge_port_table},['interface_index','port']);CTX.setAttribute(\"discovery_switch_bridge_port_table\", tableWithoutDuplicates); "} // Script execution: Custom script to perform a specific action or collect data
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Handle STP for Cisco"
comment = "Same step as \"Handle FDB for Cisco\" but on STP" // Step definition: Represents a single action or set of actions in the pattern
if {
condition = all {
eq {
get_attr {"isCisco"}
"true"
}
is_not_empty {get_attr {"vlanList"}}
eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
}
on_true = set_attr {
"notInUse"
eval {"javascript: try{ // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';var vlanList = ${vlanList};var snmpQueryResult;var debuggerFormattedTable;var stpTableName = \"dot1dStpPortTable\";var finalStpTable = new Packages.java.util.ArrayList();var joinTables = function(tabletoAddTo, tableToAdd){tabletoAddTo.addAll(tableToAdd);};var addTableToContext = function(tableToAdd){CTX.setAttribute(stpTableName, tableToAdd);};for(var i = 0; i < vlanList.size(); i++){snmpQueryResult = CTX.getCommandManager().snmpTableQueryWithContext(\"1.3.6.1.2.1.17.2.15.1\", [\"1\", \"3\", \"4\", \"6\", \"8\"], \"@\" + vlanList.get(i), \"vlan-\" + vlanList.get(i), CTX);debuggerFormattedTable = NetworkDiscoveryUtil.buildTableAttribute([\"dot1dStpPort\", \"dot1dStpPortState\", \"dot1dStpPortEnable\", \"dot1dStpPortDesignatedRoot\", \"dot1dStpPortDesignatedBridge\"], [\"1\", \"3\", \"4\", \"6\", \"8\"], null, snmpQueryResult,vlanList.get(i));joinTables(finalStpTable,debuggerFormattedTable);}addTableToContext(finalStpTable);rtrn = '';
}
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger(\"Step Failed - Handle STP for Cisco\").info(e.message);
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert data to discovery_switch_spanning_tree_table"
if {
condition = eq {
get_attr {"shouldBlockSwitchExploration"}
"false"
}
on_true = transform {
src_table_name = "dot1dStpPortTable"
target_table_name = "discovery_switch_spanning_tree_table"
operation {
set_field {
field_name = "designated_root"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
try{
var rtrn = '';var currentMacAddress = ${dot1dStpPortTable[].dot1dStpPortDesignatedRoot};rtrn = currentMacAddress.replace(/-/g, ':').slice(6).toLowerCase();
}
//In Case Of Error Display In Log
catch(e){
Packages.com.snc.sw.log.DiscoLog.getLogger (\" Step Failure -Insert data to discovery_switch_spanning_tree_table...\").error(e);
}
"}
}
set_field {
field_name = "designated_bridge_mac"
value = eval {"javascript:var rtrn = '';var currentMacAddress = ${dot1dStpPortTable[].dot1dStpPortDesignatedBridge};rtrn = currentMacAddress.replace(/-/g, ':').slice(6).toLowerCase();"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "port_enable"
value = eval {"javascript:var rtrn = '';var enableMap = {1:'enabled',2:'disabled'};var currentEnableStatus = ${dot1dStpPortTable[].dot1dStpPortEnable};rtrn = enableMap[currentEnableStatus];"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "port_state"
value = eval {"javascript:var rtrn = '';var statusMap = {1:'disabled',2:'blocking',3:'listening',4:'learning',5:'forwarding',6:'broken'};var currentState = ${dot1dStpPortTable[].dot1dStpPortState};rtrn = statusMap[currentState];"} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "port"
value = get_attr {"dot1dStpPortTable[].dot1dStpPort"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate spanning tree entries"
if {
condition = eq {
get_attr {"shouldRunSwitchLogic"}
"true"
}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${discovery_switch_spanning_tree_table},\"port\");CTX.setAttribute(\"discovery_switch_spanning_tree_table\", tableWithoutDuplicates); "} // Script execution: Custom script to perform a specific action or collect data
}
on_false = nop {}
}
}
}
|
Oracle OCI - Exadata DB Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Oracle OCI - Exadata DB Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Oracle OCI - Exadata DB Tags"
id = "fd05b7171b2964500735a9f36b4bcb97"
description = "Oracle OCI - Exadata DB Tags"
step {
name = "Oracle OCI - parse Tags"
ref {refid = "0ad0a5751be960500735a9f36b4bcba6"}
}
step {
name = "Parse definedTags Tags"
ref {refid = "b5b342b11bdf345009b2ed34b24bcba5"}
}
step {
name = "Create relation between cmdb_key_value and cmdb_ci_cloud_database"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_database"
key2_name = "object_id"
result_table_name = "tag_to_cloud_database"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Oracle OCI - Exadata DB Tags"
id = "fd05b7171b2964500735a9f36b4bcb97" // Unique identifier for the pattern
description = "Oracle OCI - Exadata DB Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Oracle OCI - parse Tags"
ref {refid = "0ad0a5751be960500735a9f36b4bcba6"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse definedTags Tags"
ref {refid = "b5b342b11bdf345009b2ed34b24bcba5"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_key_value and cmdb_ci_cloud_database"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_database"
key2_name = "object_id"
result_table_name = "tag_to_cloud_database"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Solaris - Serial Number | I would like for you to help me build a Pattern that helps achieve Discovery of Solaris - Serial Number. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Solaris - Serial Number"
id = "fd65536b9f2032001d753758442e70df"
description = ""
step {
name = "BIOS - Get serial number using smbios command"
runcmd_to_var {
cmd = "smbios -t SMB_TYPE_SYSTEM | grep Serial | cut -d ':' -f2-"
execution_mode = "DEFAULT"
var_names = "serials"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "SNEEP - Get serial using sneep command"
if {
condition = is_empty {get_attr {"serials"}}
on_true = runcmd_to_var {
cmd = "/opt/SUNWsneep/bin/sneep -T | grep ChassisSerialNumber 2> /dev/null"
var_names = "serials"
parsing_strategy = regex_parsing {regex = "ChassisSerialNumber\"\\s*\"(.*)\""}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "SNEEP Fallback - Get serial using sneep command"
if {
condition = is_empty {get_attr {"serials"}}
on_true = runcmd_to_var {
cmd = "/usr/sbin/sneep -T | grep ChassisSerialNumber 2> /dev/null"
var_names = "serials"
parsing_strategy = regex_parsing {regex = "ChassisSerialNumber\"\\s*\"(.*)\""}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Extract serial numbers to temp table"
if {
condition = all {
is_empty {get_attr {"cmdb_serial_number_temp"}}
is_not_empty {get_attr {"serials"}}
}
on_true = parse_var_to_var {
from_var_name = "serials"
to_var_names = table {
name = "cmdb_serial_number_temp"
col_names = "serial_number_type","serial_number"
}
parsing_strategy = regex_parsing {regex = "^\"(.+?)\".*\"(.+?)\"$"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = " Extract serial numbers-handle missing type"
if {
condition = all {
is_empty {get_attr {"cmdb_serial_number_temp"}}
is_not_empty {get_attr {"serials"}}
}
on_true = parse_var_to_var {
from_var_name = "serials"
to_var_names = table {
name = "cmdb_serial_number_temp"
col_names = "serial_number"
}
parsing_strategy = regex_parsing {regex = "(.*)"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Handle unknown serial"
if {
condition = contains {
get_attr {"serials"}
"unknown"
}
on_true = parse_var_to_var {
from_var_name = "serials"
to_var_names = table {
name = "cmdb_serial_number_temp"
col_names = "serial_number"
}
parsing_strategy = regex_parsing {regex = "(.*)"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Get serial number using smbios command"
disabled = "true"
if {
condition = is_empty {get_attr {"cmdb_serial_number_temp"}}
on_true = runcmd_to_var {
cmd = "smbios -t SMB_TYPE_SYSTEM | grep Serial | cut -d ':' -f2-"
var_names = table {
name = "cmdb_serial_number_temp"
col_names = "serial_number"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Insert serial numbers"
if {
condition = all {
is_not_empty {get_attr {"cmdb_serial_number_temp"}}
not_contains {
get_attr {"cmdb_serial_number_temp"}
"SMBIOS"
}
}
on_true = transform {
src_table_name = "cmdb_serial_number_temp"
target_table_name = "cmdb_serial_number"
operation {
set_field {
field_name = "serial_number"
value = get_attr {"cmdb_serial_number_temp[].serial_number"}
}
set_field {
field_name = "serial_number_type"
value = "SMB_TYPE_SYSTEM"
}
}
}
on_false = nop {}
}
}
step {
name = "Insert serial number to Solaris CI"
if {
condition = is_not_empty {get_attr {"cmdb_serial_number"}}
on_true = set_attr {
"cmdb_ci_solaris_server[*].serial_number"
get_attr {"cmdb_serial_number[1].serial_number"}
}
on_false = nop {}
}
}
step {
name = "Reference between cmdb_serial_number and Solaris CI"
if {
condition = is_not_empty {get_attr {"cmdb_serial_number"}}
on_true = relation_reference {
table1_name = "cmdb_serial_number"
table2_name = "cmdb_ci_solaris_server"
result_table_name = "serial_solaris"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
ref_direction = parentToChild
ref_field_name = "non_ci"
}
on_false = nop {}
}
}
}
| library {
name = "Solaris - Serial Number"
id = "fd65536b9f2032001d753758442e70df" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "BIOS - Get serial number using smbios command"
runcmd_to_var {
cmd = "smbios -t SMB_TYPE_SYSTEM | grep Serial | cut -d ':' -f2-"
execution_mode = "DEFAULT"
var_names = "serials"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "SNEEP - Get serial using sneep command"
if {
condition = is_empty {get_attr {"serials"}}
on_true = runcmd_to_var {
cmd = "/opt/SUNWsneep/bin/sneep -T | grep ChassisSerialNumber 2> /dev/null"
var_names = "serials"
parsing_strategy = regex_parsing {regex = "ChassisSerialNumber\"\\s*\"(.*)\""}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "SNEEP Fallback - Get serial using sneep command"
if {
condition = is_empty {get_attr {"serials"}}
on_true = runcmd_to_var {
cmd = "/usr/sbin/sneep -T | grep ChassisSerialNumber 2> /dev/null"
var_names = "serials"
parsing_strategy = regex_parsing {regex = "ChassisSerialNumber\"\\s*\"(.*)\""}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Extract serial numbers to temp table"
if {
condition = all {
is_empty {get_attr {"cmdb_serial_number_temp"}}
is_not_empty {get_attr {"serials"}}
}
on_true = parse_var_to_var {
from_var_name = "serials"
to_var_names = table {
name = "cmdb_serial_number_temp"
col_names = "serial_number_type","serial_number"
}
parsing_strategy = regex_parsing {regex = "^\"(.+?)\".*\"(.+?)\"$"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = " Extract serial numbers-handle missing type"
if {
condition = all {
is_empty {get_attr {"cmdb_serial_number_temp"}}
is_not_empty {get_attr {"serials"}}
}
on_true = parse_var_to_var {
from_var_name = "serials"
to_var_names = table {
name = "cmdb_serial_number_temp"
col_names = "serial_number"
}
parsing_strategy = regex_parsing {regex = "(.*)"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Handle unknown serial"
if {
condition = contains {
get_attr {"serials"}
"unknown"
}
on_true = parse_var_to_var {
from_var_name = "serials"
to_var_names = table {
name = "cmdb_serial_number_temp"
col_names = "serial_number"
}
parsing_strategy = regex_parsing {regex = "(.*)"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get serial number using smbios command"
disabled = "true"
if {
condition = is_empty {get_attr {"cmdb_serial_number_temp"}}
on_true = runcmd_to_var {
cmd = "smbios -t SMB_TYPE_SYSTEM | grep Serial | cut -d ':' -f2-"
var_names = table {
name = "cmdb_serial_number_temp"
col_names = "serial_number"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert serial numbers"
if {
condition = all {
is_not_empty {get_attr {"cmdb_serial_number_temp"}}
not_contains {
get_attr {"cmdb_serial_number_temp"}
"SMBIOS"
}
}
on_true = transform {
src_table_name = "cmdb_serial_number_temp"
target_table_name = "cmdb_serial_number"
operation {
set_field {
field_name = "serial_number"
value = get_attr {"cmdb_serial_number_temp[].serial_number"}
}
set_field {
field_name = "serial_number_type"
value = "SMB_TYPE_SYSTEM"
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert serial number to Solaris CI"
if {
condition = is_not_empty {get_attr {"cmdb_serial_number"}}
on_true = set_attr {
"cmdb_ci_solaris_server[*].serial_number"
get_attr {"cmdb_serial_number[1].serial_number"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference between cmdb_serial_number and Solaris CI"
if {
condition = is_not_empty {get_attr {"cmdb_serial_number"}}
on_true = relation_reference {
table1_name = "cmdb_serial_number"
table2_name = "cmdb_ci_solaris_server"
result_table_name = "serial_solaris"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
ref_direction = parentToChild
ref_field_name = "non_ci"
}
on_false = nop {}
}
}
}
|
EMC Isilon Unique Objet IDs | I would like for you to help me build a Pattern that helps achieve Discovery of EMC Isilon Unique Objet IDs. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "EMC Isilon Unique Objet IDs"
id = "fda809a41bdd1150fa738485604bcb96"
description = "EMC Isilon Unique Objet IDs"
step {
name = "Get MID Property"
set_attr {
"update_all_number_isilon_ids"
eval {"javascript: var rtrn = \"false\";
config = Packages.com.service_now.mid.services.Config.get();
rtrn = config.getProperty(\"sn_itom_pattern.discover_emc_isilon_enable_uniq_ids_extension_section\");
rtrn;"}
}
}
step {
name = "Check discover_emc_isilon_enable_uniq_ids_extension_section"
match {
contains {
get_attr {"update_all_number_isilon_ids"}
"true"
}
terminate_op = graceful
terminate_msg = "Ignore extension due to sn_itom_pattern.discover_emc_isilon_enable_uniq_ids_extension_section = false"
}
}
step {
name = "Update cmdb_ci_storage_cluster"
transform {
src_table_name = "cmdb_ci_storage_cluster"
target_table_name = "cmdb_ci_storage_cluster"
operation {
set_field {
field_name = "manufacturer"
value = get_attr {"cluster_info[1].manufacturer"}
}
set_field {
field_name = "serial_number"
value = get_attr {"cluster_info[1].correlation_id"}
}
}
}
}
step {
name = "Update cmdb_ci_storage_node_element"
transform {
src_table_name = "cmdb_ci_storage_node_element"
target_table_name = "cmdb_ci_storage_node_element"
operation {set_field {
field_name = "name"
value = concat {
get_attr {"cluster_info[1].name"}
"-"
get_attr {"cmdb_ci_storage_node_element[].name"}
}
}}
}
}
step {
name = "Update cmdb_ci_storage_server"
transform {
src_table_name = "cmdb_ci_storage_server"
target_table_name = "cmdb_ci_storage_server"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"cluster_info[1].name"}
"-"
get_attr {"cmdb_ci_storage_server[].name"}
}
}
set_field {
field_name = "zone_name"
value = get_attr {"cmdb_ci_storage_server[].name"}
}
}
}
}
step {
name = "Update cmdb_ci_storage_cluster_node"
transform {
src_table_name = "cmdb_ci_storage_cluster_node"
target_table_name = "cmdb_ci_storage_cluster_node"
operation {set_field {
field_name = "name"
value = concat {
get_attr {"cluster_info[1].name"}
"-"
get_attr {"cmdb_ci_storage_cluster_node[].name"}
}
}}
}
}
}
| library {
name = "EMC Isilon Unique Objet IDs"
id = "fda809a41bdd1150fa738485604bcb96" // Unique identifier for the pattern
description = "EMC Isilon Unique Objet IDs" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get MID Property"
set_attr {
"update_all_number_isilon_ids"
eval {"javascript: var rtrn = \"false\"; // Script execution: Custom script to perform a specific action or collect data
config = Packages.com.service_now.mid.services.Config.get();
rtrn = config.getProperty(\"sn_itom_pattern.discover_emc_isilon_enable_uniq_ids_extension_section\");
rtrn;"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check discover_emc_isilon_enable_uniq_ids_extension_section"
match {
contains {
get_attr {"update_all_number_isilon_ids"}
"true"
}
terminate_op = graceful
terminate_msg = "Ignore extension due to sn_itom_pattern.discover_emc_isilon_enable_uniq_ids_extension_section = false"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_storage_cluster"
transform {
src_table_name = "cmdb_ci_storage_cluster"
target_table_name = "cmdb_ci_storage_cluster"
operation {
set_field {
field_name = "manufacturer"
value = get_attr {"cluster_info[1].manufacturer"}
}
set_field {
field_name = "serial_number"
value = get_attr {"cluster_info[1].correlation_id"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_storage_node_element"
transform {
src_table_name = "cmdb_ci_storage_node_element"
target_table_name = "cmdb_ci_storage_node_element"
operation {set_field {
field_name = "name"
value = concat {
get_attr {"cluster_info[1].name"}
"-"
get_attr {"cmdb_ci_storage_node_element[].name"}
}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_storage_server"
transform {
src_table_name = "cmdb_ci_storage_server"
target_table_name = "cmdb_ci_storage_server"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"cluster_info[1].name"}
"-"
get_attr {"cmdb_ci_storage_server[].name"}
}
}
set_field {
field_name = "zone_name"
value = get_attr {"cmdb_ci_storage_server[].name"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_storage_cluster_node"
transform {
src_table_name = "cmdb_ci_storage_cluster_node"
target_table_name = "cmdb_ci_storage_cluster_node"
operation {set_field {
field_name = "name"
value = concat {
get_attr {"cluster_info[1].name"}
"-"
get_attr {"cmdb_ci_storage_cluster_node[].name"}
}
}}
}
}
}
|
Azure NIC Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Azure NIC Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure NIC Tags"
id = "fdd957a9db5d1010b2a1f962759619e9"
description = "Azure NIC Tags"
step {
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure NIC Tags\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_nicId};
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step {
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Create relation between Tag and NIC"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_nic"
key2_name = "object_id"
result_table_name = "tag_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Azure NIC Tags"
id = "fdd957a9db5d1010b2a1f962759619e9" // Unique identifier for the pattern
description = "Azure NIC Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure NIC Tags\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_nicId}; // Unique identifier for the pattern
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and NIC"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_nic"
key2_name = "object_id"
result_table_name = "tag_to_nic"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Linux - Distribution | I would like for you to help me build a Pattern that helps achieve Discovery of Linux - Distribution. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Linux - Distribution"
id = "fe32c7e39f2032001d753758442e7065"
description = ""
step {
name = "Get distribution"
runcmd_to_var {
cmd = "cat /etc/*release | grep -v ID_LIKE | grep -v LOGO"
var_names = "release_output"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Extract distribution version"
if {
condition = not_contains {
get_attr {"release_output"}
"ERROR"
}
on_true = set_attr {
"os_version"
eval {"javascript: var rtrn = \"\";
var rel = ${release_output};
var relStr = rel.toString();
var lowercaseOutput = relStr.toLowerCase();
var versionMatch = null;
if (lowercaseOutput.indexOf('red hat') != -1) {
versionMatch = /release ([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('red hat')));
}
else if (lowercaseOutput.indexOf('fedora') != -1) {
versionMatch = /release ([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('fedora')));
}
else if (lowercaseOutput.indexOf('suse') != -1) {
versionMatch = /version ?= ?([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('suse')));
if(versionMatch ==null){
//Sample OS version formats that are expected to match the regex are version = 15-sp1, \"15-sp1\",15, 15.1,15.1.1
versionMatch = /version ?= ?\"?([0-9]+((\\-|\\.)[a-z0-9]+)*)\"?/.exec(lowercaseOutput);
}
}
else if (lowercaseOutput.indexOf('centos') != -1) {
versionMatch = /release ([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('centos')));
}
else if (lowercaseOutput.indexOf('ubuntu') != -1) {
versionMatch = /version=\"([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('ubuntu')));
}
else if (lowercaseOutput.indexOf('oracle vm server') != -1) {
versionMatch = /release ([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('oracle vm server')));
}
if (versionMatch != null)
rtrn = versionMatch[1];"}
}
on_false = nop {}
}
}
step {
name = "Extract OS distribution"
if {
condition = not_contains {
get_attr {"release_output"}
"ERROR"
}
on_true = set_attr {
"os_distribution"
eval {"javascript: var rtrn = \"\";
var rel = ${release_output};
var relStr = rel.toString();
var lowercaseOutput = relStr.toLowerCase();
if (lowercaseOutput.indexOf('oracle linux server') != -1)
{
if(${os_version} != null){
rtrn = \"Oracle Linux \" + ${os_version} + \" (64-bit)\";
}else{
rtrn = \"Oracle Linux 4/5/6 (64-bit)\";
}
}
else if (lowercaseOutput.indexOf('centos') != -1)
{
rtrn = \"Linux CentOS\";
}
else if (lowercaseOutput.indexOf('fedora') != -1)
{
rtrn = \"Linux Fedora\";
}
else if (lowercaseOutput.indexOf('red hat') != -1)
{
rtrn = \"Linux Red Hat\";
}
else if (lowercaseOutput.indexOf('suse') != -1)
{
rtrn = \"Linux SuSE\";
}
else if (lowercaseOutput.indexOf('ubuntu') != -1)
{
rtrn = \"Linux Ubuntu\";
}
else if (lowercaseOutput.indexOf('oracle vm server') != -1)
{
rtrn = \"Oracle VM server\";
}
else
{
rtrn = \"GNU/Linux\";
}"}
}
on_false = nop {}
}
}
step {
name = "Update OS on Linux CI"
set_attr {
"cmdb_ci_linux_server[*].os"
get_attr {"os_distribution"}
}
}
step {
name = "Update OS version on Linux CI"
if {
condition = all {
is_not_empty {get_attr {"os_version"}}
is_not_empty {get_attr {"cmdb_ci_linux_server[1].os_version"}}
}
on_true = set_attr {
"cmdb_ci_linux_server[*].os_version"
get_attr {"os_version"}
}
on_false = nop {}
}
}
}
| library {
name = "Linux - Distribution"
id = "fe32c7e39f2032001d753758442e7065" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get distribution"
runcmd_to_var {
cmd = "cat /etc/*release | grep -v ID_LIKE | grep -v LOGO"
var_names = "release_output"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Extract distribution version"
if {
condition = not_contains {
get_attr {"release_output"}
"ERROR"
}
on_true = set_attr {
"os_version"
eval {"javascript: var rtrn = \"\"; // Script execution: Custom script to perform a specific action or collect data
var rel = ${release_output};
var relStr = rel.toString();
var lowercaseOutput = relStr.toLowerCase();
var versionMatch = null;
if (lowercaseOutput.indexOf('red hat') != -1) {
versionMatch = /release ([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('red hat')));
}
else if (lowercaseOutput.indexOf('fedora') != -1) {
versionMatch = /release ([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('fedora')));
}
else if (lowercaseOutput.indexOf('suse') != -1) {
versionMatch = /version ?= ?([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('suse')));
if(versionMatch ==null){
//Sample OS version formats that are expected to match the regex are version = 15-sp1, \"15-sp1\",15, 15.1,15.1.1
versionMatch = /version ?= ?\"?([0-9]+((\\-|\\.)[a-z0-9]+)*)\"?/.exec(lowercaseOutput);
}
}
else if (lowercaseOutput.indexOf('centos') != -1) {
versionMatch = /release ([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('centos')));
}
else if (lowercaseOutput.indexOf('ubuntu') != -1) {
versionMatch = /version=\"([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('ubuntu')));
}
else if (lowercaseOutput.indexOf('oracle vm server') != -1) {
versionMatch = /release ([0-9\\.]+)/.exec(lowercaseOutput.substring(lowercaseOutput.indexOf('oracle vm server')));
}
if (versionMatch != null)
rtrn = versionMatch[1];"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Extract OS distribution"
if {
condition = not_contains {
get_attr {"release_output"}
"ERROR"
}
on_true = set_attr {
"os_distribution"
eval {"javascript: var rtrn = \"\"; // Script execution: Custom script to perform a specific action or collect data
var rel = ${release_output};
var relStr = rel.toString();
var lowercaseOutput = relStr.toLowerCase();
if (lowercaseOutput.indexOf('oracle linux server') != -1)
{
if(${os_version} != null){
rtrn = \"Oracle Linux \" + ${os_version} + \" (64-bit)\";
}else{
rtrn = \"Oracle Linux 4/5/6 (64-bit)\";
}
}
else if (lowercaseOutput.indexOf('centos') != -1)
{
rtrn = \"Linux CentOS\";
}
else if (lowercaseOutput.indexOf('fedora') != -1)
{
rtrn = \"Linux Fedora\";
}
else if (lowercaseOutput.indexOf('red hat') != -1)
{
rtrn = \"Linux Red Hat\";
}
else if (lowercaseOutput.indexOf('suse') != -1)
{
rtrn = \"Linux SuSE\";
}
else if (lowercaseOutput.indexOf('ubuntu') != -1)
{
rtrn = \"Linux Ubuntu\";
}
else if (lowercaseOutput.indexOf('oracle vm server') != -1)
{
rtrn = \"Oracle VM server\";
}
else
{
rtrn = \"GNU/Linux\";
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update OS on Linux CI"
set_attr {
"cmdb_ci_linux_server[*].os"
get_attr {"os_distribution"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update OS version on Linux CI"
if {
condition = all {
is_not_empty {get_attr {"os_version"}}
is_not_empty {get_attr {"cmdb_ci_linux_server[1].os_version"}}
}
on_true = set_attr {
"cmdb_ci_linux_server[*].os_version"
get_attr {"os_version"}
}
on_false = nop {}
}
}
}
|
reference for SAP App to SAP SID | I would like for you to help me build a Pattern that helps achieve Discovery of reference for SAP App to SAP SID. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "reference for SAP App to SAP SID"
id = "fe80aa974fa93300a61e1aabb110c7d0"
description = "null"
step {
name = "build sap ci table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ci"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_ci"
target_table_name = "cmdb_ci_appl_sap_ci"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step {
name = " build sap scs table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_scs"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_scs"
target_table_name = "cmdb_ci_appl_sap_scs"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step {
name = "build sap di table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_di"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_di"
target_table_name = "cmdb_ci_appl_sap_di"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step {
name = "build sap ascs table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ascs"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_ascs"
target_table_name = "cmdb_ci_appl_sap_ascs"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step {
name = "build sap ers table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ers"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_ers"
target_table_name = "cmdb_ci_appl_sap_ers"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step {
name = "build sap jc table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_jc"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_jc"
target_table_name = "cmdb_ci_appl_sap_jc"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step {
name = "fix version for sap sid"
parse_var_to_var {
from_var_name = "version"
to_var_names = "version"
parsing_strategy = delimited_parsing {
delimiters = "."
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step {
name = "reference to patch level info lib"
ref {refid = "431289a6db2f8010b02e309d7c96196b"}
}
step {
name = "build sap sid table"
transform {
src_table_name = "cmdb_ci_sap_sid"
target_table_name = "cmdb_ci_sap_sid"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "name"
value = get_attr {"sid"}
}
set_field {
field_name = "sap_patch_info"
value = get_attr {"sap_patch_info"}
}
}
}
}
step {
name = "create relation between sap ascs and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ascs"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_ascs"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "create relation between sap di and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_di"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_di"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "create relation between sap scs and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_scs"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_scs"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "create relation between sap jc and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_jc"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_jc"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "create relation between sap ers and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ers"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_ers"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "create relation between sap ci and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ci"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_ci"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "reference for SAP App to SAP SID"
id = "fe80aa974fa93300a61e1aabb110c7d0" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "build sap ci table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ci"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_ci"
target_table_name = "cmdb_ci_appl_sap_ci"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = " build sap scs table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_scs"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_scs"
target_table_name = "cmdb_ci_appl_sap_scs"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "build sap di table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_di"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_di"
target_table_name = "cmdb_ci_appl_sap_di"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "build sap ascs table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ascs"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_ascs"
target_table_name = "cmdb_ci_appl_sap_ascs"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "build sap ers table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ers"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_ers"
target_table_name = "cmdb_ci_appl_sap_ers"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "build sap jc table"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_jc"}}
on_true = transform {
src_table_name = "cmdb_ci_appl_sap_jc"
target_table_name = "cmdb_ci_appl_sap_jc"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "sid"
value = get_attr {"sid"}
}
set_field {
field_name = "name"
value = get_attr {"name"}
}
set_field {
field_name = "system_directory"
value = get_attr {"system_directory"}
}
set_field {
field_name = "system_type"
value = get_attr {"system_type"}
}
set_field {
field_name = "instance_number"
value = get_attr {"instance_number"}
}
set_field {
field_name = "instance_name"
value = get_attr {"instance_name"}
}
set_field {
field_name = "install_directory"
value = get_attr {"install_directory"}
}
set_field {
field_name = "config_directory"
value = get_attr {"config_directory"}
}
set_field {
field_name = "config_file"
value = get_attr {"config_file"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "fix version for sap sid"
parse_var_to_var {
from_var_name = "version"
to_var_names = "version"
parsing_strategy = delimited_parsing {
delimiters = "."
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "reference to patch level info lib"
ref {refid = "431289a6db2f8010b02e309d7c96196b"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "build sap sid table"
transform {
src_table_name = "cmdb_ci_sap_sid"
target_table_name = "cmdb_ci_sap_sid"
operation {
set_field {
field_name = "version"
value = get_attr {"version"}
}
set_field {
field_name = "name"
value = get_attr {"sid"}
}
set_field {
field_name = "sap_patch_info"
value = get_attr {"sap_patch_info"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create relation between sap ascs and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ascs"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_ascs"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create relation between sap di and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_di"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_di"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create relation between sap scs and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_scs"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_scs"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create relation between sap jc and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_jc"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_jc"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create relation between sap ers and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ers"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_ers"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create relation between sap ci and sid"
if {
condition = is_not_empty {get_attr {"cmdb_ci_appl_sap_ci"}}
on_true = relation_reference {
table1_name = "cmdb_ci_appl_sap_ci"
key1_name = "sid"
table2_name = "cmdb_ci_sap_sid"
key2_name = "name"
result_table_name = "sap_app_to_sid"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
Oracle Unix for SAM customers | I would like for you to help me build a Pattern that helps achieve Discovery of Oracle Unix for SAM customers. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Oracle Unix for SAM customers"
id = "faded07b9f213200c7445f9bc32e70f7"
description = "null"
step {
name = "Select enabled options for oracle DB"
if {
condition = all {
is_not_empty {get_attr {"SAM_installed"}}
eq {
get_attr {"SAM_installed"}
"true"
}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"select parameter from V\\$option WHERE value='TRUE';\" |"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"$$username$$/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"tcp_port"}
"/"
get_attr {"servicename"}
}
var_names = table {
name = "options_table"
col_names = "option"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "re-validation"," ORA-"," ERROR:"," rows selected"," PARAMETER"," ----------------------------------------------------------------"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Select management options for oracle DB"
if {
condition = all {
is_not_empty {get_attr {"SAM_installed"}}
eq {
get_attr {"SAM_installed"}
"true"
}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"select value FROM GV$PARAMETER WHERE name LIKE ''%CONTROL_MANAGEMENT_PACK_ACCESS%';"
"|"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"$$username$$/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"tcp_port"}
"/"
get_attr {"servicename"}
}
var_names = table {
name = "management_option"
col_names = "option"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "rows selected"," PARAMETER"," ----------------------------------------------------------------"
selected_positions = 1
line_seperator = "+"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Union the option and the management"
if {
condition = all {
not_contains {
get_attr {"management_option"}
"ERROR"
}
is_not_empty {get_attr {"SAM_installed"}}
eq {
get_attr {"SAM_installed"}
"true"
}
}
on_true = union {
table1_name = "options_table"
table2_name = "management_option"
result_table_name = "options_table"
}
on_false = nop {}
}
}
step {
name = "Fill the name field of the options"
if {
condition = is_not_empty {get_attr {"options_table"}}
on_true = transform {
src_table_name = "options_table"
target_table_name = "options_table"
operation {set_field {
field_name = "name"
value = get_attr {"options_table[].option"}
}}
}
on_false = nop {}
}
}
step {
name = "Fill oracle_options table"
if {
condition = is_not_empty {get_attr {"options_table"}}
on_true = union {
table1_name = "samp_oracle_options"
table2_name = "options_table"
result_table_name = "samp_oracle_options"
}
on_false = nop {}
}
}
step {
name = "Filter empty record from oracle_options"
if {
condition = is_not_empty {get_attr {"samp_oracle_options"}}
on_true = filter {
src_table_name = "samp_oracle_options"
target_table_name = "samp_oracle_options"
condition = is_not_empty {get_attr {"samp_oracle_options[].option"}}
}
on_false = nop {}
}
}
step {
name = "Reference from oracle options table"
if {
condition = all {
is_not_empty {get_attr {"samp_oracle_options"}}
eq {
get_attr {"discovery_type"}
"horizontal"
}
}
on_true = relation_reference {
table1_name = "samp_oracle_options"
table2_name = "cmdb_ci_db_ora_instance"
result_table_name = "option"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
ref_direction = parentToChild
ref_field_name = "instance"
}
on_false = nop {}
}
}
step {
name = "Get the named_user_plus from sql query"
if {
condition = all {
is_not_empty {get_attr {"SAM_installed"}}
eq {
get_attr {"SAM_installed"}
"true"
}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"select DISTINCT(u.USERNAME) from dba_hist_active_sess_history h, dba_users u where h.USER_ID=u.USER_ID;\" |"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"$$username$$/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"tcp_port"}
"/"
get_attr {"servicename"}
}
var_names = table {
name = "users"
col_names = "user"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "re-validation"," ORA-"," ERROR:"," rows selected","USERNAME"," --------------"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Fill name field for oracle_client_access table"
if {
condition = is_not_empty {get_attr {"users"}}
on_true = transform {
src_table_name = "users"
target_table_name = "users"
operation {set_field {
field_name = "name"
value = get_attr {"users[].user"}
}}
}
on_false = nop {}
}
}
step {
name = "Fill oracle_client_access table"
if {
condition = is_not_empty {get_attr {"users"}}
on_true = union {
table1_name = "samp_client_access"
table2_name = "users"
result_table_name = "samp_client_access"
}
on_false = nop {}
}
}
step {
name = "Filter empty record from oracle_client_access"
if {
condition = is_not_empty {get_attr {"samp_client_access"}}
on_true = filter {
src_table_name = "samp_client_access"
target_table_name = "samp_client_access"
condition = is_not_empty {get_attr {"samp_client_access[].user"}}
}
on_false = nop {}
}
}
step {
name = "Reference from client access table"
if {
condition = all {
is_not_empty {get_attr {"samp_client_access"}}
eq {
get_attr {"discovery_type"}
"horizontal"
}
}
on_true = relation_reference {
table1_name = "samp_client_access"
table2_name = "cmdb_ci_db_ora_instance"
result_table_name = "client_access"
unmatched_lines = remove
condition = contains {
"1"
"1"
}
ref_direction = parentToChild
ref_field_name = "application"
}
on_false = nop {}
}
}
}
| library {
name = "Oracle Unix for SAM customers"
id = "faded07b9f213200c7445f9bc32e70f7" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Select enabled options for oracle DB"
if {
condition = all {
is_not_empty {get_attr {"SAM_installed"}}
eq {
get_attr {"SAM_installed"}
"true"
}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"select parameter from V\\$option WHERE value='TRUE';\" |"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"$$username$$/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"tcp_port"}
"/"
get_attr {"servicename"}
}
var_names = table {
name = "options_table"
col_names = "option"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "re-validation"," ORA-"," ERROR:"," rows selected"," PARAMETER"," ----------------------------------------------------------------"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Select management options for oracle DB"
if {
condition = all {
is_not_empty {get_attr {"SAM_installed"}}
eq {
get_attr {"SAM_installed"}
"true"
}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"select value FROM GV$PARAMETER WHERE name LIKE ''%CONTROL_MANAGEMENT_PACK_ACCESS%';"
"|"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"$$username$$/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"tcp_port"}
"/"
get_attr {"servicename"}
}
var_names = table {
name = "management_option"
col_names = "option"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "rows selected"," PARAMETER"," ----------------------------------------------------------------"
selected_positions = 1
line_seperator = "+"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union the option and the management"
if {
condition = all {
not_contains {
get_attr {"management_option"}
"ERROR"
}
is_not_empty {get_attr {"SAM_installed"}}
eq {
get_attr {"SAM_installed"}
"true"
}
}
on_true = union {
table1_name = "options_table"
table2_name = "management_option"
result_table_name = "options_table"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill the name field of the options"
if {
condition = is_not_empty {get_attr {"options_table"}}
on_true = transform {
src_table_name = "options_table"
target_table_name = "options_table"
operation {set_field {
field_name = "name"
value = get_attr {"options_table[].option"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill oracle_options table"
if {
condition = is_not_empty {get_attr {"options_table"}}
on_true = union {
table1_name = "samp_oracle_options"
table2_name = "options_table"
result_table_name = "samp_oracle_options"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter empty record from oracle_options"
if {
condition = is_not_empty {get_attr {"samp_oracle_options"}}
on_true = filter {
src_table_name = "samp_oracle_options"
target_table_name = "samp_oracle_options"
condition = is_not_empty {get_attr {"samp_oracle_options[].option"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference from oracle options table"
if {
condition = all {
is_not_empty {get_attr {"samp_oracle_options"}}
eq {
get_attr {"discovery_type"}
"horizontal"
}
}
on_true = relation_reference {
table1_name = "samp_oracle_options"
table2_name = "cmdb_ci_db_ora_instance"
result_table_name = "option"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
ref_direction = parentToChild
ref_field_name = "instance"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get the named_user_plus from sql query"
if {
condition = all {
is_not_empty {get_attr {"SAM_installed"}}
eq {
get_attr {"SAM_installed"}
"true"
}
}
on_true = runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;export ORACLE_HOME="
get_attr {"oracle_home"}
"; echo \"select DISTINCT(u.USERNAME) from dba_hist_active_sess_history h, dba_users u where h.USER_ID=u.USER_ID;\" |"
"\""
get_attr {"oracle_home"}
"/bin/sqlplus\" -s "
"$$username$$/'$$password$$'@"
get_attr {"computer_system.primaryHostname"}
":"
get_attr {"tcp_port"}
"/"
get_attr {"servicename"}
}
var_names = table {
name = "users"
col_names = "user"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "re-validation"," ORA-"," ERROR:"," rows selected","USERNAME"," --------------"
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill name field for oracle_client_access table"
if {
condition = is_not_empty {get_attr {"users"}}
on_true = transform {
src_table_name = "users"
target_table_name = "users"
operation {set_field {
field_name = "name"
value = get_attr {"users[].user"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill oracle_client_access table"
if {
condition = is_not_empty {get_attr {"users"}}
on_true = union {
table1_name = "samp_client_access"
table2_name = "users"
result_table_name = "samp_client_access"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter empty record from oracle_client_access"
if {
condition = is_not_empty {get_attr {"samp_client_access"}}
on_true = filter {
src_table_name = "samp_client_access"
target_table_name = "samp_client_access"
condition = is_not_empty {get_attr {"samp_client_access[].user"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference from client access table"
if {
condition = all {
is_not_empty {get_attr {"samp_client_access"}}
eq {
get_attr {"discovery_type"}
"horizontal"
}
}
on_true = relation_reference {
table1_name = "samp_client_access"
table2_name = "cmdb_ci_db_ora_instance"
result_table_name = "client_access"
unmatched_lines = remove
condition = contains {
"1"
"1"
}
ref_direction = parentToChild
ref_field_name = "application"
}
on_false = nop {}
}
}
}
|
Windows - Installed Software | I would like for you to help me build a Pattern that helps achieve Discovery of Windows - Installed Software. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Windows - Installed Software"
id = "fa88165edbc12200c06776231f9619de"
description = ""
step {
name = "Get IE versions from Microsoft registry branch"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer"
keys = "Version","svcVersion"
var_names = table {
name = "InternetExplorerVersions"
col_names = "Version","svcVersion"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Set relevant IE Version"
comment = "Value taken from InternetExplorerVersions.svcVersion if not empty, version otherwise"
if {
condition = all {
is_not_empty {get_attr {"InternetExplorerVersions[1].svcVersion"}}
is_not_empty {get_attr {"InternetExplorerVersions[1].Version"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"IeVersion"
eval {"javascript:
var rtrn = '';
rtrn = ${InternetExplorerVersions[1].svcVersion}?${InternetExplorerVersions[1].svcVersion}:${InternetExplorerVersions[1].Version};
"}
}
on_false = nop {}
}
}
step {
name = "Get IE product id from Microsoft registry branch"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer\\Registration"
keys = "ProductId"
var_names = "IEProductId"
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Get 32bit installed software data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\*\\Products\\*\\InstallProperties"
keys = "DisplayName","DisplayVersion","ProductID","Publisher"
var_names = table {
name = "SoftwareInstallData"
col_names = "name","version","product_id","vendor"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Get 64bit installed software data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Wow3264Node\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\*\\Products\\*\\InstallProperties"
keys = "DisplayName","DisplayVersion","ProductID","Publisher"
var_names = table {
name = "SoftwareInstallData64"
col_names = "name","version","product_id","vendor"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "If 32 and 64 tables have data - Union 32bit table with 64bit table"
if {
condition = all {
is_not_empty {get_attr {"SoftwareInstallData"}}
is_not_empty {get_attr {"SoftwareInstallData64"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareInstallData"
table2_name = "SoftwareInstallData64"
result_table_name = "SoftwareInstallData"
}
on_false = nop {}
}
}
step {
name = "If only 64 table has data - move its data to the software table"
if {
condition = all {
is_not_empty {get_attr {"SoftwareInstallData64"}}
is_empty {get_attr {"SoftwareInstallData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareInstallData64"
table2_name = "SoftwareInstallData64"
result_table_name = "SoftwareInstallData"
}
on_false = nop {}
}
}
step {
name = "Get 32bit Office data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Office\\*\\Registration\\*"
keys = "ProductID","DigitalProductID"
var_names = table {
name = "OfficeData"
col_names = "productid","digital_product_id"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Get 64bit Office data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Microsoft\\Office\\*\\Registration\\*"
keys = "ProductID","DigitalProductID"
var_names = table {
name = "OfficeData64"
col_names = "productid","digital_product_id"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "If 32 and 64 tables have data - Union 32bit table with 64bit table"
if {
condition = all {
is_not_empty {get_attr {"OfficeData"}}
is_not_empty {get_attr {"OfficeData64"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "OfficeData"
table2_name = "OfficeData64"
result_table_name = "OfficeData"
}
on_false = nop {}
}
}
step {
name = "If only 64 table has data - move its data to the software table"
if {
condition = all {
is_not_empty {get_attr {"OfficeData64"}}
is_empty {get_attr {"OfficeData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "OfficeData64"
table2_name = "OfficeData64"
result_table_name = "OfficeData"
}
on_false = nop {}
}
}
step {
name = "Get windows product id from Microsoft\\Windows branch"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion"
keys = "ProductId"
var_names = "WindowsProductId"
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Get windows product id from Microsoft\\Windows NT branch"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
keys = "ProductId","DigitalProductId"
var_names = table {
name = "WindowsNTIDs"
col_names = "ProductId","DigitalProductId"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Set OS product id"
comment = "The OS final product id.WindowsProductId if not empty, product id from WindowsNTIDs otherwise"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"osId"
eval {"javascript:
var rtrn = '';
rtrn = ${WindowsProductId}?${WindowsProductId}:${WindowsNTIDs[1].ProductId};
"}
}
on_false = nop {}
}
}
step {
name = "Get 32bit uninstalled software data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*"
keys = "DisplayName","DisplayVersion","InstallDate","UninstallString","Publisher","ParentDisplayName"
var_names = table {
name = "SoftwareUninstallData"
col_names = "name","version","install_date","uninstall_string","vendor","part_of"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Format dates"
comment = "Format dates to ServiceNow date formation"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareUninstallData"
target_table_name = "SoftwareUninstallData"
operation {set_field {
field_name = "install_date"
value = eval {"javascript:
var rtrn = '';
rtrn = WindowsDiscoveryUtil.formatDate(${SoftwareUninstallData[].install_date});
"}
}}
}
on_false = nop {}
}
}
step {
name = "Get 64bit uninstalled software data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*"
keys = "DisplayName","DisplayVersion","InstallDate","UninstallString","Publisher","ParentDisplayName"
var_names = table {
name = "SoftwareUninstallData64"
col_names = "name","version","install_date","uninstall_string","vendor","part_of"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Format dates"
comment = "Format dates to ServiceNow date formation"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareUninstallData64"
target_table_name = "SoftwareUninstallData64"
operation {set_field {
field_name = "install_date"
value = eval {"javascript:
var rtrn = '';
rtrn = WindowsDiscoveryUtil.formatDate(${SoftwareUninstallData64[].install_date});
"}
}}
}
on_false = nop {}
}
}
step {
name = "If 32 and 64 tables have data - Union 32bit table with 64bit table"
if {
condition = all {
is_not_empty {get_attr {"SoftwareUninstallData"}}
is_not_empty {get_attr {"SoftwareUninstallData64"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareUninstallData"
table2_name = "SoftwareUninstallData64"
result_table_name = "SoftwareUninstallData"
}
on_false = nop {}
}
}
step {
name = "If only 64 table has data - move its data to the software table"
if {
condition = all {
is_not_empty {get_attr {"SoftwareUninstallData64"}}
is_empty {get_attr {"SoftwareUninstallData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareUninstallData64"
table2_name = "SoftwareUninstallData64"
result_table_name = "SoftwareUninstallData"
}
on_false = nop {}
}
}
step {
name = "Remove install entries without name"
comment = "Remove software without name"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = filter {
src_table_name = "SoftwareInstallData"
target_table_name = "SoftwareInstallData"
condition = is_not_empty {get_attr {"SoftwareInstallData[].name"}}
}
on_false = nop {}
}
}
step {
name = "Remove uninstall entries without name"
comment = "Remove software without name"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = filter {
src_table_name = "SoftwareUninstallData"
target_table_name = "SoftwareUninstallData"
condition = is_not_empty {get_attr {"SoftwareUninstallData[].name"}}
}
on_false = nop {}
}
}
step {
name = "Add msi_id to uninstall entries"
comment = "msi_id is used for adding office software into the software table"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareUninstallData"
target_table_name = "SoftwareUninstallData"
operation {set_field {
field_name = "msi_id"
value = eval {"javascript:
var rtrn = '';
var uninstallString = ${SoftwareUninstallData[].UninstallString};
if (uninstallString && uninstallString.toLowerCase().indexOf(\"msiexec\") > -1) {
var start = uninstallString.indexOf(\"{\");
var finalString = uninstallString.substring(start+1);
var end = finalString.indexOf(\"}\");
rtrn = finalString.substring(0, end);
}
"}
}}
}
on_false = nop {}
}
}
step {
name = "Match install data to uninstall data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = merge {
table1_name = "SoftwareInstallData"
table2_name = "SoftwareUninstallData"
result_table_name = "SoftwareData"
unmatched_lines = keep
condition = all {
eq {
get_attr {"SoftwareUninstallData[].name"}
get_attr {"SoftwareInstallData[].name"}
}
eq {
get_attr {"SoftwareUninstallData[].version"}
get_attr {"SoftwareInstallData[].version"}
}
}
}
on_false = nop {}
}
}
step {
name = "Match office licenses"
if {
condition = all {
is_not_empty {get_attr {"SoftwareData"}}
is_not_empty {get_attr {"OfficeData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = merge {
table1_name = "SoftwareData"
key1_name = "msi_id"
table2_name = "OfficeData"
key2_name = "uuid"
result_table_name = "SoftwareData"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Create Internet Explorer data row compatible with SoftwareData"
comment = "Represents all Internet Explorer relevant data"
if {
condition = all {
is_not_empty {get_attr {"IeVersion"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"InternetExplorerData"
concat {
"Internet Explorer, Microsoft, "
get_attr {"IEProductId"}
","
get_attr {"IeVersion"}
}
}
on_false = nop {}
}
}
step {
name = "Populate IE data into a table"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = parse_var_to_var {
from_var_name = "InternetExplorerData"
to_var_names = table {
name = "InternetExplorerData"
col_names = "name","vendor","product_id","version"
}
parsing_strategy = delimited_parsing {
delimiters = ","
selected_positions = 1,2,3,4
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add Internet Explorer data to SoftwareData"
if {
condition = all {
is_not_empty {get_attr {"InternetExplorerData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareData"
table2_name = "InternetExplorerData"
result_table_name = "SoftwareData"
}
on_false = nop {}
}
}
step {
name = "Create OS data row compatible with SoftwareData"
comment = "Represents all OS relevant data"
if {
condition = all {
is_not_empty {get_attr {"IeVersion"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"OsData"
concat {
get_attr {"computer_system.osName"}
", Microsoft, "
get_attr {"osId"}
","
get_attr {"WindowsNTIDs[1].DigitalProductId"}
}
}
on_false = nop {}
}
}
step {
name = "Populate OS data into a table"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = parse_var_to_var {
from_var_name = "OsData"
to_var_names = table {
name = "OsData"
col_names = "name","vendor","product_id","digital_product_id"
}
parsing_strategy = delimited_parsing {
delimiters = ","
selected_positions = 1,2,3,4
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add OS data to SoftwareData"
if {
condition = all {
is_not_empty {get_attr {"OsData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareData"
table2_name = "OsData"
result_table_name = "SoftwareData"
}
on_false = nop {}
}
}
step {
name = "Trim software name and version"
comment = "PRB741013
Caused by duplicate software, that caused by 2 software entries of the same software, but one of them had an extra space in the name
This step will align names and versions (which are the key for this CI)"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
operation {
set_field {
field_name = "name"
value = eval {"javascript:
var rtrn = '';
rtrn = ${SoftwareData[].name}.trim();
"}
}
set_field {
field_name = "version"
value = eval {"javascript:
var rtrn = '';
if(${SoftwareData[].version}){
rtrn = ${SoftwareData[].version}.trim();
}
"}
}
}
}
on_false = nop {}
}
}
step {
name = "Normalize software name and version"
comment = "a.Normalize software names, versions & vendors using SoftwareMunger.mungeName, SoftwareMunger.mungeVersion & CMDBHelper.resolveVendor"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
operation {
set_field {
field_name = "version"
value = eval {"javascript:
var rtrn = '';
var match;
var softwareName = ${SoftwareData[].name};
var softwareVersion = ${SoftwareData[].version};
var normalizedVersion = softwareVersion;
var versionInNameRegex = /^(.*) v?(\\d+(?:\\.\\d+)*)$/;
var leadingZeroesRegex = /\\b0*([1-9][0-9]*|0)\\b/g;
var surplusZeroesRegex = /^(.*?(?:\\.0)?)(?:\\.0)*$/;
if (JSUtil.nil(softwareVersion) || softwareVersion == \"none\") {
match = versionInNameRegex.exec(softwareName);
normalizedVersion = match ? match[2] : null;
}
if(normalizedVersion){
normalizedVersion = normalizedVersion.replace(leadingZeroesRegex,\"$1\");
match = surplusZeroesRegex.exec(normalizedVersion);
normalizedVersion = match ? match[1] : normalizedVersion;
}
rtrn = normalizedVersion;
"}
}
set_field {
field_name = "name"
value = eval {"javascript:var rtrn = '';var softwareName = ${SoftwareData[].name};var softwareVersion = ${SoftwareData[].version};var deleteTrailing = function(stringToDeleteFrom, trailingToDelete) {if (JSUtil.nil(stringToDeleteFrom) || JSUtil.nil(trailingToDelete))return stringToDeleteFrom;if (stringToDeleteFrom.length <= trailingToDelete.length)return stringToDeleteFrom;if (!stringToDeleteFrom.endsWith(trailingToDelete))return stringToDeleteFrom;
return stringToDeleteFrom.substring(0, stringToDeleteFrom.length - trailingToDelete.length);};var normalizedName = softwareName;var versionInNameRegex = /^(.*) v?(\\d+(?:\\.\\d+)*)$/;
if (JSUtil.nil(softwareVersion) || softwareVersion == \"none\") {var match = versionInNameRegex.exec(softwareName);normalizedName = match ? match[1] : normalizedName;} else {normalizedName = deleteTrailing(normalizedName, softwareVersion).trim();normalizedName = deleteTrailing(normalizedName, \",\").trim();}normalizedName = deleteTrailing( normalizedName, \"(remove only)\" ).trim();normalizedName = deleteTrailing( normalizedName, \"(english)\" ).trim();normalizedName = deleteTrailing( normalizedName, \"[english]\" ).trim();rtrn = normalizedName;
"}
}
set_field {
field_name = "vendor"
value = eval {"javascript:var rtrn = null;var productName = ${SoftwareData[].name};if (${SoftwareData[].vendor})rtrn=${SoftwareData[].vendor};else { if (JSUtil.nil(productName)) rtrn = null; if (productName.startsWith(\"Adobe \"))rtrn = \"Adobe Systems\";if (productName.startsWith(\"Microsoft \"))rtrn = \"Microsoft\";}"}
}
}
}
on_false = nop {}
}
}
step {
name = "Fix vendor names if necessary"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
operation {set_field {
field_name = "vendor"
value = eval {"javascript:var rtrn = '';var company = ${SoftwareData[].vendor}; if (company.endsWith(\" Corporation\") || company.endsWith(\" Corp.\") || company.endsWith(\" Corp\")) company = company.substring(0, company.lastIndexOf(\" \")); if (company.endsWith(\".\")) company = company.substring(0, company.length - 1); if (company.endsWith(\" Inc\") || company.endsWith(\" Ltd\")) company = company.substring(0, company.lastIndexOf(\" \")); if (company.endsWith(\",\")) company = company.substring(0, company.length - 1); if (company.endsWith(\" Incorporated\")) company = company.substring(0, company.lastIndexOf(\" \")); if (company.endsWith(\"(R)\")) company = company.substring(0, company.length - 3);if (company.endsWith(\"\u00AE\")) company = company.substring(0, company.length - 1);if (company.endsWith(\"\u2122\")) company = company.substring(0, company.length - 1); if (company.endsWith(\"(TM)\")) company = company.substring(0, company.length - 4); /*strip off genuine, its just intel */if (company == \"GenuineIntel\") company = \"Intel\"; /*strip off computer if its dell */ if (company.toLowerCase() == \"dell computer\") company = \"Dell\"; company = company.trim();
rtrn = company;//rtrn = WindowsDiscoveryUtil.fixCompany(${SoftwareData[].vendor});"}
}}
}
on_false = nop {}
}
}
step {
name = "Mark all apps that we should keep according to filter"
comment = "add column that indicates whether the software should be filtered. The logic uses the regular expression fetched by Pre-Launch script"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
operation {set_field {
field_name = "shouldKeep"
value = eval {"javascript:
var rtrn = '';
var isIncludeMethod = ${isSoftwareFilterMethodIsInclude};
var appName = ${SoftwareData[].name};
var regex = ${softwareKeywordsRegex};
var match = WindowsDiscoveryUtil.extractFirstMatchWithRegex(appName,regex);
var isMatchFound = (match != null) && (match != \"\");
if((isIncludeMethod==\"true\" && isMatchFound) || (isIncludeMethod==\"false\" && !isMatchFound)){rtrn = \"true\";}else{rtrn = \"false\";}"}
}}
}
on_false = nop {}
}
}
step {
name = "Retain only apps chosen by user's filter"
comment = "keep only the software matched the configuration in the configuration console"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = filter {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
condition = eq {
get_attr {"SoftwareData[].shouldKeep"}
"true"
}
}
on_false = nop {}
}
}
step {
name = "Remove duplicate software entries"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"notInUse"
eval {"javascript:
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${SoftwareData},[\"name\",\"version\"],\"product_id\");
CTX.setAttribute(\"SoftwareData\", tableWithoutDuplicates);
"}
}
on_false = nop {}
}
}
step {
name = "Insert software data to cmdb_sam_sw_install"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "cmdb_sam_sw_install"
operation {
set_field {
field_name = "display_name"
value = get_attr {"SoftwareData[].name"}
}
set_field {
field_name = "publisher"
value = get_attr {"SoftwareData[].vendor"}
}
}
}
on_false = nop {}
}
}
step {
name = "Insert software data to cmdb_ci_spkg"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "cmdb_ci_spkg"
operation {
set_field {
field_name = "key"
value = concat {eval {"javascript:var rtrn = '';rtrn = ${SoftwareData[].name} + \"_:::_\" + (${SoftwareData[].version}||\"NULL\");"}}
}
set_field {
field_name = "package_name"
value = get_attr {"SoftwareData[].name"}
}
}
}
on_false = nop {}
}
}
step {
name = "Insert software data to cmdb_software_instance"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = transform {
src_table_name = "cmdb_ci_spkg"
target_table_name = "cmdb_software_instance"
operation {set_field {
field_name = "name"
value = get_attr {"cmdb_ci_spkg[].name"}
}}
}
on_false = nop {}
}
}
step {
name = "Reference between cmdb_software_instance to cmdb_ci_spkg"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = relation_reference {
table1_name = "cmdb_software_instance"
table2_name = "cmdb_ci_spkg"
result_table_name = "software_instance_spkg"
unmatched_lines = remove
condition = all {
eq {
get_attr {"cmdb_software_instance[].name"}
get_attr {"cmdb_ci_spkg[].name"}
}
eq {
get_attr {"cmdb_software_instance[].version"}
get_attr {"cmdb_ci_spkg[].version"}
}
}
ref_direction = parentToChild
ref_field_name = "software"
}
on_false = nop {}
}
}
}
| library {
name = "Windows - Installed Software"
id = "fa88165edbc12200c06776231f9619de" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get IE versions from Microsoft registry branch"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer"
keys = "Version","svcVersion"
var_names = table {
name = "InternetExplorerVersions"
col_names = "Version","svcVersion"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set relevant IE Version"
comment = "Value taken from InternetExplorerVersions.svcVersion if not empty, version otherwise"
if {
condition = all {
is_not_empty {get_attr {"InternetExplorerVersions[1].svcVersion"}}
is_not_empty {get_attr {"InternetExplorerVersions[1].Version"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"IeVersion"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
rtrn = ${InternetExplorerVersions[1].svcVersion}?${InternetExplorerVersions[1].svcVersion}:${InternetExplorerVersions[1].Version};
"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get IE product id from Microsoft registry branch"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer\\Registration"
keys = "ProductId"
var_names = "IEProductId"
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get 32bit installed software data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\*\\Products\\*\\InstallProperties"
keys = "DisplayName","DisplayVersion","ProductID","Publisher"
var_names = table {
name = "SoftwareInstallData"
col_names = "name","version","product_id","vendor"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get 64bit installed software data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Wow3264Node\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\*\\Products\\*\\InstallProperties"
keys = "DisplayName","DisplayVersion","ProductID","Publisher"
var_names = table {
name = "SoftwareInstallData64"
col_names = "name","version","product_id","vendor"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If 32 and 64 tables have data - Union 32bit table with 64bit table"
if {
condition = all {
is_not_empty {get_attr {"SoftwareInstallData"}}
is_not_empty {get_attr {"SoftwareInstallData64"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareInstallData"
table2_name = "SoftwareInstallData64"
result_table_name = "SoftwareInstallData"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If only 64 table has data - move its data to the software table"
if {
condition = all {
is_not_empty {get_attr {"SoftwareInstallData64"}}
is_empty {get_attr {"SoftwareInstallData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareInstallData64"
table2_name = "SoftwareInstallData64"
result_table_name = "SoftwareInstallData"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get 32bit Office data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Office\\*\\Registration\\*"
keys = "ProductID","DigitalProductID"
var_names = table {
name = "OfficeData"
col_names = "productid","digital_product_id"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get 64bit Office data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Microsoft\\Office\\*\\Registration\\*"
keys = "ProductID","DigitalProductID"
var_names = table {
name = "OfficeData64"
col_names = "productid","digital_product_id"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If 32 and 64 tables have data - Union 32bit table with 64bit table"
if {
condition = all {
is_not_empty {get_attr {"OfficeData"}}
is_not_empty {get_attr {"OfficeData64"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "OfficeData"
table2_name = "OfficeData64"
result_table_name = "OfficeData"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If only 64 table has data - move its data to the software table"
if {
condition = all {
is_not_empty {get_attr {"OfficeData64"}}
is_empty {get_attr {"OfficeData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "OfficeData64"
table2_name = "OfficeData64"
result_table_name = "OfficeData"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get windows product id from Microsoft\\Windows branch"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion"
keys = "ProductId"
var_names = "WindowsProductId"
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get windows product id from Microsoft\\Windows NT branch"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
keys = "ProductId","DigitalProductId"
var_names = table {
name = "WindowsNTIDs"
col_names = "ProductId","DigitalProductId"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set OS product id"
comment = "The OS final product id.WindowsProductId if not empty, product id from WindowsNTIDs otherwise"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"osId"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
rtrn = ${WindowsProductId}?${WindowsProductId}:${WindowsNTIDs[1].ProductId};
"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get 32bit uninstalled software data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*"
keys = "DisplayName","DisplayVersion","InstallDate","UninstallString","Publisher","ParentDisplayName"
var_names = table {
name = "SoftwareUninstallData"
col_names = "name","version","install_date","uninstall_string","vendor","part_of"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Format dates"
comment = "Format dates to ServiceNow date formation"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareUninstallData"
target_table_name = "SoftwareUninstallData"
operation {set_field {
field_name = "install_date"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
rtrn = WindowsDiscoveryUtil.formatDate(${SoftwareUninstallData[].install_date});
"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get 64bit uninstalled software data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = find_registry_val_to_var {
key_base_dir = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*"
keys = "DisplayName","DisplayVersion","InstallDate","UninstallString","Publisher","ParentDisplayName"
var_names = table {
name = "SoftwareUninstallData64"
col_names = "name","version","install_date","uninstall_string","vendor","part_of"
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Format dates"
comment = "Format dates to ServiceNow date formation"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareUninstallData64"
target_table_name = "SoftwareUninstallData64"
operation {set_field {
field_name = "install_date"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
rtrn = WindowsDiscoveryUtil.formatDate(${SoftwareUninstallData64[].install_date});
"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If 32 and 64 tables have data - Union 32bit table with 64bit table"
if {
condition = all {
is_not_empty {get_attr {"SoftwareUninstallData"}}
is_not_empty {get_attr {"SoftwareUninstallData64"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareUninstallData"
table2_name = "SoftwareUninstallData64"
result_table_name = "SoftwareUninstallData"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If only 64 table has data - move its data to the software table"
if {
condition = all {
is_not_empty {get_attr {"SoftwareUninstallData64"}}
is_empty {get_attr {"SoftwareUninstallData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareUninstallData64"
table2_name = "SoftwareUninstallData64"
result_table_name = "SoftwareUninstallData"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove install entries without name"
comment = "Remove software without name"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = filter {
src_table_name = "SoftwareInstallData"
target_table_name = "SoftwareInstallData"
condition = is_not_empty {get_attr {"SoftwareInstallData[].name"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove uninstall entries without name"
comment = "Remove software without name"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = filter {
src_table_name = "SoftwareUninstallData"
target_table_name = "SoftwareUninstallData"
condition = is_not_empty {get_attr {"SoftwareUninstallData[].name"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add msi_id to uninstall entries"
comment = "msi_id is used for adding office software into the software table"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareUninstallData"
target_table_name = "SoftwareUninstallData"
operation {set_field {
field_name = "msi_id"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
var uninstallString = ${SoftwareUninstallData[].UninstallString};
if (uninstallString && uninstallString.toLowerCase().indexOf(\"msiexec\") > -1) {
var start = uninstallString.indexOf(\"{\");
var finalString = uninstallString.substring(start+1);
var end = finalString.indexOf(\"}\");
rtrn = finalString.substring(0, end);
}
"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Match install data to uninstall data"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = merge {
table1_name = "SoftwareInstallData"
table2_name = "SoftwareUninstallData"
result_table_name = "SoftwareData"
unmatched_lines = keep
condition = all {
eq {
get_attr {"SoftwareUninstallData[].name"}
get_attr {"SoftwareInstallData[].name"}
}
eq {
get_attr {"SoftwareUninstallData[].version"}
get_attr {"SoftwareInstallData[].version"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Match office licenses"
if {
condition = all {
is_not_empty {get_attr {"SoftwareData"}}
is_not_empty {get_attr {"OfficeData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = merge {
table1_name = "SoftwareData"
key1_name = "msi_id"
table2_name = "OfficeData"
key2_name = "uuid"
result_table_name = "SoftwareData"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Internet Explorer data row compatible with SoftwareData"
comment = "Represents all Internet Explorer relevant data"
if {
condition = all {
is_not_empty {get_attr {"IeVersion"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"InternetExplorerData"
concat {
"Internet Explorer, Microsoft, "
get_attr {"IEProductId"}
","
get_attr {"IeVersion"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate IE data into a table"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = parse_var_to_var {
from_var_name = "InternetExplorerData"
to_var_names = table {
name = "InternetExplorerData"
col_names = "name","vendor","product_id","version"
}
parsing_strategy = delimited_parsing {
delimiters = ","
selected_positions = 1,2,3,4
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add Internet Explorer data to SoftwareData"
if {
condition = all {
is_not_empty {get_attr {"InternetExplorerData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareData"
table2_name = "InternetExplorerData"
result_table_name = "SoftwareData"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create OS data row compatible with SoftwareData"
comment = "Represents all OS relevant data"
if {
condition = all {
is_not_empty {get_attr {"IeVersion"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"OsData"
concat {
get_attr {"computer_system.osName"}
", Microsoft, "
get_attr {"osId"}
","
get_attr {"WindowsNTIDs[1].DigitalProductId"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate OS data into a table"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = parse_var_to_var {
from_var_name = "OsData"
to_var_names = table {
name = "OsData"
col_names = "name","vendor","product_id","digital_product_id"
}
parsing_strategy = delimited_parsing {
delimiters = ","
selected_positions = 1,2,3,4
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add OS data to SoftwareData"
if {
condition = all {
is_not_empty {get_attr {"OsData"}}
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = union {
table1_name = "SoftwareData"
table2_name = "OsData"
result_table_name = "SoftwareData"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Trim software name and version"
comment = "PRB741013
Caused by duplicate software, that caused by 2 software entries of the same software, but one of them had an extra space in the name
This step will align names and versions (which are the key for this CI)" // Step definition: Represents a single action or set of actions in the pattern
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
operation {
set_field {
field_name = "name"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
rtrn = ${SoftwareData[].name}.trim();
"}
}
set_field {
field_name = "version"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
if(${SoftwareData[].version}){
rtrn = ${SoftwareData[].version}.trim();
}
"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Normalize software name and version"
comment = "a.Normalize software names, versions & vendors using SoftwareMunger.mungeName, SoftwareMunger.mungeVersion & CMDBHelper.resolveVendor"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
operation {
set_field {
field_name = "version"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
var match;
var softwareName = ${SoftwareData[].name};
var softwareVersion = ${SoftwareData[].version};
var normalizedVersion = softwareVersion;
var versionInNameRegex = /^(.*) v?(\\d+(?:\\.\\d+)*)$/;
var leadingZeroesRegex = /\\b0*([1-9][0-9]*|0)\\b/g;
var surplusZeroesRegex = /^(.*?(?:\\.0)?)(?:\\.0)*$/;
if (JSUtil.nil(softwareVersion) || softwareVersion == \"none\") {
match = versionInNameRegex.exec(softwareName);
normalizedVersion = match ? match[2] : null;
}
if(normalizedVersion){
normalizedVersion = normalizedVersion.replace(leadingZeroesRegex,\"$1\");
match = surplusZeroesRegex.exec(normalizedVersion);
normalizedVersion = match ? match[1] : normalizedVersion;
}
rtrn = normalizedVersion;
"}
}
set_field {
field_name = "name"
value = eval {"javascript:var rtrn = '';var softwareName = ${SoftwareData[].name};var softwareVersion = ${SoftwareData[].version};var deleteTrailing = function(stringToDeleteFrom, trailingToDelete) {if (JSUtil.nil(stringToDeleteFrom) || JSUtil.nil(trailingToDelete))return stringToDeleteFrom;if (stringToDeleteFrom.length <= trailingToDelete.length)return stringToDeleteFrom;if (!stringToDeleteFrom.endsWith(trailingToDelete))return stringToDeleteFrom; // Script execution: Custom script to perform a specific action or collect data
return stringToDeleteFrom.substring(0, stringToDeleteFrom.length - trailingToDelete.length);};var normalizedName = softwareName;var versionInNameRegex = /^(.*) v?(\\d+(?:\\.\\d+)*)$/;
if (JSUtil.nil(softwareVersion) || softwareVersion == \"none\") {var match = versionInNameRegex.exec(softwareName);normalizedName = match ? match[1] : normalizedName;} else {normalizedName = deleteTrailing(normalizedName, softwareVersion).trim();normalizedName = deleteTrailing(normalizedName, \",\").trim();}normalizedName = deleteTrailing( normalizedName, \"(remove only)\" ).trim();normalizedName = deleteTrailing( normalizedName, \"(english)\" ).trim();normalizedName = deleteTrailing( normalizedName, \"[english]\" ).trim();rtrn = normalizedName;
"}
}
set_field {
field_name = "vendor"
value = eval {"javascript:var rtrn = null;var productName = ${SoftwareData[].name};if (${SoftwareData[].vendor})rtrn=${SoftwareData[].vendor};else { if (JSUtil.nil(productName)) rtrn = null; if (productName.startsWith(\"Adobe \"))rtrn = \"Adobe Systems\";if (productName.startsWith(\"Microsoft \"))rtrn = \"Microsoft\";}"} // Script execution: Custom script to perform a specific action or collect data
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fix vendor names if necessary"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
operation {set_field {
field_name = "vendor"
value = eval {"javascript:var rtrn = '';var company = ${SoftwareData[].vendor}; if (company.endsWith(\" Corporation\") || company.endsWith(\" Corp.\") || company.endsWith(\" Corp\")) company = company.substring(0, company.lastIndexOf(\" \")); if (company.endsWith(\".\")) company = company.substring(0, company.length - 1); if (company.endsWith(\" Inc\") || company.endsWith(\" Ltd\")) company = company.substring(0, company.lastIndexOf(\" \")); if (company.endsWith(\",\")) company = company.substring(0, company.length - 1); if (company.endsWith(\" Incorporated\")) company = company.substring(0, company.lastIndexOf(\" \")); if (company.endsWith(\"(R)\")) company = company.substring(0, company.length - 3);if (company.endsWith(\"\u00AE\")) company = company.substring(0, company.length - 1);if (company.endsWith(\"\u2122\")) company = company.substring(0, company.length - 1); if (company.endsWith(\"(TM)\")) company = company.substring(0, company.length - 4); /*strip off genuine, its just intel */if (company == \"GenuineIntel\") company = \"Intel\"; /*strip off computer if its dell */ if (company.toLowerCase() == \"dell computer\") company = \"Dell\"; company = company.trim(); // Script execution: Custom script to perform a specific action or collect data
rtrn = company;//rtrn = WindowsDiscoveryUtil.fixCompany(${SoftwareData[].vendor});"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Mark all apps that we should keep according to filter"
comment = "add column that indicates whether the software should be filtered. The logic uses the regular expression fetched by Pre-Launch script" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
operation {set_field {
field_name = "shouldKeep"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
var isIncludeMethod = ${isSoftwareFilterMethodIsInclude};
var appName = ${SoftwareData[].name};
var regex = ${softwareKeywordsRegex};
var match = WindowsDiscoveryUtil.extractFirstMatchWithRegex(appName,regex);
var isMatchFound = (match != null) && (match != \"\");
if((isIncludeMethod==\"true\" && isMatchFound) || (isIncludeMethod==\"false\" && !isMatchFound)){rtrn = \"true\";}else{rtrn = \"false\";}"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Retain only apps chosen by user's filter"
comment = "keep only the software matched the configuration in the configuration console"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = filter {
src_table_name = "SoftwareData"
target_table_name = "SoftwareData"
condition = eq {
get_attr {"SoftwareData[].shouldKeep"}
"true"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate software entries"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
}
on_true = set_attr {
"notInUse"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${SoftwareData},[\"name\",\"version\"],\"product_id\");
CTX.setAttribute(\"SoftwareData\", tableWithoutDuplicates);
"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert software data to cmdb_sam_sw_install"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"false"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "cmdb_sam_sw_install"
operation {
set_field {
field_name = "display_name"
value = get_attr {"SoftwareData[].name"}
}
set_field {
field_name = "publisher"
value = get_attr {"SoftwareData[].vendor"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert software data to cmdb_ci_spkg"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = transform {
src_table_name = "SoftwareData"
target_table_name = "cmdb_ci_spkg"
operation {
set_field {
field_name = "key"
value = concat {eval {"javascript:var rtrn = '';rtrn = ${SoftwareData[].name} + \"_:::_\" + (${SoftwareData[].version}||\"NULL\");"}} // Script execution: Custom script to perform a specific action or collect data
}
set_field {
field_name = "package_name"
value = get_attr {"SoftwareData[].name"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert software data to cmdb_software_instance"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = transform {
src_table_name = "cmdb_ci_spkg"
target_table_name = "cmdb_software_instance"
operation {set_field {
field_name = "name"
value = get_attr {"cmdb_ci_spkg[].name"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference between cmdb_software_instance to cmdb_ci_spkg"
if {
condition = all {
eq {
get_attr {"shouldDiscoverSoftware"}
"true"
}
eq {
get_attr {"isManagedBySCCM"}
"false"
}
eq {
get_attr {"shouldPopulateOldSoftwareTables"}
"true"
}
}
on_true = relation_reference {
table1_name = "cmdb_software_instance"
table2_name = "cmdb_ci_spkg"
result_table_name = "software_instance_spkg"
unmatched_lines = remove
condition = all {
eq {
get_attr {"cmdb_software_instance[].name"}
get_attr {"cmdb_ci_spkg[].name"}
}
eq {
get_attr {"cmdb_software_instance[].version"}
get_attr {"cmdb_ci_spkg[].version"}
}
}
ref_direction = parentToChild
ref_field_name = "software"
}
on_false = nop {}
}
}
}
|
Connection Simulation lib | I would like for you to help me build a Pattern that helps achieve Discovery of Connection Simulation lib. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Connection Simulation lib"
id = "f6811b0c4b6a4d1aaf0e0a3970b62995"
description = "Connection Simulation lib"
step {
name = "set content"
set_attr {
"content"
eval {"def url = ${myurl}.toURL();def result= '';url.eachLine {result += it};return result;"}
}
}
step {
name = "parse xml"
parse_var_to_var {
from_var_name = "content"
to_var_names = table {
name = "connections"
col_names = "type","label","ip","targetci","targetlabel","targetip","conntype"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/cis"
fields {
field {
col_name = "type"
xpath = "/cis/ci/type/text()"
delimiters = ""
position = 0
}
field {
col_name = "label"
xpath = "/cis/ci/label/text()"
delimiters = ""
position = 0
}
field {
col_name = "ip"
xpath = "/cis/ci/ip/text()"
delimiters = ""
position = 0
}
field {
col_name = "targetci"
xpath = "/cis/ci/conngroup/connection/targetci/text()"
delimiters = ""
position = 0
}
field {
col_name = "targetlabel"
xpath = "/cis/ci/conngroup/connection/targetlabel/text()"
delimiters = ""
position = 0
}
field {
col_name = "targetip"
xpath = "/cis/ci/conngroup/connection/host/text()"
delimiters = ""
position = 0
}
field {
col_name = "conntype"
xpath = "/cis/ci/conngroup/@type"
delimiters = ""
position = 0
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "filter relevant connections"
filter {
src_table_name = "connections"
target_table_name = "connections"
condition = all {
any {
eq {
get_attr {"connections[].ip"}
get_attr {"entry_point.ip"}
}
eq {
get_attr {"connections[].ip"}
get_attr {"parent.entry_point.ip"}
}
}
eq {
get_attr {"connections[].label"}
get_attr {"citype"}
}
}
}
}
step {
name = "filter cluster conn"
filter {
src_table_name = "connections"
target_table_name = "cluster_connections"
condition = eq {
get_attr {"connections[].conntype"}
"CLUSTER"
}
}
}
step {
name = "set cluster name"
set_attr {
"cluster_name"
concat {
get_attr {"entry_point.ip_address"}
"-"
get_attr {"citype"}
}
}
}
step {
name = "filter flow connections"
filter {
src_table_name = "connections"
target_table_name = "flow_connections"
condition = eq {
get_attr {"connections[].conntype"}
"FLOW"
}
}
}
step {
name = "filter inc conn"
filter {
src_table_name = "connections"
target_table_name = "inc_connections"
condition = eq {
get_attr {"connections[].conntype"}
"INC"
}
}
}
step {
name = "create cluster cionn"
create_connection {
connection_type = CLUSTER
cluster_name = get_attr {"cluster_name"}
entry_point_type = "1FD2311F-6F70-4D93-8ABF-9052D2A91682"
attributes {
attribute {
name = "host_name"
value = get_attr {"cluster_connections[*].targetip"}
}
attribute {
name = "targetlabel"
value = get_attr {"cluster_connections[*].targetlabel"}
}
attribute {
name = "xml_url"
value = get_attr {"myurl"}
}
}
is_artificial = "false"
traffic_based = "false"
}
}
step {
name = "create inc connections"
create_connection {
connection_type = INCLUSION
entry_point_type = "9D93191C-053E-46D9-B7C3-315651A29372"
attributes {
attribute {
name = "host_name"
value = get_attr {"inc_connections[*].targetip"}
}
attribute {
name = "targetlabel"
value = get_attr {"inc_connections[*].targetlabel"}
}
attribute {
name = "xml_url"
value = get_attr {"myurl"}
}
}
is_artificial = "false"
traffic_based = "false"
}
}
step {
name = "create flow conn"
create_connection {
connection_type = APPLICATION_FLOW
entry_point_type = "1FD2311F-6F70-4D93-8ABF-9052D2A91682"
attributes {
attribute {
name = "host_name"
value = get_attr {"flow_connections[*].targetip"}
}
attribute {
name = "targetlabel"
value = get_attr {"flow_connections[*].targetlabel"}
}
attribute {
name = "xml_url"
value = get_attr {"myurl"}
}
}
is_artificial = "false"
traffic_based = "false"
}
}
}
| library {
name = "Connection Simulation lib"
id = "f6811b0c4b6a4d1aaf0e0a3970b62995" // Unique identifier for the pattern
description = "Connection Simulation lib" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set content"
set_attr {
"content"
eval {"def url = ${myurl}.toURL();def result= '';url.eachLine {result += it};return result;"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "parse xml"
parse_var_to_var {
from_var_name = "content"
to_var_names = table {
name = "connections"
col_names = "type","label","ip","targetci","targetlabel","targetip","conntype"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/cis"
fields {
field {
col_name = "type"
xpath = "/cis/ci/type/text()"
delimiters = ""
position = 0
}
field {
col_name = "label"
xpath = "/cis/ci/label/text()"
delimiters = ""
position = 0
}
field {
col_name = "ip"
xpath = "/cis/ci/ip/text()"
delimiters = ""
position = 0
}
field {
col_name = "targetci"
xpath = "/cis/ci/conngroup/connection/targetci/text()"
delimiters = ""
position = 0
}
field {
col_name = "targetlabel"
xpath = "/cis/ci/conngroup/connection/targetlabel/text()"
delimiters = ""
position = 0
}
field {
col_name = "targetip"
xpath = "/cis/ci/conngroup/connection/host/text()"
delimiters = ""
position = 0
}
field {
col_name = "conntype"
xpath = "/cis/ci/conngroup/@type"
delimiters = ""
position = 0
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter relevant connections"
filter {
src_table_name = "connections"
target_table_name = "connections"
condition = all {
any {
eq {
get_attr {"connections[].ip"}
get_attr {"entry_point.ip"}
}
eq {
get_attr {"connections[].ip"}
get_attr {"parent.entry_point.ip"}
}
}
eq {
get_attr {"connections[].label"}
get_attr {"citype"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter cluster conn"
filter {
src_table_name = "connections"
target_table_name = "cluster_connections"
condition = eq {
get_attr {"connections[].conntype"}
"CLUSTER"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set cluster name"
set_attr {
"cluster_name"
concat {
get_attr {"entry_point.ip_address"}
"-"
get_attr {"citype"}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter flow connections"
filter {
src_table_name = "connections"
target_table_name = "flow_connections"
condition = eq {
get_attr {"connections[].conntype"}
"FLOW"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter inc conn"
filter {
src_table_name = "connections"
target_table_name = "inc_connections"
condition = eq {
get_attr {"connections[].conntype"}
"INC"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create cluster cionn"
create_connection {
connection_type = CLUSTER
cluster_name = get_attr {"cluster_name"}
entry_point_type = "1FD2311F-6F70-4D93-8ABF-9052D2A91682"
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "host_name"
value = get_attr {"cluster_connections[*].targetip"}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "targetlabel"
value = get_attr {"cluster_connections[*].targetlabel"}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "xml_url"
value = get_attr {"myurl"}
}
}
is_artificial = "false"
traffic_based = "false"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create inc connections"
create_connection {
connection_type = INCLUSION
entry_point_type = "9D93191C-053E-46D9-B7C3-315651A29372"
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "host_name"
value = get_attr {"inc_connections[*].targetip"}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "targetlabel"
value = get_attr {"inc_connections[*].targetlabel"}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "xml_url"
value = get_attr {"myurl"}
}
}
is_artificial = "false"
traffic_based = "false"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create flow conn"
create_connection {
connection_type = APPLICATION_FLOW
entry_point_type = "1FD2311F-6F70-4D93-8ABF-9052D2A91682"
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "host_name"
value = get_attr {"flow_connections[*].targetip"}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "targetlabel"
value = get_attr {"flow_connections[*].targetlabel"}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "xml_url"
value = get_attr {"myurl"}
}
}
is_artificial = "false"
traffic_based = "false"
}
}
}
|
Google Cloud Platform (GCP) - LB - Get Health Service | I would like for you to help me build a Pattern that helps achieve Discovery of Google Cloud Platform (GCP) - LB - Get Health Service. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Google Cloud Platform (GCP) - LB - Get Health Service"
id = "f78ba272f340330059ec423423612b0b"
description = ""
step {
name = "Get Cloud Load Balancer httpHealthChecks Service"
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://www.googleapis.com/compute/"
get_attr {"API_version"}
"/projects/"
get_attr {"service_account[1].account_id"}
"/global/httpHealthChecks"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "http_health_checks_rest_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "Parse Cloud Load Balancer httpHealthChecks Service"
if {
condition = is_not_empty {get_attr {"http_health_checks_rest_response"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "http_health_checks_rest_response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "lb_httpHealthChecks"
}
attribute {
name = "target_columns"
value = "health_object_id: items.id,health_check:items.name,request_path:items.requestPath, port:items.port,timeout_sec:items.timeoutSec, unhealthy_threshold:items.unhealthyThreshold,healthy_threshold:items.healthyThreshold,check_interval_sec:items.checkIntervalSec"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Adding protocol type to the lb_health_checks_http table"
if {
condition = is_not_empty {get_attr {"lb_httpHealthChecks"}}
on_true = transform {
src_table_name = "lb_httpHealthChecks"
target_table_name = "lb_httpHealthChecks"
operation {
set_field {
field_name = "type"
value = "HTTP"
}
set_field {
field_name = "health_check_region"
value = "global"
}
}
}
on_false = nop {}
}
}
step {
name = "Get Cloud Load Balancer httpsHealthChecks Service"
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://www.googleapis.com/compute/"
get_attr {"API_version"}
"/projects/"
get_attr {"service_account[1].account_id"}
"/global/httpsHealthChecks"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "https_health_checks_rest_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "Parse Cloud Load Balancer httpsHealthChecks Service"
if {
condition = is_not_empty {get_attr {"https_health_checks_rest_response"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "https_health_checks_rest_response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "lb_httpsHealthChecks"
}
attribute {
name = "target_columns"
value = "health_object_id:items.id,health_check:items.name,request_path:items.requestPath,port:items.port,timeout_sec:items.timeoutSec,unhealthy_threshold:items.unhealthyThreshold,healthy_threshold:items.healthyThreshold,check_interval_sec:items.checkIntervalSec"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Adding protocol type to the lb_https_health_checks_http table"
if {
condition = is_not_empty {get_attr {"lb_httpsHealthChecks"}}
on_true = transform {
src_table_name = "lb_httpsHealthChecks"
target_table_name = "lb_httpsHealthChecks"
operation {
set_field {
field_name = "type"
value = "HTTPS"
}
set_field {
field_name = "health_check_region"
value = "global"
}
}
}
on_false = nop {}
}
}
step {
name = "Union lb_health_checks_http and lb_https_health_checks_http"
union {
table1_name = "lb_httpHealthChecks"
table2_name = "lb_httpsHealthChecks"
result_table_name = "lb_health_checks"
}
}
step {
name = "Get Cloud Load Balancer Health Service"
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://www.googleapis.com/compute/"
get_attr {"API_version"}
"/projects/"
get_attr {"service_account[1].account_id"}
"/aggregated/healthChecks"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "health_checks_rest_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "Parse Cloud Load Balancer SSL Health Service"
if {
condition = is_not_empty {get_attr {"health_checks_rest_response"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "health_checks_rest_response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "lb_health_checks_ssl"
}
attribute {
name = "target_columns"
value = "health_object_id:items.*.healthChecks.id,health_check:items.*.healthChecks.name,timeout_sec:items.*.healthChecks.timeoutSec,unhealthy_threshold:items.*.healthChecks.unhealthyThreshold,healthy_threshold:items.*.healthChecks.healthyThreshold,check_interval_sec:items.*.healthChecks.checkIntervalSec,type:items.*.healthChecks.type,port:items.*.healthChecks.sslHealthCheck.port,health_self_link:items.*.healthChecks.selfLink"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Parse Cloud Load Balancer TCP Health Service"
if {
condition = is_not_empty {get_attr {"health_checks_rest_response"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "health_checks_rest_response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "lb_health_checks_tcp"
}
attribute {
name = "target_columns"
value = "health_object_id:items.*.healthChecks.id,health_check:items.*.healthChecks.name,timeout_sec:items.*.healthChecks.timeoutSec,unhealthy_threshold:items.*.healthChecks.unhealthyThreshold,healthy_threshold:items.*.healthChecks.healthyThreshold,check_interval_sec:items.*.healthChecks.checkIntervalSec,type:items.*.healthChecks.type,port:items.*.healthChecks.tcpHealthCheck.port,health_self_link:items.*.healthChecks.selfLink"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Parse Cloud Load Balancer HTTP Health Service"
if {
condition = is_not_empty {get_attr {"health_checks_rest_response"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "health_checks_rest_response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "lb_health_checks_http"
}
attribute {
name = "target_columns"
value = "health_object_id:items.*.healthChecks.id,health_check:items.*.healthChecks.name,timeout_sec:items.*.healthChecks.timeoutSec,unhealthy_threshold:items.*.healthChecks.unhealthyThreshold,healthy_threshold:items.*.healthChecks.healthyThreshold,check_interval_sec:items.*.healthChecks.checkIntervalSec,type:items.*.healthChecks.type,port:items.*.healthChecks.httpHealthCheck.port,health_self_link:items.*.healthChecks.selfLink"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Parse Cloud Load Balancer HTTPS Health Service"
if {
condition = is_not_empty {get_attr {"health_checks_rest_response"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "health_checks_rest_response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "lb_health_checks_https"
}
attribute {
name = "target_columns"
value = "health_object_id:items.*.healthChecks.id,health_check:items.*.healthChecks.name,timeout_sec:items.*.healthChecks.timeoutSec,unhealthy_threshold:items.*.healthChecks.unhealthyThreshold,healthy_threshold:items.*.healthChecks.healthyThreshold,check_interval_sec:items.*.healthChecks.checkIntervalSec,type:items.*.healthChecks.type,port:items.*.healthChecks.httpsHealthCheck.port,health_self_link:items.*.healthChecks.selfLink"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Union tables lb_health_checks and lb_health_checks_http"
if {
condition = is_not_empty {get_attr {"lb_health_checks_http"}}
on_true = union {
table1_name = "lb_health_checks_http"
table2_name = "lb_health_checks"
result_table_name = "lb_health_checks"
}
on_false = nop {}
}
}
step {
name = "Union tables lb_health_checks and lb_health_checks_https"
if {
condition = is_not_empty {get_attr {"lb_health_checks_https"}}
on_true = union {
table1_name = "lb_health_checks_https"
table2_name = "lb_health_checks"
result_table_name = "lb_health_checks"
}
on_false = nop {}
}
}
step {
name = "Union tables lb_health_checks and lb_health_checks_tcp"
if {
condition = is_not_empty {get_attr {"lb_health_checks_tcp"}}
on_true = union {
table1_name = "lb_health_checks_tcp"
table2_name = "lb_health_checks"
result_table_name = "lb_health_checks"
}
on_false = nop {}
}
}
step {
name = "Union tables lb_health_checks and lb_health_checks_ssl"
if {
condition = is_not_empty {get_attr {"lb_health_checks_ssl"}}
on_true = union {
table1_name = "lb_health_checks_ssl"
table2_name = "lb_health_checks"
result_table_name = "lb_health_checks"
}
on_false = nop {}
}
}
step {
name = "Filter lb_health_checks for empty ports"
comment = "Filter lb_health_checks for empty ports.
We are keeping only records with ports, so we will have only records with all relevant data."
if {
condition = is_not_empty {get_attr {"lb_health_checks"}}
on_true = filter {
src_table_name = "lb_health_checks"
target_table_name = "lb_health_checks"
condition = is_not_empty {get_attr {"lb_health_checks[].port"}}
}
on_false = nop {}
}
}
step {
name = "Populate health_checks_region in lb_health_checks"
if {
condition = is_not_empty {get_attr {"lb_health_checks"}}
on_true = transform {
src_table_name = "lb_health_checks"
target_table_name = "lb_health_checks"
operation {set_field {
field_name = "health_checks_region"
value = eval {"javascript: var health_self_link=${lb_health_checks[].health_self_link};
var health_check_region=${lb_health_checks[].health_check_region};
var rtrn=health_check_region;
if(!health_check_region && health_self_link){
var myRegexp = /.*\\/(.*)\\/healthChecks\\/.*$/;
var matches = myRegexp.exec(health_self_link);
// If we got a match - return it.
if (matches && matches[1]){
rtrn = matches[1];
}
}
rtrn;"}
}}
}
on_false = nop {}
}
}
step {
name = "Merge lb_health_checks and backend_services_lb_service - for HTTP LB"
comment = "Merge lb_health_checks_http and health_check tables.
Merging the 2 tables in order to have the object_id of the health check in the health_check table."
if {
condition = eq {
get_attr {"cmdb_ci_cloud_load_balancer[1].lb_type"}
"HTTP"
}
on_true = merge {
table1_name = "lb_health_checks"
key1_name = "health_check"
table2_name = "backend_services_lb_service"
key2_name = "b_health_check"
result_table_name = "lb_health_checks"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "Merge lb_health_checks and cmdb_ci_lb_pool - for TCP/UDP LB"
comment = "Merge lb_health_checks_http and health_check tables.
Merging the 2 tables in order to have the object_id of the health check in the health_check table."
if {
condition = is_empty {get_attr {"cmdb_ci_cloud_load_balancer[1].lb_type"}}
on_true = merge {
table1_name = "lb_health_checks"
key1_name = "health_check"
table2_name = "cmdb_ci_lb_pool"
key2_name = "health_check"
result_table_name = "lb_health_checks"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "Remove duplicate from lb_health_checks"
comment = "Remove duplicate from lb_health_checks"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${lb_health_checks},[\"health_object_id\"]);
CTX.setAttribute(\"lb_health_checks\", tableWithoutDuplicates);"}
}
}
step {
name = "Populate cmdb_ci_lb_health_service"
transform {
src_table_name = "lb_health_checks"
target_table_name = "cmdb_ci_lb_health_service"
operation {
set_field {
field_name = "object_id"
value = get_attr {"lb_health_checks[].health_object_id"}
}
set_field {
field_name = "name"
value = get_attr {"lb_health_checks[].health_check"}
}
set_field {
field_name = "monitor_type"
value = get_attr {"lb_health_checks[].type"}
}
}
}
}
step {
name = "Remove cmdb_ci_lb_health_service from CMDB in case of LDC filter"
comment = "Remove cmdb_ci_lb_health_service from CMDB in case of LDC filter."
if {
condition = eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
on_true = filter {
src_table_name = "cmdb_ci_lb_health_service"
target_table_name = "cmdb_ci_lb_health_service"
condition = any {
contains {
"global"
get_attr {"cmdb_ci_lb_health_service[].health_checks_region"}
}
eq {
eval {"${cmdb_ci_google_datacenter[*].region}.contains(${cmdb_ci_lb_health_service[].health_checks_region})"}
"true"
}
}
}
on_false = nop {}
}
}
}
| library {
name = "Google Cloud Platform (GCP) - LB - Get Health Service"
id = "f78ba272f340330059ec423423612b0b" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Cloud Load Balancer httpHealthChecks Service"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://www.googleapis.com/compute/"
get_attr {"API_version"}
"/projects/"
get_attr {"service_account[1].account_id"}
"/global/httpHealthChecks"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "http_health_checks_rest_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Cloud Load Balancer httpHealthChecks Service"
if {
condition = is_not_empty {get_attr {"http_health_checks_rest_response"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "http_health_checks_rest_response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "lb_httpHealthChecks"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "health_object_id: items.id,health_check:items.name,request_path:items.requestPath, port:items.port,timeout_sec:items.timeoutSec, unhealthy_threshold:items.unhealthyThreshold,healthy_threshold:items.healthyThreshold,check_interval_sec:items.checkIntervalSec"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Adding protocol type to the lb_health_checks_http table"
if {
condition = is_not_empty {get_attr {"lb_httpHealthChecks"}}
on_true = transform {
src_table_name = "lb_httpHealthChecks"
target_table_name = "lb_httpHealthChecks"
operation {
set_field {
field_name = "type"
value = "HTTP"
}
set_field {
field_name = "health_check_region"
value = "global"
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Cloud Load Balancer httpsHealthChecks Service"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://www.googleapis.com/compute/"
get_attr {"API_version"}
"/projects/"
get_attr {"service_account[1].account_id"}
"/global/httpsHealthChecks"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "https_health_checks_rest_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Cloud Load Balancer httpsHealthChecks Service"
if {
condition = is_not_empty {get_attr {"https_health_checks_rest_response"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "https_health_checks_rest_response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "lb_httpsHealthChecks"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "health_object_id:items.id,health_check:items.name,request_path:items.requestPath,port:items.port,timeout_sec:items.timeoutSec,unhealthy_threshold:items.unhealthyThreshold,healthy_threshold:items.healthyThreshold,check_interval_sec:items.checkIntervalSec"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Adding protocol type to the lb_https_health_checks_http table"
if {
condition = is_not_empty {get_attr {"lb_httpsHealthChecks"}}
on_true = transform {
src_table_name = "lb_httpsHealthChecks"
target_table_name = "lb_httpsHealthChecks"
operation {
set_field {
field_name = "type"
value = "HTTPS"
}
set_field {
field_name = "health_check_region"
value = "global"
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union lb_health_checks_http and lb_https_health_checks_http"
union {
table1_name = "lb_httpHealthChecks"
table2_name = "lb_httpsHealthChecks"
result_table_name = "lb_health_checks"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Cloud Load Balancer Health Service"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://www.googleapis.com/compute/"
get_attr {"API_version"}
"/projects/"
get_attr {"service_account[1].account_id"}
"/aggregated/healthChecks"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "health_checks_rest_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Cloud Load Balancer SSL Health Service"
if {
condition = is_not_empty {get_attr {"health_checks_rest_response"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "health_checks_rest_response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "lb_health_checks_ssl"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "health_object_id:items.*.healthChecks.id,health_check:items.*.healthChecks.name,timeout_sec:items.*.healthChecks.timeoutSec,unhealthy_threshold:items.*.healthChecks.unhealthyThreshold,healthy_threshold:items.*.healthChecks.healthyThreshold,check_interval_sec:items.*.healthChecks.checkIntervalSec,type:items.*.healthChecks.type,port:items.*.healthChecks.sslHealthCheck.port,health_self_link:items.*.healthChecks.selfLink"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Cloud Load Balancer TCP Health Service"
if {
condition = is_not_empty {get_attr {"health_checks_rest_response"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "health_checks_rest_response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "lb_health_checks_tcp"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "health_object_id:items.*.healthChecks.id,health_check:items.*.healthChecks.name,timeout_sec:items.*.healthChecks.timeoutSec,unhealthy_threshold:items.*.healthChecks.unhealthyThreshold,healthy_threshold:items.*.healthChecks.healthyThreshold,check_interval_sec:items.*.healthChecks.checkIntervalSec,type:items.*.healthChecks.type,port:items.*.healthChecks.tcpHealthCheck.port,health_self_link:items.*.healthChecks.selfLink"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Cloud Load Balancer HTTP Health Service"
if {
condition = is_not_empty {get_attr {"health_checks_rest_response"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "health_checks_rest_response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "lb_health_checks_http"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "health_object_id:items.*.healthChecks.id,health_check:items.*.healthChecks.name,timeout_sec:items.*.healthChecks.timeoutSec,unhealthy_threshold:items.*.healthChecks.unhealthyThreshold,healthy_threshold:items.*.healthChecks.healthyThreshold,check_interval_sec:items.*.healthChecks.checkIntervalSec,type:items.*.healthChecks.type,port:items.*.healthChecks.httpHealthCheck.port,health_self_link:items.*.healthChecks.selfLink"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Cloud Load Balancer HTTPS Health Service"
if {
condition = is_not_empty {get_attr {"health_checks_rest_response"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "health_checks_rest_response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "lb_health_checks_https"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "health_object_id:items.*.healthChecks.id,health_check:items.*.healthChecks.name,timeout_sec:items.*.healthChecks.timeoutSec,unhealthy_threshold:items.*.healthChecks.unhealthyThreshold,healthy_threshold:items.*.healthChecks.healthyThreshold,check_interval_sec:items.*.healthChecks.checkIntervalSec,type:items.*.healthChecks.type,port:items.*.healthChecks.httpsHealthCheck.port,health_self_link:items.*.healthChecks.selfLink"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union tables lb_health_checks and lb_health_checks_http"
if {
condition = is_not_empty {get_attr {"lb_health_checks_http"}}
on_true = union {
table1_name = "lb_health_checks_http"
table2_name = "lb_health_checks"
result_table_name = "lb_health_checks"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union tables lb_health_checks and lb_health_checks_https"
if {
condition = is_not_empty {get_attr {"lb_health_checks_https"}}
on_true = union {
table1_name = "lb_health_checks_https"
table2_name = "lb_health_checks"
result_table_name = "lb_health_checks"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union tables lb_health_checks and lb_health_checks_tcp"
if {
condition = is_not_empty {get_attr {"lb_health_checks_tcp"}}
on_true = union {
table1_name = "lb_health_checks_tcp"
table2_name = "lb_health_checks"
result_table_name = "lb_health_checks"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union tables lb_health_checks and lb_health_checks_ssl"
if {
condition = is_not_empty {get_attr {"lb_health_checks_ssl"}}
on_true = union {
table1_name = "lb_health_checks_ssl"
table2_name = "lb_health_checks"
result_table_name = "lb_health_checks"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter lb_health_checks for empty ports"
comment = "Filter lb_health_checks for empty ports.
We are keeping only records with ports, so we will have only records with all relevant data."
if {
condition = is_not_empty {get_attr {"lb_health_checks"}}
on_true = filter {
src_table_name = "lb_health_checks"
target_table_name = "lb_health_checks"
condition = is_not_empty {get_attr {"lb_health_checks[].port"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate health_checks_region in lb_health_checks"
if {
condition = is_not_empty {get_attr {"lb_health_checks"}}
on_true = transform {
src_table_name = "lb_health_checks"
target_table_name = "lb_health_checks"
operation {set_field {
field_name = "health_checks_region"
value = eval {"javascript: var health_self_link=${lb_health_checks[].health_self_link}; // Script execution: Custom script to perform a specific action or collect data
var health_check_region=${lb_health_checks[].health_check_region};
var rtrn=health_check_region;
if(!health_check_region && health_self_link){
var myRegexp = /.*\\/(.*)\\/healthChecks\\/.*$/;
var matches = myRegexp.exec(health_self_link);
// If we got a match - return it.
if (matches && matches[1]){
rtrn = matches[1];
}
}
rtrn;"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge lb_health_checks and backend_services_lb_service - for HTTP LB"
comment = "Merge lb_health_checks_http and health_check tables.
Merging the 2 tables in order to have the object_id of the health check in the health_check table."
if {
condition = eq {
get_attr {"cmdb_ci_cloud_load_balancer[1].lb_type"}
"HTTP"
}
on_true = merge {
table1_name = "lb_health_checks"
key1_name = "health_check"
table2_name = "backend_services_lb_service"
key2_name = "b_health_check"
result_table_name = "lb_health_checks"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge lb_health_checks and cmdb_ci_lb_pool - for TCP/UDP LB"
comment = "Merge lb_health_checks_http and health_check tables.
Merging the 2 tables in order to have the object_id of the health check in the health_check table."
if {
condition = is_empty {get_attr {"cmdb_ci_cloud_load_balancer[1].lb_type"}}
on_true = merge {
table1_name = "lb_health_checks"
key1_name = "health_check"
table2_name = "cmdb_ci_lb_pool"
key2_name = "health_check"
result_table_name = "lb_health_checks"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate from lb_health_checks"
comment = "Remove duplicate from lb_health_checks"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${lb_health_checks},[\"health_object_id\"]);
CTX.setAttribute(\"lb_health_checks\", tableWithoutDuplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_lb_health_service"
transform {
src_table_name = "lb_health_checks"
target_table_name = "cmdb_ci_lb_health_service"
operation {
set_field {
field_name = "object_id"
value = get_attr {"lb_health_checks[].health_object_id"}
}
set_field {
field_name = "name"
value = get_attr {"lb_health_checks[].health_check"}
}
set_field {
field_name = "monitor_type"
value = get_attr {"lb_health_checks[].type"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove cmdb_ci_lb_health_service from CMDB in case of LDC filter"
comment = "Remove cmdb_ci_lb_health_service from CMDB in case of LDC filter."
if {
condition = eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
on_true = filter {
src_table_name = "cmdb_ci_lb_health_service"
target_table_name = "cmdb_ci_lb_health_service"
condition = any {
contains {
"global"
get_attr {"cmdb_ci_lb_health_service[].health_checks_region"}
}
eq {
eval {"${cmdb_ci_google_datacenter[*].region}.contains(${cmdb_ci_lb_health_service[].health_checks_region})"}
"true"
}
}
}
on_false = nop {}
}
}
}
|
Google Cloud Platform (GCP) - VM and Image Labels | I would like for you to help me build a Pattern that helps achieve Discovery of Google Cloud Platform (GCP) - VM and Image Labels. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Google Cloud Platform (GCP) - VM and Image Labels"
id = "f7eb3f5b1bda37402e1cfccf1d4bcb74"
description = "Google Cloud Platform (GCP) - VM and Image Labels"
step {
name = "Parse the VM Instances with Labels"
if {
condition = is_not_empty {get_attr {"virtual_machines"}}
on_true = set_attr {
"tmp"
eval {"javascript: var json_string_list =${vm_data}
var listSize = json_string_list.size()
var new_table = new Packages.java.util.ArrayList();
try {
for (i=0; i < listSize; i++) {
var json_root = JSON.parse (json_string_list.get(i));
for(var key in json_root.items) {
if (json_root.items[key].instances.length) {
for (j = 0; j < json_root.items[key].instances.length; j++){
var row = new Packages.java.util.HashMap();
var vm_id = JSON.stringify(json_root.items[key].instances[j].id)
vm_id = vm_id.replace(/\"/g,'');
var label_json = JSON.stringify(json_root.items[key].instances[j].labels)
var colon = label_json.indexOf(\":\")
if (colon >= 0) {
label_json = label_json.replace(/\"/g,'');
label_json = label_json.substring(1, label_json.length-1)
row.put(\"vm_id\",vm_id);
row.put(\"label_json\",label_json);
new_table.add(row)
}
}
}
}
}
CTX.setAttribute('tags_with_json', new_table);
} catch (e) {
ms.log(\"GCP Virtual Server extension section\" +e.toString());
}"}
}
on_false = nop {}
}
}
step {
name = "Split the tags to unique resources"
if {
condition = is_not_empty {get_attr {"tags_with_json"}}
on_true = set_attr {
"tmp"
eval {"javascript: var new_table = new Packages.java.util.ArrayList();
var label_text = ${tags_with_json[*].label_json}
var vm_id = ${tags_with_json[*].vm_id}
var vm_count = vm_id.size()
for (i=0; i < vm_count; i++){
var label_array = label_text.get(i).split(\",\")
var length = label_array.length;
for (j=0; j <length; j++){
var row = new Packages.java.util.HashMap();
row.put(\"vm_id\",vm_id.get(i));
row.put(\"value\",label_array[j]);
new_table.add(row)
}
CTX.setAttribute('cmdb_key_value', new_table);
}"}
}
on_false = nop {}
}
}
step {
name = "Parse the Images with Labels"
if {
condition = any {
is_empty {get_attr {"input_object_id"}}
is_not_empty {get_attr {"cmdb_ci_os_template[1].object_id"}}
is_not_empty {get_attr {"cmdb_ci_cloud_os_image[1].object_id"}}
}
on_true = set_attr {
"tmp"
eval {"javascript: var json_string_list =${imagesRaw}
var listSize = json_string_list.size()
var new_table = new Packages.java.util.ArrayList();
try {
for (i=0; i < listSize; i++) {
var json_root = JSON.parse(json_string_list.get(i));
for (j = 0; j < json_root.items.length; j++){
var row = new Packages.java.util.HashMap();
var image_id = JSON.stringify(json_root.items[j].id)
image_id = image_id.replace(/\"/g,'');
var label_json = JSON.stringify(json_root.items[j].labels)
var colon = label_json.indexOf(\":\")
if (colon >= 0) {
label_json = label_json.replace(/\"/g,'');
label_json = label_json.substring(1, label_json.length-1)
row.put(\"image_id\",image_id);
row.put(\"label_json\",label_json);
new_table.add(row)
}
}
}
CTX.setAttribute('image_labels', new_table);
} catch (e) {
ms.log(\"GCP Virtual Server extension section\" +e.toString());
} "}
}
on_false = nop {}
}
}
step {
name = "Split the tags to unique resources"
if {
condition = is_not_empty {get_attr {"image_labels"}}
on_true = set_attr {
"tmp"
eval {"javascript: var new_table = new Packages.java.util.ArrayList();
var label_text = ${image_labels[*].label_json}
var image_id = ${image_labels[*].image_id}
var image_count = image_id.size()
for (i=0; i < image_count; i++){
var label_array = label_text.get(i).split(\",\")
var length = label_array.length;
for (j=0; j <length; j++){
var row = new Packages.java.util.HashMap();
row.put(\"image_id\",image_id.get(i));
row.put(\"value\",label_array[j]);
new_table.add(row)
}
CTX.setAttribute('image_labels', new_table);
}"}
}
on_false = nop {}
}
}
step {
name = "Union the VM and Image Tags"
union {
table1_name = "cmdb_key_value"
table2_name = "image_labels"
result_table_name = "cmdb_key_value"
}
}
step {
name = "Filter out empty rows without value"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].value"}}
}
}
step {
name = "Verify JSON Label parsing"
match {
any {is_not_empty {get_attr {"cmdb_key_value[1].value"}}}
terminate_op = graceful
terminate_msg = "Not possible to find any Labels. Either the JSON is empty or incorrect !"
}
}
step {
name = "Parse Tags of format <tag_key:tag_value>"
if {
condition = is_not_empty {get_attr {"cmdb_key_value[1].value"}}
on_true = transform {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
operation {
set_field {
field_name = "key"
value = eval {"javascript: var rtrn = ''
var value = ${cmdb_key_value[].value}
var colon = value.indexOf(\":\")
if (colon >= 0) {
rtrn = value.substring(0,colon)
}"}
}
set_field {
field_name = "value"
value = eval {"javascript: var rtrn = ''
var value = ${cmdb_key_value[].value}
var colon = value.indexOf(\":\")
if (colon >= 0) {
rtrn = value.substring(colon+1,value.lastIndex)
}
else (rtrn = value) "}
}
}
}
on_false = nop {}
}
}
step {
name = "Reference between cmdb_key_value and cmdb_ci_vm_instance"
if {
condition = is_not_empty {get_attr {"cmdb_key_value[1].key"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "vm_id"
table2_name = "cmdb_ci_vm_instance"
key2_name = "vm_inst_id"
result_table_name = "key_value_to_vm_instance"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
step {
name = "Reference between cmdb_key_value and cmdb_ci_os_template"
if {
condition = all {
is_not_empty {get_attr {"cmdb_key_value[1].key"}}
neq {
get_attr {"isNewImageModel"}
"true"
}
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "image_id"
table2_name = "cmdb_ci_os_template"
key2_name = "object_id"
result_table_name = "key_value_to_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
step {
name = "Reference between cmdb_key_value and cmdb_ci_cloud_os_image"
if {
condition = all {
is_not_empty {get_attr {"cmdb_key_value[1].key"}}
eq {
get_attr {"isNewImageModel"}
"true"
}
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "image_id"
table2_name = "cmdb_ci_cloud_os_image"
key2_name = "object_id"
result_table_name = "key_value_to_cloudimage"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "Google Cloud Platform (GCP) - VM and Image Labels"
id = "f7eb3f5b1bda37402e1cfccf1d4bcb74" // Unique identifier for the pattern
description = "Google Cloud Platform (GCP) - VM and Image Labels" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the VM Instances with Labels"
if {
condition = is_not_empty {get_attr {"virtual_machines"}}
on_true = set_attr {
"tmp"
eval {"javascript: var json_string_list =${vm_data} // Script execution: Custom script to perform a specific action or collect data
var listSize = json_string_list.size()
var new_table = new Packages.java.util.ArrayList();
try {
for (i=0; i < listSize; i++) {
var json_root = JSON.parse (json_string_list.get(i));
for(var key in json_root.items) {
if (json_root.items[key].instances.length) {
for (j = 0; j < json_root.items[key].instances.length; j++){
var row = new Packages.java.util.HashMap();
var vm_id = JSON.stringify(json_root.items[key].instances[j].id) // Unique identifier for the pattern
vm_id = vm_id.replace(/\"/g,''); // Unique identifier for the pattern
var label_json = JSON.stringify(json_root.items[key].instances[j].labels)
var colon = label_json.indexOf(\":\")
if (colon >= 0) {
label_json = label_json.replace(/\"/g,'');
label_json = label_json.substring(1, label_json.length-1)
row.put(\"vm_id\",vm_id);
row.put(\"label_json\",label_json);
new_table.add(row)
}
}
}
}
}
CTX.setAttribute('tags_with_json', new_table);
} catch (e) {
ms.log(\"GCP Virtual Server extension section\" +e.toString());
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Split the tags to unique resources"
if {
condition = is_not_empty {get_attr {"tags_with_json"}}
on_true = set_attr {
"tmp"
eval {"javascript: var new_table = new Packages.java.util.ArrayList(); // Script execution: Custom script to perform a specific action or collect data
var label_text = ${tags_with_json[*].label_json}
var vm_id = ${tags_with_json[*].vm_id} // Unique identifier for the pattern
var vm_count = vm_id.size()
for (i=0; i < vm_count; i++){
var label_array = label_text.get(i).split(\",\")
var length = label_array.length;
for (j=0; j <length; j++){
var row = new Packages.java.util.HashMap();
row.put(\"vm_id\",vm_id.get(i));
row.put(\"value\",label_array[j]);
new_table.add(row)
}
CTX.setAttribute('cmdb_key_value', new_table);
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Images with Labels"
if {
condition = any {
is_empty {get_attr {"input_object_id"}}
is_not_empty {get_attr {"cmdb_ci_os_template[1].object_id"}}
is_not_empty {get_attr {"cmdb_ci_cloud_os_image[1].object_id"}}
}
on_true = set_attr {
"tmp"
eval {"javascript: var json_string_list =${imagesRaw} // Script execution: Custom script to perform a specific action or collect data
var listSize = json_string_list.size()
var new_table = new Packages.java.util.ArrayList();
try {
for (i=0; i < listSize; i++) {
var json_root = JSON.parse(json_string_list.get(i));
for (j = 0; j < json_root.items.length; j++){
var row = new Packages.java.util.HashMap();
var image_id = JSON.stringify(json_root.items[j].id) // Unique identifier for the pattern
image_id = image_id.replace(/\"/g,''); // Unique identifier for the pattern
var label_json = JSON.stringify(json_root.items[j].labels)
var colon = label_json.indexOf(\":\")
if (colon >= 0) {
label_json = label_json.replace(/\"/g,'');
label_json = label_json.substring(1, label_json.length-1)
row.put(\"image_id\",image_id);
row.put(\"label_json\",label_json);
new_table.add(row)
}
}
}
CTX.setAttribute('image_labels', new_table);
} catch (e) {
ms.log(\"GCP Virtual Server extension section\" +e.toString());
} "}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Split the tags to unique resources"
if {
condition = is_not_empty {get_attr {"image_labels"}}
on_true = set_attr {
"tmp"
eval {"javascript: var new_table = new Packages.java.util.ArrayList(); // Script execution: Custom script to perform a specific action or collect data
var label_text = ${image_labels[*].label_json}
var image_id = ${image_labels[*].image_id} // Unique identifier for the pattern
var image_count = image_id.size()
for (i=0; i < image_count; i++){
var label_array = label_text.get(i).split(\",\")
var length = label_array.length;
for (j=0; j <length; j++){
var row = new Packages.java.util.HashMap();
row.put(\"image_id\",image_id.get(i));
row.put(\"value\",label_array[j]);
new_table.add(row)
}
CTX.setAttribute('image_labels', new_table);
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union the VM and Image Tags"
union {
table1_name = "cmdb_key_value"
table2_name = "image_labels"
result_table_name = "cmdb_key_value"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out empty rows without value"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].value"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Verify JSON Label parsing"
match {
any {is_not_empty {get_attr {"cmdb_key_value[1].value"}}}
terminate_op = graceful
terminate_msg = "Not possible to find any Labels. Either the JSON is empty or incorrect !"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags of format <tag_key:tag_value>"
if {
condition = is_not_empty {get_attr {"cmdb_key_value[1].value"}}
on_true = transform {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
operation {
set_field {
field_name = "key"
value = eval {"javascript: var rtrn = '' // Script execution: Custom script to perform a specific action or collect data
var value = ${cmdb_key_value[].value}
var colon = value.indexOf(\":\")
if (colon >= 0) {
rtrn = value.substring(0,colon)
}"}
}
set_field {
field_name = "value"
value = eval {"javascript: var rtrn = '' // Script execution: Custom script to perform a specific action or collect data
var value = ${cmdb_key_value[].value}
var colon = value.indexOf(\":\")
if (colon >= 0) {
rtrn = value.substring(colon+1,value.lastIndex)
}
else (rtrn = value) "}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference between cmdb_key_value and cmdb_ci_vm_instance"
if {
condition = is_not_empty {get_attr {"cmdb_key_value[1].key"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "vm_id"
table2_name = "cmdb_ci_vm_instance"
key2_name = "vm_inst_id"
result_table_name = "key_value_to_vm_instance"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference between cmdb_key_value and cmdb_ci_os_template"
if {
condition = all {
is_not_empty {get_attr {"cmdb_key_value[1].key"}}
neq {
get_attr {"isNewImageModel"}
"true"
}
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "image_id"
table2_name = "cmdb_ci_os_template"
key2_name = "object_id"
result_table_name = "key_value_to_image"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference between cmdb_key_value and cmdb_ci_cloud_os_image"
if {
condition = all {
is_not_empty {get_attr {"cmdb_key_value[1].key"}}
eq {
get_attr {"isNewImageModel"}
"true"
}
}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "image_id"
table2_name = "cmdb_ci_cloud_os_image"
key2_name = "object_id"
result_table_name = "key_value_to_cloudimage"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
Amazon AWS - Get Key Pair data | I would like for you to help me build a Pattern that helps achieve Discovery of Amazon AWS - Get Key Pair data. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Amazon AWS - Get Key Pair data"
id = "f81417c6734333008c51d6dcb7f6a755"
description = "null"
step {
name = "Get Key Pair information"
custom_operation {
attributes {
attribute {
name = "url"
value = "https://ec2.{region}.amazonaws.com/?Action=DescribeKeyPairs&Version=2016-11-15"
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "key_pair_resp"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step {
name = "Parse Key Pair"
parse_var_to_var {
from_var_name = "key_pair_resp"
to_var_names = table {
name = "key_pair"
col_names = "object_id","finger_print","region"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeKeyPairsResponse"
fields {
field {
col_name = "object_id"
xpath = "/DescribeKeyPairsResponse/keySet/item/keyName/text()"
delimiters = ""
position = 1
}
field {
col_name = "finger_print"
xpath = "/DescribeKeyPairsResponse/keySet/item/keyFingerprint/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/DescribeKeyPairsResponse/keySet/added_sn_region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Filter key_pair table"
filter {
src_table_name = "key_pair"
target_table_name = "key_pair"
condition = is_not_empty {get_attr {"key_pair[].object_id"}}
}
}
step {
name = "Fill cmdb_ci_cloud_key_pair table"
transform {
src_table_name = "key_pair"
target_table_name = "cmdb_ci_cloud_key_pair"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"cmdb_ci_cloud_service_account[1].name"}
":"
get_attr {"key_pair[].region"}
":"
get_attr {"key_pair[].object_id"}
}
}
set_field {
field_name = "install_status"
value = "1"
}
}
}
}
}
| library {
name = "Amazon AWS - Get Key Pair data"
id = "f81417c6734333008c51d6dcb7f6a755" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Key Pair information"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = "https://ec2.{region}.amazonaws.com/?Action=DescribeKeyPairs&Version=2016-11-15"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "key_pair_resp"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Key Pair"
parse_var_to_var {
from_var_name = "key_pair_resp"
to_var_names = table {
name = "key_pair"
col_names = "object_id","finger_print","region"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeKeyPairsResponse"
fields {
field {
col_name = "object_id"
xpath = "/DescribeKeyPairsResponse/keySet/item/keyName/text()"
delimiters = ""
position = 1
}
field {
col_name = "finger_print"
xpath = "/DescribeKeyPairsResponse/keySet/item/keyFingerprint/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/DescribeKeyPairsResponse/keySet/added_sn_region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter key_pair table"
filter {
src_table_name = "key_pair"
target_table_name = "key_pair"
condition = is_not_empty {get_attr {"key_pair[].object_id"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill cmdb_ci_cloud_key_pair table"
transform {
src_table_name = "key_pair"
target_table_name = "cmdb_ci_cloud_key_pair"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"cmdb_ci_cloud_service_account[1].name"}
":"
get_attr {"key_pair[].region"}
":"
get_attr {"key_pair[].object_id"}
}
}
set_field {
field_name = "install_status"
value = "1"
}
}
}
}
}
|
Kubernetes Container | I would like for you to help me build a Pattern that helps achieve Discovery of Kubernetes Container. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Kubernetes Container"
id = "f8b0f03e9f5213002b9b92ec757fcf56"
description = ""
step {
name = "safety parsing for container and images"
comment = "using regex as safety parsing when json parsing does not work"
if {
condition = all {
is_empty {get_attr {"containers_and_images"}}
is_not_empty {get_attr {"pods_label"}}
}
on_true = transform {
src_table_name = "pods_label"
target_table_name = "containers_and_images"
operation {
set_field {
field_name = "pod_name"
value = eval {"javascript: var rtrn = '';
var podsName = ${pods_label[].pods_delimeted};
var matches = podsName.match(/\"name\":\\s*\\\"([\\s\\S]*?)\\\"/);
rtrn = matches ? matches[1] : '';"}
}
set_field {
field_name = "container_name"
value = eval {"javascript: var rtrn = '';
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"containerStatuses\":\\[\\{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
rtrn = matches ? matches[1] : '';
//var matches = podLabel.match(/\"containerStatuses\":[{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
"}
}
set_field {
field_name = "image"
value = eval {"javascript: var rtrn = '';
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"containerStatuses\":\\[\\{(?:.*)\"image\":\\s*\\\"([\\s\\S]*?)\"/);
rtrn = matches ? matches[1] : '';
//var matches = podLabel.match(/\"containerStatuses\":[{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
"}
}
set_field {
field_name = "image_id"
value = eval {"javascript: var rtrn = '';
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"containerStatuses\":\\[\\{(?:.*)\"imageID\":\\s*\\\"([\\s\\S]*?)\"/);
rtrn = matches ? matches[1] : '';
//var matches = podLabel.match(/\"containerStatuses\":[{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
"}
}
set_field {
field_name = "container_id"
value = eval {"javascript: var rtrn = '';
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"containerStatuses\":\\[\\{(?:.*)\"containerID\":\\s*\\\"([\\s\\S]*?)\"/);
rtrn = matches ? matches[1] : '';
//var matches = podLabel.match(/\"containerStatuses\":[{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
"}
}
set_field {
field_name = "namespace"
value = eval {"javascript: var rtrn = '';
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"namespace\":\\s*\\\"([\\s\\S]*?)\\\"/);
rtrn = matches ? matches[1] : '';"}
}
set_field {
field_name = "node_name"
value = eval {"javascript: var rtrn = '';
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"nodeName\":\\s*\\\"([\\s\\S]*?)\\\"/);
rtrn = matches ? matches[1] : '';"}
}
set_field {
field_name = "container_state"
value = eval {"javascript: var rtrn = '';
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"phase\":\\s*\\\"([\\s\\S]*?)\\\"/);
rtrn = matches ? matches[1] : '';"}
}
}
}
on_false = nop {}
}
}
step {
name = "filter container and images"
comment = "filter container and images to verify all of them have the needed information."
if {
condition = is_not_empty {get_attr {"containers_and_images"}}
on_true = filter {
src_table_name = "containers_and_images"
target_table_name = "containers_and_images"
condition = all {
is_not_empty {get_attr {"containers_and_images[].container_name"}}
is_not_empty {get_attr {"containers_and_images[].image"}}
is_not_empty {get_attr {"containers_and_images[].namespace"}}
is_not_empty {get_attr {"containers_and_images[].container_id"}}
}
}
on_false = nop {}
}
}
step {
name = "filter containers and images based on the namespace"
if {
condition = is_not_empty {get_attr {"containers_and_images"}}
on_true = filter {
src_table_name = "containers_and_images"
target_table_name = "containers_and_images"
condition = contains {
get_attr {"namespaces[*].name"}
get_attr {"containers_and_images[].namespace"}
}
}
on_false = nop {}
}
}
}
| library {
name = "Kubernetes Container"
id = "f8b0f03e9f5213002b9b92ec757fcf56" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "safety parsing for container and images"
comment = "using regex as safety parsing when json parsing does not work"
if {
condition = all {
is_empty {get_attr {"containers_and_images"}}
is_not_empty {get_attr {"pods_label"}}
}
on_true = transform {
src_table_name = "pods_label"
target_table_name = "containers_and_images"
operation {
set_field {
field_name = "pod_name"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var podsName = ${pods_label[].pods_delimeted};
var matches = podsName.match(/\"name\":\\s*\\\"([\\s\\S]*?)\\\"/);
rtrn = matches ? matches[1] : '';"}
}
set_field {
field_name = "container_name"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"containerStatuses\":\\[\\{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
rtrn = matches ? matches[1] : '';
//var matches = podLabel.match(/\"containerStatuses\":[{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
"}
}
set_field {
field_name = "image"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"containerStatuses\":\\[\\{(?:.*)\"image\":\\s*\\\"([\\s\\S]*?)\"/);
rtrn = matches ? matches[1] : '';
//var matches = podLabel.match(/\"containerStatuses\":[{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
"}
}
set_field {
field_name = "image_id"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"containerStatuses\":\\[\\{(?:.*)\"imageID\":\\s*\\\"([\\s\\S]*?)\"/);
rtrn = matches ? matches[1] : '';
//var matches = podLabel.match(/\"containerStatuses\":[{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
"}
}
set_field {
field_name = "container_id"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"containerStatuses\":\\[\\{(?:.*)\"containerID\":\\s*\\\"([\\s\\S]*?)\"/);
rtrn = matches ? matches[1] : '';
//var matches = podLabel.match(/\"containerStatuses\":[{\"name\":\\s*\\\"([\\s\\S]*?)\"/);
"}
}
set_field {
field_name = "namespace"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"namespace\":\\s*\\\"([\\s\\S]*?)\\\"/);
rtrn = matches ? matches[1] : '';"}
}
set_field {
field_name = "node_name"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"nodeName\":\\s*\\\"([\\s\\S]*?)\\\"/);
rtrn = matches ? matches[1] : '';"}
}
set_field {
field_name = "container_state"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var podLabel = ${pods_label[].pods_delimeted};
var matches = podLabel.match(/\"phase\":\\s*\\\"([\\s\\S]*?)\\\"/);
rtrn = matches ? matches[1] : '';"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter container and images"
comment = "filter container and images to verify all of them have the needed information."
if {
condition = is_not_empty {get_attr {"containers_and_images"}}
on_true = filter {
src_table_name = "containers_and_images"
target_table_name = "containers_and_images"
condition = all {
is_not_empty {get_attr {"containers_and_images[].container_name"}}
is_not_empty {get_attr {"containers_and_images[].image"}}
is_not_empty {get_attr {"containers_and_images[].namespace"}}
is_not_empty {get_attr {"containers_and_images[].container_id"}}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter containers and images based on the namespace"
if {
condition = is_not_empty {get_attr {"containers_and_images"}}
on_true = filter {
src_table_name = "containers_and_images"
target_table_name = "containers_and_images"
condition = contains {
get_attr {"namespaces[*].name"}
get_attr {"containers_and_images[].namespace"}
}
}
on_false = nop {}
}
}
}
|
Solaris - Zones | I would like for you to help me build a Pattern that helps achieve Discovery of Solaris - Zones. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Solaris - Zones"
id = "f94adfab9f2032001d753758442e7051"
description = "null"
step {
name = "Get current device zone"
runcmd_to_var {
cmd = "/usr/bin/zonename 2> /dev/null"
var_names = "currentDeviceZone"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Get zones script output"
if {
condition = eq {
get_attr {"currentDeviceZone"}
"global"
}
on_true = custom_operation {
attributes {attribute {
name = "fileName"
value = "get-zones.sh"
}}
sys_id_op = "68367a239fc13200e9123758442e7083"
to_var_names = table {
name = "zones"
col_names = "id","status","path","net"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/zones"
fields {
field {
col_name = "id"
xpath = "/zones/zone/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "status"
xpath = "/zones/zone/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "path"
xpath = "/zones/zone/path/text()"
delimiters = ""
position = 1
}
field {
col_name = "net"
xpath = "/zones/zone/net/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "get uuid"
runcmd_to_var {
cmd = "zoneadm list -cip"
var_names = table {
name = "zone_uuid"
col_names = "name","uuid"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "global"
delimiters = ":"
selected_positions = 2,5
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "If this is not global zone, set correlation_id with the zone"
if {
condition = all {
neq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"currentDeviceZone"}}
}
on_true = set_attr {
"cmdb_ci_solaris_server[*].correlation_id"
concat {
"zone-"
get_attr {"zone_uuid[1].uuid"}
}
}
on_false = nop {}
}
}
step {
name = "Merge UUID table into zones"
if {
condition = is_not_empty {get_attr {"zone_uuid[1].uuid"}}
on_true = merge {
table1_name = "zones"
key1_name = "id"
table2_name = "zone_uuid"
key2_name = "name"
result_table_name = "zones"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Insert data to cmdb_ci_vm_zones"
comment = "Correlation ID is the unique value of this table, and it should contain the sys_id of the solatis serversys_is is not available at this point, so we created a unique key that will be replaced later on (Post-Sensor script)"
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = transform {
src_table_name = "cmdb_ci_vm_zones"
target_table_name = "cmdb_ci_vm_zones"
operation {
set_field {
field_name = "name"
value = concat {
"Zone Server@"
get_attr {"computer_system.primaryHostname"}
}
}
set_field {
field_name = "correlation_id"
value = concat {
get_attr {"computer_system.primaryHostname"}
"#"
get_attr {"computer_system.managementIP"}
"#"
get_attr {"cmdb_ci_solaris_server[].serial_number"}
"#"
get_attr {"currentDeviceZone"}
}
}
}
}
on_false = nop {}
}
}
step {
name = "Relation between cmdb_ci_vm_zones and cmdb_ci_solaris_server"
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_zones"
table2_name = "cmdb_ci_solaris_server"
result_table_name = "zone_server_solaris_server"
unmatched_lines = remove
relation_type = "Runs on::Runs"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Insert data to cmdb_ci_solaris_instance"
comment = "Correlation ID is the unique value of this table, and it should contain the sys_id of the solatis serversys_is is not available at this point, so we created a unique key that will be replaced later on (Post-Sensor script)"
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = transform {
src_table_name = "zones"
target_table_name = "cmdb_ci_solaris_instance"
operation {
set_field {
field_name = "name"
value = get_attr {"zones[].id"}
}
set_field {
field_name = "correlation_id"
value = get_attr {"zones[].uuid"}
}
set_field {
field_name = "state"
value = eval {"javascript:var rtrn = '';
rtrn = ((${zones[].status}+'')==\"running\")?\"on\":\"off\";"}
}
}
}
on_false = nop {}
}
}
step {
name = "Relation between cmdb_ci_vm_zones and cmdb_ci_solaris_instance"
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_solaris_instance"
table2_name = "cmdb_ci_vm_zones"
result_table_name = "zone_server_vm_instance"
unmatched_lines = remove
relation_type = "Registered on::Has registered"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Relation between cmdb_ci_solaris_server and cmdb_ci_solaris_instance"
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_solaris_server"
table2_name = "cmdb_ci_solaris_instance"
result_table_name = "solaris_server_vm_instance"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "Solaris - Zones"
id = "f94adfab9f2032001d753758442e7051" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get current device zone"
runcmd_to_var {
cmd = "/usr/bin/zonename 2> /dev/null"
var_names = "currentDeviceZone"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get zones script output" // Script execution: Custom script to perform a specific action or collect data
if {
condition = eq {
get_attr {"currentDeviceZone"}
"global"
}
on_true = custom_operation {
attributes {attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "fileName"
value = "get-zones.sh"
}}
sys_id_op = "68367a239fc13200e9123758442e7083"
to_var_names = table {
name = "zones"
col_names = "id","status","path","net"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/zones"
fields {
field {
col_name = "id"
xpath = "/zones/zone/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "status"
xpath = "/zones/zone/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "path"
xpath = "/zones/zone/path/text()"
delimiters = ""
position = 1
}
field {
col_name = "net"
xpath = "/zones/zone/net/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "get uuid"
runcmd_to_var {
cmd = "zoneadm list -cip"
var_names = table {
name = "zone_uuid"
col_names = "name","uuid"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "global"
delimiters = ":"
selected_positions = 2,5
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If this is not global zone, set correlation_id with the zone"
if {
condition = all {
neq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"currentDeviceZone"}}
}
on_true = set_attr {
"cmdb_ci_solaris_server[*].correlation_id"
concat {
"zone-"
get_attr {"zone_uuid[1].uuid"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge UUID table into zones"
if {
condition = is_not_empty {get_attr {"zone_uuid[1].uuid"}}
on_true = merge {
table1_name = "zones"
key1_name = "id"
table2_name = "zone_uuid"
key2_name = "name"
result_table_name = "zones"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert data to cmdb_ci_vm_zones"
comment = "Correlation ID is the unique value of this table, and it should contain the sys_id of the solatis serversys_is is not available at this point, so we created a unique key that will be replaced later on (Post-Sensor script)" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = transform {
src_table_name = "cmdb_ci_vm_zones"
target_table_name = "cmdb_ci_vm_zones"
operation {
set_field {
field_name = "name"
value = concat {
"Zone Server@"
get_attr {"computer_system.primaryHostname"}
}
}
set_field {
field_name = "correlation_id"
value = concat {
get_attr {"computer_system.primaryHostname"}
"#"
get_attr {"computer_system.managementIP"}
"#"
get_attr {"cmdb_ci_solaris_server[].serial_number"}
"#"
get_attr {"currentDeviceZone"}
}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Relation between cmdb_ci_vm_zones and cmdb_ci_solaris_server"
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_vm_zones"
table2_name = "cmdb_ci_solaris_server"
result_table_name = "zone_server_solaris_server"
unmatched_lines = remove
relation_type = "Runs on::Runs"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert data to cmdb_ci_solaris_instance"
comment = "Correlation ID is the unique value of this table, and it should contain the sys_id of the solatis serversys_is is not available at this point, so we created a unique key that will be replaced later on (Post-Sensor script)" // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = transform {
src_table_name = "zones"
target_table_name = "cmdb_ci_solaris_instance"
operation {
set_field {
field_name = "name"
value = get_attr {"zones[].id"}
}
set_field {
field_name = "correlation_id"
value = get_attr {"zones[].uuid"}
}
set_field {
field_name = "state"
value = eval {"javascript:var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
rtrn = ((${zones[].status}+'')==\"running\")?\"on\":\"off\";"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Relation between cmdb_ci_vm_zones and cmdb_ci_solaris_instance"
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_solaris_instance"
table2_name = "cmdb_ci_vm_zones"
result_table_name = "zone_server_vm_instance"
unmatched_lines = remove
relation_type = "Registered on::Has registered"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Relation between cmdb_ci_solaris_server and cmdb_ci_solaris_instance"
if {
condition = all {
eq {
get_attr {"currentDeviceZone"}
"global"
}
is_not_empty {get_attr {"zones"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_solaris_server"
table2_name = "cmdb_ci_solaris_instance"
result_table_name = "solaris_server_vm_instance"
unmatched_lines = remove
relation_type = "Owns::Owned by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
Amazon AWS - Get Cloud Network data | I would like for you to help me build a Pattern that helps achieve Discovery of Amazon AWS - Get Cloud Network data. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Amazon AWS - Get Cloud Network data"
id = "f96cf35cdb221300d504788dbf961923"
description = "null"
step {
name = "Describe VPCs rest call"
comment = "Performing rest call to the AWS account in order to retrieve information about the virtual private cloud and the network table."
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://ec2.{region}.amazonaws.com/?Action=DescribeVpcs&VpcId.1="
get_attr {"input_object_id"}
"&Version=2016-11-15"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "vpc_rest"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "Verify if we have valid response"
comment = "Validating the response from the AWS rest call 'DescribeVpcs' in order to check that the correct information is collected.
pg - the check whether actual resources is removed based on patterns review for all kind of resources."
match {
all {
not_contains {
get_attr {"vpc_rest"}
"Cloud request failed"
}
not_contains {
get_attr {"vpc_rest"}
"Invalid parameter"
}
is_not_empty {get_attr {"vpc_rest"}}
}
terminate_op = terminate
terminate_msg = ""
}
}
step {
name = "Parsing the fields for Network table "
comment = "In this step we take all the information witch is matching to he model fields, in order to populate the cmdb_ci_network table."
parse_var_to_var {
from_var_name = "vpc_rest"
to_var_names = table {
name = "network"
col_names = "vpcid","cidr","state","region"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVpcsResponse"
fields {
field {
col_name = "vpcid"
xpath = "/DescribeVpcsResponse/vpcSet/item/vpcId/text()"
delimiters = ""
position = 1
}
field {
col_name = "cidr"
xpath = "/DescribeVpcsResponse/vpcSet/item/cidrBlockAssociationSet/item/cidrBlock/text()"
delimiters = ""
position = 1
}
field {
col_name = "state"
xpath = "/DescribeVpcsResponse/vpcSet/item/state/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/DescribeVpcsResponse/vpcSet/added_sn_region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Filter network table"
filter {
src_table_name = "network"
target_table_name = "network"
condition = is_not_empty {get_attr {"network[].vpcid"}}
}
}
step {
name = "Assign the VPC ID as name"
comment = "Assigning the ID as name, so that once the Tag Name is parsed, all the networks would have name even once that do not have a Name Tag."
transform {
src_table_name = "network"
target_table_name = "network"
operation {set_field {
field_name = "name"
value = concat {
get_attr {"network[].cidr"}
"["
get_attr {"network[].vpcid"}
"]"
}
}}
}
}
step {
name = "Parse cidr"
set_attr {
"tmp"
eval {"javascript:
function asArray(prop) {
if (prop === undefined || prop === null) {
return [];
} else if (prop instanceof Array) {
return prop;
} else {
return [prop];
}
}
try{
var map = new Packages.java.util.HashMap();
var response=${vpc_rest};
response=response.get(0);
var xmlHelper=new XMLHelper(response);
response =xmlHelper.toObject().vpcSet.item;
response=asArray(response);
for(var idx in response){
try{ var vpcId=response[idx].vpcId;
var cidrBlockAssociationSet=response[idx].cidrBlockAssociationSet.item;
cidrBlockAssociationSet=asArray(cidrBlockAssociationSet);
for(var idx2 in cidrBlockAssociationSet){
var cidr=cidrBlockAssociationSet[idx2].cidrBlock;
if(map.get(vpcId)==null)map.put(vpcId,[cidr]);
else map.get(vpcId).push(cidr);
}
}catch(err){
ms.log(\" Amazon AWS Network Event Error ocurred while parsing ipv4 cidr : \" + e);
}
try{
if(response[idx].ipv6CidrBlockAssociationSet){
var ipv6CidrBlockAssociationSet=asArray(response[idx].ipv6CidrBlockAssociationSet.item);
for(var idx2 in ipv6CidrBlockAssociationSet){
var cidr=ipv6CidrBlockAssociationSet[idx2].ipv6CidrBlock;
if(map.get(vpcId)==null)map.put(vpcId,[cidr]);
else map.get(vpcId).push(cidr);
}
}
} catch(err){
ms.log(\"Amazon AWS Network Event Error ocurred while parsing ipv4 cidr : \" + e);
}
}
var table=${network};
table = DuplicateRemover.removeDuplicates(table,[\"vpcid\"]);
for(var idx=0;idx<table.size();idx++){
var network_record=table.get(idx);
var object_id= network_record.get(\"vpcid\");
var cidr=map.get(object_id);
network_record.put('cidr',cidr.toString());
}
CTX.setAttribute('network',table);
} catch(e){
ms.log(\"Amazon AWS Network Event Error ocurred while parsing cidr : \" + e);
} "}
}
}
step {
name = "Parse the Network Tags"
comment = "pg In Amazon there is no actual resource Name, but instead the Tags are used as names. These Tags are with special key value of \"Name\"."
parse_var_to_var {
from_var_name = "vpc_rest"
to_var_names = table {
name = "network_tags"
col_names = "vpcid","tag_key","name"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVpcsResponse"
fields {
field {
col_name = "vpcid"
xpath = "/DescribeVpcsResponse/vpcSet/item/vpcId/text()"
delimiters = ""
position = 1
}
field {
col_name = "tag_key"
xpath = "/DescribeVpcsResponse/vpcSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "name"
xpath = "/DescribeVpcsResponse/vpcSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Filter the Name Tags"
comment = "pg Get only the Tags that are used as Names in AWS."
if {
condition = is_not_empty {get_attr {"network_tags"}}
on_true = filter {
src_table_name = "network_tags"
target_table_name = "network_tags"
condition = eq {
"1"
eval {"javascript: var tag_key=${network_tags[].tag_key};
var rtrn;
if (tag_key.trim() == \"Name\"){
rtrn=1;
}
else {
rtrn=0;
}"}
}
}
on_false = nop {}
}
}
step {
name = "Modify the Networks names"
if {
condition = is_not_empty {get_attr {"network_tags"}}
on_true = transform {
src_table_name = "network_tags"
target_table_name = "network_tags"
operation {set_field {
field_name = "name"
value = concat {
get_attr {"network_tags[].name"}
"["
get_attr {"network_tags[].vpcid"}
"]"
}
}}
}
on_false = nop {}
}
}
step {
name = "Assign the Name Tags to the Cloud Networks"
if {
condition = is_not_empty {get_attr {"network_tags"}}
on_true = merge {
table1_name = "network_tags"
key1_name = "vpcid"
table2_name = "network"
key2_name = "vpcid"
result_table_name = "network"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Fill cmdb_ci_network table"
comment = "Filling the main table 'cmdb_ci_network' with the information stored into the temporary table 'network2'."
transform {
src_table_name = "network"
target_table_name = "cmdb_ci_network"
operation {
set_field {
field_name = "object_id"
value = get_attr {"network[].vpcid"}
}
set_field {
field_name = "name"
value = get_attr {"network[].name"}
}
set_field {
field_name = "cidr"
value = get_attr {"network[].cidr"}
}
set_field {
field_name = "state"
value = get_attr {"network[].state"}
}
set_field {
field_name = "default_gateway"
value = get_attr {"network[].igateway"}
}
set_field {
field_name = "region"
value = get_attr {"network[].region"}
}
}
}
}
}
| library {
name = "Amazon AWS - Get Cloud Network data"
id = "f96cf35cdb221300d504788dbf961923" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Describe VPCs rest call"
comment = "Performing rest call to the AWS account in order to retrieve information about the virtual private cloud and the network table."
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://ec2.{region}.amazonaws.com/?Action=DescribeVpcs&VpcId.1="
get_attr {"input_object_id"}
"&Version=2016-11-15"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "vpc_rest"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Verify if we have valid response"
comment = "Validating the response from the AWS rest call 'DescribeVpcs' in order to check that the correct information is collected.
pg - the check whether actual resources is removed based on patterns review for all kind of resources."
match {
all {
not_contains {
get_attr {"vpc_rest"}
"Cloud request failed"
}
not_contains {
get_attr {"vpc_rest"}
"Invalid parameter"
}
is_not_empty {get_attr {"vpc_rest"}}
}
terminate_op = terminate
terminate_msg = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parsing the fields for Network table "
comment = "In this step we take all the information witch is matching to he model fields, in order to populate the cmdb_ci_network table." // Step definition: Represents a single action or set of actions in the pattern
parse_var_to_var {
from_var_name = "vpc_rest"
to_var_names = table {
name = "network"
col_names = "vpcid","cidr","state","region"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVpcsResponse"
fields {
field {
col_name = "vpcid"
xpath = "/DescribeVpcsResponse/vpcSet/item/vpcId/text()"
delimiters = ""
position = 1
}
field {
col_name = "cidr"
xpath = "/DescribeVpcsResponse/vpcSet/item/cidrBlockAssociationSet/item/cidrBlock/text()"
delimiters = ""
position = 1
}
field {
col_name = "state"
xpath = "/DescribeVpcsResponse/vpcSet/item/state/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/DescribeVpcsResponse/vpcSet/added_sn_region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter network table"
filter {
src_table_name = "network"
target_table_name = "network"
condition = is_not_empty {get_attr {"network[].vpcid"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Assign the VPC ID as name"
comment = "Assigning the ID as name, so that once the Tag Name is parsed, all the networks would have name even once that do not have a Name Tag."
transform {
src_table_name = "network"
target_table_name = "network"
operation {set_field {
field_name = "name"
value = concat {
get_attr {"network[].cidr"}
"["
get_attr {"network[].vpcid"}
"]"
}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse cidr"
set_attr {
"tmp"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
function asArray(prop) {
if (prop === undefined || prop === null) {
return [];
} else if (prop instanceof Array) {
return prop;
} else {
return [prop];
}
}
try{
var map = new Packages.java.util.HashMap();
var response=${vpc_rest};
response=response.get(0);
var xmlHelper=new XMLHelper(response);
response =xmlHelper.toObject().vpcSet.item;
response=asArray(response);
for(var idx in response){
try{ var vpcId=response[idx].vpcId;
var cidrBlockAssociationSet=response[idx].cidrBlockAssociationSet.item;
cidrBlockAssociationSet=asArray(cidrBlockAssociationSet);
for(var idx2 in cidrBlockAssociationSet){
var cidr=cidrBlockAssociationSet[idx2].cidrBlock;
if(map.get(vpcId)==null)map.put(vpcId,[cidr]);
else map.get(vpcId).push(cidr);
}
}catch(err){
ms.log(\" Amazon AWS Network Event Error ocurred while parsing ipv4 cidr : \" + e);
}
try{
if(response[idx].ipv6CidrBlockAssociationSet){
var ipv6CidrBlockAssociationSet=asArray(response[idx].ipv6CidrBlockAssociationSet.item);
for(var idx2 in ipv6CidrBlockAssociationSet){
var cidr=ipv6CidrBlockAssociationSet[idx2].ipv6CidrBlock;
if(map.get(vpcId)==null)map.put(vpcId,[cidr]);
else map.get(vpcId).push(cidr);
}
}
} catch(err){
ms.log(\"Amazon AWS Network Event Error ocurred while parsing ipv4 cidr : \" + e);
}
}
var table=${network};
table = DuplicateRemover.removeDuplicates(table,[\"vpcid\"]);
for(var idx=0;idx<table.size();idx++){
var network_record=table.get(idx);
var object_id= network_record.get(\"vpcid\");
var cidr=map.get(object_id);
network_record.put('cidr',cidr.toString());
}
CTX.setAttribute('network',table);
} catch(e){
ms.log(\"Amazon AWS Network Event Error ocurred while parsing cidr : \" + e);
} "}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Network Tags"
comment = "pg In Amazon there is no actual resource Name, but instead the Tags are used as names. These Tags are with special key value of \"Name\"."
parse_var_to_var {
from_var_name = "vpc_rest"
to_var_names = table {
name = "network_tags"
col_names = "vpcid","tag_key","name"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVpcsResponse"
fields {
field {
col_name = "vpcid"
xpath = "/DescribeVpcsResponse/vpcSet/item/vpcId/text()"
delimiters = ""
position = 1
}
field {
col_name = "tag_key"
xpath = "/DescribeVpcsResponse/vpcSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "name"
xpath = "/DescribeVpcsResponse/vpcSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter the Name Tags"
comment = "pg Get only the Tags that are used as Names in AWS."
if {
condition = is_not_empty {get_attr {"network_tags"}}
on_true = filter {
src_table_name = "network_tags"
target_table_name = "network_tags"
condition = eq {
"1"
eval {"javascript: var tag_key=${network_tags[].tag_key}; // Script execution: Custom script to perform a specific action or collect data
var rtrn;
if (tag_key.trim() == \"Name\"){
rtrn=1;
}
else {
rtrn=0;
}"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Modify the Networks names"
if {
condition = is_not_empty {get_attr {"network_tags"}}
on_true = transform {
src_table_name = "network_tags"
target_table_name = "network_tags"
operation {set_field {
field_name = "name"
value = concat {
get_attr {"network_tags[].name"}
"["
get_attr {"network_tags[].vpcid"}
"]"
}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Assign the Name Tags to the Cloud Networks"
if {
condition = is_not_empty {get_attr {"network_tags"}}
on_true = merge {
table1_name = "network_tags"
key1_name = "vpcid"
table2_name = "network"
key2_name = "vpcid"
result_table_name = "network"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill cmdb_ci_network table"
comment = "Filling the main table 'cmdb_ci_network' with the information stored into the temporary table 'network2'."
transform {
src_table_name = "network"
target_table_name = "cmdb_ci_network"
operation {
set_field {
field_name = "object_id"
value = get_attr {"network[].vpcid"}
}
set_field {
field_name = "name"
value = get_attr {"network[].name"}
}
set_field {
field_name = "cidr"
value = get_attr {"network[].cidr"}
}
set_field {
field_name = "state"
value = get_attr {"network[].state"}
}
set_field {
field_name = "default_gateway"
value = get_attr {"network[].igateway"}
}
set_field {
field_name = "region"
value = get_attr {"network[].region"}
}
}
}
}
}
|
Solaris - OS Patches | I would like for you to help me build a Pattern that helps achieve Discovery of Solaris - OS Patches. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Solaris - OS Patches"
id = "f9d55b6b9f2032001d753758442e708b"
description = ""
step {
name = "Get patches"
runcmd_to_var {
cmd = "showrev -p"
var_names = table {
name = "OSPatches"
col_names = "name"
}
parsing_strategy = delimited_parsing {
delimiters = " "
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Update cmdb_ci_patches"
transform {
src_table_name = "OSPatches"
target_table_name = "cmdb_ci_patches"
operation {set_field {
field_name = "name"
value = get_attr {"OSPatches[].name"}
}}
}
}
step {
name = "Reference and relation between cmdb_ci_patches and Solaris CI"
relation_reference {
table1_name = "cmdb_ci_solaris_server"
table2_name = "cmdb_ci_patches"
result_table_name = "patch_to_Solaris"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
}
| library {
name = "Solaris - OS Patches"
id = "f9d55b6b9f2032001d753758442e708b" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get patches"
runcmd_to_var {
cmd = "showrev -p"
var_names = table {
name = "OSPatches"
col_names = "name"
}
parsing_strategy = delimited_parsing {
delimiters = " "
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_patches"
transform {
src_table_name = "OSPatches"
target_table_name = "cmdb_ci_patches"
operation {set_field {
field_name = "name"
value = get_attr {"OSPatches[].name"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference and relation between cmdb_ci_patches and Solaris CI"
relation_reference {
table1_name = "cmdb_ci_solaris_server"
table2_name = "cmdb_ci_patches"
result_table_name = "patch_to_Solaris"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Owns::Owned by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
}
|
Solaris - CPU | I would like for you to help me build a Pattern that helps achieve Discovery of Solaris - CPU. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Solaris - CPU"
id = "f9f5d76b9f2032001d753758442e7049"
description = ""
step {
name = "Get CPU"
runcmd_to_var {
cmd = "kstat cpu_info"
var_names = table {
name = "cpu_info"
col_names = "cpu_data"
}
parsing_strategy = regex_parsing {regex = "^(.*)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Keep relevant CPU data"
filter {
src_table_name = "cpu_info"
target_table_name = "cpu_info"
condition = any {
contains {
get_attr {"cpu_info[].cpu_data"}
"module"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"name"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"clock_MHz"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"chip_id"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"core_id"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"brand"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"cpu_type"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"vendor_id"
}
}
}
}
step {
name = "Parse CPU data into readable variable"
if {
condition = is_not_empty {get_attr {"cpu_info"}}
on_true = transform {
src_table_name = "cpu_info"
target_table_name = "cpu_info"
operation {set_field {
field_name = "cpu_data"
value = concat {eval {"javascript: rtrn=\"\";var line = ${cpu_info[].cpu_data};var parts = line.split(' ');if (parts[0] == \"brand\"){ for (var i = 0; i < parts.length; i++) { if (i == 0) { rtrn = parts[0] + \":\"; } else { rtrn +=parts[i] + \" \"; } }}else{ rtrn = parts[0] + \":\" + parts[parts.length -1];}"}}
}}
}
on_false = nop {}
}
}
step {
name = "Parse CPU data"
if {
condition = is_not_empty {get_attr {"cpu_info"}}
on_true = set_attr {
"cpu_data"
eval {"javascript: rtrn = \"\"; var table = ${cpu_info}; var processors = 0; var physicalIds = {}; physicalIds.count = 0; var coreIds = {}; coreIds.count = 0; var cpu_cores = 0; var physical_id_in_curr_block = ''; var result = {}; for (var i = 0; i < table.size(); i++) { var map = table.get(i); var str = map.get(\"cpu_data\"); var parts = str.split(\":\"); var name = parts[0].trim(); var value = parts[1].trim(); if (name == \"module\") { processors++; } if (name == \"clock_MHz\") { var cpu_speed = parseInt(value); if (!isNaN(cpu_speed)) { result.cpu_speed = cpu_speed+''; } } if (name == \"chip_id\") { physical_id_in_curr_block = value; if (!physicalIds[value]) { physicalIds[value] = true; physicalIds.count++; } } if (name == \"core_id\" && !coreIds[physical_id_in_curr_block + '.' + value]) { coreIds[physical_id_in_curr_block + '.' + value] = true; coreIds.count++; } if (name == \"brand\") { result.cpu_name = value; } if (name == \"cpu_type\") { result.cpu_type = value; } if (name == \"vendor_id\") { result.cpu_vendor = value; } } /* Calculate CPU count */ var cpuCount = 1; if (physicalIds.count > 0) { cpuCount = physicalIds.count; } result.cpu_count = cpuCount + ''; /* Calculate total CPU core count */ var cpuCoreCount = 1; if (coreIds.count > 0) { cpuCoreCount = coreIds.count; } /* To get core count per CPU, if core_id is not available, then just set the core count to 1.*/ result.cpu_core_count = cpuCoreCount == 1 ? cpuCoreCount+'' : (cpuCoreCount / cpuCount)+''; /* calculate threads per core */ var threadsPerCore = (processors / cpuCoreCount)+''; result.cpu_core_thread = threadsPerCore+''; rtrn = JSON.stringify(result);"}
}
on_false = nop {}
}
}
step {
name = "Save CPU data into a variable"
parse_var_to_var {
from_var_name = "cpu_data"
to_var_names = table {
name = "cpu_parsed"
col_names = "cpu_name","cpu_speed","cpu_type","cpu_count","cpu_core_count","cpu_core_thread","cpu_vendor"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "cpu_name"
xpath = "/root/cpu_name/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_speed"
xpath = "/root/cpu_speed/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_type"
xpath = "/root/cpu_type/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_count"
xpath = "/root/cpu_count/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_core_count"
xpath = "/root/cpu_core_count/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_core_thread"
xpath = "/root/cpu_core_thread/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_vendor"
xpath = "/root/cpu_vendor/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Update CPU data in Solaris CI"
transform {
src_table_name = "cmdb_ci_solaris_server"
target_table_name = "cmdb_ci_solaris_server"
operation {
set_field {
field_name = "cpu_speed"
value = get_attr {"cpu_parsed[1].cpu_speed"}
}
set_field {
field_name = "cpu_name"
value = get_attr {"cpu_parsed[1].cpu_name"}
}
set_field {
field_name = "cpu_count"
value = get_attr {"cpu_parsed[1].cpu_count"}
}
set_field {
field_name = "cpu_core_count"
value = get_attr {"cpu_parsed[1].cpu_core_count"}
}
set_field {
field_name = "cpu_core_thread"
value = get_attr {"cpu_parsed[1].cpu_core_thread"}
}
set_field {
field_name = "cpu_manufacturer"
value = get_attr {"cpu_parsed[1].cpu_vendor"}
}
set_field {
field_name = "cpu_type"
value = get_attr {"cpu_parsed[1].cpu_type"}
}
}
}
}
}
| library {
name = "Solaris - CPU"
id = "f9f5d76b9f2032001d753758442e7049" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get CPU"
runcmd_to_var {
cmd = "kstat cpu_info"
var_names = table {
name = "cpu_info"
col_names = "cpu_data"
}
parsing_strategy = regex_parsing {regex = "^(.*)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Keep relevant CPU data"
filter {
src_table_name = "cpu_info"
target_table_name = "cpu_info"
condition = any {
contains {
get_attr {"cpu_info[].cpu_data"}
"module"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"name"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"clock_MHz"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"chip_id"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"core_id"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"brand"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"cpu_type"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"vendor_id"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse CPU data into readable variable"
if {
condition = is_not_empty {get_attr {"cpu_info"}}
on_true = transform {
src_table_name = "cpu_info"
target_table_name = "cpu_info"
operation {set_field {
field_name = "cpu_data"
value = concat {eval {"javascript: rtrn=\"\";var line = ${cpu_info[].cpu_data};var parts = line.split(' ');if (parts[0] == \"brand\"){ for (var i = 0; i < parts.length; i++) { if (i == 0) { rtrn = parts[0] + \":\"; } else { rtrn +=parts[i] + \" \"; } }}else{ rtrn = parts[0] + \":\" + parts[parts.length -1];}"}} // Script execution: Custom script to perform a specific action or collect data
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse CPU data"
if {
condition = is_not_empty {get_attr {"cpu_info"}}
on_true = set_attr {
"cpu_data"
eval {"javascript: rtrn = \"\"; var table = ${cpu_info}; var processors = 0; var physicalIds = {}; physicalIds.count = 0; var coreIds = {}; coreIds.count = 0; var cpu_cores = 0; var physical_id_in_curr_block = ''; var result = {}; for (var i = 0; i < table.size(); i++) { var map = table.get(i); var str = map.get(\"cpu_data\"); var parts = str.split(\":\"); var name = parts[0].trim(); var value = parts[1].trim(); if (name == \"module\") { processors++; } if (name == \"clock_MHz\") { var cpu_speed = parseInt(value); if (!isNaN(cpu_speed)) { result.cpu_speed = cpu_speed+''; } } if (name == \"chip_id\") { physical_id_in_curr_block = value; if (!physicalIds[value]) { physicalIds[value] = true; physicalIds.count++; } } if (name == \"core_id\" && !coreIds[physical_id_in_curr_block + '.' + value]) { coreIds[physical_id_in_curr_block + '.' + value] = true; coreIds.count++; } if (name == \"brand\") { result.cpu_name = value; } if (name == \"cpu_type\") { result.cpu_type = value; } if (name == \"vendor_id\") { result.cpu_vendor = value; } } /* Calculate CPU count */ var cpuCount = 1; if (physicalIds.count > 0) { cpuCount = physicalIds.count; } result.cpu_count = cpuCount + ''; /* Calculate total CPU core count */ var cpuCoreCount = 1; if (coreIds.count > 0) { cpuCoreCount = coreIds.count; } /* To get core count per CPU, if core_id is not available, then just set the core count to 1.*/ result.cpu_core_count = cpuCoreCount == 1 ? cpuCoreCount+'' : (cpuCoreCount / cpuCount)+''; /* calculate threads per core */ var threadsPerCore = (processors / cpuCoreCount)+''; result.cpu_core_thread = threadsPerCore+''; rtrn = JSON.stringify(result);"} // Script execution: Custom script to perform a specific action or collect data
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Save CPU data into a variable"
parse_var_to_var {
from_var_name = "cpu_data"
to_var_names = table {
name = "cpu_parsed"
col_names = "cpu_name","cpu_speed","cpu_type","cpu_count","cpu_core_count","cpu_core_thread","cpu_vendor"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "cpu_name"
xpath = "/root/cpu_name/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_speed"
xpath = "/root/cpu_speed/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_type"
xpath = "/root/cpu_type/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_count"
xpath = "/root/cpu_count/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_core_count"
xpath = "/root/cpu_core_count/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_core_thread"
xpath = "/root/cpu_core_thread/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_vendor"
xpath = "/root/cpu_vendor/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update CPU data in Solaris CI"
transform {
src_table_name = "cmdb_ci_solaris_server"
target_table_name = "cmdb_ci_solaris_server"
operation {
set_field {
field_name = "cpu_speed"
value = get_attr {"cpu_parsed[1].cpu_speed"}
}
set_field {
field_name = "cpu_name"
value = get_attr {"cpu_parsed[1].cpu_name"}
}
set_field {
field_name = "cpu_count"
value = get_attr {"cpu_parsed[1].cpu_count"}
}
set_field {
field_name = "cpu_core_count"
value = get_attr {"cpu_parsed[1].cpu_core_count"}
}
set_field {
field_name = "cpu_core_thread"
value = get_attr {"cpu_parsed[1].cpu_core_thread"}
}
set_field {
field_name = "cpu_manufacturer"
value = get_attr {"cpu_parsed[1].cpu_vendor"}
}
set_field {
field_name = "cpu_type"
value = get_attr {"cpu_parsed[1].cpu_type"}
}
}
}
}
}
|
ECR Images | I would like for you to help me build a Pattern that helps achieve Discovery of ECR Images. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "ECR Images"
id = "ff5284991bc44110c95deaccac4bcbab"
description = "ECR Images"
step {
name = "PARSE Account IDs (AWS)"
comment = "Account IDs are getting pulled in through Pre-Execution Script. This sends queried data to MID Server for retrieval and use."
if {
condition = contains {
concat {
get_attr {"cmdb_ci_win_server[*].host_name"}
"10.0.18.71"
}
get_attr {"mid_host"}
}
on_true = parse_var_to_var {
from_var_name = "AWSAccountData[*].accountIDs"
to_var_names = table {
name = "AWSAccounts"
col_names = "AccountID"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = terminate {}
}
on_false = nop {}
}
}
step {
name = "GET Account Creds"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].host_name"}
get_attr {"mid_host"}
}
on_true = transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "creds"
value = eval {"javascript: var rtrn = '';
var command = \"aws sts assume-role --role-arn arn:aws:iam::\" + ${AWSAccounts[].AccountID} + \":role/otaug-snow-discovery-role --role-session-name ecr_session\"
var creds = CTX.getCommandManager().shellCommand(command,false, null, null, CTX);
rtrn = creds;"}
}}
}
on_false = nop {}
}
}
step {
name = "PARSE AccessKeyId"
transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "AccessKeyId"
value = eval {"javascript: var rtrn = '';
var creds = ${AWSAccounts[].creds};
var cred_obj = JSON.parse(creds);
var credentials = cred_obj.Credentials;
var access_key_id = credentials.AccessKeyId;
rtrn = access_key_id;
"}
}}
}
}
step {
name = "PARSE SecretAccessKey"
transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "SecretAccessKey"
value = eval {"javascript: var rtrn = '';
var creds = ${AWSAccounts[].creds};
var cred_obj = JSON.parse(creds);
var credentials = cred_obj.Credentials;
var secret = credentials.SecretAccessKey;
rtrn = secret;
"}
}}
}
}
step {
name = "PARSE SessionToken"
transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "SessionToken"
value = eval {"javascript: var rtrn = '';
var creds = ${AWSAccounts[].creds};
var cred_obj = JSON.parse(creds);
var credentials = cred_obj.Credentials;
var session_token = credentials.SessionToken;
rtrn = session_token;
"}
}}
}
}
step {
name = "GET Repos per Acct"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].host_name"}
get_attr {"mid_host"}
}
on_true = transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "Repositories"
value = eval {"javascript: var rtrn = '';
var account_id = ${AWSAccounts[].AccountID};
var access_key_id = ${AWSAccounts[].AccessKeyId};
var secret_access_key = ${AWSAccounts[].SecretAccessKey};
var session_token = ${AWSAccounts[].SessionToken};
var cmd = \"set AWS_ACCESS_KEY_ID=\" + access_key_id + \"&&set AWS_SECRET_ACCESS_KEY=\" + secret_access_key + \"&&set AWS_SESSION_TOKEN=\" + session_token + \"&&aws ecr describe-repositories\"
var repos = CTX.getCommandManager().shellCommand(cmd,false, null, null, CTX);
rtrn = repos;"}
}}
}
on_false = nop {}
}
}
step {
name = "GET Images"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].host_name"}
get_attr {"mid_host"}
}
on_true = runcmd_to_var {
cmd = eval {"javascript: var rtrn = \"success\";
var awsAccounts = CTX.getAttribute(\"AWSAccounts\").toArray();
var imageMap = new Packages.java.util.ArrayList();
for (var i = 0; i < awsAccounts.length; i++) {
var account = awsAccounts[i];
var repositories = JSON.parse(account.get(\"Repositories\")).repositories;
var accessKeyId = account.get(\"AccessKeyId\");
var secretAccessKey = account.get(\"SecretAccessKey\");
var sessionToken = account.get(\"SessionToken\");
for (var j = 0; j < repositories.length; j++) {
var repo = repositories[j];
var repositoryName = repo.repositoryName;
var registryId = repo.registryId;
// Construct the AWS CLI command
var cmd = \"set AWS_ACCESS_KEY_ID=\" + accessKeyId +
\"&&set AWS_SECRET_ACCESS_KEY=\" + secretAccessKey +
\"&&set AWS_SESSION_TOKEN=\" + sessionToken +
\"&&aws ecr describe-images --repository-name \" + repositoryName +
\" --registry-id \" + registryId;
try {
// Execute the command and capture the output
var output = CTX.getCommandManager().shellCommand(cmd, false, null, null, CTX);
// Parse the output JSON to get the list of images
var imageJson = JSON.parse(output);
var images = imageJson.imageDetails;
// Loop through each image and add it to the allImagesTable
for (var k = 0; k < images.length; k++) {
var image = images[k];
var row = new Packages.java.util.HashMap();
row.put(\"raw_image\", JSON.stringify(image));
row.put(\"AccountID\", account.get(\"AccountID\"));
row.put(\"RepositoryName\", repositoryName);
row.put(\"RegistryID\", registryId);
row.put(\"ImageDigest\", image.imageDigest);
row.put(\"ImageTag\", image.imageTags[0] || \"None\");
imageMap.add(row);
}
} catch (e) {
var row = new Packages.java.util.HashMap();
row.put('error', \"Failed to list images for repository: \" + repositoryName + \" in account: \" + account.get(\"AccountID\") + \". Error: \" + e);
imageMap.add(row);
}
}
}
// Update the context with the allImagesTable
CTX.setAttribute(\"ECRImages\", imageMap);
result = \"finished\";"}
execution_mode = "DEFAULT"
var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "INSERT Images to Cloud Resource"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].host_name"}
get_attr {"mid_host"}
}
on_true = transform {
src_table_name = "ECRImages"
target_table_name = "cmdb_ci_cmp_resource"
operation {
set_field {
field_name = "object_id"
value = concat {
get_attr {"ECRImages[].RepositoryName"}
":"
get_attr {"ECRImages[].ImageTag"}
}
}
set_field {
field_name = "name"
value = concat {
get_attr {"ECRImages[].RepositoryName"}
":"
get_attr {"ECRImages[].ImageTag"}
}
}
set_field {
field_name = "correlation_id"
value = get_attr {"ECRImages[].ImageDigest"}
}
set_field {
field_name = "resource_type"
value = "AWS::ECR::Image"
}
}
}
on_false = nop {}
}
}
}
| library {
name = "ECR Images"
id = "ff5284991bc44110c95deaccac4bcbab" // Unique identifier for the pattern
description = "ECR Images" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "PARSE Account IDs (AWS)"
comment = "Account IDs are getting pulled in through Pre-Execution Script. This sends queried data to MID Server for retrieval and use."
if {
condition = contains {
concat {
get_attr {"cmdb_ci_win_server[*].host_name"}
"10.0.18.71"
}
get_attr {"mid_host"}
}
on_true = parse_var_to_var {
from_var_name = "AWSAccountData[*].accountIDs"
to_var_names = table {
name = "AWSAccounts"
col_names = "AccountID"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = terminate {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "GET Account Creds"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].host_name"}
get_attr {"mid_host"}
}
on_true = transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "creds"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var command = \"aws sts assume-role --role-arn arn:aws:iam::\" + ${AWSAccounts[].AccountID} + \":role/otaug-snow-discovery-role --role-session-name ecr_session\"
var creds = CTX.getCommandManager().shellCommand(command,false, null, null, CTX);
rtrn = creds;"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "PARSE AccessKeyId"
transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "AccessKeyId"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var creds = ${AWSAccounts[].creds};
var cred_obj = JSON.parse(creds);
var credentials = cred_obj.Credentials;
var access_key_id = credentials.AccessKeyId; // Unique identifier for the pattern
rtrn = access_key_id;
"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "PARSE SecretAccessKey"
transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "SecretAccessKey"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var creds = ${AWSAccounts[].creds};
var cred_obj = JSON.parse(creds);
var credentials = cred_obj.Credentials;
var secret = credentials.SecretAccessKey;
rtrn = secret;
"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "PARSE SessionToken"
transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "SessionToken"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var creds = ${AWSAccounts[].creds};
var cred_obj = JSON.parse(creds);
var credentials = cred_obj.Credentials;
var session_token = credentials.SessionToken;
rtrn = session_token;
"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "GET Repos per Acct"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].host_name"}
get_attr {"mid_host"}
}
on_true = transform {
src_table_name = "AWSAccounts"
target_table_name = "AWSAccounts"
operation {set_field {
field_name = "Repositories"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var account_id = ${AWSAccounts[].AccountID}; // Unique identifier for the pattern
var access_key_id = ${AWSAccounts[].AccessKeyId}; // Unique identifier for the pattern
var secret_access_key = ${AWSAccounts[].SecretAccessKey};
var session_token = ${AWSAccounts[].SessionToken};
var cmd = \"set AWS_ACCESS_KEY_ID=\" + access_key_id + \"&&set AWS_SECRET_ACCESS_KEY=\" + secret_access_key + \"&&set AWS_SESSION_TOKEN=\" + session_token + \"&&aws ecr describe-repositories\"
var repos = CTX.getCommandManager().shellCommand(cmd,false, null, null, CTX);
rtrn = repos;"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "GET Images"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].host_name"}
get_attr {"mid_host"}
}
on_true = runcmd_to_var {
cmd = eval {"javascript: var rtrn = \"success\"; // Script execution: Custom script to perform a specific action or collect data
var awsAccounts = CTX.getAttribute(\"AWSAccounts\").toArray();
var imageMap = new Packages.java.util.ArrayList();
for (var i = 0; i < awsAccounts.length; i++) {
var account = awsAccounts[i];
var repositories = JSON.parse(account.get(\"Repositories\")).repositories;
var accessKeyId = account.get(\"AccessKeyId\");
var secretAccessKey = account.get(\"SecretAccessKey\");
var sessionToken = account.get(\"SessionToken\");
for (var j = 0; j < repositories.length; j++) {
var repo = repositories[j];
var repositoryName = repo.repositoryName;
var registryId = repo.registryId;
// Construct the AWS CLI command
var cmd = \"set AWS_ACCESS_KEY_ID=\" + accessKeyId +
\"&&set AWS_SECRET_ACCESS_KEY=\" + secretAccessKey +
\"&&set AWS_SESSION_TOKEN=\" + sessionToken +
\"&&aws ecr describe-images --repository-name \" + repositoryName +
\" --registry-id \" + registryId;
try {
// Execute the command and capture the output
var output = CTX.getCommandManager().shellCommand(cmd, false, null, null, CTX);
// Parse the output JSON to get the list of images
var imageJson = JSON.parse(output);
var images = imageJson.imageDetails;
// Loop through each image and add it to the allImagesTable
for (var k = 0; k < images.length; k++) {
var image = images[k];
var row = new Packages.java.util.HashMap();
row.put(\"raw_image\", JSON.stringify(image));
row.put(\"AccountID\", account.get(\"AccountID\"));
row.put(\"RepositoryName\", repositoryName);
row.put(\"RegistryID\", registryId);
row.put(\"ImageDigest\", image.imageDigest);
row.put(\"ImageTag\", image.imageTags[0] || \"None\");
imageMap.add(row);
}
} catch (e) {
var row = new Packages.java.util.HashMap();
row.put('error', \"Failed to list images for repository: \" + repositoryName + \" in account: \" + account.get(\"AccountID\") + \". Error: \" + e);
imageMap.add(row);
}
}
}
// Update the context with the allImagesTable
CTX.setAttribute(\"ECRImages\", imageMap);
result = \"finished\";"}
execution_mode = "DEFAULT"
var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "INSERT Images to Cloud Resource"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].host_name"}
get_attr {"mid_host"}
}
on_true = transform {
src_table_name = "ECRImages"
target_table_name = "cmdb_ci_cmp_resource"
operation {
set_field {
field_name = "object_id"
value = concat {
get_attr {"ECRImages[].RepositoryName"}
":"
get_attr {"ECRImages[].ImageTag"}
}
}
set_field {
field_name = "name"
value = concat {
get_attr {"ECRImages[].RepositoryName"}
":"
get_attr {"ECRImages[].ImageTag"}
}
}
set_field {
field_name = "correlation_id"
value = get_attr {"ECRImages[].ImageDigest"}
}
set_field {
field_name = "resource_type"
value = "AWS::ECR::Image"
}
}
}
on_false = nop {}
}
}
}
|
Get Object Id For GCP Windows Server | I would like for you to help me build a Pattern that helps achieve Discovery of Get Object Id For GCP Windows Server. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Get Object Id For GCP Windows Server"
id = "d61174c087f37c1072a131173cbb358c"
description = "Get Object Id For GCP Windows Server"
step {
name = "Create isGCP variable"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].manufacturer"}
"Google"
}
on_true = set_attr {
"isGCP"
"true"
}
on_false = nop {}
}
}
step {
name = "Get Object ID"
if {
condition = eq {
get_attr {"isGCP"}
"true"
}
on_true = runcmd_to_var {
cmd = "powershell \"$uri = 'http://metadata.google.internal/computeMetadata/v1/instance/id'; $headers = @{'Metadata-Flavor' = 'Google'} ; Invoke-RestMethod -Headers $headers -Uri $uri \""
execution_mode = "DEFAULT"
var_names = "gcp_object_id"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Set server as virtual"
if {
condition = eq {
get_attr {"isGCP"}
"true"
}
on_true = set_attr {
"cmdb_ci_win_server[*].virtual"
"true"
}
on_false = nop {}
}
}
step {
name = "Set server object_id"
if {
condition = is_not_empty {get_attr {"gcp_object_id"}}
on_true = set_attr {
"cmdb_ci_win_server[*].object_id"
get_attr {"gcp_object_id"}
}
on_false = nop {}
}
}
}
| library {
name = "Get Object Id For GCP Windows Server"
id = "d61174c087f37c1072a131173cbb358c" // Unique identifier for the pattern
description = "Get Object Id For GCP Windows Server" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create isGCP variable"
if {
condition = contains {
get_attr {"cmdb_ci_win_server[*].manufacturer"}
"Google"
}
on_true = set_attr {
"isGCP"
"true"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Object ID"
if {
condition = eq {
get_attr {"isGCP"}
"true"
}
on_true = runcmd_to_var {
cmd = "powershell \"$uri = 'http://metadata.google.internal/computeMetadata/v1/instance/id'; $headers = @{'Metadata-Flavor' = 'Google'} ; Invoke-RestMethod -Headers $headers -Uri $uri \"" // Metadata section: Contains metadata information about the pattern
execution_mode = "DEFAULT"
var_names = "gcp_object_id"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set server as virtual"
if {
condition = eq {
get_attr {"isGCP"}
"true"
}
on_true = set_attr {
"cmdb_ci_win_server[*].virtual"
"true"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set server object_id"
if {
condition = is_not_empty {get_attr {"gcp_object_id"}}
on_true = set_attr {
"cmdb_ci_win_server[*].object_id"
get_attr {"gcp_object_id"}
}
on_false = nop {}
}
}
}
|
Windows - NDP Table | I would like for you to help me build a Pattern that helps achieve Discovery of Windows - NDP Table. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Windows - NDP Table"
id = "dd3d55141b36811082cd642aab4bcb32"
description = "null"
step {
name = "Get NDP Table IPv4"
if {
condition = is_empty {get_attr {"ArpTable"}}
on_true = runcmd_to_var {
cmd = "netsh int ipv4 show neigh"
execution_mode = "DEFAULT"
var_names = table {
name = "NdpTableV4"
col_names = "ip_address","mac_address"
}
parsing_strategy = regex_parsing {regex = "([0-9\\.]+)\\s+([A-Fa-f0-9\\-]+)"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Replace '-' with ':' in mac_address"
if {
condition = is_not_empty {get_attr {"NdpTableV4"}}
on_true = transform {
src_table_name = "NdpTableV4"
target_table_name = "NdpTableV4"
operation {set_field {
field_name = "mac_address"
value = eval {"javascript:
var rtrn = '';
rtrn = ${NdpTableV4[].mac_address}.replace(/-/g,':').toLowerCase();
"}
}}
}
on_false = nop {}
}
}
step {
name = "Remove unnecessary mac addresses"
if {
condition = is_not_empty {get_attr {"NdpTableV4"}}
on_true = filter {
src_table_name = "NdpTableV4"
target_table_name = "NdpTableV4"
condition = all {
is_not_empty {get_attr {"NdpTableV4[].ip_address"}}
is_not_empty {get_attr {"NdpTableV4[].mac_address"}}
neq {
get_attr {"NdpTableV4[].mac_address"}
"ff:ff:ff:ff:ff:ff"
}
}
}
on_false = nop {}
}
}
step {
name = "Insert NDP entries to discovery_net_arp_table"
if {
condition = is_not_empty {get_attr {"NdpTableV4"}}
on_true = transform {
src_table_name = "NdpTableV4"
target_table_name = "discovery_net_arp_table"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"NdpTableV4[].ip_address"}
}
set_field {
field_name = "mac_address"
value = get_attr {"NdpTableV4[].mac_address"}
}
}
}
on_false = nop {}
}
}
step {
name = "Get NDP Table IPv6"
runcmd_to_var {
cmd = "for /f \"tokens=1,2,3*\" %i in ('netsh int ipv6 show neigh') do @echo %i %j %k"
execution_mode = "DEFAULT"
var_names = table {
name = "RawNdpTableV6"
col_names = "ip_address","mac_address"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "-----"
delimiters = " "
selected_positions = 1,2
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Replace '-' with ':' in mac_address"
if {
condition = is_not_empty {get_attr {"RawNdpTableV6"}}
on_true = transform {
src_table_name = "RawNdpTableV6"
target_table_name = "RawNdpTableV6"
operation {set_field {
field_name = "mac_address"
value = eval {"javascript:
var rtrn = '';
rtrn = ${RawNdpTableV6[].mac_address}.replace(/-/g,':').toLowerCase();
"}
}}
}
on_false = nop {}
}
}
step {
name = "Remove invalid rows"
if {
condition = is_not_empty {get_attr {"RawNdpTableV6"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Windows - NDP Table\");
var SncIPAddress = Packages.com.snc.commons.networks.IPAddress;
var rawNdpTable = new Packages.java.util.ArrayList();
var ndpTable = new Packages.java.util.ArrayList();
var rtrn = 0;
try {
rawNdpTable = ${RawNdpTableV6};
var ndpTableIt = rawNdpTable.iterator();
while (ndpTableIt.hasNext())
{
var currRow = ndpTableIt.next();
var ipAddress = currRow.get(\"ip_address\");
var macAddress = currRow.get(\"mac_address\");
if (SncIPAddress.isV6(ipAddress) && isMacAddress(macAddress))
{
var row = new Packages.java.util.HashMap();
row.put(\"ip_address\", ipAddress);
row.put(\"mac_address\", macAddress);
ndpTable.add(row);
}
}
CTX.setAttribute('NdpTableV6', ndpTable);
rtrn = ndpTable.size();
rtrn;
}
catch (ex) {
logger.debug(\"Error filtering invalid rows. Message=\" + ex);
}
function isMacAddress (address)
{
try
{
var macRegex = /^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})|([0-9a-fA-F]{4}\\\\.[0-9a-fA-F]{4}\\\\.[0-9a-fA-F]{4})$/gi;
var match = macRegex.exec(address);
if(match)
{
return (match[0] == address);
}
else
{
return false;
}
}
catch(ex)
{
logger.debug(\"Error tesing mac address. Message=\" + ex);
}
}"}
}
on_false = nop {}
}
}
step {
name = "Union IPv4 and IPv6 tables"
if {
condition = is_not_empty {get_attr {"NdpTableV6"}}
on_true = union {
table1_name = "NdpTableV6"
table2_name = "discovery_net_arp_table"
result_table_name = "discovery_net_arp_table"
}
on_false = nop {}
}
}
step {
name = "Remove duplicate entries"
comment = "Insertion to \"cmdb_serial_number\" implemented inside EVAL"
if {
condition = is_not_empty {get_attr {"discovery_net_arp_table"}}
on_true = set_attr {
"notInUse"
eval {"javascript:
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${discovery_net_arp_table},[\"ip_address\",\"mac_address\"]);
CTX.setAttribute(\"discovery_net_arp_table\", tableWithoutDuplicates);
"}
}
on_false = nop {}
}
}
}
| library {
name = "Windows - NDP Table"
id = "dd3d55141b36811082cd642aab4bcb32" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get NDP Table IPv4"
if {
condition = is_empty {get_attr {"ArpTable"}}
on_true = runcmd_to_var {
cmd = "netsh int ipv4 show neigh"
execution_mode = "DEFAULT"
var_names = table {
name = "NdpTableV4"
col_names = "ip_address","mac_address"
}
parsing_strategy = regex_parsing {regex = "([0-9\\.]+)\\s+([A-Fa-f0-9\\-]+)"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Replace '-' with ':' in mac_address"
if {
condition = is_not_empty {get_attr {"NdpTableV4"}}
on_true = transform {
src_table_name = "NdpTableV4"
target_table_name = "NdpTableV4"
operation {set_field {
field_name = "mac_address"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
rtrn = ${NdpTableV4[].mac_address}.replace(/-/g,':').toLowerCase();
"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove unnecessary mac addresses"
if {
condition = is_not_empty {get_attr {"NdpTableV4"}}
on_true = filter {
src_table_name = "NdpTableV4"
target_table_name = "NdpTableV4"
condition = all {
is_not_empty {get_attr {"NdpTableV4[].ip_address"}}
is_not_empty {get_attr {"NdpTableV4[].mac_address"}}
neq {
get_attr {"NdpTableV4[].mac_address"}
"ff:ff:ff:ff:ff:ff"
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert NDP entries to discovery_net_arp_table"
if {
condition = is_not_empty {get_attr {"NdpTableV4"}}
on_true = transform {
src_table_name = "NdpTableV4"
target_table_name = "discovery_net_arp_table"
operation {
set_field {
field_name = "ip_address"
value = get_attr {"NdpTableV4[].ip_address"}
}
set_field {
field_name = "mac_address"
value = get_attr {"NdpTableV4[].mac_address"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get NDP Table IPv6"
runcmd_to_var {
cmd = "for /f \"tokens=1,2,3*\" %i in ('netsh int ipv6 show neigh') do @echo %i %j %k"
execution_mode = "DEFAULT"
var_names = table {
name = "RawNdpTableV6"
col_names = "ip_address","mac_address"
}
parsing_strategy = delimited_parsing {
exclude_lines_pattern = "-----"
delimiters = " "
selected_positions = 1,2
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Replace '-' with ':' in mac_address"
if {
condition = is_not_empty {get_attr {"RawNdpTableV6"}}
on_true = transform {
src_table_name = "RawNdpTableV6"
target_table_name = "RawNdpTableV6"
operation {set_field {
field_name = "mac_address"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
rtrn = ${RawNdpTableV6[].mac_address}.replace(/-/g,':').toLowerCase();
"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove invalid rows"
if {
condition = is_not_empty {get_attr {"RawNdpTableV6"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Windows - NDP Table\"); // Script execution: Custom script to perform a specific action or collect data
var SncIPAddress = Packages.com.snc.commons.networks.IPAddress;
var rawNdpTable = new Packages.java.util.ArrayList();
var ndpTable = new Packages.java.util.ArrayList();
var rtrn = 0;
try {
rawNdpTable = ${RawNdpTableV6};
var ndpTableIt = rawNdpTable.iterator();
while (ndpTableIt.hasNext())
{
var currRow = ndpTableIt.next();
var ipAddress = currRow.get(\"ip_address\");
var macAddress = currRow.get(\"mac_address\");
if (SncIPAddress.isV6(ipAddress) && isMacAddress(macAddress))
{
var row = new Packages.java.util.HashMap();
row.put(\"ip_address\", ipAddress);
row.put(\"mac_address\", macAddress);
ndpTable.add(row);
}
}
CTX.setAttribute('NdpTableV6', ndpTable);
rtrn = ndpTable.size();
rtrn;
}
catch (ex) {
logger.debug(\"Error filtering invalid rows. Message=\" + ex);
}
function isMacAddress (address)
{
try
{
var macRegex = /^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})|([0-9a-fA-F]{4}\\\\.[0-9a-fA-F]{4}\\\\.[0-9a-fA-F]{4})$/gi;
var match = macRegex.exec(address);
if(match)
{
return (match[0] == address);
}
else
{
return false;
}
}
catch(ex)
{
logger.debug(\"Error tesing mac address. Message=\" + ex);
}
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union IPv4 and IPv6 tables"
if {
condition = is_not_empty {get_attr {"NdpTableV6"}}
on_true = union {
table1_name = "NdpTableV6"
table2_name = "discovery_net_arp_table"
result_table_name = "discovery_net_arp_table"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate entries"
comment = "Insertion to \"cmdb_serial_number\" implemented inside EVAL"
if {
condition = is_not_empty {get_attr {"discovery_net_arp_table"}}
on_true = set_attr {
"notInUse"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${discovery_net_arp_table},[\"ip_address\",\"mac_address\"]);
CTX.setAttribute(\"discovery_net_arp_table\", tableWithoutDuplicates);
"}
}
on_false = nop {}
}
}
}
|
Amazon Get ECS Services | I would like for you to help me build a Pattern that helps achieve Discovery of Amazon Get ECS Services. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Amazon Get ECS Services"
id = "dd6b51cadb3b3b000ae47e8f2996196b"
description = "null"
step {
name = "List ECS Services per Cluster"
comment = "- results in error if you try to pull tasks in with incorrect clustoer/region, aka regions without cluster will RESULT in error. I suspect it is because of bellow point
- has default value for cluster parameter so this has to be specified
- returs tasks with FILTERED STATUS - running by default. I assume I have to make 2 calls per each status (https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListTasks.html). Running status is ignored!
Question - what status Tasks should we collect - RUNNING, STOPPED or both? Clusters show info only about running tasks so I think only running."
if {
condition = is_not_empty {get_attr {"clusters"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Amazon AWS - ECS pattern\");
var cloudcall = new CloudRestAPIClient();
var result = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var new_response = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var cluster_arn = ${clusters[*].cluster_arn}.toArray()
var cluster_region = ${clusters[*].region}.toArray()
headersMap.put(\"x-amz-target\", \"AmazonEC2ContainerServiceV20141113.ListServices\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
for (var index = 0; index < cluster_arn.length; index++) {
var ecsurl = \"https://ecs.\" + cluster_region[index] + \".amazonaws.com/\";
var requestBody = '{\"cluster\":\"' + cluster_arn[index] + '\"}';
//CTX.setAttribute('api_body'+index, requestBody);
try{
result = cloudcall.arrayListExecute(${service_account},null, ecsurl, headersMap, 'POST', requestBody, 'true', CTX );
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
break;
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources result=\" + result);
if (result) {
for (var j = 0; j < result.size(); j++){
//result.set(j, '{ \"root\": [' + result.get(j) +']}');
var newJson = parseUtil.addTagToResult(\"region\",cluster_region[index],result.get(j).toString());
newJson = parseUtil.addTagToResult(\"cluster\",cluster_arn[index],newJson);
new_response.add(newJson);
}
}
}
CTX.setAttribute('list_services_response', new_response);"}
}
on_false = nop {}
}
}
step {
name = "Parse ECS Service ARNs"
if {
condition = is_not_empty {get_attr {"list_services_response"}}
on_true = parse_var_to_var {
from_var_name = "list_services_response"
to_var_names = table {
name = "services"
col_names = "service_arn","cluster_arn","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "service_arn"
xpath = "/root/serviceArns/text()"
delimiters = ""
position = 1
}
field {
col_name = "cluster_arn"
xpath = "/root/cluster/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Filter out rows without service_arn"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = filter {
src_table_name = "services"
target_table_name = "services"
condition = is_not_empty {get_attr {"services[].service_arn"}}
}
on_false = nop {}
}
}
step {
name = "Get the Services details"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Amazon AWS - ECS pattern\");
var cloudcall = new CloudRestAPIClient();
var result = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var new_response = new Packages.java.util.ArrayList();
var resource_arn = ${services[*].service_arn}.toArray()
var resource_region = ${services[*].region}.toArray()
var cluster_arn = ${services[*].cluster_arn}.toArray()
headersMap.put(\"x-amz-target\", \"AmazonEC2ContainerServiceV20141113.DescribeServices\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
for (var index = 0; index < resource_arn.length; index++) {
var ecsurl = \"https://ecs.\" + resource_region[index] + \".amazonaws.com/\";
var requestBody = '{\"cluster\": \"' + cluster_arn[index] + '\", \"services\":[\"' + resource_arn[index] + '\"],\"include\": [ \"TAGS\" ]}';
try{
result = cloudcall.arrayListExecute(${service_account},null, ecsurl, headersMap, 'POST', requestBody, 'true', CTX );
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
break;
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources result=\" + result);
for (var j = 0; j < result.size(); j++){
new_response.add(result.get(j));
}
}
CTX.setAttribute('describe_services_response', new_response);"}
}
on_false = nop {}
}
}
step {
name = "Parse Services details"
if {
condition = is_not_empty {get_attr {"describe_services_response"}}
on_true = parse_var_to_var {
from_var_name = "describe_services_response"
to_var_names = table {
name = "services_details"
col_names = "service_arn","service_name","td_arn","launch_type","service_status","scheduling_strategy"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "service_arn"
xpath = "/root/services/serviceArn/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_name"
xpath = "/root/services/serviceName/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_arn"
xpath = "/root/services/taskDefinition/text()"
delimiters = ""
position = 1
}
field {
col_name = "launch_type"
xpath = "/root/services/launchType/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_status"
xpath = "/root/services/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "scheduling_strategy"
xpath = "/root/services/schedulingStrategy/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Merge the Services tables"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = merge {
table1_name = "services"
key1_name = "service_arn"
table2_name = "services_details"
key2_name = "service_arn"
result_table_name = "services"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_cloud_ecs_service table"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = transform {
src_table_name = "services"
target_table_name = "cmdb_ci_cloud_ecs_service"
operation {
set_field {
field_name = "object_id"
value = get_attr {"services[].service_arn"}
}
set_field {
field_name = "name"
value = get_attr {"services[].service_name"}
}
set_field {
field_name = "status"
value = get_attr {"services[].service_status"}
}
set_field {
field_name = "launch_type"
value = get_attr {"services[].launch_type"}
}
set_field {
field_name = "scheduling_strategy"
value = get_attr {"services[].scheduling_strategy"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_cloud_ecs_service and cmdb_ci_aws_datacenter"
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_ecs_service"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_ecs_service"
key1_name = "region"
table2_name = "cmdb_ci_aws_datacenter"
key2_name = "region"
result_table_name = "service_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create relation between cmdb_ci_cloud_ecs_service and cmdb_ci_cloud_ecs_cluster"
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_ecs_task"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_ecs_service"
key1_name = "cluster_arn"
table2_name = "cmdb_ci_cloud_ecs_cluster"
key2_name = "cluster_arn"
result_table_name = "cluster_to_service"
unmatched_lines = remove
relation_type = "Runs on::Runs"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create relation between $cmdb_ci_cloud_ecs_service and cmdb_ci_cloud_ecs_task_definition"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_cloud_ecs_service"}}
is_not_empty {get_attr {"cmdb_ci_cloud_ecs_task_definition"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_ecs_service"
key1_name = "td_arn"
table2_name = "cmdb_ci_cloud_ecs_task_definition"
key2_name = "td_arn"
result_table_name = "service_to_task_definition"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "Amazon Get ECS Services"
id = "dd6b51cadb3b3b000ae47e8f2996196b" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "List ECS Services per Cluster"
comment = "- results in error if you try to pull tasks in with incorrect clustoer/region, aka regions without cluster will RESULT in error. I suspect it is because of bellow point
- has default value for cluster parameter so this has to be specified
- returs tasks with FILTERED STATUS - running by default. I assume I have to make 2 calls per each status (https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListTasks.html). Running status is ignored!
Question - what status Tasks should we collect - RUNNING, STOPPED or both? Clusters show info only about running tasks so I think only running."
if {
condition = is_not_empty {get_attr {"clusters"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Amazon AWS - ECS pattern\"); // Script execution: Custom script to perform a specific action or collect data
var cloudcall = new CloudRestAPIClient();
var result = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var new_response = new Packages.java.util.ArrayList();
var parseUtil = new PatternsParserHelper();
var cluster_arn = ${clusters[*].cluster_arn}.toArray()
var cluster_region = ${clusters[*].region}.toArray()
headersMap.put(\"x-amz-target\", \"AmazonEC2ContainerServiceV20141113.ListServices\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
for (var index = 0; index < cluster_arn.length; index++) {
var ecsurl = \"https://ecs.\" + cluster_region[index] + \".amazonaws.com/\";
var requestBody = '{\"cluster\":\"' + cluster_arn[index] + '\"}';
//CTX.setAttribute('api_body'+index, requestBody);
try{
result = cloudcall.arrayListExecute(${service_account},null, ecsurl, headersMap, 'POST', requestBody, 'true', CTX );
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
break;
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources result=\" + result);
if (result) {
for (var j = 0; j < result.size(); j++){
//result.set(j, '{ \"root\": [' + result.get(j) +']}');
var newJson = parseUtil.addTagToResult(\"region\",cluster_region[index],result.get(j).toString());
newJson = parseUtil.addTagToResult(\"cluster\",cluster_arn[index],newJson);
new_response.add(newJson);
}
}
}
CTX.setAttribute('list_services_response', new_response);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse ECS Service ARNs"
if {
condition = is_not_empty {get_attr {"list_services_response"}}
on_true = parse_var_to_var {
from_var_name = "list_services_response"
to_var_names = table {
name = "services"
col_names = "service_arn","cluster_arn","region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "service_arn"
xpath = "/root/serviceArns/text()"
delimiters = ""
position = 1
}
field {
col_name = "cluster_arn"
xpath = "/root/cluster/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out rows without service_arn"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = filter {
src_table_name = "services"
target_table_name = "services"
condition = is_not_empty {get_attr {"services[].service_arn"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get the Services details"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Amazon AWS - ECS pattern\"); // Script execution: Custom script to perform a specific action or collect data
var cloudcall = new CloudRestAPIClient();
var result = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var new_response = new Packages.java.util.ArrayList();
var resource_arn = ${services[*].service_arn}.toArray()
var resource_region = ${services[*].region}.toArray()
var cluster_arn = ${services[*].cluster_arn}.toArray()
headersMap.put(\"x-amz-target\", \"AmazonEC2ContainerServiceV20141113.DescribeServices\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
for (var index = 0; index < resource_arn.length; index++) {
var ecsurl = \"https://ecs.\" + resource_region[index] + \".amazonaws.com/\";
var requestBody = '{\"cluster\": \"' + cluster_arn[index] + '\", \"services\":[\"' + resource_arn[index] + '\"],\"include\": [ \"TAGS\" ]}';
try{
result = cloudcall.arrayListExecute(${service_account},null, ecsurl, headersMap, 'POST', requestBody, 'true', CTX );
}
catch (e){
logger.error(\"generic resource REST request failed. exception=\" + e);
break;
}
logger.debug(\">>>>>>>>>>>>>>>>>>>>> response from generic resources result=\" + result);
for (var j = 0; j < result.size(); j++){
new_response.add(result.get(j));
}
}
CTX.setAttribute('describe_services_response', new_response);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Services details"
if {
condition = is_not_empty {get_attr {"describe_services_response"}}
on_true = parse_var_to_var {
from_var_name = "describe_services_response"
to_var_names = table {
name = "services_details"
col_names = "service_arn","service_name","td_arn","launch_type","service_status","scheduling_strategy"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "service_arn"
xpath = "/root/services/serviceArn/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_name"
xpath = "/root/services/serviceName/text()"
delimiters = ""
position = 1
}
field {
col_name = "td_arn"
xpath = "/root/services/taskDefinition/text()"
delimiters = ""
position = 1
}
field {
col_name = "launch_type"
xpath = "/root/services/launchType/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_status"
xpath = "/root/services/status/text()"
delimiters = ""
position = 1
}
field {
col_name = "scheduling_strategy"
xpath = "/root/services/schedulingStrategy/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge the Services tables"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = merge {
table1_name = "services"
key1_name = "service_arn"
table2_name = "services_details"
key2_name = "service_arn"
result_table_name = "services"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_cloud_ecs_service table"
if {
condition = is_not_empty {get_attr {"services"}}
on_true = transform {
src_table_name = "services"
target_table_name = "cmdb_ci_cloud_ecs_service"
operation {
set_field {
field_name = "object_id"
value = get_attr {"services[].service_arn"}
}
set_field {
field_name = "name"
value = get_attr {"services[].service_name"}
}
set_field {
field_name = "status"
value = get_attr {"services[].service_status"}
}
set_field {
field_name = "launch_type"
value = get_attr {"services[].launch_type"}
}
set_field {
field_name = "scheduling_strategy"
value = get_attr {"services[].scheduling_strategy"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_cloud_ecs_service and cmdb_ci_aws_datacenter"
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_ecs_service"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_ecs_service"
key1_name = "region"
table2_name = "cmdb_ci_aws_datacenter"
key2_name = "region"
result_table_name = "service_to_ldc"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between cmdb_ci_cloud_ecs_service and cmdb_ci_cloud_ecs_cluster"
if {
condition = is_not_empty {get_attr {"cmdb_ci_cloud_ecs_task"}}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_ecs_service"
key1_name = "cluster_arn"
table2_name = "cmdb_ci_cloud_ecs_cluster"
key2_name = "cluster_arn"
result_table_name = "cluster_to_service"
unmatched_lines = remove
relation_type = "Runs on::Runs"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between $cmdb_ci_cloud_ecs_service and cmdb_ci_cloud_ecs_task_definition"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_cloud_ecs_service"}}
is_not_empty {get_attr {"cmdb_ci_cloud_ecs_task_definition"}}
}
on_true = relation_reference {
table1_name = "cmdb_ci_cloud_ecs_service"
key1_name = "td_arn"
table2_name = "cmdb_ci_cloud_ecs_task_definition"
key2_name = "td_arn"
result_table_name = "service_to_task_definition"
unmatched_lines = remove
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
MSSQL populate database table | I would like for you to help me build a Pattern that helps achieve Discovery of MSSQL populate database table. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "MSSQL populate database table"
id = "dd88d71f9f613200c7445f9bc32e7059"
description = ""
step {
name = "Set parameter for Condition one - list db from wmi"
if {
condition = eq {
get_attr {"instance_name"}
"MSSQLSERVER"
}
on_true = set_attr {
"condition_one"
"SELECT name FROM Win32_PerfFormattedData_MSSQLSERVER_SQLServerDatabases"
}
on_false = nop {}
}
}
step {
name = "Set parameter for Condition two - list db from wmi"
if {
condition = neq {
get_attr {"instance_name"}
"MSSQLSERVER"
}
on_true = set_attr {
"condition_one"
concat {
"SELECT name FROM Win32_PerfFormattedData_MSSQL"
get_attr {"instance_name"}
"_MSSQL"
get_attr {"instance_name"}
"Databases"
}
}
on_false = nop {}
}
}
step {
name = "Get list of DB from wmi "
if {
condition = is_not_empty {get_attr {"condition_one"}}
on_true = run_wmi_query_to_var {
namespace = "root/cimv2"
query = get_attr {"condition_one"}
var_names = table {
name = "db_output_from_wmi"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Failover for Condition two - list db from wmi"
comment = "It was observed that for instance names that has _ the query is failing and it works only if _ is removed."
if {
condition = all {
neq {
get_attr {"instance_name"}
"MSSQLSERVER"
}
contains {
get_attr {"instance_name"}
"_"
}
is_empty {get_attr {"db_output_from_wmi"}}
}
on_true = set_attr {
"condition_new"
eval {"javascript: var rtrn = '';
var instName = new Packages.java.lang.String(${instance_name});
var instNameFormatted = instName.replaceAll('_', '');
try {
if (instNameFormatted) {
rtrn = 'SELECT name FROM Win32_PerfFormattedData_MSSQL' + instNameFormatted + '_MSSQL' + instNameFormatted + 'Databases';
}
else {
rtrn;
}
} catch (e) {
ms.log(e);
}
rtrn;"}
}
on_false = nop {}
}
}
step {
name = "Failover for Get list of DB from wmi "
if {
condition = is_not_empty {get_attr {"condition_new"}}
on_true = run_wmi_query_to_var {
namespace = "root/cimv2"
query = get_attr {"condition_new"}
var_names = table {
name = "db_output_from_wmi"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Create db table from the wmi output"
if {
condition = is_not_empty {get_attr {"db_output_from_wmi[1].Name"}}
on_true = parse_var_to_var {
from_var_name = "db_output_from_wmi[*].Name"
to_var_names = table {
name = "dbs"
col_names = "database"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Terminate if no MSSQL Databases found"
match {
is_not_empty {get_attr {"dbs[1].database"}}
terminate_op = graceful
terminate_msg = "No MSSQL Databases returned from the WMI query, terminating the pattern."
}
}
step {
name = "Filter out _Total from dbs"
comment = "Filter out _Total DB from the list of DBs"
filter {
src_table_name = "dbs"
target_table_name = "dbs"
condition = neq {
get_attr {"dbs[].database"}
"_Total"
}
}
}
step {
name = "Fill name field for dbs"
transform {
src_table_name = "dbs"
target_table_name = "dbs"
operation {set_field {
field_name = "name"
value = get_attr {"dbs[].database"}
}}
}
}
step {
name = "Remove duplicates from dbs table"
set_attr {
"dedup"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${dbs},[\"database\"]);
CTX.setAttribute(\"dbs\", tableWithoutDuplicates);
"}
}
}
step {
name = "Fill mssql database table"
comment = "Only if the pattern will run as part of Horizontal Discovery then the pattern will create new records for all the mssql databases."
if {
condition = eq {
get_attr {"discovery_type"}
"horizontal"
}
on_true = union {
table1_name = "cmdb_ci_db_mssql_database"
table2_name = "dbs"
result_table_name = "cmdb_ci_db_mssql_database"
}
on_false = nop {}
}
}
step {
name = "Filter empty records from mssql database table"
comment = "Only if the pattern will run as part of Horizontal Discovery then the pattern will create new records for all the mssql databases."
filter {
src_table_name = "cmdb_ci_db_mssql_database"
target_table_name = "cmdb_ci_db_mssql_database"
condition = is_not_empty {get_attr {"cmdb_ci_db_mssql_database[].name"}}
}
}
step {
name = "Create reletaion for mssql database"
comment = "Only if the pattern will run as part of Horizontal Discovery then the pattern will create new records for all the mssql databases."
if {
condition = eq {
get_attr {"discovery_type"}
"horizontal"
}
on_true = relation_reference {
table1_name = "cmdb_ci_db_mssql_instance"
table2_name = "cmdb_ci_db_mssql_database"
result_table_name = "mssql_database"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create db reference to to mssql instance"
comment = "Only if the pattern will run as part of Horizontal Discovery then the pattern will create new records for all the mssql databases."
if {
condition = eq {
get_attr {"discovery_type"}
"horizontal"
}
on_true = relation_reference {
table1_name = "cmdb_ci_db_mssql_database"
table2_name = "cmdb_ci_db_mssql_instance"
result_table_name = "mssql_database_ref_to_instance"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "instance_name"
}
on_false = nop {}
}
}
}
| library {
name = "MSSQL populate database table"
id = "dd88d71f9f613200c7445f9bc32e7059" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set parameter for Condition one - list db from wmi"
if {
condition = eq {
get_attr {"instance_name"}
"MSSQLSERVER"
}
on_true = set_attr {
"condition_one"
"SELECT name FROM Win32_PerfFormattedData_MSSQLSERVER_SQLServerDatabases"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set parameter for Condition two - list db from wmi"
if {
condition = neq {
get_attr {"instance_name"}
"MSSQLSERVER"
}
on_true = set_attr {
"condition_one"
concat {
"SELECT name FROM Win32_PerfFormattedData_MSSQL"
get_attr {"instance_name"}
"_MSSQL"
get_attr {"instance_name"}
"Databases"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get list of DB from wmi "
if {
condition = is_not_empty {get_attr {"condition_one"}}
on_true = run_wmi_query_to_var {
namespace = "root/cimv2"
query = get_attr {"condition_one"}
var_names = table {
name = "db_output_from_wmi"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Failover for Condition two - list db from wmi"
comment = "It was observed that for instance names that has _ the query is failing and it works only if _ is removed."
if {
condition = all {
neq {
get_attr {"instance_name"}
"MSSQLSERVER"
}
contains {
get_attr {"instance_name"}
"_"
}
is_empty {get_attr {"db_output_from_wmi"}}
}
on_true = set_attr {
"condition_new"
eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var instName = new Packages.java.lang.String(${instance_name});
var instNameFormatted = instName.replaceAll('_', '');
try {
if (instNameFormatted) {
rtrn = 'SELECT name FROM Win32_PerfFormattedData_MSSQL' + instNameFormatted + '_MSSQL' + instNameFormatted + 'Databases';
}
else {
rtrn;
}
} catch (e) {
ms.log(e);
}
rtrn;"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Failover for Get list of DB from wmi "
if {
condition = is_not_empty {get_attr {"condition_new"}}
on_true = run_wmi_query_to_var {
namespace = "root/cimv2"
query = get_attr {"condition_new"}
var_names = table {
name = "db_output_from_wmi"
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create db table from the wmi output"
if {
condition = is_not_empty {get_attr {"db_output_from_wmi[1].Name"}}
on_true = parse_var_to_var {
from_var_name = "db_output_from_wmi[*].Name"
to_var_names = table {
name = "dbs"
col_names = "database"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Terminate if no MSSQL Databases found"
match {
is_not_empty {get_attr {"dbs[1].database"}}
terminate_op = graceful
terminate_msg = "No MSSQL Databases returned from the WMI query, terminating the pattern."
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out _Total from dbs"
comment = "Filter out _Total DB from the list of DBs"
filter {
src_table_name = "dbs"
target_table_name = "dbs"
condition = neq {
get_attr {"dbs[].database"}
"_Total"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill name field for dbs"
transform {
src_table_name = "dbs"
target_table_name = "dbs"
operation {set_field {
field_name = "name"
value = get_attr {"dbs[].database"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicates from dbs table"
set_attr {
"dedup"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${dbs},[\"database\"]);
CTX.setAttribute(\"dbs\", tableWithoutDuplicates);
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill mssql database table"
comment = "Only if the pattern will run as part of Horizontal Discovery then the pattern will create new records for all the mssql databases."
if {
condition = eq {
get_attr {"discovery_type"}
"horizontal"
}
on_true = union {
table1_name = "cmdb_ci_db_mssql_database"
table2_name = "dbs"
result_table_name = "cmdb_ci_db_mssql_database"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter empty records from mssql database table"
comment = "Only if the pattern will run as part of Horizontal Discovery then the pattern will create new records for all the mssql databases."
filter {
src_table_name = "cmdb_ci_db_mssql_database"
target_table_name = "cmdb_ci_db_mssql_database"
condition = is_not_empty {get_attr {"cmdb_ci_db_mssql_database[].name"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reletaion for mssql database"
comment = "Only if the pattern will run as part of Horizontal Discovery then the pattern will create new records for all the mssql databases."
if {
condition = eq {
get_attr {"discovery_type"}
"horizontal"
}
on_true = relation_reference {
table1_name = "cmdb_ci_db_mssql_instance"
table2_name = "cmdb_ci_db_mssql_database"
result_table_name = "mssql_database"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create db reference to to mssql instance"
comment = "Only if the pattern will run as part of Horizontal Discovery then the pattern will create new records for all the mssql databases."
if {
condition = eq {
get_attr {"discovery_type"}
"horizontal"
}
on_true = relation_reference {
table1_name = "cmdb_ci_db_mssql_database"
table2_name = "cmdb_ci_db_mssql_instance"
result_table_name = "mssql_database_ref_to_instance"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "instance_name"
}
on_false = nop {}
}
}
}
|
AWS Accounts Tags | I would like for you to help me build a Pattern that helps achieve Discovery of AWS Accounts Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "AWS Accounts Tags"
id = "dd95f7e31b4b30905ae54336dc4bcb54"
description = "AWS Accounts Tags"
step {
name = "get all account ids"
parse_var_to_var {
from_var_name = "cmdb_ci_cloud_service_account[*].account_id"
to_var_names = table {
name = "accounts"
col_names = "id"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step {
name = "verifry accounts not empty"
match {
is_not_empty {get_attr {"accounts"}}
terminate_op = terminate
terminate_msg = ""
}
}
step {
name = "get service account tags"
transform {
src_table_name = "accounts"
target_table_name = "accounts"
operation {set_field {
field_name = "response"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"AWS Service Account Tags Extension\");
var cloudcall = new CloudRestAPIClient();
var tagResult = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var tag_table = new Packages.java.util.ArrayList();
var urlAwsTags = \"https://organizations.\"+${region};
var rtrn = \"none\";
headersMap.put(\"X-Amz-Target\", \"AWSOrganizationsV20161128.ListTagsForResource\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
headersMap.put(\"Accept\", \"application/json\");
var tagBody = '{\\\"ResourceId\\\": \\\"'+${accounts[].id}+'\\\"}';
try{
tagResult = cloudcall.arrayListExecute(${service_account},null, urlAwsTags, headersMap, \"POST\", tagBody, \"true\", CTX );
}
catch (e){
logger.error(\"Sub Accunt Tags REST request failed. exception=\" + e);
}
for (var j = 0; j < tagResult.size(); j++){
tag_table.add(tagResult.get(j));
}
rtrn = tag_table;"}
}}
}
}
step {
name = "filter out empty tags"
filter {
src_table_name = "accounts"
target_table_name = "accounts"
condition = all {
contains {
get_attr {"accounts[].response"}
"\"Key\""
}
contains {
get_attr {"accounts[].response"}
"\"Value\""
}
}
}
}
step {
name = "verify accounts not empty"
match {
is_not_empty {get_attr {"accounts"}}
terminate_op = terminate
terminate_msg = ""
}
}
step {
name = "reformat tags"
transform {
src_table_name = "accounts"
target_table_name = "accounts"
operation {set_field {
field_name = "response"
value = eval {"str = ${accounts[].response}
str = str.replaceAll(\"\\r\", \"\")
str = str.replaceAll(\"\\n\", \"\")
arry = str.split('},')
str = \"\"
for(i=0;i<arry.size();i++)
{
str=str+\"ID:\"+${accounts[].id}+\"#\"+arry[i]+ \"\\n\"
}
return str"}
}}
}
}
step {
name = "build cmdb key value"
parse_var_to_var {
from_var_name = "accounts[*].response"
to_var_names = table {
name = "cmdb_key_value"
col_names = "account_id","key","value"
}
parsing_strategy = regex_parsing {regex = "(\\d+)#.*Key\"\\s+:\\s+\\\"([^\"]*)\",\\s+\"Value\"\\s+:\\s+\"([^\"]*)"}
if_not_found_do = nop {}
}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"account_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "create reference to accounts"
if {
condition = is_not_empty {get_attr {"cmdb_key_value[1].key"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "account_id"
table2_name = "cmdb_ci_cloud_service_account"
key2_name = "account_id"
result_table_name = "key_value_to_accounts"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "AWS Accounts Tags"
id = "dd95f7e31b4b30905ae54336dc4bcb54" // Unique identifier for the pattern
description = "AWS Accounts Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "get all account ids"
parse_var_to_var {
from_var_name = "cmdb_ci_cloud_service_account[*].account_id"
to_var_names = table {
name = "accounts"
col_names = "id"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "verifry accounts not empty"
match {
is_not_empty {get_attr {"accounts"}}
terminate_op = terminate
terminate_msg = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "get service account tags"
transform {
src_table_name = "accounts"
target_table_name = "accounts"
operation {set_field {
field_name = "response"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"AWS Service Account Tags Extension\"); // Script execution: Custom script to perform a specific action or collect data
var cloudcall = new CloudRestAPIClient();
var tagResult = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var tag_table = new Packages.java.util.ArrayList();
var urlAwsTags = \"https://organizations.\"+${region};
var rtrn = \"none\";
headersMap.put(\"X-Amz-Target\", \"AWSOrganizationsV20161128.ListTagsForResource\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
headersMap.put(\"Accept\", \"application/json\");
var tagBody = '{\\\"ResourceId\\\": \\\"'+${accounts[].id}+'\\\"}';
try{
tagResult = cloudcall.arrayListExecute(${service_account},null, urlAwsTags, headersMap, \"POST\", tagBody, \"true\", CTX );
}
catch (e){
logger.error(\"Sub Accunt Tags REST request failed. exception=\" + e);
}
for (var j = 0; j < tagResult.size(); j++){
tag_table.add(tagResult.get(j));
}
rtrn = tag_table;"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter out empty tags"
filter {
src_table_name = "accounts"
target_table_name = "accounts"
condition = all {
contains {
get_attr {"accounts[].response"}
"\"Key\""
}
contains {
get_attr {"accounts[].response"}
"\"Value\""
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "verify accounts not empty"
match {
is_not_empty {get_attr {"accounts"}}
terminate_op = terminate
terminate_msg = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "reformat tags"
transform {
src_table_name = "accounts"
target_table_name = "accounts"
operation {set_field {
field_name = "response"
value = eval {"str = ${accounts[].response}
str = str.replaceAll(\"\\r\", \"\")
str = str.replaceAll(\"\\n\", \"\")
arry = str.split('},')
str = \"\"
for(i=0;i<arry.size();i++)
{
str=str+\"ID:\"+${accounts[].id}+\"#\"+arry[i]+ \"\\n\"
}
return str"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "build cmdb key value"
parse_var_to_var {
from_var_name = "accounts[*].response"
to_var_names = table {
name = "cmdb_key_value"
col_names = "account_id","key","value"
}
parsing_strategy = regex_parsing {regex = "(\\d+)#.*Key\"\\s+:\\s+\\\"([^\"]*)\",\\s+\"Value\"\\s+:\\s+\"([^\"]*)"}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"account_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create reference to accounts"
if {
condition = is_not_empty {get_attr {"cmdb_key_value[1].key"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "account_id"
table2_name = "cmdb_ci_cloud_service_account"
key2_name = "account_id"
result_table_name = "key_value_to_accounts"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
Oracle OCI - VM Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Oracle OCI - VM Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Oracle OCI - VM Tags"
id = "dec606701b4d60100735a9f36b4bcb2e"
description = "Oracle OCI - VM Tags"
step {
name = "Parse Tags"
ref {refid = "0ad0a5751be960500735a9f36b4bcba6"}
}
step {
name = "Parse definedTags Tags"
ref {refid = "b5b342b11bdf345009b2ed34b24bcba5"}
}
step {
name = "Create relation between Tag and VM"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_vm_instance"
key2_name = "object_id"
result_table_name = "tag_to_vm"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Oracle OCI - VM Tags"
id = "dec606701b4d60100735a9f36b4bcb2e" // Unique identifier for the pattern
description = "Oracle OCI - VM Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags"
ref {refid = "0ad0a5751be960500735a9f36b4bcba6"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse definedTags Tags"
ref {refid = "b5b342b11bdf345009b2ed34b24bcba5"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and VM"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_vm_instance"
key2_name = "object_id"
result_table_name = "tag_to_vm"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Delete Exchange temp Files | I would like for you to help me build a Pattern that helps achieve Discovery of Delete Exchange temp Files. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Delete Exchange temp Files"
id = "df7c2a81ce244db08d7267007005fefa"
description = "Delete Exchange temp Files"
step {
name = "set temp folder"
runcmd_to_var {
cmd = "echo %TEMP%"
var_names = "temp"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step {
name = "delete temp xml"
runcmd_to_var {
cmd = "del /F %TEMP%\\exchange_pwrshell_output.xml"
var_names = "dummy"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step {
name = "populate process_ids array"
runcmd_to_var {
cmd = "tasklist"
var_names = "process_ids"
parsing_strategy = delimited_parsing {
include_lines_pattern = "emsmta.exe|exmgmt.exe|mad.exe|exfba.exe|Exchange|Transport|ActiveDirectory"
delimiters = " "
selected_positions = 2
}
if_not_found_do = nop {}
}
}
}
| library {
name = "Delete Exchange temp Files"
id = "df7c2a81ce244db08d7267007005fefa" // Unique identifier for the pattern
description = "Delete Exchange temp Files" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set temp folder"
runcmd_to_var {
cmd = "echo %TEMP%"
var_names = "temp"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "delete temp xml"
runcmd_to_var {
cmd = "del /F %TEMP%\\exchange_pwrshell_output.xml"
var_names = "dummy"
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "populate process_ids array"
runcmd_to_var {
cmd = "tasklist"
var_names = "process_ids"
parsing_strategy = delimited_parsing {
include_lines_pattern = "emsmta.exe|exmgmt.exe|mad.exe|exfba.exe|Exchange|Transport|ActiveDirectory"
delimiters = " "
selected_positions = 2
}
if_not_found_do = nop {}
}
}
}
|
Google Cloud Platform (GCP) - Get Storage Volumes | I would like for you to help me build a Pattern that helps achieve Discovery of Google Cloud Platform (GCP) - Get Storage Volumes. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Google Cloud Platform (GCP) - Get Storage Volumes"
id = "e0100022db442300d504788dbf961999"
description = ""
step {
name = "Get all Google disks"
comment = "pg - Condition is introduced so the API call is not executed if the pattern is event triggered and there are no related disks to the VM Instance."
if {
condition = any {
is_empty {get_attr {"input_object_id"}}
is_not_empty {get_attr {"filter"}}
}
on_true = custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://www.googleapis.com/compute/"
get_attr {"API_version"}
"/projects/"
get_attr {"service_account[1].account_id"}
"/aggregated/disks"
get_attr {"filter"}
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "disksJson"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Parse disks data"
if {
condition = is_not_empty {get_attr {"disksJson"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "disksJson"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "google_disks"
}
attribute {
name = "target_columns"
value = "object_id:items.*.disks.id,name:items.*.disks.name,sizeGB:items.*.disks.sizeGb,zone_link:items.*.disks.zone,typeCode_link:items.*.disks.type,status:items.*.disks.status,description:items.*.disks.description,snapshotId:items.*.disks.sourceSnapshotId"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Parse disks data - replicaZone cases"
if {
condition = is_not_empty {get_attr {"disksJson"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "disksJson"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "google_disks_replica"
}
attribute {
name = "target_columns"
value = "object_id:items.*.disks.id,replicaZone_link:items.*.disks.replicaZones"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Populate replicaZone in google_disks_replica"
if {
condition = is_not_empty {get_attr {"google_disks_replica"}}
on_true = transform {
src_table_name = "google_disks_replica"
target_table_name = "google_disks_replica"
operation {set_field {
field_name = "replicaZone"
value = eval {"javascript: var replicaZone_link = ${google_disks_replica[].replicaZone_link};
var rtrn = \"\";
if(replicaZone_link){
var myRegexp = /.*\\/zones\\/(.*)$/;
var matches=myRegexp.exec(replicaZone_link);
// If we got a match - return it.
if (matches && matches[1])
rtrn = matches[1];
}
rtrn;"}
}}
}
on_false = nop {}
}
}
step {
name = "Get AZ to Storage Map"
if {
condition = eq {
eval {"javascript: rtrn = false;
if(${google_disks_replica})
{
var gcReplicaTable = ${google_disks_replica};
for (var i=0 ; i < gcReplicaTable.size(); i++){
var obj_id = gcReplicaTable.get(i).get('object_id');
if(JSUtil.notNil(obj_id))
{
rtrn = true;
}
}
}
rtrn = rtrn;"}
"true"
}
on_true = set_attr {
"tmp"
eval {"javascript: rtrn = '';
var gcReplicaTable = ${google_disks_replica};
var storageVolToAZHashSet = new Packages.java.util.HashMap();
for (var i=0 ; i < gcReplicaTable.size(); i++){
var obj_id = gcReplicaTable.get(i).get('object_id');
var rep_zone = gcReplicaTable.get(i).get('replicaZone');
//if(rep_zone != null)
if(JSUtil.notNil(rep_zone))
{
//only in case we have a replicaZone value we will add it to the map
if (storageVolToAZHashSet.containsKey(obj_id)){
(storageVolToAZHashSet.get(obj_id)).add(rep_zone);
}
else {
var azSet = new Packages.java.util.HashSet();
azSet.add(rep_zone);
storageVolToAZHashSet.put(obj_id,azSet);
}
}
}
CTX.setAttribute(\"ReplicaDiskAZCache\", storageVolToAZHashSet);"}
}
on_false = nop {}
}
}
step {
name = "Parse disks users"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "disksJson"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "google_disks_users"
}
attribute {
name = "target_columns"
value = "object_id:items.*.disks.id,users:items.*.disks.users"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Set users on google disks"
if {
condition = is_not_empty {get_attr {"google_disks_users"}}
on_true = merge {
table1_name = "google_disks"
key1_name = "object_id"
table2_name = "google_disks_users"
key2_name = "object_id"
result_table_name = "google_disks"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Keep only disks attached to VMs if needed"
if {
condition = all {
is_not_empty {get_attr {"filterBasedOnVMs"}}
eq {
get_attr {"filterBasedOnVMs"}
"true"
}
is_not_empty {get_attr {"google_disks"}}
}
on_true = filter {
src_table_name = "google_disks"
target_table_name = "google_disks"
condition = is_not_empty {get_attr {"google_disks[].users"}}
}
on_false = nop {}
}
}
step {
name = "Extract zone, typeCode, region, sizeBytes and users"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = transform {
src_table_name = "google_disks"
target_table_name = "google_disks"
operation {
set_field {
field_name = "zone"
value = eval {"javascript: var zone_link = ${google_disks[].zone_link};
var rtrn = \"\";
if(zone_link){
var myRegexp = /.*\\/zones\\/(.*)$/;
var matches=myRegexp.exec(zone_link);
// If we got a match - return it.
if (matches && matches[1])
rtrn = matches[1];
}
rtrn;"}
}
set_field {
field_name = "typeCode"
value = eval {"javascript: var typeCode_link = ${google_disks[].typeCode_link};
var rtrn = \"\";
if(typeCode_link){
var myRegexp = /.*\\/diskTypes\\/(.*)$/;
var matches=myRegexp.exec(typeCode_link);
// If we got a match - return it.
if (matches && matches[1])
rtrn = matches[1];
}
rtrn;"}
}
set_field {
field_name = "region"
value = eval {"javascript: var zone = ${google_disks[].zone};
if(JSUtil.nil(zone))
{
var obj = ${google_disks[].object_id};
var replicaSet = ${ReplicaDiskAZCache}.get(obj);
var itr = replicaSet.iterator();
var firstZone = itr.next();
zone = firstZone;
}
rtn = zone;
// Catch all characters until the last dash (-)
var myRegexp = /(.*)-/;
var matches = null;
if (zone)
matches = myRegexp.exec(zone);
// If we got a match - return it.
if (matches && matches[1])
rtn = matches[1];
// Last assigned value is returned.
rtn = rtn;"}
}
set_field {
field_name = "users"
value = eval {"javascript: var users = ${google_disks[].users};
var rtn = users;
// Capture the users, right after the word instances
var myRegexp = /instances\\/(.*)/i;
var matches = null;
if (users)
matches = myRegexp.exec(users);
// If we got a match - return it.
if (matches && matches[1])
rtn = matches[1];
// Last assigned value is returned.
rtn = rtn;"}
}
set_field {
field_name = "sizeBytes"
value = eval {"javascript: var sizeGB = ${google_disks[].sizeGB};
var rtn = sizeGB;
try{
rtn = parseInt(sizeGB);
// GB to Bytes
rtn = rtn * 1024 * 1024 * 1024;
}
// Nothing to do with catch
catch (e){}
// Last assigned value is returned.
rtn = rtn;"}
}
}
}
on_false = nop {}
}
}
step {
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"google_disks"}}
}
on_true = filter {
src_table_name = "google_disks"
target_table_name = "google_disks"
condition = eq {
eval {"${cmdb_ci_google_datacenter[*].region}.contains(${google_disks[].region})"}
"true"
}
}
on_false = nop {}
}
}
step {
name = "Aggregate disk size by vm instance"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = set_attr {
"tmp"
eval {"javascript: rtrn = '';
var googleDisks = ${google_disks};
var diskHashMap = new Packages.java.util.HashMap();
try{
for (var i=0 ; i < googleDisks.size(); i++){
var key = googleDisks.get(i).get('users');
var value = googleDisks.get(i).get('sizeGB');
if (diskHashMap.containsKey(key)){
var sum = parseInt(diskHashMap.get(key))+parseInt(value);
diskHashMap.put(key,sum);
}
else {
diskHashMap.put(key,parseInt(value));
}
}
}
catch(e){
ms.log(\"Error message from step 'Aggregate disk size by vm instance' in 'Get Storage Volumes' shared library : \" + e);
}
CTX.setAttribute(\"diskHashMap\", diskHashMap);"}
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_vm_instance table with disk size"
transform {
src_table_name = "cmdb_ci_vm_instance"
target_table_name = "cmdb_ci_vm_instance"
operation {set_field {
field_name = "disks_size"
value = eval {"javascript: var rtrn = 0;
var diskHashMapVal;
try{
diskHashMapVal = ${diskHashMap};
var vmName = ${cmdb_ci_vm_instance[].name};
if(diskHashMapVal&&vmName){
rtrn = parseInt(diskHashMapVal.get(vmName));
}
}
catch(e){
ms.log(\"Error message from step 'Populate cmdb_ci_vm_instance table with disk size' in 'Get Storage Volumes' shared library : \" + e);
}
rtrn;"}
}}
}
}
step {
name = "Populate cmdb_ci_storage_volume table"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = transform {
src_table_name = "google_disks"
target_table_name = "cmdb_ci_storage_volume"
operation {
set_field {
field_name = "object_id"
value = get_attr {"google_disks[].object_id"}
}
set_field {
field_name = "name"
value = get_attr {"google_disks[].name"}
}
set_field {
field_name = "volume_id"
value = get_attr {"google_disks[].object_id"}
}
set_field {
field_name = "storage_type"
value = get_attr {"google_disks[].typeCode"}
}
set_field {
field_name = "size_bytes"
value = get_attr {"google_disks[].sizeBytes"}
}
set_field {
field_name = "state"
value = eval {"javascript: var rtn;
switch (${google_disks[].status}) {
case \"CREATING\": rtn = \"offline\"; break;
case \"RESTORING\": rtn = \"offline\"; break;
case \"FAILED\": rtn = \"terminated\"; break;
case \"READY\": rtn = \"available\"; break;
case \"DELETING\": rtn = \"terminated\"; break;
}
if(${google_disks[].users}) {
rtn = \"in_use\";
}"}
}
set_field {
field_name = "install_status"
value = eval {"javascript: var rtn;
switch (${google_disks[].status}) {
case \"CREATING\": rtn = \"4\"; break;
case \"RESTORING\": rtn = \"3\"; break;
case \"FAILED\": rtn = \"100\"; break;
case \"READY\": rtn = \"1\"; break;
case \"DELETING\": rtn = \"7\"; break;
}"}
}
set_field {
field_name = "short_description"
value = get_attr {"google_disks[].description"}
}
}
}
on_false = nop {}
}
}
step {
name = "Create relationship between LDC and storage volume"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = relation_reference {
table1_name = "cmdb_ci_storage_volume"
key1_name = "region"
table2_name = "cmdb_ci_google_datacenter"
key2_name = "region"
result_table_name = "ldc_to_storage_volume"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create relationship between Zone and storage volume"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = relation_reference {
table1_name = "cmdb_ci_availability_zone"
table2_name = "cmdb_ci_storage_volume"
result_table_name = "zone_to_disks"
unmatched_lines = remove
condition = eq {
eval {"javascript: var rtrn = false;
var zoneName = ${cmdb_ci_availability_zone[].name};
var zone = ${cmdb_ci_storage_volume[].zone};
if(JSUtil.nil(zone))
{
var objId = ${cmdb_ci_storage_volume[].object_id};
var azHashSet = ${ReplicaDiskAZCache}.get(objId);
if (azHashSet){
rtrn = azHashSet.contains(zoneName);
}
}
else
{
if(zone.equals(zoneName))
{
rtrn = true;
}
}
rtrn = rtrn;"}
"true"
}
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
| library {
name = "Google Cloud Platform (GCP) - Get Storage Volumes"
id = "e0100022db442300d504788dbf961999" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get all Google disks"
comment = "pg - Condition is introduced so the API call is not executed if the pattern is event triggered and there are no related disks to the VM Instance."
if {
condition = any {
is_empty {get_attr {"input_object_id"}}
is_not_empty {get_attr {"filter"}}
}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://www.googleapis.com/compute/"
get_attr {"API_version"}
"/projects/"
get_attr {"service_account[1].account_id"}
"/aggregated/disks"
get_attr {"filter"}
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "disksJson"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse disks data"
if {
condition = is_not_empty {get_attr {"disksJson"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "disksJson"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "google_disks"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "object_id:items.*.disks.id,name:items.*.disks.name,sizeGB:items.*.disks.sizeGb,zone_link:items.*.disks.zone,typeCode_link:items.*.disks.type,status:items.*.disks.status,description:items.*.disks.description,snapshotId:items.*.disks.sourceSnapshotId" // Script execution: Custom script to perform a specific action or collect data
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse disks data - replicaZone cases"
if {
condition = is_not_empty {get_attr {"disksJson"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "disksJson"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "google_disks_replica"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "object_id:items.*.disks.id,replicaZone_link:items.*.disks.replicaZones"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate replicaZone in google_disks_replica"
if {
condition = is_not_empty {get_attr {"google_disks_replica"}}
on_true = transform {
src_table_name = "google_disks_replica"
target_table_name = "google_disks_replica"
operation {set_field {
field_name = "replicaZone"
value = eval {"javascript: var replicaZone_link = ${google_disks_replica[].replicaZone_link}; // Script execution: Custom script to perform a specific action or collect data
var rtrn = \"\";
if(replicaZone_link){
var myRegexp = /.*\\/zones\\/(.*)$/;
var matches=myRegexp.exec(replicaZone_link);
// If we got a match - return it.
if (matches && matches[1])
rtrn = matches[1];
}
rtrn;"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get AZ to Storage Map"
if {
condition = eq {
eval {"javascript: rtrn = false; // Script execution: Custom script to perform a specific action or collect data
if(${google_disks_replica})
{
var gcReplicaTable = ${google_disks_replica};
for (var i=0 ; i < gcReplicaTable.size(); i++){
var obj_id = gcReplicaTable.get(i).get('object_id'); // Unique identifier for the pattern
if(JSUtil.notNil(obj_id))
{
rtrn = true;
}
}
}
rtrn = rtrn;"}
"true"
}
on_true = set_attr {
"tmp"
eval {"javascript: rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var gcReplicaTable = ${google_disks_replica};
var storageVolToAZHashSet = new Packages.java.util.HashMap();
for (var i=0 ; i < gcReplicaTable.size(); i++){
var obj_id = gcReplicaTable.get(i).get('object_id'); // Unique identifier for the pattern
var rep_zone = gcReplicaTable.get(i).get('replicaZone');
//if(rep_zone != null)
if(JSUtil.notNil(rep_zone))
{
//only in case we have a replicaZone value we will add it to the map
if (storageVolToAZHashSet.containsKey(obj_id)){
(storageVolToAZHashSet.get(obj_id)).add(rep_zone);
}
else {
var azSet = new Packages.java.util.HashSet();
azSet.add(rep_zone);
storageVolToAZHashSet.put(obj_id,azSet);
}
}
}
CTX.setAttribute(\"ReplicaDiskAZCache\", storageVolToAZHashSet);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse disks users"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "disksJson"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "google_disks_users"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "object_id:items.*.disks.id,users:items.*.disks.users"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set users on google disks"
if {
condition = is_not_empty {get_attr {"google_disks_users"}}
on_true = merge {
table1_name = "google_disks"
key1_name = "object_id"
table2_name = "google_disks_users"
key2_name = "object_id"
result_table_name = "google_disks"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Keep only disks attached to VMs if needed"
if {
condition = all {
is_not_empty {get_attr {"filterBasedOnVMs"}}
eq {
get_attr {"filterBasedOnVMs"}
"true"
}
is_not_empty {get_attr {"google_disks"}}
}
on_true = filter {
src_table_name = "google_disks"
target_table_name = "google_disks"
condition = is_not_empty {get_attr {"google_disks[].users"}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Extract zone, typeCode, region, sizeBytes and users"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = transform {
src_table_name = "google_disks"
target_table_name = "google_disks"
operation {
set_field {
field_name = "zone"
value = eval {"javascript: var zone_link = ${google_disks[].zone_link}; // Script execution: Custom script to perform a specific action or collect data
var rtrn = \"\";
if(zone_link){
var myRegexp = /.*\\/zones\\/(.*)$/;
var matches=myRegexp.exec(zone_link);
// If we got a match - return it.
if (matches && matches[1])
rtrn = matches[1];
}
rtrn;"}
}
set_field {
field_name = "typeCode"
value = eval {"javascript: var typeCode_link = ${google_disks[].typeCode_link}; // Script execution: Custom script to perform a specific action or collect data
var rtrn = \"\";
if(typeCode_link){
var myRegexp = /.*\\/diskTypes\\/(.*)$/;
var matches=myRegexp.exec(typeCode_link);
// If we got a match - return it.
if (matches && matches[1])
rtrn = matches[1];
}
rtrn;"}
}
set_field {
field_name = "region"
value = eval {"javascript: var zone = ${google_disks[].zone}; // Script execution: Custom script to perform a specific action or collect data
if(JSUtil.nil(zone))
{
var obj = ${google_disks[].object_id};
var replicaSet = ${ReplicaDiskAZCache}.get(obj);
var itr = replicaSet.iterator();
var firstZone = itr.next();
zone = firstZone;
}
rtn = zone;
// Catch all characters until the last dash (-)
var myRegexp = /(.*)-/;
var matches = null;
if (zone)
matches = myRegexp.exec(zone);
// If we got a match - return it.
if (matches && matches[1])
rtn = matches[1];
// Last assigned value is returned.
rtn = rtn;"}
}
set_field {
field_name = "users"
value = eval {"javascript: var users = ${google_disks[].users}; // Script execution: Custom script to perform a specific action or collect data
var rtn = users;
// Capture the users, right after the word instances
var myRegexp = /instances\\/(.*)/i;
var matches = null;
if (users)
matches = myRegexp.exec(users);
// If we got a match - return it.
if (matches && matches[1])
rtn = matches[1];
// Last assigned value is returned.
rtn = rtn;"}
}
set_field {
field_name = "sizeBytes"
value = eval {"javascript: var sizeGB = ${google_disks[].sizeGB}; // Script execution: Custom script to perform a specific action or collect data
var rtn = sizeGB;
try{
rtn = parseInt(sizeGB);
// GB to Bytes
rtn = rtn * 1024 * 1024 * 1024;
}
// Nothing to do with catch
catch (e){}
// Last assigned value is returned.
rtn = rtn;"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter based on input LDCs only if we got less LDCs as input than in the query"
if {
condition = all {
eq {
get_attr {"shouldFilterBasedOnLDC"}
"true"
}
is_not_empty {get_attr {"google_disks"}}
}
on_true = filter {
src_table_name = "google_disks"
target_table_name = "google_disks"
condition = eq {
eval {"${cmdb_ci_google_datacenter[*].region}.contains(${google_disks[].region})"}
"true"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Aggregate disk size by vm instance"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = set_attr {
"tmp"
eval {"javascript: rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var googleDisks = ${google_disks};
var diskHashMap = new Packages.java.util.HashMap();
try{
for (var i=0 ; i < googleDisks.size(); i++){
var key = googleDisks.get(i).get('users');
var value = googleDisks.get(i).get('sizeGB');
if (diskHashMap.containsKey(key)){
var sum = parseInt(diskHashMap.get(key))+parseInt(value);
diskHashMap.put(key,sum);
}
else {
diskHashMap.put(key,parseInt(value));
}
}
}
catch(e){
ms.log(\"Error message from step 'Aggregate disk size by vm instance' in 'Get Storage Volumes' shared library : \" + e); // Step definition: Represents a single action or set of actions in the pattern
}
CTX.setAttribute(\"diskHashMap\", diskHashMap);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_vm_instance table with disk size"
transform {
src_table_name = "cmdb_ci_vm_instance"
target_table_name = "cmdb_ci_vm_instance"
operation {set_field {
field_name = "disks_size"
value = eval {"javascript: var rtrn = 0; // Script execution: Custom script to perform a specific action or collect data
var diskHashMapVal;
try{
diskHashMapVal = ${diskHashMap};
var vmName = ${cmdb_ci_vm_instance[].name};
if(diskHashMapVal&&vmName){
rtrn = parseInt(diskHashMapVal.get(vmName));
}
}
catch(e){
ms.log(\"Error message from step 'Populate cmdb_ci_vm_instance table with disk size' in 'Get Storage Volumes' shared library : \" + e); // Step definition: Represents a single action or set of actions in the pattern
}
rtrn;"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_storage_volume table"
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = transform {
src_table_name = "google_disks"
target_table_name = "cmdb_ci_storage_volume"
operation {
set_field {
field_name = "object_id"
value = get_attr {"google_disks[].object_id"}
}
set_field {
field_name = "name"
value = get_attr {"google_disks[].name"}
}
set_field {
field_name = "volume_id"
value = get_attr {"google_disks[].object_id"}
}
set_field {
field_name = "storage_type"
value = get_attr {"google_disks[].typeCode"}
}
set_field {
field_name = "size_bytes"
value = get_attr {"google_disks[].sizeBytes"}
}
set_field {
field_name = "state"
value = eval {"javascript: var rtn; // Script execution: Custom script to perform a specific action or collect data
switch (${google_disks[].status}) {
case \"CREATING\": rtn = \"offline\"; break;
case \"RESTORING\": rtn = \"offline\"; break;
case \"FAILED\": rtn = \"terminated\"; break;
case \"READY\": rtn = \"available\"; break;
case \"DELETING\": rtn = \"terminated\"; break;
}
if(${google_disks[].users}) {
rtn = \"in_use\";
}"}
}
set_field {
field_name = "install_status"
value = eval {"javascript: var rtn; // Script execution: Custom script to perform a specific action or collect data
switch (${google_disks[].status}) {
case \"CREATING\": rtn = \"4\"; break;
case \"RESTORING\": rtn = \"3\"; break;
case \"FAILED\": rtn = \"100\"; break;
case \"READY\": rtn = \"1\"; break;
case \"DELETING\": rtn = \"7\"; break;
}"}
}
set_field {
field_name = "short_description" // Script execution: Custom script to perform a specific action or collect data
value = get_attr {"google_disks[].description"} // Script execution: Custom script to perform a specific action or collect data
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relationship between LDC and storage volume" // Relationship mapping: Identifies and records relationships between CIs
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = relation_reference {
table1_name = "cmdb_ci_storage_volume"
key1_name = "region"
table2_name = "cmdb_ci_google_datacenter"
key2_name = "region"
result_table_name = "ldc_to_storage_volume"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relationship between Zone and storage volume" // Relationship mapping: Identifies and records relationships between CIs
if {
condition = is_not_empty {get_attr {"google_disks"}}
on_true = relation_reference {
table1_name = "cmdb_ci_availability_zone"
table2_name = "cmdb_ci_storage_volume"
result_table_name = "zone_to_disks"
unmatched_lines = remove
condition = eq {
eval {"javascript: var rtrn = false; // Script execution: Custom script to perform a specific action or collect data
var zoneName = ${cmdb_ci_availability_zone[].name};
var zone = ${cmdb_ci_storage_volume[].zone};
if(JSUtil.nil(zone))
{
var objId = ${cmdb_ci_storage_volume[].object_id};
var azHashSet = ${ReplicaDiskAZCache}.get(objId);
if (azHashSet){
rtrn = azHashSet.contains(zoneName);
}
}
else
{
if(zone.equals(zoneName))
{
rtrn = true;
}
}
rtrn = rtrn;"}
"true"
}
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
}
|
OpenStack - Get Token and Regions | I would like for you to help me build a Pattern that helps achieve Discovery of OpenStack - Get Token and Regions. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "OpenStack - Get Token and Regions"
id = "e069b79e1bfc00109d13ed3f6e4bcb4c"
description = "null"
step {
name = "Set supported version - keystone"
set_attr {
"keystone_supported_version"
"3"
}
}
step {
name = "Check if there are LDCs"
set_attr {
"is_ldc"
eval {"javascript: var ans = 'false';
if (${cmdb_ci_openstack_datacenter}.size() > 0){
var first_region = ${cmdb_ci_openstack_datacenter}.get(0);
try{
var regex = /.*, name=(.*?),.*/;
var is_ldc = regex.exec(first_region);
if(is_ldc[0] && is_ldc[1]){
ans = 'true';
}
} catch(e){
ms.log(e);
}
}
ans=ans;"}
}
}
step {
name = "Set to not filter based on LDCs as default"
set_attr {
"shouldFilterBasedOnLDC"
"false"
}
}
step {
name = "Set a flag to filter based on LDCs"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_openstack_datacenter"}}
eq {
get_attr {"is_ldc"}
"true"
}
}
on_true = set_attr {
"shouldFilterBasedOnLDC"
"true"
}
on_false = nop {}
}
}
step {
name = "Create service account table"
comment = "table is required for use with \"Cloud Rest * \" custom operation. Currently not in use in the pattern but this will be changed, as soon as OpenStack is added as cloud provider to the custom operation."
if {
condition = is_empty {get_attr {"service_account"}}
on_true = parse_var_to_var {
from_var_name = "cloud_datacenter_type"
to_var_names = table {
name = "service_account"
col_names = "datacenter_type"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Add credentials and account ID to service account table if don't exist"
if {
condition = all {
is_empty {get_attr {"service_account[1].discovery_credentials"}}
is_empty {get_attr {"service_account[1].account_id"}}
}
on_true = transform {
src_table_name = "service_account"
target_table_name = "service_account"
operation {
set_field {
field_name = "account_id"
value = get_attr {"cloud_account_id"}
}
set_field {
field_name = "object_id"
value = get_attr {"cloud_account_id"}
}
set_field {
field_name = "discovery_credentials"
value = get_attr {"cloud_cred_id"}
}
set_field {
field_name = "datacenter_url"
value = get_attr {"datacenter_url"}
}
}
}
on_false = nop {}
}
}
step {
name = "Get Token and credential details"
comment = "Currently the Token is generated against as Project scoped, using the domain_id and the project_name for the generation URL."
set_attr {
"tmp"
eval {"javascript: //Java class loading
var httpRequest = Packages.com.glide.communications.HTTPRequest;
var URI = Packages.java.net.URI;
var uriException = Packages.java.net.URISyntaxException;
var rtrn;
//Context loading
var urlAuth = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
//var credsAlias = CTX.getAttribute('cloud_cred_alias');
var cred_id = CTX.getAttribute('service_account[1].discovery_credentials');
var project_id = CTX.getAttribute('service_account[1].object_id');
var parameter_domain_id = CTX.getAttribute('cloud_domain_id');
var token = CTX.getAttribute('token');
var openstack_auth = new OpenstackAuthenticationString();
var content = openstack_auth.create_string(project_id,cred_id,parameter_domain_id);
if(!token) {
try{
var auth_url = new URI(urlAuth);
}catch(err){
ms.log(\"Not a valid auth_url. e.g. https://host:port. Current is \" + urlAuth);
throw new uriException(err.getMessage(), \"Not a valid auth_url. e.g. https://host:port\");
}
// Construct auth auth_url
urlAuth = urlAuth + \"/v\" + keystone_version + \"/auth/tokens\" ;
CTX.setAttribute(\"endpoint_keystone\",urlAuth);
var httpAuthRequest = new httpRequest(urlAuth);
httpAuthRequest.addHeader('Content-Type','application/json');
httpAuthRequest.addHeader('Accept','application/json');
var httpAuthResponse = httpAuthRequest.post(content);
rtrn = httpAuthResponse.getHeader('X-Subject-Token');
//bellow is added to hide value from discovery log, the it is restored back to default
Packages.com.snc.sw.log.DiscoLog.setDisabled(true);
CTX.setAttribute(\"token\",rtrn);
rtrn = 'success';
Packages.com.snc.sw.log.DiscoLog.setDisabled(false);
}
rtrn;"}
}
}
step {
name = "Verify Token is created"
match {
is_not_empty {get_attr {"token"}}
terminate_op = graceful
terminate_msg = "Token creation failed. Please verify that the project in the OpenStack credentials is configured correctly."
}
}
step {
name = "Validate Token"
comment = "pg - currently the token is generated without scoping, but the response is always scoped?"
set_attr {
"service_links"
eval {"javascript: //Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var urlAuth = CTX.getAttribute('endpoint_keystone');
var token = CTX.getAttribute('token');
if (token) {
var headers = [];
headers.push(\"X-Auth-Token:\" + token);
headers.push(\"X-Subject-Token:\" + token);
var response = httpClient.invoke(CTX, urlAuth, 'GET', null, null, ciType, headers, 'false');
var rtrn;
rtrn = response;
}"}
}
}
step {
name = "Parse Token project authorization scope "
comment = "pg - currently the token is always generated with domain scoping so this should always brings us data."
parse_var_to_var {
from_var_name = "service_links"
to_var_names = table {
name = "token_project_authorization"
col_names = "project_id","project_name","domain_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "project_id"
xpath = "/root/token/project/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_name"
xpath = "/root/token/project/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "domain_id"
xpath = "/root/token/project/domain/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Merge the parsed project with the service_account table"
merge {
table1_name = "service_account"
key1_name = "account_id"
table2_name = "token_project_authorization"
key2_name = "project_id"
result_table_name = "service_account"
unmatched_lines = remove
}
}
step {
name = "Validate Token is generated for correct project"
comment = "pg - currently the token is generated without scoping, but the response is always scoped?"
match {
is_not_empty {get_attr {"service_account"}}
terminate_op = graceful
terminate_msg = "Generated Token is for different Project/Service Account. Stopping the pattern to not create incorrect relations."
}
}
step {
name = "Populate cmdb_ci_cloud_service_account table"
transform {
src_table_name = "service_account"
target_table_name = "cmdb_ci_cloud_service_account"
operation {
set_field {
field_name = "account_id"
value = get_attr {"service_account[].account_id"}
}
set_field {
field_name = "object_id"
value = get_attr {"service_account[].account_id"}
}
set_field {
field_name = "name"
value = get_attr {"service_account[1].project_name"}
}
set_field {
field_name = "datacenter_type"
value = get_attr {"service_account[].datacenter_type"}
}
set_field {
field_name = "discovery_credentials"
value = get_attr {"service_account[].discovery_credentials"}
}
}
}
}
step {
name = "Parse service links"
parse_var_to_var {
from_var_name = "service_links"
to_var_names = table {
name = "links"
col_names = "name","type","url","interface","region","service_uuid","endpoint_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "name"
xpath = "/root/token/catalog/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "type"
xpath = "/root/token/catalog/type/text()"
delimiters = ""
position = 1
}
field {
col_name = "url"
xpath = "/root/token/catalog/endpoints/url/text()"
delimiters = ""
position = 1
}
field {
col_name = "interface"
xpath = "/root/token/catalog/endpoints/interface/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/token/catalog/endpoints/region_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_uuid"
xpath = "/root/token/catalog/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "endpoint_id"
xpath = "/root/token/catalog/endpoints/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Filter Public Links"
filter {
src_table_name = "links"
target_table_name = "links_public"
condition = eq {
get_attr {"links[].interface"}
"public"
}
}
}
step {
name = "Remove the project_id from the Service URLs if present"
if {
condition = is_not_empty {get_attr {"links_public"}}
on_true = transform {
src_table_name = "links_public"
target_table_name = "links_public"
operation {set_field {
field_name = "url"
value = eval {"javascript: var url = ${links_public[].url}.toString()
var project_id = ${token_project_authorization[1].project_id}
if (url.indexOf(\"/\"+project_id) > 0) {
url = url.replace(\"/\"+project_id,\"\")
}
url"}
}}
}
on_false = nop {}
}
}
step {
name = "Get Regions"
set_attr {
"regions_list_response"
eval {"javascript:
//Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var rtrn;
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var serviceURL = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
var token = CTX.getAttribute('token');
var resource = \"regions\";
serviceURL = serviceURL + \"/v\" + keystone_version
if (token) {
var header = \"X-Auth-Token:\" + token;
serviceURL = serviceURL + \"/\" + resource ;
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
rtrn = response;
}
"}
}
}
step {
name = "Parse the Regions"
parse_var_to_var {
from_var_name = "regions_list_response"
to_var_names = table {
name = "regions"
col_names = "region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "region"
xpath = "/root/regions/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Get unique regions from Token Catalog "
comment = "Alternative way to populate the regions if the user does not have sufficient rights to use the List Regions Identity API call."
if {
condition = is_empty {get_attr {"regions"}}
on_true = set_attr {
"tmp"
eval {"javascript:
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${links},[\"region\"]);
// removes the duplicate values for a table based on a column or columns
CTX.setAttribute(\"regions\", tableWithoutDuplicates);
// pushes the result into a NEW table inside the pattern
"}
}
on_false = nop {}
}
}
step {
name = "Create a diff table between input LDCs and query LDCs"
if {
condition = eq {
get_attr {"is_ldc"}
"true"
}
on_true = filter {
src_table_name = "regions"
target_table_name = "region_diff"
condition = neq {
get_attr {"regions[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray()
var length = ldc.length
var region = ${regions[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step {
name = "Check if the input LDCs and REST result LDCs are the same"
if {
condition = is_empty {get_attr {"region_diff"}}
on_true = set_attr {
"isInputLDCsAndRestLDCsEquale"
"true"
}
on_false = nop {}
}
}
step {
name = "If input LDCs and REST results LDCs are the same - set no need to filter based on LDCs"
if {
condition = eq {
get_attr {"isInputLDCsAndRestLDCsEquale"}
"true"
}
on_true = set_attr {
"shouldFilterBasedOnLDC"
"false"
}
on_false = nop {}
}
}
step {
name = "Update LDC filter for event patterns"
if {
condition = is_not_empty {get_attr {"input_object_id"}}
on_true = set_attr {
"shouldFilterBasedOnLDC"
"false"
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_openstack_datacenter table"
if {
condition = eq {
get_attr {"is_ldc"}
"false"
}
on_true = transform {
src_table_name = "regions"
target_table_name = "cmdb_ci_openstack_datacenter"
operation {
set_field {
field_name = "object_id"
value = get_attr {"regions[].region"}
}
set_field {
field_name = "name"
value = get_attr {"regions[].region"}
}
}
}
on_false = nop {}
}
}
step {
name = "Make Relation between cmdb_ci_openstack_datacenter and cmdb_ci_cloud_service_account"
relation_reference {
table1_name = "cmdb_ci_openstack_datacenter"
table2_name = "cmdb_ci_cloud_service_account"
result_table_name = "account_to_ldc"
unmatched_lines = keep
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
}
}
| library {
name = "OpenStack - Get Token and Regions"
id = "e069b79e1bfc00109d13ed3f6e4bcb4c" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set supported version - keystone"
set_attr {
"keystone_supported_version"
"3"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check if there are LDCs"
set_attr {
"is_ldc"
eval {"javascript: var ans = 'false'; // Script execution: Custom script to perform a specific action or collect data
if (${cmdb_ci_openstack_datacenter}.size() > 0){
var first_region = ${cmdb_ci_openstack_datacenter}.get(0);
try{
var regex = /.*, name=(.*?),.*/;
var is_ldc = regex.exec(first_region);
if(is_ldc[0] && is_ldc[1]){
ans = 'true';
}
} catch(e){
ms.log(e);
}
}
ans=ans;"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set to not filter based on LDCs as default"
set_attr {
"shouldFilterBasedOnLDC"
"false"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set a flag to filter based on LDCs"
if {
condition = all {
is_not_empty {get_attr {"cmdb_ci_openstack_datacenter"}}
eq {
get_attr {"is_ldc"}
"true"
}
}
on_true = set_attr {
"shouldFilterBasedOnLDC"
"true"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create service account table"
comment = "table is required for use with \"Cloud Rest * \" custom operation. Currently not in use in the pattern but this will be changed, as soon as OpenStack is added as cloud provider to the custom operation."
if {
condition = is_empty {get_attr {"service_account"}}
on_true = parse_var_to_var {
from_var_name = "cloud_datacenter_type"
to_var_names = table {
name = "service_account"
col_names = "datacenter_type"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add credentials and account ID to service account table if don't exist"
if {
condition = all {
is_empty {get_attr {"service_account[1].discovery_credentials"}}
is_empty {get_attr {"service_account[1].account_id"}}
}
on_true = transform {
src_table_name = "service_account"
target_table_name = "service_account"
operation {
set_field {
field_name = "account_id"
value = get_attr {"cloud_account_id"}
}
set_field {
field_name = "object_id"
value = get_attr {"cloud_account_id"}
}
set_field {
field_name = "discovery_credentials"
value = get_attr {"cloud_cred_id"}
}
set_field {
field_name = "datacenter_url"
value = get_attr {"datacenter_url"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Token and credential details"
comment = "Currently the Token is generated against as Project scoped, using the domain_id and the project_name for the generation URL."
set_attr {
"tmp"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpRequest = Packages.com.glide.communications.HTTPRequest;
var URI = Packages.java.net.URI;
var uriException = Packages.java.net.URISyntaxException;
var rtrn;
//Context loading
var urlAuth = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
//var credsAlias = CTX.getAttribute('cloud_cred_alias');
var cred_id = CTX.getAttribute('service_account[1].discovery_credentials'); // Unique identifier for the pattern
var project_id = CTX.getAttribute('service_account[1].object_id'); // Unique identifier for the pattern
var parameter_domain_id = CTX.getAttribute('cloud_domain_id'); // Unique identifier for the pattern
var token = CTX.getAttribute('token');
var openstack_auth = new OpenstackAuthenticationString();
var content = openstack_auth.create_string(project_id,cred_id,parameter_domain_id);
if(!token) {
try{
var auth_url = new URI(urlAuth);
}catch(err){
ms.log(\"Not a valid auth_url. e.g. https://host:port. Current is \" + urlAuth);
throw new uriException(err.getMessage(), \"Not a valid auth_url. e.g. https://host:port\");
}
// Construct auth auth_url
urlAuth = urlAuth + \"/v\" + keystone_version + \"/auth/tokens\" ;
CTX.setAttribute(\"endpoint_keystone\",urlAuth);
var httpAuthRequest = new httpRequest(urlAuth);
httpAuthRequest.addHeader('Content-Type','application/json');
httpAuthRequest.addHeader('Accept','application/json');
var httpAuthResponse = httpAuthRequest.post(content);
rtrn = httpAuthResponse.getHeader('X-Subject-Token');
//bellow is added to hide value from discovery log, the it is restored back to default
Packages.com.snc.sw.log.DiscoLog.setDisabled(true);
CTX.setAttribute(\"token\",rtrn);
rtrn = 'success';
Packages.com.snc.sw.log.DiscoLog.setDisabled(false);
}
rtrn;"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Verify Token is created"
match {
is_not_empty {get_attr {"token"}}
terminate_op = graceful
terminate_msg = "Token creation failed. Please verify that the project in the OpenStack credentials is configured correctly."
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Validate Token"
comment = "pg - currently the token is generated without scoping, but the response is always scoped?"
set_attr {
"service_links"
eval {"javascript: //Java class loading // Script execution: Custom script to perform a specific action or collect data
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var urlAuth = CTX.getAttribute('endpoint_keystone');
var token = CTX.getAttribute('token');
if (token) {
var headers = [];
headers.push(\"X-Auth-Token:\" + token);
headers.push(\"X-Subject-Token:\" + token);
var response = httpClient.invoke(CTX, urlAuth, 'GET', null, null, ciType, headers, 'false');
var rtrn;
rtrn = response;
}"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Token project authorization scope "
comment = "pg - currently the token is always generated with domain scoping so this should always brings us data."
parse_var_to_var {
from_var_name = "service_links"
to_var_names = table {
name = "token_project_authorization"
col_names = "project_id","project_name","domain_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "project_id"
xpath = "/root/token/project/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "project_name"
xpath = "/root/token/project/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "domain_id"
xpath = "/root/token/project/domain/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge the parsed project with the service_account table"
merge {
table1_name = "service_account"
key1_name = "account_id"
table2_name = "token_project_authorization"
key2_name = "project_id"
result_table_name = "service_account"
unmatched_lines = remove
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Validate Token is generated for correct project"
comment = "pg - currently the token is generated without scoping, but the response is always scoped?"
match {
is_not_empty {get_attr {"service_account"}}
terminate_op = graceful
terminate_msg = "Generated Token is for different Project/Service Account. Stopping the pattern to not create incorrect relations."
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_cloud_service_account table"
transform {
src_table_name = "service_account"
target_table_name = "cmdb_ci_cloud_service_account"
operation {
set_field {
field_name = "account_id"
value = get_attr {"service_account[].account_id"}
}
set_field {
field_name = "object_id"
value = get_attr {"service_account[].account_id"}
}
set_field {
field_name = "name"
value = get_attr {"service_account[1].project_name"}
}
set_field {
field_name = "datacenter_type"
value = get_attr {"service_account[].datacenter_type"}
}
set_field {
field_name = "discovery_credentials"
value = get_attr {"service_account[].discovery_credentials"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse service links"
parse_var_to_var {
from_var_name = "service_links"
to_var_names = table {
name = "links"
col_names = "name","type","url","interface","region","service_uuid","endpoint_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "name"
xpath = "/root/token/catalog/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "type"
xpath = "/root/token/catalog/type/text()"
delimiters = ""
position = 1
}
field {
col_name = "url"
xpath = "/root/token/catalog/endpoints/url/text()"
delimiters = ""
position = 1
}
field {
col_name = "interface"
xpath = "/root/token/catalog/endpoints/interface/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/root/token/catalog/endpoints/region_id/text()"
delimiters = ""
position = 1
}
field {
col_name = "service_uuid"
xpath = "/root/token/catalog/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "endpoint_id"
xpath = "/root/token/catalog/endpoints/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter Public Links"
filter {
src_table_name = "links"
target_table_name = "links_public"
condition = eq {
get_attr {"links[].interface"}
"public"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove the project_id from the Service URLs if present"
if {
condition = is_not_empty {get_attr {"links_public"}}
on_true = transform {
src_table_name = "links_public"
target_table_name = "links_public"
operation {set_field {
field_name = "url"
value = eval {"javascript: var url = ${links_public[].url}.toString() // Script execution: Custom script to perform a specific action or collect data
var project_id = ${token_project_authorization[1].project_id} // Unique identifier for the pattern
if (url.indexOf(\"/\"+project_id) > 0) {
url = url.replace(\"/\"+project_id,\"\")
}
url"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Regions"
set_attr {
"regions_list_response"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
//Java class loading
var httpCall = Packages.com.snc.sw.commands.HttpCallHandler;
var httpClientAuth = new httpCall();
var httpClient = new httpCall();
var rtrn;
//Context loading
var ciType = CTX.getAttribute('pattern_cit_id');
var serviceURL = CTX.getAttribute('service_account[1].datacenter_url');
var keystone_version = CTX.getAttribute('keystone_supported_version');
var token = CTX.getAttribute('token');
var resource = \"regions\";
serviceURL = serviceURL + \"/v\" + keystone_version
if (token) {
var header = \"X-Auth-Token:\" + token;
serviceURL = serviceURL + \"/\" + resource ;
var response = httpClient.invoke(CTX, serviceURL, 'GET', null, null, ciType, header, 'false');
rtrn = response;
}
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Regions"
parse_var_to_var {
from_var_name = "regions_list_response"
to_var_names = table {
name = "regions"
col_names = "region"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "region"
xpath = "/root/regions/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get unique regions from Token Catalog "
comment = "Alternative way to populate the regions if the user does not have sufficient rights to use the List Regions Identity API call."
if {
condition = is_empty {get_attr {"regions"}}
on_true = set_attr {
"tmp"
eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${links},[\"region\"]);
// removes the duplicate values for a table based on a column or columns
CTX.setAttribute(\"regions\", tableWithoutDuplicates);
// pushes the result into a NEW table inside the pattern
"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create a diff table between input LDCs and query LDCs"
if {
condition = eq {
get_attr {"is_ldc"}
"true"
}
on_true = filter {
src_table_name = "regions"
target_table_name = "region_diff"
condition = neq {
get_attr {"regions[].region"}
eval {"javascript: var ldc = ${cmdb_ci_openstack_datacenter[*].region}.toArray() // Script execution: Custom script to perform a specific action or collect data
var length = ldc.length
var region = ${regions[].region}
var rtrn = \"false\"
for (i=0; i < length; i++) {
if ( region == ldc[i] ) {
rtrn = region
break;
}
}
rtrn"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check if the input LDCs and REST result LDCs are the same"
if {
condition = is_empty {get_attr {"region_diff"}}
on_true = set_attr {
"isInputLDCsAndRestLDCsEquale"
"true"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "If input LDCs and REST results LDCs are the same - set no need to filter based on LDCs"
if {
condition = eq {
get_attr {"isInputLDCsAndRestLDCsEquale"}
"true"
}
on_true = set_attr {
"shouldFilterBasedOnLDC"
"false"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update LDC filter for event patterns"
if {
condition = is_not_empty {get_attr {"input_object_id"}}
on_true = set_attr {
"shouldFilterBasedOnLDC"
"false"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_openstack_datacenter table"
if {
condition = eq {
get_attr {"is_ldc"}
"false"
}
on_true = transform {
src_table_name = "regions"
target_table_name = "cmdb_ci_openstack_datacenter"
operation {
set_field {
field_name = "object_id"
value = get_attr {"regions[].region"}
}
set_field {
field_name = "name"
value = get_attr {"regions[].region"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Make Relation between cmdb_ci_openstack_datacenter and cmdb_ci_cloud_service_account"
relation_reference {
table1_name = "cmdb_ci_openstack_datacenter"
table2_name = "cmdb_ci_cloud_service_account"
result_table_name = "account_to_ldc"
unmatched_lines = keep
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
}
}
|
Amazon AWS - Get VPN Connection (LP) | I would like for you to help me build a Pattern that helps achieve Discovery of Amazon AWS - Get VPN Connection (LP). \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Amazon AWS - Get VPN Connection (LP)"
id = "e0a9c99496dc451a8ee181ab4adb261a"
description = "null"
step {
name = "Describe VPN connections"
comment = "AWS rest call for describing the VPN connectons and parsing them by the variable 'vpn_conn_rest'."
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
get_attr {"awsQueryUrl"}
"/?Action=DescribeVpnConnections&Version=2016-11-15"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "vpn_conn_rest"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 1
}
}
step {
name = "Verify if we have valid responce"
comment = "Validation of the response from the previous call 'describe vpn conections' if the needed data is parsed.
pg - the check whether actual resources is removed based on patterns review for all kind of resources."
match {
all {
not_contains {
get_attr {"vpn_conn_rest"}
"Cloud request failed"
}
not_contains {
get_attr {"vpn_conn_rest"}
"Invalid parameter"
}
is_not_empty {get_attr {"vpn_conn_rest"}}
}
terminate_op = terminate
terminate_msg = ""
}
}
step {
name = "Parsing fields for VPN connection"
comment = "Filling a temporary table 'cpnconn' with the desired information regarding the VPN connections by parsing the variable 'vpn_conn_rest'."
parse_var_to_var {
from_var_name = "vpn_conn_rest"
to_var_names = table {
name = "vpnconn"
col_names = "cgwid","vgwid","vpnid","state","conntype","region"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVpnConnectionsResponse"
fields {
field {
col_name = "cgwid"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/customerGatewayId/text()"
delimiters = ""
position = 1
}
field {
col_name = "vgwid"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/vpnGatewayId/text()"
delimiters = ""
position = 1
}
field {
col_name = "vpnid"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/vpnConnectionId/text()"
delimiters = ""
position = 1
}
field {
col_name = "state"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/state/text()"
delimiters = ""
position = 1
}
field {
col_name = "conntype"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/type/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/added_sn_region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Filter vpnconn table"
filter {
src_table_name = "vpnconn"
target_table_name = "vpnconn"
condition = is_not_empty {get_attr {"vpnconn[].vpnid"}}
}
}
step {
name = "Assign the ID as name"
if {
condition = is_not_empty {get_attr {"vpnconn[*].vpnid"}}
on_true = transform {
src_table_name = "vpnconn"
target_table_name = "vpnconn"
operation {set_field {
field_name = "vpn_connection_name"
value = get_attr {"vpnconn[].vpnid"}
}}
}
on_false = nop {}
}
}
step {
name = "Parse the VPN Connections Tags"
comment = "Parsing the variable containing the information about the tags."
if {
condition = is_not_empty {get_attr {"vpn_conn_rest"}}
on_true = parse_var_to_var {
from_var_name = "vpn_conn_rest"
to_var_names = table {
name = "vpnconn_tags"
col_names = "vpnid","tag_key","vpn_connection_name"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVpnConnectionsResponse"
fields {
field {
col_name = "vpnid"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/vpnConnectionId/text()"
delimiters = ""
position = 1
}
field {
col_name = "tag_key"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "vpn_connection_name"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "Filter the Name Tags"
if {
condition = is_not_empty {get_attr {"vpnconn_tags"}}
on_true = filter {
src_table_name = "vpnconn_tags"
target_table_name = "vpnconn_tags"
condition = eq {
"1"
eval {"javascript: var tag_key=${vpnconn_tags[].tag_key};
var rtrn;
if (tag_key.trim() == \"Name\"){
rtrn=1;
}
else {
rtrn=0;
}"}
}
}
on_false = nop {}
}
}
step {
name = "Merging vpnconn and vpnconn_name"
comment = "Merging the temporary tables 'vpnconn' and 'vpnconn_name', the first one is containing basic information about the VPN connections and the second is storing the filtered information from the tags containing names for the VPN connections. The merge criteria is the object ID for the VPN connections."
if {
condition = is_not_empty {get_attr {"vpnconn_tags"}}
on_true = merge {
table1_name = "vpnconn_tags"
key1_name = "vpnid"
table2_name = "vpnconn"
key2_name = "vpnid"
result_table_name = "vpnconn"
unmatched_lines = keep
}
on_false = nop {}
}
}
step {
name = "Fill cmdb_ci_vpn_connection"
comment = "Filling the table 'cmdb_ci_vpn_connection' table with information stored into the temporary table 'vpnconn'."
if {
condition = is_not_empty {get_attr {"vpnconn[1].vpnid"}}
on_true = transform {
src_table_name = "vpnconn"
target_table_name = "cmdb_ci_vpn_connection"
operation {
set_field {
field_name = "object_id"
value = get_attr {"vpnconn[].vpnid"}
}
set_field {
field_name = "name"
value = get_attr {"vpnconn[].vpn_connection_name"}
}
set_field {
field_name = "connection_type"
value = get_attr {"vpnconn[].conntype"}
}
set_field {
field_name = "customer_gateway"
value = get_attr {"vpnconn[].cgwid"}
}
set_field {
field_name = "virtual_private_gateway"
value = get_attr {"vpnconn[].vgwid"}
}
set_field {
field_name = "region"
value = get_attr {"vpnconn[].region"}
}
}
}
on_false = nop {}
}
}
}
| library {
name = "Amazon AWS - Get VPN Connection (LP)"
id = "e0a9c99496dc451a8ee181ab4adb261a" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Describe VPN connections"
comment = "AWS rest call for describing the VPN connectons and parsing them by the variable 'vpn_conn_rest'."
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
get_attr {"awsQueryUrl"}
"/?Action=DescribeVpnConnections&Version=2016-11-15"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "vpn_conn_rest"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 1
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Verify if we have valid responce"
comment = "Validation of the response from the previous call 'describe vpn conections' if the needed data is parsed.
pg - the check whether actual resources is removed based on patterns review for all kind of resources."
match {
all {
not_contains {
get_attr {"vpn_conn_rest"}
"Cloud request failed"
}
not_contains {
get_attr {"vpn_conn_rest"}
"Invalid parameter"
}
is_not_empty {get_attr {"vpn_conn_rest"}}
}
terminate_op = terminate
terminate_msg = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parsing fields for VPN connection"
comment = "Filling a temporary table 'cpnconn' with the desired information regarding the VPN connections by parsing the variable 'vpn_conn_rest'."
parse_var_to_var {
from_var_name = "vpn_conn_rest"
to_var_names = table {
name = "vpnconn"
col_names = "cgwid","vgwid","vpnid","state","conntype","region"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVpnConnectionsResponse"
fields {
field {
col_name = "cgwid"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/customerGatewayId/text()"
delimiters = ""
position = 1
}
field {
col_name = "vgwid"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/vpnGatewayId/text()"
delimiters = ""
position = 1
}
field {
col_name = "vpnid"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/vpnConnectionId/text()"
delimiters = ""
position = 1
}
field {
col_name = "state"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/state/text()"
delimiters = ""
position = 1
}
field {
col_name = "conntype"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/type/text()"
delimiters = ""
position = 1
}
field {
col_name = "region"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/added_sn_region/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter vpnconn table"
filter {
src_table_name = "vpnconn"
target_table_name = "vpnconn"
condition = is_not_empty {get_attr {"vpnconn[].vpnid"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Assign the ID as name"
if {
condition = is_not_empty {get_attr {"vpnconn[*].vpnid"}}
on_true = transform {
src_table_name = "vpnconn"
target_table_name = "vpnconn"
operation {set_field {
field_name = "vpn_connection_name"
value = get_attr {"vpnconn[].vpnid"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the VPN Connections Tags"
comment = "Parsing the variable containing the information about the tags."
if {
condition = is_not_empty {get_attr {"vpn_conn_rest"}}
on_true = parse_var_to_var {
from_var_name = "vpn_conn_rest"
to_var_names = table {
name = "vpnconn_tags"
col_names = "vpnid","tag_key","vpn_connection_name"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVpnConnectionsResponse"
fields {
field {
col_name = "vpnid"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/vpnConnectionId/text()"
delimiters = ""
position = 1
}
field {
col_name = "tag_key"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "vpn_connection_name"
xpath = "/DescribeVpnConnectionsResponse/vpnConnectionSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter the Name Tags"
if {
condition = is_not_empty {get_attr {"vpnconn_tags"}}
on_true = filter {
src_table_name = "vpnconn_tags"
target_table_name = "vpnconn_tags"
condition = eq {
"1"
eval {"javascript: var tag_key=${vpnconn_tags[].tag_key}; // Script execution: Custom script to perform a specific action or collect data
var rtrn;
if (tag_key.trim() == \"Name\"){
rtrn=1;
}
else {
rtrn=0;
}"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merging vpnconn and vpnconn_name"
comment = "Merging the temporary tables 'vpnconn' and 'vpnconn_name', the first one is containing basic information about the VPN connections and the second is storing the filtered information from the tags containing names for the VPN connections. The merge criteria is the object ID for the VPN connections."
if {
condition = is_not_empty {get_attr {"vpnconn_tags"}}
on_true = merge {
table1_name = "vpnconn_tags"
key1_name = "vpnid"
table2_name = "vpnconn"
key2_name = "vpnid"
result_table_name = "vpnconn"
unmatched_lines = keep
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill cmdb_ci_vpn_connection"
comment = "Filling the table 'cmdb_ci_vpn_connection' table with information stored into the temporary table 'vpnconn'."
if {
condition = is_not_empty {get_attr {"vpnconn[1].vpnid"}}
on_true = transform {
src_table_name = "vpnconn"
target_table_name = "cmdb_ci_vpn_connection"
operation {
set_field {
field_name = "object_id"
value = get_attr {"vpnconn[].vpnid"}
}
set_field {
field_name = "name"
value = get_attr {"vpnconn[].vpn_connection_name"}
}
set_field {
field_name = "connection_type"
value = get_attr {"vpnconn[].conntype"}
}
set_field {
field_name = "customer_gateway"
value = get_attr {"vpnconn[].cgwid"}
}
set_field {
field_name = "virtual_private_gateway"
value = get_attr {"vpnconn[].vgwid"}
}
set_field {
field_name = "region"
value = get_attr {"vpnconn[].region"}
}
}
}
on_false = nop {}
}
}
}
|
Azure NAT Gateway Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Azure NAT Gateway Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure NAT Gateway Tags"
id = "dc75de201b42b0103c55eced7b4bcbd7"
description = "Azure NAT Gateway Tags"
step {
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure NAT Gateway Tags\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id};
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step {
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Create relation between Tag and NAT Gateway"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_nat_gateway"
key2_name = "object_id"
result_table_name = "tag_to_nat"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Azure NAT Gateway Tags"
id = "dc75de201b42b0103c55eced7b4bcbd7" // Unique identifier for the pattern
description = "Azure NAT Gateway Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure NAT Gateway Tags\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id}; // Unique identifier for the pattern
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and NAT Gateway"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_nat_gateway"
key2_name = "object_id"
result_table_name = "tag_to_nat"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Linux - Memory Modules | I would like for you to help me build a Pattern that helps achieve Discovery of Linux - Memory Modules. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Linux - Memory Modules"
id = "dc334fe39f2032001d753758442e70b7"
description = "null"
step {
name = "Set the privileged command to use"
set_attr {
"sudo"
eval {"return ${ctx}.getDiscoveryProvider(com.snc.sw.dto.ProviderType.SSH).getPrivilegedCommand();"}
}
}
step {
name = "Get Memory Modules without Restart"
runcmd_to_var {
cmd = concat {
get_attr {"sudo"}
" lshw"
}
execution_mode = "DEFAULT"
var_names = "lshw_out"
parsing_strategy = delimited_parsing {
selected_positions = 1
line_seperator = "nonExistingLineSeparator"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Fetch Memory Module from Command Output"
if {
condition = is_not_empty {get_attr {"lshw_out"}}
on_true = set_attr {
"mem_desired"
eval {"javascript: var rtrn = '';
var output = ${lshw_out};
var temp = output.split('*-bank');
if (temp[1]) {
if (temp[1].contains('*-'))
rtrn = temp[1].substring(0, temp[1].indexOf('*-'))
else
rtrn = temp[1];}"}
}
on_false = nop {}
}
}
step {
name = "Fetch Memory Attributes"
parse_var_to_var {
from_var_name = "mem_desired"
to_var_names = table {col_names = "mem_form_factor","mem_type","mem_type_detail"}
parsing_strategy = delimited_parsing {
include_lines_pattern = "description"
delimiters = " "
selected_positions = 2,3,4
}
if_not_found_do = nop {}
}
}
step {
name = "Get Display Name"
parse_var_to_var {
from_var_name = "mem_desired"
to_var_names = "mem_disp_name"
parsing_strategy = delimited_parsing {
include_lines_pattern = "slot"
delimiters = ":"
selected_positions = 2
}
if_not_found_do = nop {}
}
}
step {
name = "Get Size"
parse_var_to_var {
from_var_name = "mem_desired"
to_var_names = "mem_size"
parsing_strategy = delimited_parsing {
include_lines_pattern = "size"
delimiters = ":"
selected_positions = 2
}
if_not_found_do = nop {}
}
}
step {
name = "Get Width"
parse_var_to_var {
from_var_name = "mem_desired"
to_var_names = "mem_width"
parsing_strategy = delimited_parsing {
include_lines_pattern = "width"
delimiters = ":"," "
selected_positions = 2
}
if_not_found_do = nop {}
}
}
step {
name = "Update cmdb_ci_memory_module"
if {
condition = is_not_empty {get_attr {"lshw_out"}}
on_true = transform {
src_table_name = "cmdb_ci_memory_module"
target_table_name = "cmdb_ci_memory_module"
operation {
set_field {
field_name = "form_factor"
value = get_attr {"mem_form_factor"}
}
set_field {
field_name = "type"
value = get_attr {"mem_type"}
}
set_field {
field_name = "type_detail"
value = get_attr {"mem_type_detail"}
}
set_field {
field_name = "bank_label"
value = get_attr {"mem_disp_name"}
}
set_field {
field_name = "device_locator"
value = get_attr {"mem_disp_name"}
}
set_field {
field_name = "name"
value = get_attr {"mem_disp_name"}
}
set_field {
field_name = "total_width"
value = get_attr {"mem_width"}
}
set_field {
field_name = "data_width"
value = get_attr {"mem_width"}
}
set_field {
field_name = "capacity"
value = eval {"str = \"\"
if (${mem_size})
{
if (${mem_size}.endsWith('GB') || ${mem_size}.endsWith('GiB'))
{
str = ${mem_size}.split('G')[0]
str = str.toInteger()
str = str * 1024
return str;
}
else if (${mem_size}.endsWith('MB') || ${mem_size}.endsWith('MiB'))
{
str = ${mem_size}.split('M')[0]
str = str.toInteger()
return str;
}
else
{
return ${mem_size};
}
}
else
return str;"}
}
}
}
on_false = nop {}
}
}
step {
name = "Get memory modules"
runcmd_to_var {
cmd = concat {
get_attr {"sudo"}
" dmidecode -t 17 | cat"
}
var_names = table {
name = "mem_mod"
col_names = "Mod"
}
parsing_strategy = regex_parsing {regex = "^(.*)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "translate GB to MB"
transform {
src_table_name = "mem_mod"
target_table_name = "mem_mod"
operation {set_field {
field_name = "Mod"
value = eval {"str = \"\"
if (${mem_mod[].Mod}.startsWith('Size:') && ${mem_mod[].Mod}.endsWith('GB'))
{
str = ${mem_mod[].Mod}.split(' ')[1]
str = str.toInteger()
str = str * 1024
return \"Size: \"+str+\" MB\"
}
else
{return ${mem_mod[].Mod}}"}
}}
}
}
step {
name = "Filter modules"
filter {
src_table_name = "mem_mod"
target_table_name = "mem_mod"
condition = any {
contains {
get_attr {"mem_mod[].Mod"}
"Total Width"
}
contains {
get_attr {"mem_mod[].Mod"}
"Data Width"
}
contains {
get_attr {"mem_mod[].Mod"}
"Size"
}
contains {
get_attr {"mem_mod[].Mod"}
"Form Factor"
}
contains {
get_attr {"mem_mod[].Mod"}
"Locator"
}
contains {
get_attr {"mem_mod[].Mod"}
"Bank Locator"
}
contains {
get_attr {"mem_mod[].Mod"}
"Type"
}
contains {
get_attr {"mem_mod[].Mod"}
"Speed"
}
contains {
get_attr {"mem_mod[].Mod"}
"Serial Number"
}
contains {
get_attr {"mem_mod[].Mod"}
"Part Number"
}
}
}
}
step {
name = "Filter DMI"
filter {
src_table_name = "mem_mod"
target_table_name = "mem_mod"
condition = not_contains {
get_attr {"mem_mod[].Mod"}
"DMI"
}
}
}
step {
name = "Create new modules table"
union {
table1_name = "MModules"
table2_name = "MModules"
result_table_name = "MModules"
}
}
step {
name = "Fill modules table"
if {
condition = is_not_empty {get_attr {"mem_mod"}}
on_true = set_attr {
"dump_var"
eval {"javascript: rtrun = function() {
rtrn = \"\";
var table = ${mem_mod};
if (table.size() == 0 )
return;
var rowed = table.get(0);
var row = rowed.clone();
for (var i = 0; i < table.size(); i++)
{
var map = table.get(i);
var str = map.get(\"Mod\");
var parts = str.split(\":\");
var name = parts[0].trim();
var value = parts[1].trim();
if (name == \"Total Width\")
{
row.remove(\"Mod\");
row.put(\"total_width\",value.split(\" \")[0]);
}
if (name == \"Data Width\")
{
row.put(\"data_width\",value.split(\" \")[0]);
}
if (name == \"Size\")
{
row.put(\"capacity\",((value == \"No Module Installed\") ? null : value.split(\" \")[0]));
}
if (name == \"Form Factor\")
{
row.put(\"form_factor\",(value.startsWith(\"FB-\")) ? value.split(\"-\")[1] : value);
}
if (name == \"Locator\")
{
row.put(\"device_locator\",value);
row.put(\"name\",value);
}
if (name == \"Bank Locator\")
{
row.put(\"bank_label\",((value == \"Not Specified\") ? null : value));
}
if (name == \"Type\")
{
row.put(\"type\",value.split(\" \")[0]);
}
if (name == \"Type Detail\")
{
row.put(\"type_detail\",value);
}
if (name == \"Speed\")
{
row.put(\"speed\",((value == \"Unknown\") ? null : value.split(\" \")[0]));
}
if (name == \"Serial Number\")
{
row.put(\"serial_number\",value);
}
if (name == \"Part Number\")
{
row.put(\"part_number\",value);
${MModules}.add(row);
row = rowed.clone();
}
}
rtrn = row;
return rtrn;
}();"}
}
on_false = nop {}
}
}
step {
name = "Filter modules"
filter {
src_table_name = "MModules"
target_table_name = "MModules"
condition = is_not_empty {get_attr {"MModules[].capacity"}}
}
}
step {
name = "Update cmdb_ci_memory_module"
if {
condition = is_empty {get_attr {"mem_disp_name"}}
on_true = transform {
src_table_name = "MModules"
target_table_name = "cmdb_ci_memory_module"
operation {set_field {
field_name = "total_width"
value = get_attr {"MModules[].total_width"}
}}
}
on_false = nop {}
}
}
step {
name = "Remove duplicate memory module"
set_attr {
"memeorydump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_memory_module}, [\"name\",\"serial_number\"]);
CTX.setAttribute(\"cmdb_ci_memory_module\", tableWithoutDuplicates);"}
}
}
step {
name = "Ref/Rel between cmdb_ci_memory_module and Linux CI"
relation_reference {
table1_name = "cmdb_ci_linux_server"
table2_name = "cmdb_ci_memory_module"
result_table_name = "mem_to_linux"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Contains::Contained by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
}
| library {
name = "Linux - Memory Modules"
id = "dc334fe39f2032001d753758442e70b7" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set the privileged command to use"
set_attr {
"sudo"
eval {"return ${ctx}.getDiscoveryProvider(com.snc.sw.dto.ProviderType.SSH).getPrivilegedCommand();"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Memory Modules without Restart"
runcmd_to_var {
cmd = concat {
get_attr {"sudo"}
" lshw"
}
execution_mode = "DEFAULT"
var_names = "lshw_out"
parsing_strategy = delimited_parsing {
selected_positions = 1
line_seperator = "nonExistingLineSeparator"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fetch Memory Module from Command Output"
if {
condition = is_not_empty {get_attr {"lshw_out"}}
on_true = set_attr {
"mem_desired"
eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var output = ${lshw_out};
var temp = output.split('*-bank');
if (temp[1]) {
if (temp[1].contains('*-'))
rtrn = temp[1].substring(0, temp[1].indexOf('*-'))
else
rtrn = temp[1];}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fetch Memory Attributes"
parse_var_to_var {
from_var_name = "mem_desired"
to_var_names = table {col_names = "mem_form_factor","mem_type","mem_type_detail"}
parsing_strategy = delimited_parsing {
include_lines_pattern = "description" // Script execution: Custom script to perform a specific action or collect data
delimiters = " "
selected_positions = 2,3,4
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Display Name"
parse_var_to_var {
from_var_name = "mem_desired"
to_var_names = "mem_disp_name"
parsing_strategy = delimited_parsing {
include_lines_pattern = "slot"
delimiters = ":"
selected_positions = 2
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Size"
parse_var_to_var {
from_var_name = "mem_desired"
to_var_names = "mem_size"
parsing_strategy = delimited_parsing {
include_lines_pattern = "size"
delimiters = ":"
selected_positions = 2
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Width"
parse_var_to_var {
from_var_name = "mem_desired"
to_var_names = "mem_width"
parsing_strategy = delimited_parsing {
include_lines_pattern = "width"
delimiters = ":"," "
selected_positions = 2
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_memory_module"
if {
condition = is_not_empty {get_attr {"lshw_out"}}
on_true = transform {
src_table_name = "cmdb_ci_memory_module"
target_table_name = "cmdb_ci_memory_module"
operation {
set_field {
field_name = "form_factor"
value = get_attr {"mem_form_factor"}
}
set_field {
field_name = "type"
value = get_attr {"mem_type"}
}
set_field {
field_name = "type_detail"
value = get_attr {"mem_type_detail"}
}
set_field {
field_name = "bank_label"
value = get_attr {"mem_disp_name"}
}
set_field {
field_name = "device_locator"
value = get_attr {"mem_disp_name"}
}
set_field {
field_name = "name"
value = get_attr {"mem_disp_name"}
}
set_field {
field_name = "total_width"
value = get_attr {"mem_width"}
}
set_field {
field_name = "data_width"
value = get_attr {"mem_width"}
}
set_field {
field_name = "capacity"
value = eval {"str = \"\"
if (${mem_size})
{
if (${mem_size}.endsWith('GB') || ${mem_size}.endsWith('GiB'))
{
str = ${mem_size}.split('G')[0]
str = str.toInteger()
str = str * 1024
return str;
}
else if (${mem_size}.endsWith('MB') || ${mem_size}.endsWith('MiB'))
{
str = ${mem_size}.split('M')[0]
str = str.toInteger()
return str;
}
else
{
return ${mem_size};
}
}
else
return str;"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get memory modules"
runcmd_to_var {
cmd = concat {
get_attr {"sudo"}
" dmidecode -t 17 | cat"
}
var_names = table {
name = "mem_mod"
col_names = "Mod"
}
parsing_strategy = regex_parsing {regex = "^(.*)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "translate GB to MB"
transform {
src_table_name = "mem_mod"
target_table_name = "mem_mod"
operation {set_field {
field_name = "Mod"
value = eval {"str = \"\"
if (${mem_mod[].Mod}.startsWith('Size:') && ${mem_mod[].Mod}.endsWith('GB'))
{
str = ${mem_mod[].Mod}.split(' ')[1]
str = str.toInteger()
str = str * 1024
return \"Size: \"+str+\" MB\"
}
else
{return ${mem_mod[].Mod}}"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter modules"
filter {
src_table_name = "mem_mod"
target_table_name = "mem_mod"
condition = any {
contains {
get_attr {"mem_mod[].Mod"}
"Total Width"
}
contains {
get_attr {"mem_mod[].Mod"}
"Data Width"
}
contains {
get_attr {"mem_mod[].Mod"}
"Size"
}
contains {
get_attr {"mem_mod[].Mod"}
"Form Factor"
}
contains {
get_attr {"mem_mod[].Mod"}
"Locator"
}
contains {
get_attr {"mem_mod[].Mod"}
"Bank Locator"
}
contains {
get_attr {"mem_mod[].Mod"}
"Type"
}
contains {
get_attr {"mem_mod[].Mod"}
"Speed"
}
contains {
get_attr {"mem_mod[].Mod"}
"Serial Number"
}
contains {
get_attr {"mem_mod[].Mod"}
"Part Number"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter DMI"
filter {
src_table_name = "mem_mod"
target_table_name = "mem_mod"
condition = not_contains {
get_attr {"mem_mod[].Mod"}
"DMI"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create new modules table"
union {
table1_name = "MModules"
table2_name = "MModules"
result_table_name = "MModules"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Fill modules table"
if {
condition = is_not_empty {get_attr {"mem_mod"}}
on_true = set_attr {
"dump_var"
eval {"javascript: rtrun = function() { // Script execution: Custom script to perform a specific action or collect data
rtrn = \"\";
var table = ${mem_mod};
if (table.size() == 0 )
return;
var rowed = table.get(0);
var row = rowed.clone();
for (var i = 0; i < table.size(); i++)
{
var map = table.get(i);
var str = map.get(\"Mod\");
var parts = str.split(\":\");
var name = parts[0].trim();
var value = parts[1].trim();
if (name == \"Total Width\")
{
row.remove(\"Mod\");
row.put(\"total_width\",value.split(\" \")[0]);
}
if (name == \"Data Width\")
{
row.put(\"data_width\",value.split(\" \")[0]);
}
if (name == \"Size\")
{
row.put(\"capacity\",((value == \"No Module Installed\") ? null : value.split(\" \")[0]));
}
if (name == \"Form Factor\")
{
row.put(\"form_factor\",(value.startsWith(\"FB-\")) ? value.split(\"-\")[1] : value);
}
if (name == \"Locator\")
{
row.put(\"device_locator\",value);
row.put(\"name\",value);
}
if (name == \"Bank Locator\")
{
row.put(\"bank_label\",((value == \"Not Specified\") ? null : value));
}
if (name == \"Type\")
{
row.put(\"type\",value.split(\" \")[0]);
}
if (name == \"Type Detail\")
{
row.put(\"type_detail\",value);
}
if (name == \"Speed\")
{
row.put(\"speed\",((value == \"Unknown\") ? null : value.split(\" \")[0]));
}
if (name == \"Serial Number\")
{
row.put(\"serial_number\",value);
}
if (name == \"Part Number\")
{
row.put(\"part_number\",value);
${MModules}.add(row);
row = rowed.clone();
}
}
rtrn = row;
return rtrn;
}();"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter modules"
filter {
src_table_name = "MModules"
target_table_name = "MModules"
condition = is_not_empty {get_attr {"MModules[].capacity"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update cmdb_ci_memory_module"
if {
condition = is_empty {get_attr {"mem_disp_name"}}
on_true = transform {
src_table_name = "MModules"
target_table_name = "cmdb_ci_memory_module"
operation {set_field {
field_name = "total_width"
value = get_attr {"MModules[].total_width"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate memory module"
set_attr {
"memeorydump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_ci_memory_module}, [\"name\",\"serial_number\"]);
CTX.setAttribute(\"cmdb_ci_memory_module\", tableWithoutDuplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref/Rel between cmdb_ci_memory_module and Linux CI"
relation_reference {
table1_name = "cmdb_ci_linux_server"
table2_name = "cmdb_ci_memory_module"
result_table_name = "mem_to_linux"
unmatched_lines = remove
condition = eq {
"1"
"1"
}
relation_type = "Contains::Contained by"
ref_direction = childToParent
ref_field_name = "cmdb_ci"
}
}
}
|
Generate SBOM shared library | I would like for you to help me build a Pattern that helps achieve Discovery of Generate SBOM shared library. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Generate SBOM shared library"
id = "d63bbebd97c56590fb5d317c1253afe1"
description = "null"
step {
name = "set default sbom output format"
if {
condition = all {
is_empty {get_attr {"sbom_format"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
}
on_true = set_attr {
"sbom_format"
"cyclonedx"
}
on_false = nop {}
}
}
step {
name = "Build the SBOM command"
if {
condition = all {
is_not_empty {get_attr {"image_name"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
}
on_true = set_attr {
"cmd_sbom"
concat {
"./work/uploaded_files/trivy image --format "
get_attr {"sbom_format"}
" --timeout "
get_attr {"trivyTimeout"}
"s "
" "
get_attr {"image_name"}
" 2> /dev/null"
}
}
on_false = nop {}
}
}
step {
name = "Run trivy SBOM command"
comment = "Don't gracefully terminate this pattern even if trivy command fails.
Pre-sensor script will update the message value in the sn_itom_pattern_container_image_scan_status table with trivy command failure message."
if {
condition = all {
is_not_empty {get_attr {"cmd_sbom"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
}
on_true = set_attr {
"output_sbom"
eval {"javascript: var rtrn='';
var result = '';
var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Scan Container Image \");
var command = ${cmd_sbom};
var runner = new Packages.com.snc.sw.context.support.proc.LocalCommandRunner();
var timeoutValue = 240000; /* 240 seconds or 4 minutes */
var timeout = parseInt(timeoutValue);
var sbomFormat = ${sbom_format};
logger.debug(\" Run Trivy: Execting Trivy command is \"+ command + \" and timeout value is \"+ timeout);
runner.executeCommandWithTimeout(command,timeout);
if (runner.getStderr()) {
logger.debug(\" Run Trivy: Trivy command \"+ command + \" returned failed with error message -\" + runner.getStderr());
CTX.setAttribute(\"error_message\", runner.getStderr());
rtrn = 'Failed to Generate SBOM: May be this image doesn\u2019t support given sbom output format';
}else{
var resultSBOM = runner.getStdout();
logger.debug(\" Run Trivy: Trivy command \"+ command + \" executed successfully\");
if(sbomFormat != 'spdx'){
result = resultSBOM.substring(resultSBOM.indexOf('{'),resultSBOM.lastIndexOf('}')+1);
if(isValidJson(result)){
rtrn = result;
}
}else{
if(verifySpdxSBOM(resultSBOM)){
rtrn = resultSBOM;
}
}
}
rtrn;
function isValidJson(json) {
try {
JSON.parse(json);
return true;
} catch (e) {
return false;
}
}
function verifySpdxSBOM(content) {
if (content.indexOf('SPDXID')>0) {
return true;
}else{
return false;
}
}"}
}
on_false = nop {}
}
}
step {
name = "Failover of Build the SBOM command"
if {
condition = all {
is_not_empty {get_attr {"image_name"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
is_empty {get_attr {"output_sbom"}}
}
on_true = set_attr {
"cmd_sbom2"
concat {
"trivy image --format "
get_attr {"sbom_format"}
" --timeout "
get_attr {"trivyTimeout"}
"s "
" "
get_attr {"image_name"}
" 2> /dev/null"
}
}
on_false = nop {}
}
}
step {
name = "Failover of Run trivy SBOM command"
comment = "Don't gracefully terminate this pattern even if trivy command fails.
Pre-sensor script will update the message value in the sn_itom_pattern_container_image_scan_status table with trivy command failure message."
if {
condition = all {
is_not_empty {get_attr {"cmd_sbom2"}}
is_empty {get_attr {"output_sbom"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
}
on_true = set_attr {
"output_sbom"
eval {"javascript: var rtrn='';
var result = '';
var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Scan Container Image \");
var command = ${cmd_sbom2};
var runner = new Packages.com.snc.sw.context.support.proc.LocalCommandRunner();
var timeoutValue = 240000; /* 240 seconds or 4 minutes */
var timeout = parseInt(timeoutValue);
var sbomFormat = ${sbom_format};
logger.debug(\" Run Trivy: Execting Trivy command is \"+ command + \" and timeout value is \"+ timeout);
runner.executeCommandWithTimeout(command,timeout);
if (runner.getStderr()) {
logger.debug(\" Run Trivy: Trivy command \"+ command + \" returned failed with error message -\" + runner.getStderr());
CTX.setAttribute(\"error_message\", runner.getStderr());
rtrn = 'Failed to Generate SBOM: May be this image doesn\u2019t support given sbom output format';
}else{
var resultSBOM = runner.getStdout();
logger.debug(\" Run Trivy: Trivy command \"+ command + \" executed successfully\");
if(sbomFormat != 'spdx'){
result = resultSBOM.substring(resultSBOM.indexOf('{'),resultSBOM.lastIndexOf('}')+1);
if(isValidJson(result)){
rtrn = result;
}
}else{
if(verifySpdxSBOM(resultSBOM)){
rtrn = resultSBOM;
}
}
}
rtrn;
function isValidJson(json) {
try {
JSON.parse(json);
return true;
} catch (e) {
return false;
}
}
function verifySpdxSBOM(content) {
if (content.indexOf('SPDXID')>0) {
return true;
}else{
return false;
}
}"}
}
on_false = nop {}
}
}
step {
name = "Validate SBOM json"
if {
condition = all {
neq {
get_attr {"sbom_format"}
"spdx"
}
is_not_empty {get_attr {"output_sbom"}}
}
on_true = set_attr {
"isValidSBOM"
eval {"javascript: var sbom = ${output_sbom};
var rtrn = '';
if(sbom){
rtrn = isValidJson(sbom);
}else{
rtrn = false;
}
function isValidJson(json) {
if (typeof json !== \"string\") {
return false;
}
try {
JSON.parse(json);
return true;
} catch (error) {
return false;
}
}"}
}
on_false = nop {}
}
}
step {
name = "Validate SPDX SBOM Content"
if {
condition = all {
eq {
get_attr {"sbom_format"}
"spdx"
}
is_not_empty {get_attr {"output_sbom"}}
}
on_true = set_attr {
"isValidSBOM"
eval {"javascript: var sbom = ${output_sbom};
var rtrn = '';
if(sbom){
rtrn = isValidSBOM(sbom);
}else{
rtrn = false;
}
function isValidSBOM(content) {
if (typeof content == \"string\" && content.indexOf('SPDXID')>0) {
return true;
}else{
return false;
}
}"}
}
on_false = nop {}
}
}
step {
name = "populate SBOM data"
if {
condition = is_not_empty {get_attr {"output_sbom"}}
on_true = transform {
src_table_name = "cmdb_ci_docker_image"
target_table_name = "cmdb_ci_docker_image"
operation {
set_field {
field_name = "attributes"
value = get_attr {"output_sbom"}
}
set_field {
field_name = "sys_id"
value = get_attr {"image_sys_id"}
}
}
}
on_false = nop {}
}
}
}
| library {
name = "Generate SBOM shared library"
id = "d63bbebd97c56590fb5d317c1253afe1" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set default sbom output format"
if {
condition = all {
is_empty {get_attr {"sbom_format"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
}
on_true = set_attr {
"sbom_format"
"cyclonedx"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Build the SBOM command"
if {
condition = all {
is_not_empty {get_attr {"image_name"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
}
on_true = set_attr {
"cmd_sbom"
concat {
"./work/uploaded_files/trivy image --format "
get_attr {"sbom_format"}
" --timeout "
get_attr {"trivyTimeout"}
"s "
" "
get_attr {"image_name"}
" 2> /dev/null"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Run trivy SBOM command"
comment = "Don't gracefully terminate this pattern even if trivy command fails.
Pre-sensor script will update the message value in the sn_itom_pattern_container_image_scan_status table with trivy command failure message." // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"cmd_sbom"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
}
on_true = set_attr {
"output_sbom"
eval {"javascript: var rtrn=''; // Script execution: Custom script to perform a specific action or collect data
var result = '';
var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Scan Container Image \");
var command = ${cmd_sbom};
var runner = new Packages.com.snc.sw.context.support.proc.LocalCommandRunner();
var timeoutValue = 240000; /* 240 seconds or 4 minutes */
var timeout = parseInt(timeoutValue);
var sbomFormat = ${sbom_format};
logger.debug(\" Run Trivy: Execting Trivy command is \"+ command + \" and timeout value is \"+ timeout);
runner.executeCommandWithTimeout(command,timeout);
if (runner.getStderr()) {
logger.debug(\" Run Trivy: Trivy command \"+ command + \" returned failed with error message -\" + runner.getStderr());
CTX.setAttribute(\"error_message\", runner.getStderr());
rtrn = 'Failed to Generate SBOM: May be this image doesn\u2019t support given sbom output format';
}else{
var resultSBOM = runner.getStdout();
logger.debug(\" Run Trivy: Trivy command \"+ command + \" executed successfully\");
if(sbomFormat != 'spdx'){
result = resultSBOM.substring(resultSBOM.indexOf('{'),resultSBOM.lastIndexOf('}')+1);
if(isValidJson(result)){
rtrn = result;
}
}else{
if(verifySpdxSBOM(resultSBOM)){
rtrn = resultSBOM;
}
}
}
rtrn;
function isValidJson(json) {
try {
JSON.parse(json);
return true;
} catch (e) {
return false;
}
}
function verifySpdxSBOM(content) {
if (content.indexOf('SPDXID')>0) {
return true;
}else{
return false;
}
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Failover of Build the SBOM command"
if {
condition = all {
is_not_empty {get_attr {"image_name"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
is_empty {get_attr {"output_sbom"}}
}
on_true = set_attr {
"cmd_sbom2"
concat {
"trivy image --format "
get_attr {"sbom_format"}
" --timeout "
get_attr {"trivyTimeout"}
"s "
" "
get_attr {"image_name"}
" 2> /dev/null"
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Failover of Run trivy SBOM command"
comment = "Don't gracefully terminate this pattern even if trivy command fails.
Pre-sensor script will update the message value in the sn_itom_pattern_container_image_scan_status table with trivy command failure message." // Script execution: Custom script to perform a specific action or collect data
if {
condition = all {
is_not_empty {get_attr {"cmd_sbom2"}}
is_empty {get_attr {"output_sbom"}}
not_contains {
get_attr {"sbom_format"}
"none"
}
}
on_true = set_attr {
"output_sbom"
eval {"javascript: var rtrn=''; // Script execution: Custom script to perform a specific action or collect data
var result = '';
var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Scan Container Image \");
var command = ${cmd_sbom2};
var runner = new Packages.com.snc.sw.context.support.proc.LocalCommandRunner();
var timeoutValue = 240000; /* 240 seconds or 4 minutes */
var timeout = parseInt(timeoutValue);
var sbomFormat = ${sbom_format};
logger.debug(\" Run Trivy: Execting Trivy command is \"+ command + \" and timeout value is \"+ timeout);
runner.executeCommandWithTimeout(command,timeout);
if (runner.getStderr()) {
logger.debug(\" Run Trivy: Trivy command \"+ command + \" returned failed with error message -\" + runner.getStderr());
CTX.setAttribute(\"error_message\", runner.getStderr());
rtrn = 'Failed to Generate SBOM: May be this image doesn\u2019t support given sbom output format';
}else{
var resultSBOM = runner.getStdout();
logger.debug(\" Run Trivy: Trivy command \"+ command + \" executed successfully\");
if(sbomFormat != 'spdx'){
result = resultSBOM.substring(resultSBOM.indexOf('{'),resultSBOM.lastIndexOf('}')+1);
if(isValidJson(result)){
rtrn = result;
}
}else{
if(verifySpdxSBOM(resultSBOM)){
rtrn = resultSBOM;
}
}
}
rtrn;
function isValidJson(json) {
try {
JSON.parse(json);
return true;
} catch (e) {
return false;
}
}
function verifySpdxSBOM(content) {
if (content.indexOf('SPDXID')>0) {
return true;
}else{
return false;
}
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Validate SBOM json"
if {
condition = all {
neq {
get_attr {"sbom_format"}
"spdx"
}
is_not_empty {get_attr {"output_sbom"}}
}
on_true = set_attr {
"isValidSBOM"
eval {"javascript: var sbom = ${output_sbom}; // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
if(sbom){
rtrn = isValidJson(sbom);
}else{
rtrn = false;
}
function isValidJson(json) {
if (typeof json !== \"string\") {
return false;
}
try {
JSON.parse(json);
return true;
} catch (error) {
return false;
}
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Validate SPDX SBOM Content"
if {
condition = all {
eq {
get_attr {"sbom_format"}
"spdx"
}
is_not_empty {get_attr {"output_sbom"}}
}
on_true = set_attr {
"isValidSBOM"
eval {"javascript: var sbom = ${output_sbom}; // Script execution: Custom script to perform a specific action or collect data
var rtrn = '';
if(sbom){
rtrn = isValidSBOM(sbom);
}else{
rtrn = false;
}
function isValidSBOM(content) {
if (typeof content == \"string\" && content.indexOf('SPDXID')>0) {
return true;
}else{
return false;
}
}"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "populate SBOM data"
if {
condition = is_not_empty {get_attr {"output_sbom"}}
on_true = transform {
src_table_name = "cmdb_ci_docker_image"
target_table_name = "cmdb_ci_docker_image"
operation {
set_field {
field_name = "attributes" // Attribute collection: Collects specific attributes from the discovered CI
value = get_attr {"output_sbom"}
}
set_field {
field_name = "sys_id"
value = get_attr {"image_sys_id"}
}
}
}
on_false = nop {}
}
}
}
|
Azure - Database Convert Json to XML | I would like for you to help me build a Pattern that helps achieve Discovery of Azure - Database Convert Json to XML. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure - Database Convert Json to XML"
id = "d6dd7326531332008ec4b6eccec5874d"
description = "null"
step {
name = "Check if there was a timeout"
filter {
src_table_name = "databases_table_generic"
target_table_name = "databases_table_generic_timeout"
condition = contains {
get_attr {"databases_table_generic[].database_info"}
"timed out"
}
}
}
step {
name = "Quit pattern if timeout-try to increase cloud timeout on MID parameters"
match {
is_empty {get_attr {"databases_table_generic_timeout"}}
terminate_op = terminate
terminate_msg = ""
}
}
step {
name = "Change format from Json to XML"
if {
condition = is_not_empty {get_attr {"databases_table_generic[1].database_info"}}
on_true = transform {
src_table_name = "databases_table_generic"
target_table_name = "databases_table_generic"
operation {set_field {
field_name = "db_info_xml"
value = eval {"def o = ${databases_table_generic[].database_info};
def xml = '';
o = '{\"objects\":' + o + '}';
def json_obj = new org.json.JSONObject(o);
xml += org.json.XML.toString(json_obj) + \"\\n\";
return xml;"}
}}
}
on_false = nop {}
}
}
step {
name = "Remove empty lines"
parse_var_to_var {
from_var_name = "databases_table_generic[*].db_info_xml"
to_var_names = table {
name = "xml"
col_names = "line"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step {
name = "Combine XMLs to one XML"
set_attr {
"database_info_table_generic"
eval {"res = \"\"
arry = ${xml[*].line}
for (i=0;i<arry.size();i++)
{
res = res + arry[i]
}
return \"<xml>\" + res + \"</xml>\""}
}
}
step {
name = "Clear generic table"
filter {
src_table_name = "databases_table_generic"
target_table_name = "databases_table_generic"
condition = contains {
"1"
"2"
}
}
}
}
| library {
name = "Azure - Database Convert Json to XML"
id = "d6dd7326531332008ec4b6eccec5874d" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check if there was a timeout"
filter {
src_table_name = "databases_table_generic"
target_table_name = "databases_table_generic_timeout"
condition = contains {
get_attr {"databases_table_generic[].database_info"}
"timed out"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Quit pattern if timeout-try to increase cloud timeout on MID parameters"
match {
is_empty {get_attr {"databases_table_generic_timeout"}}
terminate_op = terminate
terminate_msg = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Change format from Json to XML"
if {
condition = is_not_empty {get_attr {"databases_table_generic[1].database_info"}}
on_true = transform {
src_table_name = "databases_table_generic"
target_table_name = "databases_table_generic"
operation {set_field {
field_name = "db_info_xml"
value = eval {"def o = ${databases_table_generic[].database_info};
def xml = '';
o = '{\"objects\":' + o + '}';
def json_obj = new org.json.JSONObject(o);
xml += org.json.XML.toString(json_obj) + \"\\n\";
return xml;"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove empty lines"
parse_var_to_var {
from_var_name = "databases_table_generic[*].db_info_xml"
to_var_names = table {
name = "xml"
col_names = "line"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Combine XMLs to one XML"
set_attr {
"database_info_table_generic"
eval {"res = \"\"
arry = ${xml[*].line}
for (i=0;i<arry.size();i++)
{
res = res + arry[i]
}
return \"<xml>\" + res + \"</xml>\""}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Clear generic table"
filter {
src_table_name = "databases_table_generic"
target_table_name = "databases_table_generic"
condition = contains {
"1"
"2"
}
}
}
}
|
Get Cassandra Cluster and Cluster Nodes - Unix | I would like for you to help me build a Pattern that helps achieve Discovery of Get Cassandra Cluster and Cluster Nodes - Unix. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Get Cassandra Cluster and Cluster Nodes - Unix"
id = "d879b24c1b2d90907e0e31901a4bcb45"
description = "Get Cassandra Cluster and Cluster Nodes - Unix"
step {
name = "Check for HD Mode"
comment = "Extension section is used to discover all cassandra inventory (Cluster, Cluster Nodes and Keyspace CIs).
This ES is meant to run only for HD mode, so checking the discovery mode."
match {
eq {
get_attr {"pattern_runtime_mode"}
"horizontal"
}
terminate_op = graceful
terminate_msg = "This ES runs only in Horizontal Discovery"
}
}
step {
name = "Check for OS Type"
comment = "This ES is meant to run only for UNIX OS Family and so was the check. Separate ES will be created to support Windows OS Family if required."
match {
contains {
get_attr {"computer_system.osFamily"}
"UNIX"
}
terminate_op = graceful
terminate_msg = "This ES runs only for Unix OS Family"
}
}
step {
name = "Get Keyspaces"
runcmd_to_var {
cmd = concat {
get_attr {"exec_method"}
" tablestats"
}
var_names = table {
name = "keyspaces"
col_names = "keyspace"
}
parsing_strategy = regex_parsing {regex = "Keyspace : (\\S*)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Insert data to cmdb_ci_cassandra_cluster"
if {
condition = is_not_empty {get_attr {"cluster_name"}}
on_true = transform {
src_table_name = "cmdb_ci_cassandra_cluster"
target_table_name = "cmdb_ci_cassandra_cluster"
operation {
set_field {
field_name = "name"
value = get_attr {"cluster_name"}
}
set_field {
field_name = "ip_address"
value = get_attr {"computer_system.managementIP"}
}
}
}
on_false = nop {}
}
}
step {
name = "Insert data to cmdb_ci_cassandra_cluster_node"
comment = "Cluster node is ideally a host server, so the server field populated here is updated with server CI as a reference and relation will be created to the host server in pre and post sensor scripts."
if {
condition = is_not_empty {get_attr {"cluster_name"}}
on_true = transform {
src_table_name = "cmdb_ci_cassandra_cluster_node"
target_table_name = "cmdb_ci_cassandra_cluster_node"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"cluster_name"}
"@"
get_attr {"computer_system.primaryHostname"}
}
}
set_field {
field_name = "cluster_name"
value = get_attr {"cluster_name"}
}
set_field {
field_name = "ip_address"
value = get_attr {"computer_system.managementIP"}
}
set_field {
field_name = "operational_status"
value = "1"
}
set_field {
field_name = "server"
value = get_attr {"computer_system.primaryHostname"}
}
}
}
on_false = nop {}
}
}
step {
name = "Insert keyspaces data to cmdb_ci_cassandra_keyspace"
if {
condition = all {
is_not_empty {get_attr {"keyspaces"}}
is_not_empty {get_attr {"cluster_name"}}
}
on_true = transform {
src_table_name = "keyspaces"
target_table_name = "cmdb_ci_cassandra_keyspace"
operation {
set_field {
field_name = "keyspace_name"
value = get_attr {"keyspaces[].keyspace"}
}
set_field {
field_name = "cluster_name"
value = get_attr {"cluster_name"}
}
set_field {
field_name = "name"
value = concat {
get_attr {"keyspaces[].keyspace"}
"@"
get_attr {"cluster_name"}
}
}
}
}
on_false = nop {}
}
}
step {
name = "Reference and Relation between cmdb_ci_cassandra_keyspace to cmdb_ci_cassandra_cluster"
comment = "As Cassandra is distributed db, keyspace is a distributed entity which will be same across all cluster nodes of a particular cluster. So is this hosted on relation with cluster."
relation_reference {
table1_name = "cmdb_ci_cassandra_keyspace"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cassandra_cluster"
key2_name = "name"
result_table_name = "clus_keyspc"
unmatched_lines = keep
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = "cluster"
}
}
step {
name = "Reference and Relation between cmdb_ci_cassandra_cluster_node to cmdb_ci_cassandra_cluster"
relation_reference {
table1_name = "cmdb_ci_cassandra_cluster_node"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cassandra_cluster"
key2_name = "name"
result_table_name = "clstr_clstrnode"
unmatched_lines = keep
relation_type = "Cluster of::Cluster"
ref_direction = parentToChild
ref_field_name = "cluster"
}
}
step {
name = "Reference and Relation between cmdb_ci_cassandra_instance to cmdb_ci_cassandra_cluster_node"
relation_reference {
table1_name = "cmdb_ci_cassandra_instance"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cassandra_cluster_node"
key2_name = "cluster_name"
result_table_name = "inst_clstrnode"
unmatched_lines = keep
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
}
}
| library {
name = "Get Cassandra Cluster and Cluster Nodes - Unix"
id = "d879b24c1b2d90907e0e31901a4bcb45" // Unique identifier for the pattern
description = "Get Cassandra Cluster and Cluster Nodes - Unix" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check for HD Mode"
comment = "Extension section is used to discover all cassandra inventory (Cluster, Cluster Nodes and Keyspace CIs).
This ES is meant to run only for HD mode, so checking the discovery mode."
match {
eq {
get_attr {"pattern_runtime_mode"}
"horizontal"
}
terminate_op = graceful
terminate_msg = "This ES runs only in Horizontal Discovery"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check for OS Type"
comment = "This ES is meant to run only for UNIX OS Family and so was the check. Separate ES will be created to support Windows OS Family if required."
match {
contains {
get_attr {"computer_system.osFamily"}
"UNIX"
}
terminate_op = graceful
terminate_msg = "This ES runs only for Unix OS Family"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Keyspaces"
runcmd_to_var {
cmd = concat {
get_attr {"exec_method"}
" tablestats"
}
var_names = table {
name = "keyspaces"
col_names = "keyspace"
}
parsing_strategy = regex_parsing {regex = "Keyspace : (\\S*)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert data to cmdb_ci_cassandra_cluster"
if {
condition = is_not_empty {get_attr {"cluster_name"}}
on_true = transform {
src_table_name = "cmdb_ci_cassandra_cluster"
target_table_name = "cmdb_ci_cassandra_cluster"
operation {
set_field {
field_name = "name"
value = get_attr {"cluster_name"}
}
set_field {
field_name = "ip_address"
value = get_attr {"computer_system.managementIP"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert data to cmdb_ci_cassandra_cluster_node"
comment = "Cluster node is ideally a host server, so the server field populated here is updated with server CI as a reference and relation will be created to the host server in pre and post sensor scripts." // Script execution: Custom script to perform a specific action or collect data
if {
condition = is_not_empty {get_attr {"cluster_name"}}
on_true = transform {
src_table_name = "cmdb_ci_cassandra_cluster_node"
target_table_name = "cmdb_ci_cassandra_cluster_node"
operation {
set_field {
field_name = "name"
value = concat {
get_attr {"cluster_name"}
"@"
get_attr {"computer_system.primaryHostname"}
}
}
set_field {
field_name = "cluster_name"
value = get_attr {"cluster_name"}
}
set_field {
field_name = "ip_address"
value = get_attr {"computer_system.managementIP"}
}
set_field {
field_name = "operational_status"
value = "1"
}
set_field {
field_name = "server"
value = get_attr {"computer_system.primaryHostname"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert keyspaces data to cmdb_ci_cassandra_keyspace"
if {
condition = all {
is_not_empty {get_attr {"keyspaces"}}
is_not_empty {get_attr {"cluster_name"}}
}
on_true = transform {
src_table_name = "keyspaces"
target_table_name = "cmdb_ci_cassandra_keyspace"
operation {
set_field {
field_name = "keyspace_name"
value = get_attr {"keyspaces[].keyspace"}
}
set_field {
field_name = "cluster_name"
value = get_attr {"cluster_name"}
}
set_field {
field_name = "name"
value = concat {
get_attr {"keyspaces[].keyspace"}
"@"
get_attr {"cluster_name"}
}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference and Relation between cmdb_ci_cassandra_keyspace to cmdb_ci_cassandra_cluster"
comment = "As Cassandra is distributed db, keyspace is a distributed entity which will be same across all cluster nodes of a particular cluster. So is this hosted on relation with cluster."
relation_reference {
table1_name = "cmdb_ci_cassandra_keyspace"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cassandra_cluster"
key2_name = "name"
result_table_name = "clus_keyspc"
unmatched_lines = keep
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = "cluster"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference and Relation between cmdb_ci_cassandra_cluster_node to cmdb_ci_cassandra_cluster"
relation_reference {
table1_name = "cmdb_ci_cassandra_cluster_node"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cassandra_cluster"
key2_name = "name"
result_table_name = "clstr_clstrnode"
unmatched_lines = keep
relation_type = "Cluster of::Cluster"
ref_direction = parentToChild
ref_field_name = "cluster"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference and Relation between cmdb_ci_cassandra_instance to cmdb_ci_cassandra_cluster_node"
relation_reference {
table1_name = "cmdb_ci_cassandra_instance"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cassandra_cluster_node"
key2_name = "cluster_name"
result_table_name = "inst_clstrnode"
unmatched_lines = keep
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
}
}
|
HP-UX - Total Memory | I would like for you to help me build a Pattern that helps achieve Discovery of HP-UX - Total Memory. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "HP-UX - Total Memory"
id = "d95338779fa032001d753758442e70ad"
description = ""
step {
name = "Extract memory from machine data"
parse_var_to_var {
from_var_name = "machine_data"
to_var_names = table {
name = "Memory"
col_names = "Memory"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "Memory"
delimiters = " ","="
selected_positions = 2
}
if_not_found_do = nop {}
}
}
step {
name = "Update memory in HPUX CI"
set_attr {
"cmdb_ci_hpux_server[*].ram"
get_attr {"Memory[1].Memory"}
}
}
}
| library {
name = "HP-UX - Total Memory"
id = "d95338779fa032001d753758442e70ad" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Extract memory from machine data"
parse_var_to_var {
from_var_name = "machine_data"
to_var_names = table {
name = "Memory"
col_names = "Memory"
}
parsing_strategy = delimited_parsing {
include_lines_pattern = "Memory"
delimiters = " ","="
selected_positions = 2
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Update memory in HPUX CI"
set_attr {
"cmdb_ci_hpux_server[*].ram"
get_attr {"Memory[1].Memory"}
}
}
}
|
Set Edition if empty | I would like for you to help me build a Pattern that helps achieve Discovery of Set Edition if empty. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Set Edition if empty"
id = "d9a997651ba3d414b1b8542f0a4bcb7a"
description = "Set Edition if empty"
step {
name = "verify edition is empty"
match {
is_empty {get_attr {"cmdb_ci_db_mssql_instance[1].edition"}}
terminate_op = terminate
terminate_msg = "Edition value is already populated "
}
}
step {
name = "build the command line"
parse_var_to_var {
from_var_name = "process.commandLine"
to_var_names = table {col_names = "sqlservr_path","cmd_args"}
parsing_strategy = regex_parsing {regex = "([^\"]*sqlservr)[^-]*(-.*-s[^\\s]*)"}
if_not_found_do = nop {}
}
}
step {
name = "build the command line 2"
if {
condition = is_empty {get_attr {"sqlservr_path"}}
on_true = parse_var_to_var {
from_var_name = "process.commandLine"
to_var_names = table {col_names = "sqlservr_path","cmd_args"}
parsing_strategy = regex_parsing {regex = "([^\"]*sqlservr)[^-]*(-s[^\\s]*)"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "set edition if empty"
runcmd_to_var {
cmd = concat {
"\""
get_attr {"sqlservr_path"}
"\" -v "
get_attr {"cmd_args"}
}
var_names = "edition"
parsing_strategy = regex_parsing {regex = "(.*Edition.*)\\s+on\\s+"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "setedition if empty 2"
if {
condition = is_empty {get_attr {"edition"}}
on_true = runcmd_to_var {
cmd = concat {
"\""
get_attr {"sqlservr_path"}
"\" -v "
get_attr {"cmd_args"}
}
var_names = "edition"
parsing_strategy = regex_parsing {regex = "(.*Database.*)\\s+on\\s+"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "set edition if not empty"
if {
condition = is_not_empty {get_attr {"edition"}}
on_true = transform {
src_table_name = "cmdb_ci_db_mssql_instance"
target_table_name = "cmdb_ci_db_mssql_instance"
operation {set_field {
field_name = "edition"
value = get_attr {"edition"}
}}
}
on_false = nop {}
}
}
}
| library {
name = "Set Edition if empty"
id = "d9a997651ba3d414b1b8542f0a4bcb7a" // Unique identifier for the pattern
description = "Set Edition if empty" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "verify edition is empty"
match {
is_empty {get_attr {"cmdb_ci_db_mssql_instance[1].edition"}}
terminate_op = terminate
terminate_msg = "Edition value is already populated "
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "build the command line"
parse_var_to_var {
from_var_name = "process.commandLine"
to_var_names = table {col_names = "sqlservr_path","cmd_args"}
parsing_strategy = regex_parsing {regex = "([^\"]*sqlservr)[^-]*(-.*-s[^\\s]*)"}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "build the command line 2"
if {
condition = is_empty {get_attr {"sqlservr_path"}}
on_true = parse_var_to_var {
from_var_name = "process.commandLine"
to_var_names = table {col_names = "sqlservr_path","cmd_args"}
parsing_strategy = regex_parsing {regex = "([^\"]*sqlservr)[^-]*(-s[^\\s]*)"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set edition if empty"
runcmd_to_var {
cmd = concat {
"\""
get_attr {"sqlservr_path"}
"\" -v "
get_attr {"cmd_args"}
}
var_names = "edition"
parsing_strategy = regex_parsing {regex = "(.*Edition.*)\\s+on\\s+"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "setedition if empty 2"
if {
condition = is_empty {get_attr {"edition"}}
on_true = runcmd_to_var {
cmd = concat {
"\""
get_attr {"sqlservr_path"}
"\" -v "
get_attr {"cmd_args"}
}
var_names = "edition"
parsing_strategy = regex_parsing {regex = "(.*Database.*)\\s+on\\s+"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set edition if not empty"
if {
condition = is_not_empty {get_attr {"edition"}}
on_true = transform {
src_table_name = "cmdb_ci_db_mssql_instance"
target_table_name = "cmdb_ci_db_mssql_instance"
operation {set_field {
field_name = "edition"
value = get_attr {"edition"}
}}
}
on_false = nop {}
}
}
}
|
CloudFoundry Droplets | I would like for you to help me build a Pattern that helps achieve Discovery of CloudFoundry Droplets. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "CloudFoundry Droplets"
id = "db90b5ec476b9590ad02906a436d4303"
description = ""
step {
name = "Get Droplets"
comment = "Get Droplets is only available for V3 of the API calls."
custom_operation {
attributes {
attribute {
name = "resource"
value = "droplets"
}
attribute {
name = "api_version"
value = "v3"
}
attribute {
name = "response_name"
value = "response"
}
}
sys_id_op = "5ed749eedb8da700f1d2f3451d96196a"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "Parse the droplets"
if {
condition = eq {
get_attr {"api_version_used"}
"v3"
}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "droplets"
}
attribute {
name = "target_columns"
value = "pcf_guid:resources.guid, url:resources.links.self.href, app_url:resources.links.app.href"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Filter droplets table on apps"
if {
condition = neq {
get_attr {"Organization"}
"*"
}
on_true = merge {
table1_name = "droplets"
key1_name = "app_url"
table2_name = "apps"
key2_name = "url"
result_table_name = "droplets"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "Parse droplets tags"
if {
condition = all {
eq {
get_attr {"api_version_used"}
"v3"
}
is_not_empty {get_attr {"droplets"}}
}
on_true = custom_operation {
attributes {
attribute {
name = "source"
value = "response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "droplets_tags"
}
attribute {
name = "target_columns"
value = "pcf_guid:resources.guid,label_key:resources.metadata.labels.*,annotation_key:resources.metadata.annotations.*"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step {
name = "Filter out empty key rows"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = filter {
src_table_name = "droplets_tags"
target_table_name = "droplets_tags"
condition = any {
is_not_empty {get_attr {"droplets_tags[].label_key"}}
is_not_empty {get_attr {"droplets_tags[].annotation_key"}}
}
}
on_false = nop {}
}
}
step {
name = "Filter out tags based on selected organizations"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = merge {
table1_name = "droplets_tags"
key1_name = "pcf_guid"
table2_name = "droplets"
key2_name = "pcf_guid"
result_table_name = "droplets_tags"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = " Modify the droplet tags"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = transform {
src_table_name = "droplets_tags"
target_table_name = "droplets_tags"
operation {
set_field {
field_name = "key"
value = eval {"javascript: var rtrn = '';
var label_key = ${droplets_tags[].label_key};
var annotation_key = ${droplets_tags[].annotation_key}
if (label_key) {
rtrn = label_key;
} else if (annotation_key) {
rtrn = annotation_key;
}
rtrn;"}
}
set_field {
field_name = "value"
value = eval {"javascript: var rtrn = '';
var label_key = ${droplets_tags[].label_key_value};
var annotation_key = ${droplets_tags[].annotation_key_value}
if (label_key) {
rtrn = label_key;
} else if (annotation_key) {
rtrn = annotation_key;
}
rtrn;"}
}
}
}
on_false = nop {}
}
}
step {
name = "\u0410dd the droplets tags to the cmdb_key_value table"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = union {
table1_name = "cmdb_key_value"
table2_name = "droplets_tags"
result_table_name = "cmdb_key_value"
}
on_false = nop {}
}
}
step {
name = "Populate cmdb_ci_pcf_droplet"
if {
condition = is_not_empty {get_attr {"droplets"}}
on_true = transform {
src_table_name = "droplets"
target_table_name = "cmdb_ci_pcf_droplet"
operation {
set_field {
field_name = "name"
value = get_attr {"droplets[].url"}
}
set_field {
field_name = "install_status"
value = "1"
}
set_field {
field_name = "operational_status"
value = "1"
}
}
}
on_false = nop {}
}
}
step {
name = "Create relation to cmdb_ci_pcf_appl"
if {
condition = is_not_empty {get_attr {"droplets"}}
on_true = relation_reference {
table1_name = "cmdb_ci_pcf_appl"
key1_name = "url"
table2_name = "cmdb_ci_pcf_droplet"
key2_name = "app_url"
result_table_name = "app_to_droplet"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step {
name = "Create Tags reference to cmdb_ci_pcf_appl"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "pcf_guid"
table2_name = "cmdb_ci_pcf_droplet"
key2_name = "pcf_guid"
result_table_name = "apps_to_key_value"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "CloudFoundry Droplets"
id = "db90b5ec476b9590ad02906a436d4303" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Droplets"
comment = "Get Droplets is only available for V3 of the API calls."
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "resource"
value = "droplets"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "api_version"
value = "v3"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "response_name"
value = "response"
}
}
sys_id_op = "5ed749eedb8da700f1d2f3451d96196a"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the droplets"
if {
condition = eq {
get_attr {"api_version_used"}
"v3"
}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "droplets"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "pcf_guid:resources.guid, url:resources.links.self.href, app_url:resources.links.app.href"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter droplets table on apps"
if {
condition = neq {
get_attr {"Organization"}
"*"
}
on_true = merge {
table1_name = "droplets"
key1_name = "app_url"
table2_name = "apps"
key2_name = "url"
result_table_name = "droplets"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse droplets tags"
if {
condition = all {
eq {
get_attr {"api_version_used"}
"v3"
}
is_not_empty {get_attr {"droplets"}}
}
on_true = custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "droplets_tags"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "pcf_guid:resources.guid,label_key:resources.metadata.labels.*,annotation_key:resources.metadata.annotations.*" // Metadata section: Contains metadata information about the pattern
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out empty key rows"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = filter {
src_table_name = "droplets_tags"
target_table_name = "droplets_tags"
condition = any {
is_not_empty {get_attr {"droplets_tags[].label_key"}}
is_not_empty {get_attr {"droplets_tags[].annotation_key"}}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out tags based on selected organizations"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = merge {
table1_name = "droplets_tags"
key1_name = "pcf_guid"
table2_name = "droplets"
key2_name = "pcf_guid"
result_table_name = "droplets_tags"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = " Modify the droplet tags"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = transform {
src_table_name = "droplets_tags"
target_table_name = "droplets_tags"
operation {
set_field {
field_name = "key"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var label_key = ${droplets_tags[].label_key};
var annotation_key = ${droplets_tags[].annotation_key}
if (label_key) {
rtrn = label_key;
} else if (annotation_key) {
rtrn = annotation_key;
}
rtrn;"}
}
set_field {
field_name = "value"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var label_key = ${droplets_tags[].label_key_value};
var annotation_key = ${droplets_tags[].annotation_key_value}
if (label_key) {
rtrn = label_key;
} else if (annotation_key) {
rtrn = annotation_key;
}
rtrn;"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "\u0410dd the droplets tags to the cmdb_key_value table"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = union {
table1_name = "cmdb_key_value"
table2_name = "droplets_tags"
result_table_name = "cmdb_key_value"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_pcf_droplet"
if {
condition = is_not_empty {get_attr {"droplets"}}
on_true = transform {
src_table_name = "droplets"
target_table_name = "cmdb_ci_pcf_droplet"
operation {
set_field {
field_name = "name"
value = get_attr {"droplets[].url"}
}
set_field {
field_name = "install_status"
value = "1"
}
set_field {
field_name = "operational_status"
value = "1"
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation to cmdb_ci_pcf_appl"
if {
condition = is_not_empty {get_attr {"droplets"}}
on_true = relation_reference {
table1_name = "cmdb_ci_pcf_appl"
key1_name = "url"
table2_name = "cmdb_ci_pcf_droplet"
key2_name = "app_url"
result_table_name = "app_to_droplet"
unmatched_lines = remove
relation_type = "Contains::Contained by"
ref_direction = parentToChild
ref_field_name = ""
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Tags reference to cmdb_ci_pcf_appl"
if {
condition = is_not_empty {get_attr {"droplets_tags"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "pcf_guid"
table2_name = "cmdb_ci_pcf_droplet"
key2_name = "pcf_guid"
result_table_name = "apps_to_key_value"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
NAT Gateway Tags | I would like for you to help me build a Pattern that helps achieve Discovery of NAT Gateway Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "NAT Gateway Tags"
id = "dbccb140db8f44109149f2131f9619ab"
description = "NAT Gateway Tags"
step {
name = "Parse NAT Gateway Tags"
parse_var_to_var {
from_var_name = "nat_rest"
to_var_names = table {
name = "cmdb_key_value"
col_names = "object_id","key","value"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeNatGatewaysResponse"
fields {
field {
col_name = "object_id"
xpath = "/DescribeNatGatewaysResponse/natGatewaySet/item/natGatewayId/text()"
delimiters = ""
position = 1
}
field {
col_name = "key"
xpath = "/DescribeNatGatewaysResponse/natGatewaySet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeNatGatewaysResponse/natGatewaySet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "filter out tags without value"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Create reference between Tags and NAT Gateway"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_nat_gateway"
key2_name = "object_id"
result_table_name = "tag_to_nat"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "NAT Gateway Tags"
id = "dbccb140db8f44109149f2131f9619ab" // Unique identifier for the pattern
description = "NAT Gateway Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse NAT Gateway Tags"
parse_var_to_var {
from_var_name = "nat_rest"
to_var_names = table {
name = "cmdb_key_value"
col_names = "object_id","key","value"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeNatGatewaysResponse"
fields {
field {
col_name = "object_id"
xpath = "/DescribeNatGatewaysResponse/natGatewaySet/item/natGatewayId/text()"
delimiters = ""
position = 1
}
field {
col_name = "key"
xpath = "/DescribeNatGatewaysResponse/natGatewaySet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeNatGatewaysResponse/natGatewaySet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter out tags without value"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference between Tags and NAT Gateway"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_nat_gateway"
key2_name = "object_id"
result_table_name = "tag_to_nat"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
populate label from service name - Windows and Linux | I would like for you to help me build a Pattern that helps achieve Discovery of populate label from service name - Windows and Linux. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "populate label from service name - Windows and Linux"
id = "dbd4fd0813677e00d4013192e144b0b8"
description = "null"
step {
name = "get windows service name by tasklist command"
comment = "get windows service name by tasklist command."
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = runcmd_to_var {
cmd = concat {
"tasklist /svc /fi \" pid eq "
get_attr {"pid_info[1].pid"}
"\" | findstr "
get_attr {"pid_info[1].pid"}
}
var_names = table {
name = "services"
col_names = "service_name"
}
parsing_strategy = regex_parsing {regex = "\\S+\\s+\\S*(.*\\S)"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "populate label from service name - Windows"
comment = "populate label from service name - Windows"
if {
condition = all {
is_not_empty {get_attr {"services[1].service_name"}}
neq {
get_attr {"services[1].service_name"}
"N/A"
}
eq {
get_attr {"computer_system.osFamily"}
"Windows"
}
}
on_true = set_attr {
"name"
get_attr {"services[1].service_name"}
}
on_false = nop {}
}
}
step {
name = "populate label from request queue name - Windows"
comment = "populate label from request queue name - Windows"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"Windows"
}
eq {
get_attr {"services[1].service_name"}
"N/A"
}
is_not_empty {get_attr {"request_queue_name"}}
}
on_true = set_attr {
"name"
get_attr {"request_queue_name"}
}
on_false = nop {}
}
}
step {
name = "populate label from service name - Linux"
comment = "populate label from service name - Linux"
if {
condition = all {
is_not_empty {get_attr {"linux_service_name"}}
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
}
on_true = set_attr {
"name"
get_attr {"linux_service_name"}
}
on_false = nop {}
}
}
}
| library {
name = "populate label from service name - Windows and Linux"
id = "dbd4fd0813677e00d4013192e144b0b8" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "get windows service name by tasklist command"
comment = "get windows service name by tasklist command."
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = runcmd_to_var {
cmd = concat {
"tasklist /svc /fi \" pid eq "
get_attr {"pid_info[1].pid"}
"\" | findstr "
get_attr {"pid_info[1].pid"}
}
var_names = table {
name = "services"
col_names = "service_name"
}
parsing_strategy = regex_parsing {regex = "\\S+\\s+\\S*(.*\\S)"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "populate label from service name - Windows"
comment = "populate label from service name - Windows"
if {
condition = all {
is_not_empty {get_attr {"services[1].service_name"}}
neq {
get_attr {"services[1].service_name"}
"N/A"
}
eq {
get_attr {"computer_system.osFamily"}
"Windows"
}
}
on_true = set_attr {
"name"
get_attr {"services[1].service_name"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "populate label from request queue name - Windows"
comment = "populate label from request queue name - Windows"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"Windows"
}
eq {
get_attr {"services[1].service_name"}
"N/A"
}
is_not_empty {get_attr {"request_queue_name"}}
}
on_true = set_attr {
"name"
get_attr {"request_queue_name"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "populate label from service name - Linux"
comment = "populate label from service name - Linux"
if {
condition = all {
is_not_empty {get_attr {"linux_service_name"}}
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
}
on_true = set_attr {
"name"
get_attr {"linux_service_name"}
}
on_false = nop {}
}
}
}
|
Nutanix Categories (Tags) | I would like for you to help me build a Pattern that helps achieve Discovery of Nutanix Categories (Tags). \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Nutanix Categories (Tags)"
id = "dc242baadb8abb0097db90c7db96194d"
description = "null"
step {
name = "List all Categories"
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
get_attr {"prism_url"}
"/api/nutanix/v3/categories/list"
}
}
attribute {
name = "method"
value = "POST"
}
attribute {
name = "body"
value = "{\"kind\": \"category\"}"
}
attribute {
name = "response_variable_name"
value = "categories_keys_respons"
}
}
sys_id_op = "fd927f69dbe9730097db90c7db961912"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step {
name = "Parse Categories Keys"
parse_var_to_var {
from_var_name = "categories_keys_respons"
to_var_names = "category_keys"
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "category_keys"
xpath = "/root/entities/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Get all Categories Values"
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
get_attr {"prism_url"}
"/api/nutanix/v3/categories/{category_keys}/list"
}
}
attribute {
name = "method"
value = "POST"
}
attribute {
name = "body"
value = "{\"kind\": \"category\"}"
}
attribute {
name = "response_variable_name"
value = "categories_values_response"
}
}
sys_id_op = "fd927f69dbe9730097db90c7db961912"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step {
name = "Parse Categories Values"
parse_var_to_var {
from_var_name = "categories_values_response"
to_var_names = table {
name = "categories_key_value"
col_names = "key","value"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "key"
xpath = "/root/added_sn_tag/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/root/entities/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Create categories_body"
comment = "This variable will be used in the next step to list all the tags that in use and their related CIs"
set_attr {
"categories_body"
eval {"javascript: rtrn = '';
var categories_key_value = ${categories_key_value};
var categoriesHashMap = new Packages.java.util.HashMap();
for (var i=0 ; i < categories_key_value.size(); i++){
var key = \"\\\"\" + categories_key_value.get(i).get('key') + \"\\\"\";
var value = \"\\\"\" + categories_key_value.get(i).get('value') + \"\\\"\";
if (categoriesHashMap.containsKey(key)){
(categoriesHashMap.get(key)).add(value);
}
else {
var categoriesSet = new Packages.java.util.HashSet();
categoriesSet.add(value);
categoriesHashMap.put(key,categoriesSet);
}
}
var body = \"{\\\"usage_type\\\": \\\"APPLIED_TO\\\",\\\"category_filter\\\": {\\\"type\\\": \\\"CATEGORIES_MATCH_ANY\\\",\\\"params\\\": \" + categoriesHashMap.toString().replace(\"=\",\":\") + \"}}\"
body;"}
}
}
step {
name = "Get Categories in use"
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
get_attr {"prism_url"}
"/api/nutanix/v3/category/query"
}
}
attribute {
name = "method"
value = "POST"
}
attribute {
name = "body"
value = get_attr {"categories_body"}
}
attribute {
name = "response_variable_name"
value = "tags_and_cis"
}
}
sys_id_op = "fd927f69dbe9730097db90c7db961912"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step {
name = "Parse CIs and Tags"
set_attr {
"tmp"
eval {"javascript: var ArrayList = Packages.java.util.ArrayList;
var result = new ArrayList();
for (var tag = 0; tag < ${tags_and_cis}.size(); tag++){
var tags_json = JSON.parse(${tags_and_cis}.get(tag));
for (var i in tags_json.results){
var ci_type = tags_json.results[i].kind;
if (ci_type == \"vm\" || ci_type == \"host\"){
for (var j = 0 ; j < tags_json.results[i].kind_reference_list.length; j++){
var ci_uuid = tags_json.results[i].kind_reference_list[j].uuid;
for (var k in tags_json.results[i].kind_reference_list[j].categories){
result.add(\"ci_type: \" + ci_type + \", ci_uuid: \" + ci_uuid + \", category_key: \" + k + \", category_value: \" + tags_json.results[i].kind_reference_list[j].categories[k]);
}
}
}
}
}
CTX.setAttribute(\"tags_and_cis_not_json\",result);"}
}
}
step {
name = "Create Tags"
parse_var_to_var {
from_var_name = "tags_and_cis_not_json"
to_var_names = table {
name = "cmdb_key_value"
col_names = "ci_type","ci_uuid","key","value"
}
parsing_strategy = delimited_parsing {
delimiters = "ci_type: ",", ci_uuid: ",", category_key: ",", category_value: "
selected_positions = 1,2,3,4
}
if_not_found_do = nop {}
}
}
step {
name = "Create reference between Tag and Host"
relation_reference {
table1_name = "cmdb_key_value"
table2_name = "cmdb_ci_nutanix_host"
result_table_name = "tags_to_host"
unmatched_lines = remove
condition = all {
eq {
get_attr {"cmdb_key_value[].ci_type"}
"host"
}
eq {
get_attr {"cmdb_key_value[].ci_uuid"}
get_attr {"cmdb_ci_nutanix_host[].object_id"}
}
}
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
step {
name = "Create relation between Tag and VM"
relation_reference {
table1_name = "cmdb_key_value"
table2_name = "cmdb_ci_nutanix_vm_instance"
result_table_name = "tags_to_vm"
unmatched_lines = remove
condition = all {
eq {
get_attr {"cmdb_key_value[].ci_type"}
"vm"
}
eq {
get_attr {"cmdb_key_value[].ci_uuid"}
get_attr {"cmdb_ci_nutanix_vm_instance[].vm_inst_id"}
}
}
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Nutanix Categories (Tags)"
id = "dc242baadb8abb0097db90c7db96194d" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "List all Categories"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
get_attr {"prism_url"}
"/api/nutanix/v3/categories/list"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "POST"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = "{\"kind\": \"category\"}"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "response_variable_name"
value = "categories_keys_respons"
}
}
sys_id_op = "fd927f69dbe9730097db90c7db961912"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Categories Keys"
parse_var_to_var {
from_var_name = "categories_keys_respons"
to_var_names = "category_keys"
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "category_keys"
xpath = "/root/entities/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get all Categories Values"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
get_attr {"prism_url"}
"/api/nutanix/v3/categories/{category_keys}/list"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "POST"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = "{\"kind\": \"category\"}"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "response_variable_name"
value = "categories_values_response"
}
}
sys_id_op = "fd927f69dbe9730097db90c7db961912"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Categories Values"
parse_var_to_var {
from_var_name = "categories_values_response"
to_var_names = table {
name = "categories_key_value"
col_names = "key","value"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "key"
xpath = "/root/added_sn_tag/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/root/entities/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create categories_body"
comment = "This variable will be used in the next step to list all the tags that in use and their related CIs" // Step definition: Represents a single action or set of actions in the pattern
set_attr {
"categories_body"
eval {"javascript: rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var categories_key_value = ${categories_key_value};
var categoriesHashMap = new Packages.java.util.HashMap();
for (var i=0 ; i < categories_key_value.size(); i++){
var key = \"\\\"\" + categories_key_value.get(i).get('key') + \"\\\"\";
var value = \"\\\"\" + categories_key_value.get(i).get('value') + \"\\\"\";
if (categoriesHashMap.containsKey(key)){
(categoriesHashMap.get(key)).add(value);
}
else {
var categoriesSet = new Packages.java.util.HashSet();
categoriesSet.add(value);
categoriesHashMap.put(key,categoriesSet);
}
}
var body = \"{\\\"usage_type\\\": \\\"APPLIED_TO\\\",\\\"category_filter\\\": {\\\"type\\\": \\\"CATEGORIES_MATCH_ANY\\\",\\\"params\\\": \" + categoriesHashMap.toString().replace(\"=\",\":\") + \"}}\"
body;"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Categories in use"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
get_attr {"prism_url"}
"/api/nutanix/v3/category/query"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "POST"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = get_attr {"categories_body"}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "response_variable_name"
value = "tags_and_cis"
}
}
sys_id_op = "fd927f69dbe9730097db90c7db961912"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse CIs and Tags"
set_attr {
"tmp"
eval {"javascript: var ArrayList = Packages.java.util.ArrayList; // Script execution: Custom script to perform a specific action or collect data
var result = new ArrayList();
for (var tag = 0; tag < ${tags_and_cis}.size(); tag++){
var tags_json = JSON.parse(${tags_and_cis}.get(tag));
for (var i in tags_json.results){
var ci_type = tags_json.results[i].kind;
if (ci_type == \"vm\" || ci_type == \"host\"){
for (var j = 0 ; j < tags_json.results[i].kind_reference_list.length; j++){
var ci_uuid = tags_json.results[i].kind_reference_list[j].uuid; // Unique identifier for the pattern
for (var k in tags_json.results[i].kind_reference_list[j].categories){
result.add(\"ci_type: \" + ci_type + \", ci_uuid: \" + ci_uuid + \", category_key: \" + k + \", category_value: \" + tags_json.results[i].kind_reference_list[j].categories[k]);
}
}
}
}
}
CTX.setAttribute(\"tags_and_cis_not_json\",result);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create Tags"
parse_var_to_var {
from_var_name = "tags_and_cis_not_json"
to_var_names = table {
name = "cmdb_key_value"
col_names = "ci_type","ci_uuid","key","value"
}
parsing_strategy = delimited_parsing {
delimiters = "ci_type: ",", ci_uuid: ",", category_key: ",", category_value: "
selected_positions = 1,2,3,4
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference between Tag and Host"
relation_reference {
table1_name = "cmdb_key_value"
table2_name = "cmdb_ci_nutanix_host"
result_table_name = "tags_to_host"
unmatched_lines = remove
condition = all {
eq {
get_attr {"cmdb_key_value[].ci_type"}
"host"
}
eq {
get_attr {"cmdb_key_value[].ci_uuid"}
get_attr {"cmdb_ci_nutanix_host[].object_id"}
}
}
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and VM"
relation_reference {
table1_name = "cmdb_key_value"
table2_name = "cmdb_ci_nutanix_vm_instance"
result_table_name = "tags_to_vm"
unmatched_lines = remove
condition = all {
eq {
get_attr {"cmdb_key_value[].ci_type"}
"vm"
}
eq {
get_attr {"cmdb_key_value[].ci_uuid"}
get_attr {"cmdb_ci_nutanix_vm_instance[].vm_inst_id"}
}
}
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
IBM Cloud Storage Volume table | I would like for you to help me build a Pattern that helps achieve Discovery of IBM Cloud Storage Volume table. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "IBM Cloud Storage Volume table"
id = "e0d8a983dbe32300578654dadc961934"
description = "null"
step {
name = "Set the API version"
comment = "At the moment of pattern creation the current API version is 'v3.1'. Modify the value of the current version with the actual one when needed, as it's saved as a variable at the moment."
set_attr {
"api_version"
"v3.1"
}
}
step {
name = "Get All Cloud Storages response"
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://api.softlayer.com/rest/"
"api_version"
"/SoftLayer_Account/getNetworkStorage"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
attribute {
name = "arrayName"
value = "storage_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step {
name = "Correct the JSON format so that it can be parsed"
set_attr {
"tmp"
eval {"javascript: var storage_response = ${storage_response};
for (var i = 0; i < storage_response.size(); i++){
storage_response.set(i, '{\"result\":[' + storage_response.get(i) + ']}');
}
CTX.setAttribute(\"storage_response\", storage_response);"}
}
}
step {
name = "Parse initial Cloud Storage volume attributes"
parse_var_to_var {
from_var_name = "storage_response"
to_var_names = table {
name = "network_storage_without_ip"
col_names = "account_id","storage_object_id","storage_type","storage_name","size","resource_name","storage_type_id","guest_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "account_id"
xpath = "/root/result/accountId/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_object_id"
xpath = "/root/result/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_type"
xpath = "/root/result/nasType/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_name"
xpath = "/root/result/username/text()"
delimiters = ""
position = 1
}
field {
col_name = "size"
xpath = "/root/result/capacityGb/text()"
delimiters = ""
position = 1
}
field {
col_name = "resource_name"
xpath = "/root/result/serviceResourceName/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_type_id"
xpath = "/root/result/storageTypeId/text()"
delimiters = ""
position = 1
}
field {
col_name = "guest_id"
xpath = "/root/result/guestId/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Parse additional Cloud Storage volume attributes"
parse_var_to_var {
from_var_name = "storage_response"
to_var_names = table {
name = "network_storage"
col_names = "storage_object_id","storage_type","resource_backend_ip_address"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "storage_object_id"
xpath = "/root/result/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_type"
xpath = "/root/result/nasType/text()"
delimiters = ""
position = 1
}
field {
col_name = "resource_backend_ip_address"
xpath = "/root/result/serviceResourceBackendIpAddress/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Merge final Storage Volume table"
comment = "Combining the information from the previous two steps where we get information relevant for the Storage Volume table (main CI in the model). The reason merge is used, is that not all of the resources returned from the call have a filed 'resource_backend_ip_address'. The merge is done in order to be sure when populating the cmdb_ci_storage_volume_table all the needed information will be populated and prevention of data loss."
merge {
table1_name = "network_storage"
key1_name = "storage_object_id"
table2_name = "network_storage_without_ip"
key2_name = "storage_object_id"
result_table_name = "network_storage"
unmatched_lines = keep
}
}
step {
name = "Filter table to remove decommissioned items"
comment = "Filtering the table from items that has been deleted from the console , this is done in order to prevent items which are not longer existing to be populated into the tables."
filter {
src_table_name = "network_storage"
target_table_name = "network_storage"
condition = not_contains {
get_attr {"network_storage[].resource_name"}
"PerfStor Aggr"
}
}
}
step {
name = "Remove nasType Hub, Evault and Snapshot"
comment = "Removing the information populated into the temporary table 'network storage' for snapshots and HUB nas storages types. Doing this because in the next steps the information about snapshots is populated into another temporary table 'storage_snapshots'. The nas storage of type HUB is removed for now."
if {
condition = is_not_empty {get_attr {"network_storage"}}
on_true = filter {
src_table_name = "network_storage"
target_table_name = "network_storage"
condition = all {
neq {
get_attr {"network_storage[].storage_type"}
"SNAPSHOT"
}
neq {
get_attr {"network_storage[].storage_type"}
"HUB"
}
neq {
get_attr {"network_storage[].storage_type"}
"EVAULT"
}
}
}
on_false = nop {}
}
}
step {
name = "Define Network Storage Availability Zone"
comment = "Transform table step where with an EVAL script and regex matching, transform the information from the response from the previous step in order to normalize the 'availability zone' value."
transform {
src_table_name = "network_storage"
target_table_name = "network_storage"
operation {set_field {
field_name = "availability_zone"
value = eval {"javascript: var rtrn;
var resource_group = ${network_storage[].resource_name};
var regex = /(\\w{3}\\d{2})/;
var az_name = regex.exec(resource_group);
if (az_name) {
rtrn = az_name[1];
} else {
rtrn;
}"}
}}
}
}
step {
name = "Define Network Storage LDC"
comment = "Transform table step for transforming the information for the availability zones to regions. This is done for later creating of reference/relation between the desired tables."
if {
condition = is_not_empty {get_attr {"network_storage"}}
on_true = transform {
src_table_name = "network_storage"
target_table_name = "network_storage"
operation {set_field {
field_name = "region"
value = eval {"javascript: var res = \"\";
res = IbmCloudDcToRegion.convertDctoRegion(${network_storage[].availability_zone});"}
}}
}
on_false = nop {}
}
}
step {
name = "Filter Network Storage table by LDCs"
if {
condition = eq {
get_attr {"is_ldc"}
"true"
}
on_true = filter {
src_table_name = "network_storage"
target_table_name = "network_storage"
condition = contains {
get_attr {"ldc_list"}
get_attr {"network_storage[].region"}
}
}
on_false = nop {}
}
}
step {
name = "Transform the size in bytes"
comment = "Transforming the size value for the storages from gigabytes to bytes and storing the new value to the field 'size_bytes'."
transform {
src_table_name = "network_storage"
target_table_name = "network_storage"
operation {set_field {
field_name = "size_bytes"
value = eval {"javascript: var rtrn = '';
var size = ${network_storage[].size};
rtrn = (parseInt(size) * 1073741824) + '';"}
}}
}
}
step {
name = "Populate cmdb_ci_storage_volume"
comment = "Populating the information for the storage volumes from the temporary table 'network_storage' to the 'cmdb_ci_storage_volume' table."
transform {
src_table_name = "network_storage"
target_table_name = "cmdb_ci_storage_volume"
operation {
set_field {
field_name = "object_id"
value = get_attr {"network_storage[].storage_object_id"}
}
set_field {
field_name = "volume_id"
value = get_attr {"network_storage[].storage_object_id"}
}
set_field {
field_name = "name"
value = get_attr {"network_storage[].storage_name"}
}
set_field {
field_name = "size"
value = get_attr {"network_storage[].size"}
}
set_field {
field_name = "label"
value = get_attr {"network_storage[].resource_name"}
}
set_field {
field_name = "storage_type"
value = get_attr {"network_storage[].storage_type"}
}
set_field {
field_name = "fqdn"
value = get_attr {"network_storage[].resource_backend_ip_address"}
}
set_field {
field_name = "device"
value = get_attr {"network_storage[].guest_id"}
}
}
}
}
}
| library {
name = "IBM Cloud Storage Volume table"
id = "e0d8a983dbe32300578654dadc961934" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set the API version"
comment = "At the moment of pattern creation the current API version is 'v3.1'. Modify the value of the current version with the actual one when needed, as it's saved as a variable at the moment."
set_attr {
"api_version"
"v3.1"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get All Cloud Storages response"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://api.softlayer.com/rest/"
"api_version"
"/SoftLayer_Account/getNetworkStorage"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "arrayName"
value = "storage_response"
}
}
sys_id_op = "a6e5288173b363008c51d6dcb7f6a75e"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Correct the JSON format so that it can be parsed"
set_attr {
"tmp"
eval {"javascript: var storage_response = ${storage_response}; // Script execution: Custom script to perform a specific action or collect data
for (var i = 0; i < storage_response.size(); i++){
storage_response.set(i, '{\"result\":[' + storage_response.get(i) + ']}');
}
CTX.setAttribute(\"storage_response\", storage_response);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse initial Cloud Storage volume attributes" // Attribute collection: Collects specific attributes from the discovered CI
parse_var_to_var {
from_var_name = "storage_response"
to_var_names = table {
name = "network_storage_without_ip"
col_names = "account_id","storage_object_id","storage_type","storage_name","size","resource_name","storage_type_id","guest_id"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "account_id"
xpath = "/root/result/accountId/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_object_id"
xpath = "/root/result/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_type"
xpath = "/root/result/nasType/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_name"
xpath = "/root/result/username/text()"
delimiters = ""
position = 1
}
field {
col_name = "size"
xpath = "/root/result/capacityGb/text()"
delimiters = ""
position = 1
}
field {
col_name = "resource_name"
xpath = "/root/result/serviceResourceName/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_type_id"
xpath = "/root/result/storageTypeId/text()"
delimiters = ""
position = 1
}
field {
col_name = "guest_id"
xpath = "/root/result/guestId/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse additional Cloud Storage volume attributes" // Attribute collection: Collects specific attributes from the discovered CI
parse_var_to_var {
from_var_name = "storage_response"
to_var_names = table {
name = "network_storage"
col_names = "storage_object_id","storage_type","resource_backend_ip_address"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "storage_object_id"
xpath = "/root/result/id/text()"
delimiters = ""
position = 1
}
field {
col_name = "storage_type"
xpath = "/root/result/nasType/text()"
delimiters = ""
position = 1
}
field {
col_name = "resource_backend_ip_address"
xpath = "/root/result/serviceResourceBackendIpAddress/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Merge final Storage Volume table"
comment = "Combining the information from the previous two steps where we get information relevant for the Storage Volume table (main CI in the model). The reason merge is used, is that not all of the resources returned from the call have a filed 'resource_backend_ip_address'. The merge is done in order to be sure when populating the cmdb_ci_storage_volume_table all the needed information will be populated and prevention of data loss." // Step definition: Represents a single action or set of actions in the pattern
merge {
table1_name = "network_storage"
key1_name = "storage_object_id"
table2_name = "network_storage_without_ip"
key2_name = "storage_object_id"
result_table_name = "network_storage"
unmatched_lines = keep
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter table to remove decommissioned items"
comment = "Filtering the table from items that has been deleted from the console , this is done in order to prevent items which are not longer existing to be populated into the tables."
filter {
src_table_name = "network_storage"
target_table_name = "network_storage"
condition = not_contains {
get_attr {"network_storage[].resource_name"}
"PerfStor Aggr"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove nasType Hub, Evault and Snapshot"
comment = "Removing the information populated into the temporary table 'network storage' for snapshots and HUB nas storages types. Doing this because in the next steps the information about snapshots is populated into another temporary table 'storage_snapshots'. The nas storage of type HUB is removed for now." // Step definition: Represents a single action or set of actions in the pattern
if {
condition = is_not_empty {get_attr {"network_storage"}}
on_true = filter {
src_table_name = "network_storage"
target_table_name = "network_storage"
condition = all {
neq {
get_attr {"network_storage[].storage_type"}
"SNAPSHOT"
}
neq {
get_attr {"network_storage[].storage_type"}
"HUB"
}
neq {
get_attr {"network_storage[].storage_type"}
"EVAULT"
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Define Network Storage Availability Zone"
comment = "Transform table step where with an EVAL script and regex matching, transform the information from the response from the previous step in order to normalize the 'availability zone' value." // Step definition: Represents a single action or set of actions in the pattern
transform {
src_table_name = "network_storage"
target_table_name = "network_storage"
operation {set_field {
field_name = "availability_zone"
value = eval {"javascript: var rtrn; // Script execution: Custom script to perform a specific action or collect data
var resource_group = ${network_storage[].resource_name};
var regex = /(\\w{3}\\d{2})/;
var az_name = regex.exec(resource_group);
if (az_name) {
rtrn = az_name[1];
} else {
rtrn;
}"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Define Network Storage LDC"
comment = "Transform table step for transforming the information for the availability zones to regions. This is done for later creating of reference/relation between the desired tables." // Step definition: Represents a single action or set of actions in the pattern
if {
condition = is_not_empty {get_attr {"network_storage"}}
on_true = transform {
src_table_name = "network_storage"
target_table_name = "network_storage"
operation {set_field {
field_name = "region"
value = eval {"javascript: var res = \"\"; // Script execution: Custom script to perform a specific action or collect data
res = IbmCloudDcToRegion.convertDctoRegion(${network_storage[].availability_zone});"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter Network Storage table by LDCs"
if {
condition = eq {
get_attr {"is_ldc"}
"true"
}
on_true = filter {
src_table_name = "network_storage"
target_table_name = "network_storage"
condition = contains {
get_attr {"ldc_list"}
get_attr {"network_storage[].region"}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Transform the size in bytes"
comment = "Transforming the size value for the storages from gigabytes to bytes and storing the new value to the field 'size_bytes'."
transform {
src_table_name = "network_storage"
target_table_name = "network_storage"
operation {set_field {
field_name = "size_bytes"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var size = ${network_storage[].size};
rtrn = (parseInt(size) * 1073741824) + '';"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate cmdb_ci_storage_volume"
comment = "Populating the information for the storage volumes from the temporary table 'network_storage' to the 'cmdb_ci_storage_volume' table."
transform {
src_table_name = "network_storage"
target_table_name = "cmdb_ci_storage_volume"
operation {
set_field {
field_name = "object_id"
value = get_attr {"network_storage[].storage_object_id"}
}
set_field {
field_name = "volume_id"
value = get_attr {"network_storage[].storage_object_id"}
}
set_field {
field_name = "name"
value = get_attr {"network_storage[].storage_name"}
}
set_field {
field_name = "size"
value = get_attr {"network_storage[].size"}
}
set_field {
field_name = "label"
value = get_attr {"network_storage[].resource_name"}
}
set_field {
field_name = "storage_type"
value = get_attr {"network_storage[].storage_type"}
}
set_field {
field_name = "fqdn"
value = get_attr {"network_storage[].resource_backend_ip_address"}
}
set_field {
field_name = "device"
value = get_attr {"network_storage[].guest_id"}
}
}
}
}
}
|
Azure Functions Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Azure Functions Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure Functions Tags"
id = "e27816691bd02010f565437cbc4bcb99"
description = "Azure Functions Tags"
step {
name = "Parse the Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Functions Tags\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id};
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step {
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Create relation between tags and functions"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_function"
key2_name = "object_id"
result_table_name = "tags_to_functions"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "Azure Functions Tags"
id = "e27816691bd02010f565437cbc4bcb99" // Unique identifier for the pattern
description = "Azure Functions Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Functions Tags\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id}; // Unique identifier for the pattern
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between tags and functions"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_function"
key2_name = "object_id"
result_table_name = "tags_to_functions"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
S3 Tags | I would like for you to help me build a Pattern that helps achieve Discovery of S3 Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "S3 Tags"
id = "e59d82eedbc93300b0f0f9c9bf9619b2"
description = "S3 Tags"
step {
name = "Set resource type"
set_attr {
"resource_type"
"s3"
}
}
step {
name = "Tags library"
ref {refid = "91986c05db0d3300bbebf13bbf961949"}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Reference between cmdb_ci_cloud_object storage and cmdb_key_value"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_object_storage"
key2_name = "object_id"
result_table_name = "keyToS3"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "S3 Tags"
id = "e59d82eedbc93300b0f0f9c9bf9619b2" // Unique identifier for the pattern
description = "S3 Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set resource type"
set_attr {
"resource_type"
"s3"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Tags library"
ref {refid = "91986c05db0d3300bbebf13bbf961949"} // Unique identifier for the pattern
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference between cmdb_ci_cloud_object storage and cmdb_key_value"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_object_storage"
key2_name = "object_id"
result_table_name = "keyToS3"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
glassfish_databse_connection | I would like for you to help me build a Pattern that helps achieve Discovery of glassfish_databse_connection. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "glassfish_databse_connection"
id = "e5adcac6c3a54e14adfc1792a7404b23"
description = ""
step {
name = "filter uniq class"
filter {
src_table_name = "propeties_class"
target_table_name = "propeties_class2"
condition = any {
eq {
get_attr {"propeties_class[].property_name"}
"portNumber"
}
eq {
get_attr {"propeties_class[].property_name"}
"databaseName"
}
eq {
get_attr {"propeties_class[].property_name"}
"serverName"
}
}
}
}
step {
name = "filter by host"
filter {
src_table_name = "propeties_class2"
target_table_name = "properies_host"
condition = eq {
get_attr {"propeties_class2[].property_name"}
"serverName"
}
}
}
step {
name = "transform_ip"
transform {
src_table_name = "properies_host"
target_table_name = "properies_host"
operation {set_field {
field_name = "ip"
value = get_attr {"properies_host[].property_value"}
}}
}
}
step {
name = "filter by port"
filter {
src_table_name = "propeties_class2"
target_table_name = "properies_port"
condition = eq {
get_attr {"propeties_class2[].property_name"}
"portNumber"
}
}
}
step {
name = "transform_port"
transform {
src_table_name = "properies_port"
target_table_name = "properies_port"
operation {set_field {
field_name = "port"
value = get_attr {"properies_port[].property_value"}
}}
}
}
step {
name = "filter by inst name"
filter {
src_table_name = "propeties_class2"
target_table_name = "properies_inst_name"
condition = eq {
get_attr {"propeties_class2[].property_name"}
"databaseName"
}
}
}
step {
name = "transform_inst"
transform {
src_table_name = "properies_inst_name"
target_table_name = "properies_inst_name"
operation {set_field {
field_name = "instance"
value = get_attr {"properies_inst_name[].property_value"}
}}
}
}
step {
name = "merge tables 1"
merge {
table1_name = "properies_host"
key1_name = "datasource_name"
table2_name = "properies_port"
key2_name = "datasource_name"
result_table_name = "properies_host_port"
unmatched_lines = remove
}
}
step {
name = "merge tables 2"
merge {
table1_name = "properies_host_port"
key1_name = "datasource_name"
table2_name = "properies_inst_name"
key2_name = "datasource_name"
result_table_name = "properies_connection"
unmatched_lines = remove
}
}
}
| library {
name = "glassfish_databse_connection"
id = "e5adcac6c3a54e14adfc1792a7404b23" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter uniq class"
filter {
src_table_name = "propeties_class"
target_table_name = "propeties_class2"
condition = any {
eq {
get_attr {"propeties_class[].property_name"}
"portNumber"
}
eq {
get_attr {"propeties_class[].property_name"}
"databaseName"
}
eq {
get_attr {"propeties_class[].property_name"}
"serverName"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter by host"
filter {
src_table_name = "propeties_class2"
target_table_name = "properies_host"
condition = eq {
get_attr {"propeties_class2[].property_name"}
"serverName"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "transform_ip"
transform {
src_table_name = "properies_host"
target_table_name = "properies_host"
operation {set_field {
field_name = "ip"
value = get_attr {"properies_host[].property_value"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter by port"
filter {
src_table_name = "propeties_class2"
target_table_name = "properies_port"
condition = eq {
get_attr {"propeties_class2[].property_name"}
"portNumber"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "transform_port"
transform {
src_table_name = "properies_port"
target_table_name = "properies_port"
operation {set_field {
field_name = "port"
value = get_attr {"properies_port[].property_value"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter by inst name"
filter {
src_table_name = "propeties_class2"
target_table_name = "properies_inst_name"
condition = eq {
get_attr {"propeties_class2[].property_name"}
"databaseName"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "transform_inst"
transform {
src_table_name = "properies_inst_name"
target_table_name = "properies_inst_name"
operation {set_field {
field_name = "instance"
value = get_attr {"properies_inst_name[].property_value"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "merge tables 1"
merge {
table1_name = "properies_host"
key1_name = "datasource_name"
table2_name = "properies_port"
key2_name = "datasource_name"
result_table_name = "properies_host_port"
unmatched_lines = remove
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "merge tables 2"
merge {
table1_name = "properies_host_port"
key1_name = "datasource_name"
table2_name = "properies_inst_name"
key2_name = "datasource_name"
result_table_name = "properies_connection"
unmatched_lines = remove
}
}
}
|
Collect Azure DataBase Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Collect Azure DataBase Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Collect Azure DataBase Tags"
id = "e65083721b57e890113131de034bcbde"
description = "Collect Azure DataBase Tags"
step {
name = "Verify HD mode"
match {
eq {
get_attr {"pattern_runtime_mode"}
"horizontal"
}
terminate_op = terminate
terminate_msg = ""
}
}
step {
name = "Determine the Identification Section version"
comment = "Check if the response contains the tags object.
If it doesn't, it means that we're running after an old Identification Section (which used an old API that didn't return the tags in the response)."
set_attr {
"matchIdentSectionVersion"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Database Tags Extension\");
var rtrn = \"\";
var matchIdentSectionVersion = \"old\";
try {
parseDBInfo(${databases_table_mssql[1].database_info});
rtrn = matchIdentSectionVersion;
rtrn;
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
}
function parseDBInfo(db_info) {
var tags_obj = \"\";
try {
json = Packages.org.json.JSONObject(db_info);
var value_array = json.getJSONArray(\"value\");
logger.debug(\"Checking response for containing tags: value_array=\" + value_array);
logger.debug(\"Parsing tags: value_array.length()=\" + value_array.length());
tags_obj = value_array.getJSONObject(0).getJSONObject(\"tags\");
logger.debug(\"Checking if the reponse contains tags object. tags_obj=\" + tags_obj);
if (tags_obj != \"\")
{
matchIdentSectionVersion = \"new\";
}
}
catch (ex) {
logger.debug(\"Error checking response for tags. Message=\" + ex);
}
}// end parseDBInfo"}
}
}
step {
name = "Parse Azure National Region"
if {
condition = is_empty {get_attr {"resource_url"}}
on_true = set_attr {
"resource_url"
eval {"javascript: var dc_url = ${service_account[1].datacenter_url};
var result = \"azure.com\"; // setting Global Region as default
try {
var gov_cloud = new AzureNationalCloudParser();
result = gov_cloud.parseResourceURL(dc_url);
}
catch (e){
ms.log(\"AzureNationalCloudParser class not found or run failed. Using the default region - Global Region. \" + e);
}
result;"}
}
on_false = nop {}
}
}
step {
name = "Get Databases MSSQL"
if {
condition = eq {
get_attr {"matchIdentSectionVersion"}
"old"
}
on_true = transform {
src_table_name = "resourcegroups_table"
target_table_name = "databases_table_mssql"
operation {set_field {
field_name = "database_info"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure DataBase\");
var cloudcall = new CloudRestAPIClient();
var resource_url = ${resource_url};
var api_url = 'https://management.' + resource_url + '/subscriptions/' + ${service_account[1].account_id} + '/providers/Microsoft.Sql/servers?api-version=2019-06-01-preview';
var ret = '';
try{
var result = cloudcall.execute(${service_account},null, api_url, 'GET', 'true', CTX );
}
catch(e) {
logger.error(\" MSSQL REST query failed with error: \" + e.getMessage() );
result = '';
}
ret = result;"}
}}
}
on_false = nop {}
}
}
step {
name = "Get Databases MSSQL no server"
if {
condition = eq {
get_attr {"matchIdentSectionVersion"}
"old"
}
on_true = transform {
src_table_name = "resourcegroups_table"
target_table_name = "databases_table_mssql_noserver"
operation {set_field {
field_name = "database_info"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure DataBase\");
var cloudcall = new CloudRestAPIClient();
var resource_url = ${resource_url};
var api_url = 'https://management.' + resource_url + '/subscriptions/'+ ${service_account[1].account_id} + '/providers/Microsoft.Sql/managedInstances?api-version=2020-02-02-preview';
var ret = '';
try{
var result = cloudcall.execute(${service_account},null, api_url, 'GET', 'true', CTX );
}
catch(e) {
ms.log(\" MSSQL REST query failed with error: \" + e.getMessage() );
logger.error(\"MSSQL REST query failed with error: \" + e.getMessage() );
result = '';
}
ret = result;"}
}}
}
on_false = nop {}
}
}
step {
name = "Extract tags from all database_info tables"
set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Database Tags Extension\");
var rtrn = \"\";
var tags_table = new Packages.java.util.ArrayList();
var tags_obj = \"\";
var arr_db_info_tables = [${databases_table_nosql[1].database_info},
${databases_table_mysql[1].database_info},
${databases_table_mssql[1].database_info},
${databases_table_mssql_noserver[1].database_info},
${databases_table_redis[1].database_info},
${databases_table_postgres[1].database_info}];
try {
arr_db_info_tables.forEach(parseDBInfo);
rtrn = tags_table;
CTX.setAttribute('cmdb_key_value',tags_table);
rtrn;
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
}
function parseDBInfo(db_info) {
try {
json = Packages.org.json.JSONObject(db_info);
var value_array = json.getJSONArray(\"value\");
logger.debug(\"Parsing tags: value_array=\" + value_array);
logger.debug(\"Parsing tags: value_array.length()=\" + value_array.length());
for (var i=0; i<value_array.length();i++){
try {
object_id = value_array.getJSONObject(i).getString(\"id\");
tags_obj = value_array.getJSONObject(i).getJSONObject(\"tags\");
restype_obj = value_array.getJSONObject(i).getString(\"type\");
logger.debug(\"Parsing tags. tags_obj=\" + tags_obj);
logger.debug(\"Parsing tags: object_id=\" + object_id);
logger.debug(\"Parsing tags: restype_obj=\" + restype_obj);
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
continue;
}
var tags_array = tags_obj.toString().split(\",\"); // for logging only
logger.debug(\"Parsing tags. tags_array.length=\" + tags_array.length);
logger.debug(\"Parsing tags. tags_array[0]=\" + tags_array[0]);
logger.debug(\"Tag keys: value_array.getJSONObject(i).getJSONObject(\\\"tags\\\").keys()=\" + tags.toString());
var tags = tags_obj.keys();
var tag_key;
var tag_val;
while(tags.hasNext()) {
var tag_key = tags.next();
var tag_val = tags_obj.get(tag_key);
logger.debug(\"Parsing tags. tag_key=\" + tag_key);
logger.debug(\"Parsing tags. tag_val=\" + tag_val);
var row = new Packages.java.util.HashMap();
row.put(\"resource_type\", restype_obj);
row.put(\"object_id\", object_id);
row.put(\"key\", tag_key);
row.put(\"value\", tag_val);
tags_table.add(row);
}
}
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
}
}// end parseDBInfo
"}
}
}
step {
name = "keep tags with values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Remove duplicates from cmdb_key_value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"object_id\",\"key\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Create reference to tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_database"
key2_name = "object_id"
result_table_name = "keyToDBServer"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
step {
name = "Verify there are databases"
match {
is_not_empty {get_attr {"cmdb_ci_database"}}
terminate_op = graceful
terminate_msg = "No databases (instances) found for db servers."
}
}
step {
name = "Prepare table for merge to include resource type"
transform {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cloud_database_with_resource_type"
operation {set_field {
field_name = "resource_type"
value = get_attr {"cmdb_ci_cloud_database[].type"}
}}
}
}
step {
name = "Get all servers and their databases"
if {
condition = is_not_empty {get_attr {"cmdb_ci_database[1].Server"}}
on_true = merge {
table1_name = "cmdb_ci_database"
key1_name = "Server"
table2_name = "cloud_database_with_resource_type"
key2_name = "name"
result_table_name = "all_servers_databases"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "Get all servers and their databases - support older releases"
if {
condition = is_not_empty {get_attr {"cmdb_ci_database[1].sqlServer"}}
on_true = merge {
table1_name = "cmdb_ci_database"
key1_name = "sqlServer"
table2_name = "cloud_database_with_resource_type"
key2_name = "name"
result_table_name = "all_servers_databases"
unmatched_lines = remove
}
on_false = nop {}
}
}
step {
name = "Query details of databases per instance"
comment = "Earlier we've collected the tags for the cloud databases (servers).
Now we have to issue an API call to get the tags for each and every database resides on the server."
if {
condition = any {
is_not_empty {get_attr {"all_servers_databases"}}
is_not_empty {get_attr {"resource_url"}}
}
on_true = transform {
src_table_name = "all_servers_databases"
target_table_name = "all_servers_databases"
operation {set_field {
field_name = "json"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Database Tags Extension\");
var cloudcall = new CloudRestAPIClient();
var resource_url = ${resource_url};
var apiVersions = new Packages.java.util.HashMap();
apiVersions.put(\"Microsoft.Sql/servers\",\"2015-05-01-preview\");
apiVersions.put(\"Microsoft.DBforMySQL/servers\", \"2017-12-01-preview\");
apiVersions.put(\"Microsoft.DBforPostgreSQL/servers\",\"2017-12-01-preview\");
apiVersions.put(\"Microsoft.Cache/Redis\",\"2019-07-01\");
apiVersions.put(\"Microsoft.DBforMariaDB/servers\",\"2017-12-01-preview\");
apiVersions.put(\"Microsoft.Sql/managedInstances\",\"2020-02-02-preview\");
apiVersions.put(\"Microsoft.DocumentDB/databaseAccounts\", \"2016-03-31\");
try
{
var resourceGroup = ${all_servers_databases[].resourceGroup};
if ( resourceGroup && resourceGroup != '' )
{
var returnResult = '';
var apiVersion = apiVersions.get(${all_servers_databases[].resource_type});
var apiUrl = \"https://management.\" + resource_url + \"/subscriptions/\"+${service_account[1].account_id}+\"/resourcegroups/\"+resourceGroup +\"/providers/\" + ${all_servers_databases[].resource_type} + \"/\" + ${all_servers_databases[].instance}+\"/databases/\"+ ${all_servers_databases[].db_name}+\"?api-version=\" + apiVersion;
var result = cloudcall.execute(${service_account}, null, apiUrl, 'GET', 'true', CTX );
if (result)
{
try {
var str = '\"tags\" ###' + ${all_servers_databases[].name};
var tempResult = result.replaceAll('\"tags\"',str);
var str2 = '}, EndOfSection\\n';
returnResult = tempResult.replaceAll('},',str2);
}
catch(ex)
{
logger.debug(\"Error while processing database tags info. Message=\" + ex);
}
}
returnResult;
}
else
{
resourceGroup = '';
}
}
catch(ex) {
logger.debug(\"Error while extracting instance databases info. Message=\" + ex);
}
"}
}}
}
on_false = nop {}
}
}
step {
name = "Transform to table"
parse_var_to_var {
from_var_name = "all_servers_databases[*].json"
to_var_names = table {
name = "services_databases_tags"
col_names = "line"
}
parsing_strategy = delimited_parsing {
delimiters = "###"
selected_positions = 2
line_seperator = ", EndOfSection"
}
if_not_found_do = nop {}
}
}
step {
name = "Remove empty lines from table"
filter {
src_table_name = "services_databases_tags"
target_table_name = "services_databases_tags"
condition = is_not_empty {get_attr {"services_databases_tags[].line"}}
}
}
step {
name = "Verify we have tags"
match {
is_not_empty {get_attr {"services_databases_tags"}}
terminate_op = graceful
terminate_msg = "No tags found for databases (instances)."
}
}
step {
name = "Parse databases tags info"
set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Database Tags Extension\");
var ArrayList = Packages.java.util.ArrayList;
var HashMap = Packages.java.util.HashMap;
var tagsTable = new ArrayList();
var dbAndTagsLines = ${services_databases_tags[*].line};
var rtrn = \"\";
try {
var tagsLinesIt = dbAndTagsLines.iterator();
while (tagsLinesIt.hasNext())
{
var currTagsLine = tagsLinesIt.next();
parseTagsLine(currTagsLine);
}
rtrn = tagsTable;
CTX.setAttribute('cmdb_key_value2',tagsTable);
rtrn;
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
}
function parseTagsLine(dbTagsLine) {
try {
var parts = dbTagsLine.split(\":\");
var dbName = parts[0].trim();
var tagsIndex = dbTagsLine.indexOf(\"{\");
var tags = dbTagsLine.substring(tagsIndex);
var tagsObj = JSON.parse(tags);
buildTagsTableRow(tagsObj, dbName);
}
catch(ex)
{
ex.getMessage();
}
}
function buildTagsTableRow(tagsObj, dbName)
{
try {
logger.debug(\"Parsing tags for database:\" + dbName);
for (tagKey in tagsObj)
{
var row = new HashMap();
row.put(\"db_name\", dbName);
row.put(\"key\", tagKey);
row.put(\"value\", tagsObj[tagKey]);
tagsTable.add(row);
}
}
catch (ex)
{
logger.debug(\"Error parsing tags. Message=\" + ex);
}
}"}
}
}
step {
name = "Filter out entries with empty db_name"
filter {
src_table_name = "cmdb_key_value2"
target_table_name = "cmdb_key_value2"
condition = is_not_empty {get_attr {"cmdb_key_value2[].db_name"}}
}
}
step {
name = "Remove duplicates from cmdb_key_value2"
if {
condition = is_not_empty {get_attr {"cmdb_key_value2"}}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value2},[\"db_name\",\"key\"]);
CTX.setAttribute(\"cmdb_key_value2\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Union key value tables"
union {
table1_name = "cmdb_key_value"
table2_name = "cmdb_key_value2"
result_table_name = "cmdb_key_value"
}
}
step {
name = "Filter out empty rows from result"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "create reference to tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "db_name"
table2_name = "cmdb_ci_database"
key2_name = "name"
result_table_name = "keyToInstDB"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Collect Azure DataBase Tags"
id = "e65083721b57e890113131de034bcbde" // Unique identifier for the pattern
description = "Collect Azure DataBase Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Verify HD mode"
match {
eq {
get_attr {"pattern_runtime_mode"}
"horizontal"
}
terminate_op = terminate
terminate_msg = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Determine the Identification Section version"
comment = "Check if the response contains the tags object.
If it doesn't, it means that we're running after an old Identification Section (which used an old API that didn't return the tags in the response)."
set_attr {
"matchIdentSectionVersion"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Database Tags Extension\"); // Script execution: Custom script to perform a specific action or collect data
var rtrn = \"\";
var matchIdentSectionVersion = \"old\";
try {
parseDBInfo(${databases_table_mssql[1].database_info});
rtrn = matchIdentSectionVersion;
rtrn;
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
}
function parseDBInfo(db_info) {
var tags_obj = \"\";
try {
json = Packages.org.json.JSONObject(db_info);
var value_array = json.getJSONArray(\"value\");
logger.debug(\"Checking response for containing tags: value_array=\" + value_array);
logger.debug(\"Parsing tags: value_array.length()=\" + value_array.length());
tags_obj = value_array.getJSONObject(0).getJSONObject(\"tags\");
logger.debug(\"Checking if the reponse contains tags object. tags_obj=\" + tags_obj);
if (tags_obj != \"\")
{
matchIdentSectionVersion = \"new\";
}
}
catch (ex) {
logger.debug(\"Error checking response for tags. Message=\" + ex);
}
}// end parseDBInfo"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Azure National Region"
if {
condition = is_empty {get_attr {"resource_url"}}
on_true = set_attr {
"resource_url"
eval {"javascript: var dc_url = ${service_account[1].datacenter_url}; // Script execution: Custom script to perform a specific action or collect data
var result = \"azure.com\"; // setting Global Region as default
try {
var gov_cloud = new AzureNationalCloudParser();
result = gov_cloud.parseResourceURL(dc_url);
}
catch (e){
ms.log(\"AzureNationalCloudParser class not found or run failed. Using the default region - Global Region. \" + e);
}
result;"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Databases MSSQL"
if {
condition = eq {
get_attr {"matchIdentSectionVersion"}
"old"
}
on_true = transform {
src_table_name = "resourcegroups_table"
target_table_name = "databases_table_mssql"
operation {set_field {
field_name = "database_info"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure DataBase\"); // Script execution: Custom script to perform a specific action or collect data
var cloudcall = new CloudRestAPIClient();
var resource_url = ${resource_url};
var api_url = 'https://management.' + resource_url + '/subscriptions/' + ${service_account[1].account_id} + '/providers/Microsoft.Sql/servers?api-version=2019-06-01-preview'; // Script execution: Custom script to perform a specific action or collect data
var ret = '';
try{
var result = cloudcall.execute(${service_account},null, api_url, 'GET', 'true', CTX );
}
catch(e) {
logger.error(\" MSSQL REST query failed with error: \" + e.getMessage() );
result = '';
}
ret = result;"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Databases MSSQL no server"
if {
condition = eq {
get_attr {"matchIdentSectionVersion"}
"old"
}
on_true = transform {
src_table_name = "resourcegroups_table"
target_table_name = "databases_table_mssql_noserver"
operation {set_field {
field_name = "database_info"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure DataBase\"); // Script execution: Custom script to perform a specific action or collect data
var cloudcall = new CloudRestAPIClient();
var resource_url = ${resource_url};
var api_url = 'https://management.' + resource_url + '/subscriptions/'+ ${service_account[1].account_id} + '/providers/Microsoft.Sql/managedInstances?api-version=2020-02-02-preview'; // Script execution: Custom script to perform a specific action or collect data
var ret = '';
try{
var result = cloudcall.execute(${service_account},null, api_url, 'GET', 'true', CTX );
}
catch(e) {
ms.log(\" MSSQL REST query failed with error: \" + e.getMessage() );
logger.error(\"MSSQL REST query failed with error: \" + e.getMessage() );
result = '';
}
ret = result;"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Extract tags from all database_info tables"
set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Database Tags Extension\"); // Script execution: Custom script to perform a specific action or collect data
var rtrn = \"\";
var tags_table = new Packages.java.util.ArrayList();
var tags_obj = \"\";
var arr_db_info_tables = [${databases_table_nosql[1].database_info},
${databases_table_mysql[1].database_info},
${databases_table_mssql[1].database_info},
${databases_table_mssql_noserver[1].database_info},
${databases_table_redis[1].database_info},
${databases_table_postgres[1].database_info}];
try {
arr_db_info_tables.forEach(parseDBInfo);
rtrn = tags_table;
CTX.setAttribute('cmdb_key_value',tags_table);
rtrn;
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
}
function parseDBInfo(db_info) {
try {
json = Packages.org.json.JSONObject(db_info);
var value_array = json.getJSONArray(\"value\");
logger.debug(\"Parsing tags: value_array=\" + value_array);
logger.debug(\"Parsing tags: value_array.length()=\" + value_array.length());
for (var i=0; i<value_array.length();i++){
try {
object_id = value_array.getJSONObject(i).getString(\"id\"); // Unique identifier for the pattern
tags_obj = value_array.getJSONObject(i).getJSONObject(\"tags\");
restype_obj = value_array.getJSONObject(i).getString(\"type\");
logger.debug(\"Parsing tags. tags_obj=\" + tags_obj);
logger.debug(\"Parsing tags: object_id=\" + object_id);
logger.debug(\"Parsing tags: restype_obj=\" + restype_obj);
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
continue;
}
var tags_array = tags_obj.toString().split(\",\"); // for logging only
logger.debug(\"Parsing tags. tags_array.length=\" + tags_array.length);
logger.debug(\"Parsing tags. tags_array[0]=\" + tags_array[0]);
logger.debug(\"Tag keys: value_array.getJSONObject(i).getJSONObject(\\\"tags\\\").keys()=\" + tags.toString());
var tags = tags_obj.keys();
var tag_key;
var tag_val;
while(tags.hasNext()) {
var tag_key = tags.next();
var tag_val = tags_obj.get(tag_key);
logger.debug(\"Parsing tags. tag_key=\" + tag_key);
logger.debug(\"Parsing tags. tag_val=\" + tag_val);
var row = new Packages.java.util.HashMap();
row.put(\"resource_type\", restype_obj);
row.put(\"object_id\", object_id);
row.put(\"key\", tag_key);
row.put(\"value\", tag_val);
tags_table.add(row);
}
}
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
}
}// end parseDBInfo
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "keep tags with values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicates from cmdb_key_value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"object_id\",\"key\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference to tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_database"
key2_name = "object_id"
result_table_name = "keyToDBServer"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Verify there are databases"
match {
is_not_empty {get_attr {"cmdb_ci_database"}}
terminate_op = graceful
terminate_msg = "No databases (instances) found for db servers."
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Prepare table for merge to include resource type"
transform {
src_table_name = "cmdb_ci_cloud_database"
target_table_name = "cloud_database_with_resource_type"
operation {set_field {
field_name = "resource_type"
value = get_attr {"cmdb_ci_cloud_database[].type"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get all servers and their databases"
if {
condition = is_not_empty {get_attr {"cmdb_ci_database[1].Server"}}
on_true = merge {
table1_name = "cmdb_ci_database"
key1_name = "Server"
table2_name = "cloud_database_with_resource_type"
key2_name = "name"
result_table_name = "all_servers_databases"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get all servers and their databases - support older releases"
if {
condition = is_not_empty {get_attr {"cmdb_ci_database[1].sqlServer"}}
on_true = merge {
table1_name = "cmdb_ci_database"
key1_name = "sqlServer"
table2_name = "cloud_database_with_resource_type"
key2_name = "name"
result_table_name = "all_servers_databases"
unmatched_lines = remove
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Query details of databases per instance"
comment = "Earlier we've collected the tags for the cloud databases (servers).
Now we have to issue an API call to get the tags for each and every database resides on the server."
if {
condition = any {
is_not_empty {get_attr {"all_servers_databases"}}
is_not_empty {get_attr {"resource_url"}}
}
on_true = transform {
src_table_name = "all_servers_databases"
target_table_name = "all_servers_databases"
operation {set_field {
field_name = "json"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Database Tags Extension\"); // Script execution: Custom script to perform a specific action or collect data
var cloudcall = new CloudRestAPIClient();
var resource_url = ${resource_url};
var apiVersions = new Packages.java.util.HashMap();
apiVersions.put(\"Microsoft.Sql/servers\",\"2015-05-01-preview\");
apiVersions.put(\"Microsoft.DBforMySQL/servers\", \"2017-12-01-preview\");
apiVersions.put(\"Microsoft.DBforPostgreSQL/servers\",\"2017-12-01-preview\");
apiVersions.put(\"Microsoft.Cache/Redis\",\"2019-07-01\");
apiVersions.put(\"Microsoft.DBforMariaDB/servers\",\"2017-12-01-preview\");
apiVersions.put(\"Microsoft.Sql/managedInstances\",\"2020-02-02-preview\");
apiVersions.put(\"Microsoft.DocumentDB/databaseAccounts\", \"2016-03-31\");
try
{
var resourceGroup = ${all_servers_databases[].resourceGroup};
if ( resourceGroup && resourceGroup != '' )
{
var returnResult = '';
var apiVersion = apiVersions.get(${all_servers_databases[].resource_type});
var apiUrl = \"https://management.\" + resource_url + \"/subscriptions/\"+${service_account[1].account_id}+\"/resourcegroups/\"+resourceGroup +\"/providers/\" + ${all_servers_databases[].resource_type} + \"/\" + ${all_servers_databases[].instance}+\"/databases/\"+ ${all_servers_databases[].db_name}+\"?api-version=\" + apiVersion; // Script execution: Custom script to perform a specific action or collect data
var result = cloudcall.execute(${service_account}, null, apiUrl, 'GET', 'true', CTX );
if (result)
{
try {
var str = '\"tags\" ###' + ${all_servers_databases[].name};
var tempResult = result.replaceAll('\"tags\"',str);
var str2 = '}, EndOfSection\\n';
returnResult = tempResult.replaceAll('},',str2);
}
catch(ex)
{
logger.debug(\"Error while processing database tags info. Message=\" + ex);
}
}
returnResult;
}
else
{
resourceGroup = '';
}
}
catch(ex) {
logger.debug(\"Error while extracting instance databases info. Message=\" + ex);
}
"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Transform to table"
parse_var_to_var {
from_var_name = "all_servers_databases[*].json"
to_var_names = table {
name = "services_databases_tags"
col_names = "line"
}
parsing_strategy = delimited_parsing {
delimiters = "###"
selected_positions = 2
line_seperator = ", EndOfSection"
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove empty lines from table"
filter {
src_table_name = "services_databases_tags"
target_table_name = "services_databases_tags"
condition = is_not_empty {get_attr {"services_databases_tags[].line"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Verify we have tags"
match {
is_not_empty {get_attr {"services_databases_tags"}}
terminate_op = graceful
terminate_msg = "No tags found for databases (instances)."
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse databases tags info"
set_attr {
"tmp"
eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Database Tags Extension\"); // Script execution: Custom script to perform a specific action or collect data
var ArrayList = Packages.java.util.ArrayList;
var HashMap = Packages.java.util.HashMap;
var tagsTable = new ArrayList();
var dbAndTagsLines = ${services_databases_tags[*].line};
var rtrn = \"\";
try {
var tagsLinesIt = dbAndTagsLines.iterator();
while (tagsLinesIt.hasNext())
{
var currTagsLine = tagsLinesIt.next();
parseTagsLine(currTagsLine);
}
rtrn = tagsTable;
CTX.setAttribute('cmdb_key_value2',tagsTable);
rtrn;
}
catch (ex) {
logger.debug(\"Error parsing tags. Message=\" + ex);
}
function parseTagsLine(dbTagsLine) {
try {
var parts = dbTagsLine.split(\":\");
var dbName = parts[0].trim();
var tagsIndex = dbTagsLine.indexOf(\"{\");
var tags = dbTagsLine.substring(tagsIndex);
var tagsObj = JSON.parse(tags);
buildTagsTableRow(tagsObj, dbName);
}
catch(ex)
{
ex.getMessage();
}
}
function buildTagsTableRow(tagsObj, dbName)
{
try {
logger.debug(\"Parsing tags for database:\" + dbName);
for (tagKey in tagsObj)
{
var row = new HashMap();
row.put(\"db_name\", dbName);
row.put(\"key\", tagKey);
row.put(\"value\", tagsObj[tagKey]);
tagsTable.add(row);
}
}
catch (ex)
{
logger.debug(\"Error parsing tags. Message=\" + ex);
}
}"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out entries with empty db_name"
filter {
src_table_name = "cmdb_key_value2"
target_table_name = "cmdb_key_value2"
condition = is_not_empty {get_attr {"cmdb_key_value2[].db_name"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicates from cmdb_key_value2"
if {
condition = is_not_empty {get_attr {"cmdb_key_value2"}}
on_true = set_attr {
"notInUse"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value2},[\"db_name\",\"key\"]);
CTX.setAttribute(\"cmdb_key_value2\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Union key value tables"
union {
table1_name = "cmdb_key_value"
table2_name = "cmdb_key_value2"
result_table_name = "cmdb_key_value"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out empty rows from result"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create reference to tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "db_name"
table2_name = "cmdb_ci_database"
key2_name = "name"
result_table_name = "keyToInstDB"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Linux - CPU | I would like for you to help me build a Pattern that helps achieve Discovery of Linux - CPU. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Linux - CPU"
id = "e69343279f2032001d753758442e7067"
description = ""
step {
name = "Get CPU info"
runcmd_to_var {
cmd = "cat /proc/cpuinfo"
var_names = table {
name = "cpu_info"
col_names = "cpu_data"
}
parsing_strategy = regex_parsing {regex = "^(.*)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Get flags data"
runcmd_to_var {
cmd = "grep hypervisor /proc/cpuinfo "
var_names = "hasHyper"
parsing_strategy = regex_parsing {regex = ".*(hypervisor)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Check if is virtual"
set_attr {
"isVirtual"
eval {"javascript: rtrn =\"\";
var isReal = ${hasHyper};
if (isReal)
{
rtrn = true;
}
else
{
rtrn = false;
}
"}
}
}
step {
name = "Filter CPU data"
filter {
src_table_name = "cpu_info"
target_table_name = "cpu_info"
condition = any {
contains {
get_attr {"cpu_info[].cpu_data"}
"processor"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"cpu MHz"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"physical id"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"core id"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"cpu cores"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"model name"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"vendor_id"
}
}
}
}
step {
name = "Get thread core"
runcmd_to_var {
cmd = "lscpu"
var_names = "thread_core"
parsing_strategy = delimited_parsing {
include_lines_pattern = "Thread"
delimiters = " "
selected_positions = 4
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Parse CPU data"
set_attr {
"cpu_data"
eval {"javascript: rtrn = \"\";
var table = ${cpu_info};
var physicalIds = {};
physicalIds.count = 0;
var coreIds = {};
coreIds.count = 0;
var cpu_cores = 0;
var physical_id_in_curr_block = '';
var result = {};
var processors = 0;
var threadCore = ${thread_core};
for (var i = 0; i < table.size(); i++)
{
var map = table.get(i);
var str = map.get(\"cpu_data\");
var parts = str.split(\":\");
if (parts.length < 2)
{
continue;
}
var name = parts[0].trim();
var value = parts[1].trim();
if (name == \"processor\")
{
processors++;
}
if (name == \"cpu MHz\")
{
var cpu_speed = parseInt(value);
result.cpu_speed = (cpu_speed != Number.NaN ? cpu_speed : \"\");
}
if (name == \"physical id\")
{
physical_id_in_curr_block = value;
if (!physicalIds[value])
{
physicalIds[value] = true;
physicalIds.count++;
}
}
if (name == \"core id\" && !coreIds[physical_id_in_curr_block + '.' + value])
{
coreIds[physical_id_in_curr_block + '.' + value] = true;
coreIds.count++;
}
if (name == \"cpu cores\")
{
cpu_cores = parseInt(value);
}
if (name == \"model name\")
{
result.cpu_name = value;
}
if (name == \"vendor_id\")
{
result.cpu_vendor = value;
}
}
var cpuCount = 1;
if (physicalIds.count > 0)
{
cpuCount = physicalIds.count;
result.hasPhysicalId = true;
}
else{
cpuCount = processors;
result.hasPhysicalId = false;
}
result.cpu_count = cpuCount;
var cpuCoreCount = 1;
if (coreIds.count > 0 || cpu_cores > 0)
{
if (cpu_cores > coreIds.count)
{
cpuCoreCount = cpu_cores;
}
else
{
cpuCoreCount = coreIds.count / cpuCount;
}
}
result.cpu_core_count = cpuCoreCount;
if (${isVirtual} == true && !JSUtil.toBoolean(result.hasPhysicalId))
{
result.cpu_core_count = result.cpu_count;
result.cpu_count = 1;
}
if(threadCore != null){
result.cpu_core_thread = parseInt(threadCore);
}
result.processors = processors;
rtrn = JSON.stringify(result);"}
}
}
step {
name = "Extract CPU data"
parse_var_to_var {
from_var_name = "cpu_data"
to_var_names = table {
name = "cpu_parsed"
col_names = "cpu_vendor","cpu_name","cpu_speed","cpu_count","hasPhysical","cpu_core_count","cpu_core_thread","processors"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "cpu_vendor"
xpath = "/root/cpu_vendor/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_name"
xpath = "/root/cpu_name/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_speed"
xpath = "/root/cpu_speed/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_count"
xpath = "/root/cpu_count/text()"
delimiters = ""
position = 1
}
field {
col_name = "hasPhysical"
xpath = "/root/hasPhysicalId/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_core_count"
xpath = "/root/cpu_core_count/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_core_thread"
xpath = "/root/cpu_core_thread/text()"
delimiters = ""
position = 1
}
field {
col_name = "processors"
xpath = "/root/processors/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Failover: get CPU name"
if {
condition = is_empty {get_attr {"cpu_parsed[1].cpu_name"}}
on_true = runcmd_to_var {
cmd = "lscpu"
execution_mode = "DEFAULT"
var_names = "cpu_name"
parsing_strategy = delimited_parsing {
include_lines_pattern = "Model name"
delimiters = ":"
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Failover: set CPU name"
if {
condition = all {
is_empty {get_attr {"cpu_parsed[1].cpu_name"}}
is_not_empty {get_attr {"cpu_name"}}
}
on_true = set_attr {
"cpu_parsed[1].cpu_name"
get_attr {"cpu_name"}
}
on_false = nop {}
}
}
step {
name = "Failover: get CPU vendor"
if {
condition = is_empty {get_attr {"cpu_parsed[1].cpu_vendor"}}
on_true = runcmd_to_var {
cmd = "lscpu"
execution_mode = "DEFAULT"
var_names = "cpu_vendor"
parsing_strategy = delimited_parsing {
include_lines_pattern = "Vendor ID"
delimiters = ":"
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "Failover: set CPU vendor"
if {
condition = all {
is_empty {get_attr {"cpu_parsed[1].cpu_vendor"}}
is_not_empty {get_attr {"cpu_vendor"}}
}
on_true = set_attr {
"cpu_parsed[1].cpu_vendor"
get_attr {"cpu_vendor"}
}
on_false = nop {}
}
}
step {
name = "Insert CPU data to cmdb_ci_linux_server"
transform {
src_table_name = "cmdb_ci_linux_server"
target_table_name = "cmdb_ci_linux_server"
operation {
set_field {
field_name = "cpu_speed"
value = get_attr {"cpu_parsed[1].cpu_speed"}
}
set_field {
field_name = "cpu_name"
value = get_attr {"cpu_parsed[1].cpu_name"}
}
set_field {
field_name = "cpu_count"
value = get_attr {"cpu_parsed[1].cpu_count"}
}
set_field {
field_name = "cpu_core_count"
value = get_attr {"cpu_parsed[1].cpu_core_count"}
}
set_field {
field_name = "cpu_core_thread"
value = get_attr {"cpu_parsed[1].cpu_core_thread"}
}
set_field {
field_name = "cpu_manufacturer"
value = get_attr {"cpu_parsed[1].cpu_vendor"}
}
set_field {
field_name = "cpu_type"
value = get_attr {"cpu_parsed[1].cpu_vendor"}
}
}
}
}
}
| library {
name = "Linux - CPU"
id = "e69343279f2032001d753758442e7067" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get CPU info"
runcmd_to_var {
cmd = "cat /proc/cpuinfo"
var_names = table {
name = "cpu_info"
col_names = "cpu_data"
}
parsing_strategy = regex_parsing {regex = "^(.*)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get flags data"
runcmd_to_var {
cmd = "grep hypervisor /proc/cpuinfo "
var_names = "hasHyper"
parsing_strategy = regex_parsing {regex = ".*(hypervisor)"}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Check if is virtual"
set_attr {
"isVirtual"
eval {"javascript: rtrn =\"\"; // Script execution: Custom script to perform a specific action or collect data
var isReal = ${hasHyper};
if (isReal)
{
rtrn = true;
}
else
{
rtrn = false;
}
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter CPU data"
filter {
src_table_name = "cpu_info"
target_table_name = "cpu_info"
condition = any {
contains {
get_attr {"cpu_info[].cpu_data"}
"processor"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"cpu MHz"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"physical id"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"core id"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"cpu cores"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"model name"
}
contains {
get_attr {"cpu_info[].cpu_data"}
"vendor_id"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get thread core"
runcmd_to_var {
cmd = "lscpu"
var_names = "thread_core"
parsing_strategy = delimited_parsing {
include_lines_pattern = "Thread"
delimiters = " "
selected_positions = 4
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse CPU data"
set_attr {
"cpu_data"
eval {"javascript: rtrn = \"\"; // Script execution: Custom script to perform a specific action or collect data
var table = ${cpu_info};
var physicalIds = {};
physicalIds.count = 0;
var coreIds = {};
coreIds.count = 0;
var cpu_cores = 0;
var physical_id_in_curr_block = '';
var result = {};
var processors = 0;
var threadCore = ${thread_core};
for (var i = 0; i < table.size(); i++)
{
var map = table.get(i);
var str = map.get(\"cpu_data\");
var parts = str.split(\":\");
if (parts.length < 2)
{
continue;
}
var name = parts[0].trim();
var value = parts[1].trim();
if (name == \"processor\")
{
processors++;
}
if (name == \"cpu MHz\")
{
var cpu_speed = parseInt(value);
result.cpu_speed = (cpu_speed != Number.NaN ? cpu_speed : \"\");
}
if (name == \"physical id\")
{
physical_id_in_curr_block = value;
if (!physicalIds[value])
{
physicalIds[value] = true;
physicalIds.count++;
}
}
if (name == \"core id\" && !coreIds[physical_id_in_curr_block + '.' + value])
{
coreIds[physical_id_in_curr_block + '.' + value] = true;
coreIds.count++;
}
if (name == \"cpu cores\")
{
cpu_cores = parseInt(value);
}
if (name == \"model name\")
{
result.cpu_name = value;
}
if (name == \"vendor_id\")
{
result.cpu_vendor = value;
}
}
var cpuCount = 1;
if (physicalIds.count > 0)
{
cpuCount = physicalIds.count;
result.hasPhysicalId = true;
}
else{
cpuCount = processors;
result.hasPhysicalId = false;
}
result.cpu_count = cpuCount;
var cpuCoreCount = 1;
if (coreIds.count > 0 || cpu_cores > 0)
{
if (cpu_cores > coreIds.count)
{
cpuCoreCount = cpu_cores;
}
else
{
cpuCoreCount = coreIds.count / cpuCount;
}
}
result.cpu_core_count = cpuCoreCount;
if (${isVirtual} == true && !JSUtil.toBoolean(result.hasPhysicalId))
{
result.cpu_core_count = result.cpu_count;
result.cpu_count = 1;
}
if(threadCore != null){
result.cpu_core_thread = parseInt(threadCore);
}
result.processors = processors;
rtrn = JSON.stringify(result);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Extract CPU data"
parse_var_to_var {
from_var_name = "cpu_data"
to_var_names = table {
name = "cpu_parsed"
col_names = "cpu_vendor","cpu_name","cpu_speed","cpu_count","hasPhysical","cpu_core_count","cpu_core_thread","processors"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "cpu_vendor"
xpath = "/root/cpu_vendor/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_name"
xpath = "/root/cpu_name/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_speed"
xpath = "/root/cpu_speed/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_count"
xpath = "/root/cpu_count/text()"
delimiters = ""
position = 1
}
field {
col_name = "hasPhysical"
xpath = "/root/hasPhysicalId/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_core_count"
xpath = "/root/cpu_core_count/text()"
delimiters = ""
position = 1
}
field {
col_name = "cpu_core_thread"
xpath = "/root/cpu_core_thread/text()"
delimiters = ""
position = 1
}
field {
col_name = "processors"
xpath = "/root/processors/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Failover: get CPU name"
if {
condition = is_empty {get_attr {"cpu_parsed[1].cpu_name"}}
on_true = runcmd_to_var {
cmd = "lscpu"
execution_mode = "DEFAULT"
var_names = "cpu_name"
parsing_strategy = delimited_parsing {
include_lines_pattern = "Model name"
delimiters = ":"
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Failover: set CPU name"
if {
condition = all {
is_empty {get_attr {"cpu_parsed[1].cpu_name"}}
is_not_empty {get_attr {"cpu_name"}}
}
on_true = set_attr {
"cpu_parsed[1].cpu_name"
get_attr {"cpu_name"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Failover: get CPU vendor"
if {
condition = is_empty {get_attr {"cpu_parsed[1].cpu_vendor"}}
on_true = runcmd_to_var {
cmd = "lscpu"
execution_mode = "DEFAULT"
var_names = "cpu_vendor"
parsing_strategy = delimited_parsing {
include_lines_pattern = "Vendor ID"
delimiters = ":"
selected_positions = 2
}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Failover: set CPU vendor"
if {
condition = all {
is_empty {get_attr {"cpu_parsed[1].cpu_vendor"}}
is_not_empty {get_attr {"cpu_vendor"}}
}
on_true = set_attr {
"cpu_parsed[1].cpu_vendor"
get_attr {"cpu_vendor"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Insert CPU data to cmdb_ci_linux_server"
transform {
src_table_name = "cmdb_ci_linux_server"
target_table_name = "cmdb_ci_linux_server"
operation {
set_field {
field_name = "cpu_speed"
value = get_attr {"cpu_parsed[1].cpu_speed"}
}
set_field {
field_name = "cpu_name"
value = get_attr {"cpu_parsed[1].cpu_name"}
}
set_field {
field_name = "cpu_count"
value = get_attr {"cpu_parsed[1].cpu_count"}
}
set_field {
field_name = "cpu_core_count"
value = get_attr {"cpu_parsed[1].cpu_core_count"}
}
set_field {
field_name = "cpu_core_thread"
value = get_attr {"cpu_parsed[1].cpu_core_thread"}
}
set_field {
field_name = "cpu_manufacturer"
value = get_attr {"cpu_parsed[1].cpu_vendor"}
}
set_field {
field_name = "cpu_type"
value = get_attr {"cpu_parsed[1].cpu_vendor"}
}
}
}
}
}
|
F5 - Cluster information | I would like for you to help me build a Pattern that helps achieve Discovery of F5 - Cluster information. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "F5 - Cluster information"
id = "e7c75a18db945300fdaf5845dc961956"
description = "null"
step {
name = "Get traffic group information"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.3375.2.1.14.5.2.1"
col_names = "1","2","3"
}
var_names = table {
name = "sysCmTrafficGroupStatusEntry"
col_names = "sysCmTrafficGroupStatusTrafficGroup","sysCmTrafficGroupStatusDeviceName","sysCmTrafficGroupStatusFailoverStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step {
name = "Remove Duplicate Traffic Groups"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${sysCmTrafficGroupStatusEntry},[\"sysCmTrafficGroupStatusDeviceName\"]);
CTX.setAttribute(\"sysCmTrafficGroupStatusEntry\", tableWithoutDuplicates);"}
}
}
step {
name = "Create a unique cluster name"
set_attr {
"tmp_cluster_name"
eval {"arry = ${sysCmTrafficGroupStatusEntry[*].sysCmTrafficGroupStatusDeviceName}
arry = arry.sort()
str = \"\"
for (i=0;i<arry.size();i++)
{arry[i] = arry[i].replaceAll('/Common/','')
arry[i] = arry[i].toLowerCase()
str =arry[i]+\"_\"+str}
return str"}
}
}
step {
name = "Remove last _ from cluster name"
parse_var_to_var {
from_var_name = "tmp_cluster_name"
to_var_names = table {
name = "unique_cluster"
col_names = "cluster_name"
}
parsing_strategy = regex_parsing {regex = "(.*)_"}
if_not_found_do = nop {}
}
}
step {
name = "Parse node names"
parse_var_to_var {
from_var_name = "sysCmTrafficGroupStatusEntry[*].sysCmTrafficGroupStatusDeviceName"
to_var_names = table {
name = "clean_node"
col_names = "clean_node_name"
}
parsing_strategy = delimited_parsing {
delimiters = "/Common/"
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step {
name = "Parse cluster names"
parse_var_to_var {
from_var_name = "sysCmTrafficGroupStatusEntry[*].sysCmTrafficGroupStatusTrafficGroup"
to_var_names = table {
name = "clean_cluster"
col_names = "clean_cluster_name"
}
parsing_strategy = delimited_parsing {
delimiters = "/Common/"
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step {
name = "merge unique name to cluster information table"
merge {
table1_name = "unique_cluster"
table2_name = "sysCmTrafficGroupStatusEntry"
result_table_name = "cluster_info"
unmatched_lines = keep
condition = eq {
"1"
"1"
}
}
}
step {
name = "merge clean node names to cluster info table"
merge {
table1_name = "clean_node"
table2_name = "cluster_info"
result_table_name = "cluster_info"
unmatched_lines = remove
condition = contains {
get_attr {"cluster_info[].sysCmTrafficGroupStatusDeviceName"}
get_attr {"clean_node[].clean_node_name"}
}
}
}
step {
name = "merge clean cluster name to cluster info table"
merge {
table1_name = "clean_cluster"
table2_name = "cluster_info"
result_table_name = "cluster_info"
unmatched_lines = remove
condition = contains {
get_attr {"cluster_info[].sysCmTrafficGroupStatusTrafficGroup"}
get_attr {"clean_cluster[].clean_cluster_name"}
}
}
}
step {
name = "Remove Duplicate Cluster CleanNodeName"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cluster_info},[\"clean_node_name\"]);
CTX.setAttribute(\"cluster_info\", tableWithoutDuplicates);"}
}
}
step {
name = "populate cluster CI table"
if {
condition = is_not_empty {get_attr {"cluster_info"}}
on_true = transform {
src_table_name = "cmdb_ci_cluster"
target_table_name = "cmdb_ci_cluster"
operation {
set_field {
field_name = "name"
value = get_attr {"cluster_info[1].clean_cluster_name"}
}
set_field {
field_name = "cluster_status"
value = eval {"javascript: var state = ${sysCmTrafficGroupStatusEntry[*].sysCmTrafficGroupStatusFailoverStatus};
state = state.toArray();
var rtrn='';
var cluster_status=\"Offline\";
for (var i = 0; i < state.length; i++)
{
if (state[i] == \"4\")
{
cluster_status=\"Online\";
}
}
rtrn=cluster_status;
"}
}
set_field {
field_name = "cluster_id"
value = get_attr {"cluster_info[1].cluster_name"}
}
}
}
on_false = nop {}
}
}
step {
name = "populate cluster nodes to CI table"
transform {
src_table_name = "cluster_info"
target_table_name = "cmdb_ci_cluster_node"
operation {
set_field {
field_name = "operational_status"
value = eval {"javascript: var rtrn = '';
var status = ${cluster_info[].sysCmTrafficGroupStatusFailoverStatus};
if (status=='3') {
rtrn='1';
}else {
rtrn='2';
}
"}
}
set_field {
field_name = "name"
value = get_attr {"cluster_info[].clean_node_name"}
}
set_field {
field_name = "cluster_name"
value = get_attr {"cluster_info[].clean_cluster_name"}
}
set_field {
field_name = "node_name"
value = get_attr {"cluster_info[].clean_node_name"}
}
}
}
}
step {
name = "Add cluster name to LB table"
transform {
src_table_name = "cmdb_ci_lb_bigip"
target_table_name = "cmdb_ci_lb_bigip"
operation {set_field {
field_name = "cluster_name"
value = get_attr {"cluster_info[1].clean_cluster_name"}
}}
}
}
step {
name = "Rel between LB and cluster"
relation_reference {
table1_name = "cmdb_ci_lb_bigip"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cluster"
key2_name = "name"
result_table_name = "lb_to_cluster_rel"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
}
step {
name = "Ref\\Rel between cluster node and LB"
relation_reference {
table1_name = "cmdb_ci_cluster_node"
key1_name = "cluster_name"
table2_name = "cmdb_ci_lb_bigip"
key2_name = "cluster_name"
result_table_name = "node_to_lb_rel"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = "cluster_ref"
}
}
step {
name = "Ref\\Rel between cluster node and cluster"
relation_reference {
table1_name = "cmdb_ci_cluster_node"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cluster"
key2_name = "name"
result_table_name = "node_to_cluster_rel"
unmatched_lines = remove
relation_type = "Cluster of::Cluster"
ref_direction = parentToChild
ref_field_name = "cluster"
}
}
}
| library {
name = "F5 - Cluster information"
id = "e7c75a18db945300fdaf5845dc961956" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get traffic group information"
run_snmp_to_var {
snmp_object_ids = table {
name = "1.3.6.1.4.1.3375.2.1.14.5.2.1"
col_names = "1","2","3"
}
var_names = table {
name = "sysCmTrafficGroupStatusEntry"
col_names = "sysCmTrafficGroupStatusTrafficGroup","sysCmTrafficGroupStatusDeviceName","sysCmTrafficGroupStatusFailoverStatus"
}
if_not_found_do = nop {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove Duplicate Traffic Groups"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${sysCmTrafficGroupStatusEntry},[\"sysCmTrafficGroupStatusDeviceName\"]);
CTX.setAttribute(\"sysCmTrafficGroupStatusEntry\", tableWithoutDuplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create a unique cluster name"
set_attr {
"tmp_cluster_name"
eval {"arry = ${sysCmTrafficGroupStatusEntry[*].sysCmTrafficGroupStatusDeviceName}
arry = arry.sort()
str = \"\"
for (i=0;i<arry.size();i++)
{arry[i] = arry[i].replaceAll('/Common/','')
arry[i] = arry[i].toLowerCase()
str =arry[i]+\"_\"+str}
return str"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove last _ from cluster name"
parse_var_to_var {
from_var_name = "tmp_cluster_name"
to_var_names = table {
name = "unique_cluster"
col_names = "cluster_name"
}
parsing_strategy = regex_parsing {regex = "(.*)_"}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse node names"
parse_var_to_var {
from_var_name = "sysCmTrafficGroupStatusEntry[*].sysCmTrafficGroupStatusDeviceName"
to_var_names = table {
name = "clean_node"
col_names = "clean_node_name"
}
parsing_strategy = delimited_parsing {
delimiters = "/Common/"
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse cluster names"
parse_var_to_var {
from_var_name = "sysCmTrafficGroupStatusEntry[*].sysCmTrafficGroupStatusTrafficGroup"
to_var_names = table {
name = "clean_cluster"
col_names = "clean_cluster_name"
}
parsing_strategy = delimited_parsing {
delimiters = "/Common/"
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "merge unique name to cluster information table"
merge {
table1_name = "unique_cluster"
table2_name = "sysCmTrafficGroupStatusEntry"
result_table_name = "cluster_info"
unmatched_lines = keep
condition = eq {
"1"
"1"
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "merge clean node names to cluster info table"
merge {
table1_name = "clean_node"
table2_name = "cluster_info"
result_table_name = "cluster_info"
unmatched_lines = remove
condition = contains {
get_attr {"cluster_info[].sysCmTrafficGroupStatusDeviceName"}
get_attr {"clean_node[].clean_node_name"}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "merge clean cluster name to cluster info table"
merge {
table1_name = "clean_cluster"
table2_name = "cluster_info"
result_table_name = "cluster_info"
unmatched_lines = remove
condition = contains {
get_attr {"cluster_info[].sysCmTrafficGroupStatusTrafficGroup"}
get_attr {"clean_cluster[].clean_cluster_name"}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove Duplicate Cluster CleanNodeName"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cluster_info},[\"clean_node_name\"]);
CTX.setAttribute(\"cluster_info\", tableWithoutDuplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "populate cluster CI table"
if {
condition = is_not_empty {get_attr {"cluster_info"}}
on_true = transform {
src_table_name = "cmdb_ci_cluster"
target_table_name = "cmdb_ci_cluster"
operation {
set_field {
field_name = "name"
value = get_attr {"cluster_info[1].clean_cluster_name"}
}
set_field {
field_name = "cluster_status"
value = eval {"javascript: var state = ${sysCmTrafficGroupStatusEntry[*].sysCmTrafficGroupStatusFailoverStatus}; // Script execution: Custom script to perform a specific action or collect data
state = state.toArray();
var rtrn='';
var cluster_status=\"Offline\";
for (var i = 0; i < state.length; i++)
{
if (state[i] == \"4\")
{
cluster_status=\"Online\";
}
}
rtrn=cluster_status;
"}
}
set_field {
field_name = "cluster_id"
value = get_attr {"cluster_info[1].cluster_name"}
}
}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "populate cluster nodes to CI table"
transform {
src_table_name = "cluster_info"
target_table_name = "cmdb_ci_cluster_node"
operation {
set_field {
field_name = "operational_status"
value = eval {"javascript: var rtrn = ''; // Script execution: Custom script to perform a specific action or collect data
var status = ${cluster_info[].sysCmTrafficGroupStatusFailoverStatus};
if (status=='3') {
rtrn='1';
}else {
rtrn='2';
}
"}
}
set_field {
field_name = "name"
value = get_attr {"cluster_info[].clean_node_name"}
}
set_field {
field_name = "cluster_name"
value = get_attr {"cluster_info[].clean_cluster_name"}
}
set_field {
field_name = "node_name"
value = get_attr {"cluster_info[].clean_node_name"}
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Add cluster name to LB table"
transform {
src_table_name = "cmdb_ci_lb_bigip"
target_table_name = "cmdb_ci_lb_bigip"
operation {set_field {
field_name = "cluster_name"
value = get_attr {"cluster_info[1].clean_cluster_name"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Rel between LB and cluster"
relation_reference {
table1_name = "cmdb_ci_lb_bigip"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cluster"
key2_name = "name"
result_table_name = "lb_to_cluster_rel"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref\\Rel between cluster node and LB"
relation_reference {
table1_name = "cmdb_ci_cluster_node"
key1_name = "cluster_name"
table2_name = "cmdb_ci_lb_bigip"
key2_name = "cluster_name"
result_table_name = "node_to_lb_rel"
unmatched_lines = remove
relation_type = "Hosted on::Hosts"
ref_direction = parentToChild
ref_field_name = "cluster_ref"
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Ref\\Rel between cluster node and cluster"
relation_reference {
table1_name = "cmdb_ci_cluster_node"
key1_name = "cluster_name"
table2_name = "cmdb_ci_cluster"
key2_name = "name"
result_table_name = "node_to_cluster_rel"
unmatched_lines = remove
relation_type = "Cluster of::Cluster"
ref_direction = parentToChild
ref_field_name = "cluster"
}
}
}
|
Populate Listener Services | I would like for you to help me build a Pattern that helps achieve Discovery of Populate Listener Services. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Populate Listener Services"
id = "e8b0728b979ddd14ed60371e6253af6c"
description = "Populate Listener Services"
step {
name = "get listener command response"
runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;"
"export ORACLE_BASE="
get_attr {"oracle_home"}
";"
"export ORACLE_HOME="
get_attr {"oracle_home"}
";"
get_attr {"oracle_home"}
"/bin/lsnrctl status "
get_attr {"scan_listener_name"}
}
execution_mode = "DEFAULT"
var_names = "services_response"
parsing_strategy = delimited_parsing {
delimiters = "Services Summary..."
selected_positions = 2
line_seperator = "NotExistLineSeperator"
}
if_not_found_do = terminate {}
cache_flag = 0
}
}
step {
name = "split response to services"
parse_var_to_var {
from_var_name = "services_response"
to_var_names = table {
name = "services"
col_names = "service"
}
parsing_strategy = delimited_parsing {
delimiters = "NotExist"
selected_positions = 1
line_seperator = "Serv"
}
if_not_found_do = nop {}
}
}
step {
name = "populate service CI"
parse_var_to_var {
from_var_name = "services[*].service"
to_var_names = table {
name = "cmdb_ci_db_ora_service"
col_names = "name"
}
parsing_strategy = regex_parsing {regex = "^ice \"([^\"]*)"}
if_not_found_do = terminate {}
}
}
step {
name = "merge services table"
merge {
table1_name = "cmdb_ci_db_ora_service"
table2_name = "services"
result_table_name = "cmdb_ci_db_ora_service"
unmatched_lines = remove
condition = starts_with {
concat {
"ice \""
get_attr {"cmdb_ci_db_ora_service[].name"}
"\""
}
get_attr {"services[].service"}
}
}
}
step {
name = "Populate version and port"
transform {
src_table_name = "cmdb_ci_db_ora_service"
target_table_name = "cmdb_ci_db_ora_service"
operation {
set_field {
field_name = "version"
value = get_attr {"cmdb_ci_db_ora_listener[1].version"}
}
set_field {
field_name = "tcp_port"
value = get_attr {"cmdb_ci_db_ora_listener[1].tcp_port"}
}
set_field {
field_name = "listener_name"
value = get_attr {"cmdb_ci_db_ora_listener[1].name"}
}
set_field {
field_name = "name"
value = concat {
get_attr {"cmdb_ci_db_ora_service[].name"}
"@"
get_attr {"computer_system.primaryHostname"}
}
}
set_field {
field_name = "install_status"
value = "1"
}
set_field {
field_name = "operational_status"
value = "1"
}
}
}
}
step {
name = "create relation between listener and services"
relation_reference {
table1_name = "cmdb_ci_db_ora_service"
table2_name = "cmdb_ci_db_ora_listener"
result_table_name = "list_2_serv"
unmatched_lines = keep
relation_type = "Managed by::Manages"
ref_direction = parentToChild
ref_field_name = ""
}
}
step {
name = "create relation between service and instances"
relation_reference {
table1_name = "cmdb_ci_db_ora_instance"
table2_name = "cmdb_ci_db_ora_service"
result_table_name = "inst_2_serv"
unmatched_lines = remove
condition = contains {
get_attr {"cmdb_ci_db_ora_service[].service"}
concat {
"Instance \""
get_attr {"cmdb_ci_db_ora_instance[].sid"}
"\", status"
}
}
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
}
}
| library {
name = "Populate Listener Services"
id = "e8b0728b979ddd14ed60371e6253af6c" // Unique identifier for the pattern
description = "Populate Listener Services" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "get listener command response"
runcmd_to_var {
cmd = concat {
"export TNS_ADMIN="
get_attr {"oracle_home"}
"/network/admin;"
"export ORACLE_BASE="
get_attr {"oracle_home"}
";"
"export ORACLE_HOME="
get_attr {"oracle_home"}
";"
get_attr {"oracle_home"}
"/bin/lsnrctl status "
get_attr {"scan_listener_name"}
}
execution_mode = "DEFAULT"
var_names = "services_response"
parsing_strategy = delimited_parsing {
delimiters = "Services Summary..."
selected_positions = 2
line_seperator = "NotExistLineSeperator"
}
if_not_found_do = terminate {}
cache_flag = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "split response to services"
parse_var_to_var {
from_var_name = "services_response"
to_var_names = table {
name = "services"
col_names = "service"
}
parsing_strategy = delimited_parsing {
delimiters = "NotExist"
selected_positions = 1
line_seperator = "Serv"
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "populate service CI"
parse_var_to_var {
from_var_name = "services[*].service"
to_var_names = table {
name = "cmdb_ci_db_ora_service"
col_names = "name"
}
parsing_strategy = regex_parsing {regex = "^ice \"([^\"]*)"}
if_not_found_do = terminate {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "merge services table"
merge {
table1_name = "cmdb_ci_db_ora_service"
table2_name = "services"
result_table_name = "cmdb_ci_db_ora_service"
unmatched_lines = remove
condition = starts_with {
concat {
"ice \""
get_attr {"cmdb_ci_db_ora_service[].name"}
"\""
}
get_attr {"services[].service"}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Populate version and port"
transform {
src_table_name = "cmdb_ci_db_ora_service"
target_table_name = "cmdb_ci_db_ora_service"
operation {
set_field {
field_name = "version"
value = get_attr {"cmdb_ci_db_ora_listener[1].version"}
}
set_field {
field_name = "tcp_port"
value = get_attr {"cmdb_ci_db_ora_listener[1].tcp_port"}
}
set_field {
field_name = "listener_name"
value = get_attr {"cmdb_ci_db_ora_listener[1].name"}
}
set_field {
field_name = "name"
value = concat {
get_attr {"cmdb_ci_db_ora_service[].name"}
"@"
get_attr {"computer_system.primaryHostname"}
}
}
set_field {
field_name = "install_status"
value = "1"
}
set_field {
field_name = "operational_status"
value = "1"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create relation between listener and services"
relation_reference {
table1_name = "cmdb_ci_db_ora_service"
table2_name = "cmdb_ci_db_ora_listener"
result_table_name = "list_2_serv"
unmatched_lines = keep
relation_type = "Managed by::Manages"
ref_direction = parentToChild
ref_field_name = ""
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create relation between service and instances"
relation_reference {
table1_name = "cmdb_ci_db_ora_instance"
table2_name = "cmdb_ci_db_ora_service"
result_table_name = "inst_2_serv"
unmatched_lines = remove
condition = contains {
get_attr {"cmdb_ci_db_ora_service[].service"}
concat {
"Instance \""
get_attr {"cmdb_ci_db_ora_instance[].sid"}
"\", status"
}
}
relation_type = "Uses::Used by"
ref_direction = parentToChild
ref_field_name = ""
}
}
}
|
SAP Version Library | I would like for you to help me build a Pattern that helps achieve Discovery of SAP Version Library. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "SAP Version Library"
id = "e99df6f83bf14d8a968389cb10ff39b1"
description = ""
step {
name = "set our exe CI and DI"
if {
condition = starts_with {
"D"
get_attr {"instance_name"}
}
on_true = set_attr {
"exefile"
concat {"disp+work"}
}
on_false = nop {}
}
}
step {
name = "set our exe ASCS and SCS"
if {
condition = any {
starts_with {
"ASCS"
get_attr {"instance_name"}
}
starts_with {
"SCS"
get_attr {"instance_name"}
}
}
on_true = set_attr {
"exefile"
"msg_server"
}
on_false = nop {}
}
}
step {
name = "set our exe JC"
if {
condition = starts_with {
"JC"
get_attr {"instance_name"}
}
on_true = set_attr {
"exefile"
"jlaunch"
}
on_false = nop {}
}
}
step {
name = "set our exe ERS"
if {
condition = starts_with {
"ERS"
get_attr {"instance_name"}
}
on_true = set_attr {
"exefile"
"enrepserver"
}
on_false = nop {}
}
}
step {
name = "set version"
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
on_true = runcmd_to_var {
cmd = concat {
"export PATH=$PATH:"
get_attr {"system_directory"}
"exe/run;export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"
get_attr {"system_directory"}
"exe/run;export SAPSYSTEMNAME="
get_attr {"sid"}
"; "
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = delimited_parsing {
include_lines_pattern = "build version"
delimiters = "="
selected_positions = 2
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "set version win"
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"install_directory"}
"exe\\"
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = delimited_parsing {
include_lines_pattern = "build version "
delimiters = "="
selected_positions = 2
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "set version win if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"install_directory"}
"exe\\"
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "^kernel release\\s+(\\d+)$"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "failover to set version win if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"install_directory"}
"exe\\"
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "^server release\\s+(\\d+)$"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "failover to set version win if 7.8 fails"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"install_directory"}
"exe\\"
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "release\\s+(\\d+)$"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "set version unix if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export PATH=$PATH:"
get_attr {"system_directory"}
"exe/run;export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"
get_attr {"system_directory"}
"exe/run;export SAPSYSTEMNAME="
get_attr {"sid"}
"; "
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "^kernel release\\s+(\\d+)$"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step {
name = "failover to set version unix if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export PATH=$PATH:"
get_attr {"system_directory"}
"exe/run;export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"
get_attr {"system_directory"}
"exe/run;export SAPSYSTEMNAME="
get_attr {"sid"}
"; "
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "^server release\\s+(\\d+)$"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step {
name = "failover to set version unix if 7.11 fails"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export PATH=$PATH:"
get_attr {"system_directory"}
"exe/run;export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"
get_attr {"system_directory"}
"exe/run;export SAPSYSTEMNAME="
get_attr {"sid"}
"; "
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "release\\s+(\\d+)$"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
}
| library {
name = "SAP Version Library"
id = "e99df6f83bf14d8a968389cb10ff39b1" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set our exe CI and DI"
if {
condition = starts_with {
"D"
get_attr {"instance_name"}
}
on_true = set_attr {
"exefile"
concat {"disp+work"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set our exe ASCS and SCS"
if {
condition = any {
starts_with {
"ASCS"
get_attr {"instance_name"}
}
starts_with {
"SCS"
get_attr {"instance_name"}
}
}
on_true = set_attr {
"exefile"
"msg_server"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set our exe JC"
if {
condition = starts_with {
"JC"
get_attr {"instance_name"}
}
on_true = set_attr {
"exefile"
"jlaunch"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set our exe ERS"
if {
condition = starts_with {
"ERS"
get_attr {"instance_name"}
}
on_true = set_attr {
"exefile"
"enrepserver"
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set version"
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
on_true = runcmd_to_var {
cmd = concat {
"export PATH=$PATH:"
get_attr {"system_directory"}
"exe/run;export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"
get_attr {"system_directory"}
"exe/run;export SAPSYSTEMNAME="
get_attr {"sid"}
"; "
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = delimited_parsing {
include_lines_pattern = "build version"
delimiters = "="
selected_positions = 2
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set version win"
if {
condition = eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"install_directory"}
"exe\\"
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = delimited_parsing {
include_lines_pattern = "build version "
delimiters = "="
selected_positions = 2
}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set version win if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"install_directory"}
"exe\\"
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "^kernel release\\s+(\\d+)$"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover to set version win if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"install_directory"}
"exe\\"
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "^server release\\s+(\\d+)$"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover to set version win if 7.8 fails"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"WINDOWS"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
get_attr {"install_directory"}
"exe\\"
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "release\\s+(\\d+)$"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "set version unix if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export PATH=$PATH:"
get_attr {"system_directory"}
"exe/run;export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"
get_attr {"system_directory"}
"exe/run;export SAPSYSTEMNAME="
get_attr {"sid"}
"; "
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "^kernel release\\s+(\\d+)$"}
if_not_found_do = nop {}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover to set version unix if empty"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export PATH=$PATH:"
get_attr {"system_directory"}
"exe/run;export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"
get_attr {"system_directory"}
"exe/run;export SAPSYSTEMNAME="
get_attr {"sid"}
"; "
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "^server release\\s+(\\d+)$"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "failover to set version unix if 7.11 fails"
if {
condition = all {
eq {
get_attr {"computer_system.osFamily"}
"UNIX"
}
is_empty {get_attr {"version"}}
}
on_true = runcmd_to_var {
cmd = concat {
"export PATH=$PATH:"
get_attr {"system_directory"}
"exe/run;export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"
get_attr {"system_directory"}
"exe/run;export SAPSYSTEMNAME="
get_attr {"sid"}
"; "
get_attr {"exefile"}
" -V"
}
var_names = "version"
parsing_strategy = regex_parsing {regex = "release\\s+(\\d+)$"}
if_not_found_do = nop {}
cache_flag = 0
}
on_false = nop {}
}
}
}
|
Azure Public IP Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Azure Public IP Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure Public IP Tags"
id = "e9bd36addbd91010b2a1f962759619c3"
description = "Azure Public IP Tags"
step {
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Public IP Tags\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id};
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step {
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Create relation between Tag and Public IP"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_public_ipaddress"
key2_name = "object_id"
result_table_name = "tag_to_public_ip"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Azure Public IP Tags"
id = "e9bd36addbd91010b2a1f962759619c3" // Unique identifier for the pattern
description = "Azure Public IP Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Public IP Tags\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id}; // Unique identifier for the pattern
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and Public IP"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_cloud_public_ipaddress"
key2_name = "object_id"
result_table_name = "tag_to_public_ip"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Storage Volume Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Storage Volume Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Storage Volume Tags"
id = "e9fe2918739733008c51d6dcb7f6a7f0"
description = "Storage Volume Tags"
step {
name = "Parse Storage Volume Tags"
parse_var_to_var {
from_var_name = "rest_resp_volume"
to_var_names = table {
name = "cmdb_key_value"
col_names = "volume_id","key","value"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVolumesResponse"
fields {
field {
col_name = "volume_id"
xpath = "/DescribeVolumesResponse/volumeSet/item/volumeId/text()"
delimiters = ""
position = 1
}
field {
col_name = "key"
xpath = "/DescribeVolumesResponse/volumeSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeVolumesResponse/volumeSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "filter out tags without values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"volume_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Create reference to Tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "volume_id"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "key_to_volume"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Storage Volume Tags"
id = "e9fe2918739733008c51d6dcb7f6a7f0" // Unique identifier for the pattern
description = "Storage Volume Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Storage Volume Tags"
parse_var_to_var {
from_var_name = "rest_resp_volume"
to_var_names = table {
name = "cmdb_key_value"
col_names = "volume_id","key","value"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeVolumesResponse"
fields {
field {
col_name = "volume_id"
xpath = "/DescribeVolumesResponse/volumeSet/item/volumeId/text()"
delimiters = ""
position = 1
}
field {
col_name = "key"
xpath = "/DescribeVolumesResponse/volumeSet/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeVolumesResponse/volumeSet/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter out tags without values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"volume_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference to Tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "volume_id"
table2_name = "cmdb_ci_storage_volume"
key2_name = "object_id"
result_table_name = "key_to_volume"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Oracle OCI - Set API Version | I would like for you to help me build a Pattern that helps achieve Discovery of Oracle OCI - Set API Version. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Oracle OCI - Set API Version"
id = "e57a7eb9db302010d258623b4b96195b"
description = ""
step {
name = "Set API version"
set_attr {
"API_version"
"20160918"
}
}
}
| library {
name = "Oracle OCI - Set API Version"
id = "e57a7eb9db302010d258623b4b96195b" // Unique identifier for the pattern
description = "" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Set API version"
set_attr {
"API_version"
"20160918"
}
}
}
|
Azure Virtual Machine Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Azure Virtual Machine Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Azure Virtual Machine Tags"
id = "e5702ae51b55101010a6dce7cc4bcb75"
description = "Azure Virtual Machine Tags"
step {
name = "Parse the Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Virtual Machine Tags\");
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id};
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id];
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step {
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Create relation between Tag and VM"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_vm_instance"
key2_name = "object_id"
result_table_name = "tag_to_vm"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "Azure Virtual Machine Tags"
id = "e5702ae51b55101010a6dce7cc4bcb75" // Unique identifier for the pattern
description = "Azure Virtual Machine Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Tags"
set_attr {
"tmp"
eval {"javascript: var logger = Packages.com.snc.sw.log.DiscoLog.getLogger(\"Azure Virtual Machine Tags\"); // Script execution: Custom script to perform a specific action or collect data
var resource_table = new Packages.java.util.ArrayList();
var response_tags = ${response_tags};
var response_id = ${response_id}; // Unique identifier for the pattern
for (var i = 0; i < ${resource_response}.size(); i++){
var json = JSON.parse(${resource_response}.get(i));
for (var row in json.data.rows){
try{
var resource_id = json.data.rows[row][response_id]; // Unique identifier for the pattern
for (var tag in json.data.rows[row][response_tags]){
var key = tag;
var value = json.data.rows[row][response_tags][tag];
var resource_line = new Packages.java.util.HashMap();
resource_line.put(\"object_id\", resource_id);
resource_line.put(\"key\", key);
resource_line.put(\"value\", value);
resource_table.add(resource_line);
}
} catch(e) {
logger.error(\"generic resource JSON parse failed with exception = \" + e);
logger.error(\"generic resource JSON parse for element = \" + json.data.rows[row]);
}
}
}
CTX.setAttribute(\"cmdb_key_value\", resource_table);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter cmdb_key_value table"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create relation between Tag and VM"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_vm_instance"
key2_name = "object_id"
result_table_name = "tag_to_vm"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
Amazon AWS - Autoscaling Groups Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Amazon AWS - Autoscaling Groups Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Amazon AWS - Autoscaling Groups Tags"
id = "e2f443a61b211514d298fdd49b4bcb70"
description = "Amazon AWS - Autoscaling Groups Tags"
step {
name = "Parse the Tags"
custom_operation {
attributes {
attribute {
name = "source"
value = "rest_response"
}
attribute {
name = "source_column"
value = ""
}
attribute {
name = "table_name"
value = "cmdb_key_value"
}
attribute {
name = "target_columns"
value = "object_id:DescribeAutoScalingGroupsResponse.DescribeAutoScalingGroupsResult.AutoScalingGroups.AutoScalingGroupARN,key:DescribeAutoScalingGroupsResponse.DescribeAutoScalingGroupsResult.AutoScalingGroups.Tags.Key,value:DescribeAutoScalingGroupsResponse.DescribeAutoScalingGroupsResult.AutoScalingGroups.Tags.Value"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step {
name = "filter out tags without values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Create reference between Autoscaling Groups and Tags"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_instance_scale_set"
key2_name = "object_id"
result_table_name = "autoscaling_groups_to_tags"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
| library {
name = "Amazon AWS - Autoscaling Groups Tags"
id = "e2f443a61b211514d298fdd49b4bcb70" // Unique identifier for the pattern
description = "Amazon AWS - Autoscaling Groups Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Tags"
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source"
value = "rest_response"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "source_column"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "table_name"
value = "cmdb_key_value"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "target_columns"
value = "object_id:DescribeAutoScalingGroupsResponse.DescribeAutoScalingGroupsResult.AutoScalingGroups.AutoScalingGroupARN,key:DescribeAutoScalingGroupsResponse.DescribeAutoScalingGroupsResult.AutoScalingGroups.Tags.Key,value:DescribeAutoScalingGroupsResponse.DescribeAutoScalingGroupsResult.AutoScalingGroups.Tags.Value"
}
}
sys_id_op = "eb6ef2e353a533003e76ddeeff7b124d"
to_var_names = "SystemVariable"
parsing_strategy = empty_strategy {}
if_not_found_do = nop {}
is_paginated = 0
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "filter out tags without values"
filter {
src_table_name = "cmdb_key_value"
target_table_name = "cmdb_key_value"
condition = is_not_empty {get_attr {"cmdb_key_value[].key"}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference between Autoscaling Groups and Tags"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_instance_scale_set"
key2_name = "object_id"
result_table_name = "autoscaling_groups_to_tags"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
on_false = nop {}
}
}
}
|
Perform Azure query | I would like for you to help me build a Pattern that helps achieve Discovery of Perform Azure query. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Perform Azure query"
id = "e31dd99a67da32008ec4a4db2685ef71"
description = "This shared library execute an Azure REST API.
The input is $azureSuffix and output is info_table"
step {
name = "Get All ResourceGroups"
comment = "Using this Azure API URL to get list of resource groups using the specifics subscription ID."
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://management.azure.com/subscriptions/"
get_attr {"service_account[1].account_id"}
"/resourcegroups?api-version=2015-01-01"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
}
sys_id_op = "ce1305cec33322003e76741e81d3aefe"
to_var_names = table {
name = "resourcegroups_table"
col_names = "resourcegroup_name"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "resourcegroup_name"
xpath = "/root/value/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Get location name to display name"
comment = "Using this Azure API URL to get a list of locations using the specifics subscription ID."
custom_operation {
attributes {
attribute {
name = "url"
value = concat {
"https://management.azure.com/subscriptions/"
get_attr {"service_account[1].account_id"}
"/locations?api-version=2014-04-01"
}
}
attribute {
name = "method"
value = "GET"
}
attribute {
name = "body"
value = ""
}
attribute {
name = "headers"
value = ""
}
attribute {
name = "formatted"
value = "true"
}
}
sys_id_op = "ce1305cec33322003e76741e81d3aefe"
to_var_names = table {
name = "ldc_table"
col_names = "display_name","ldc_name"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a"
rootXpath = "/root"
fields {
field {
col_name = "display_name"
xpath = "/root/value/displayName/text()"
delimiters = ""
position = 1
}
field {
col_name = "ldc_name"
xpath = "/root/value/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Filter locations to current location"
comment = "Filter out logical data centers according to LDC table."
filter {
src_table_name = "ldc_table"
target_table_name = "ldc_table"
condition = contains {
get_attr {"ldc_table[].ldc_name"}
get_attr {"ldc[1].region"}
}
}
}
step {
name = "Get Azure query results"
comment = "Using the loop functionality of the \"Transform Table\" operation to get WebSites list."
transform {
src_table_name = "resourcegroups_table"
target_table_name = "info_table"
operation {set_field {
field_name = "payload_info"
value = eval {"javascript:
try{
var result = CTX.getCommandManager().cloudApi('https://management.azure.com/subscriptions/'+${service_account[1].account_id}+'/resourcegroups/'+${resourcegroups_table[].resourcegroup_name}+'/providers'+${azureSuffix},'cloud_context', ${service_account[1].discovery_credentials}, null, 'GET', null, true, CTX);
result;
}
catch(e) { e.getMessage();
}"}
}}
}
}
step {
name = "Remove empty resource groups"
filter {
src_table_name = "info_table"
target_table_name = "info_table"
condition = all {
not_contains {
get_attr {"info_table[].payload_info"}
"[ ]"
}
not_contains {
get_attr {"info_table[].payload_info"}
"[]"
}
}
}
}
step {
name = "Reference to library \"Azure JSON to XML\""
comment = "The functionality of this shared library is to convert Json payload format to XML format, remove empty lines and add \\\"xml\\\" tags in the beginning and the end of the payload."
ref {refid = "56ba953353c13200859ca638cec587c4"}
}
}
| library {
name = "Perform Azure query"
id = "e31dd99a67da32008ec4a4db2685ef71" // Unique identifier for the pattern
description = "This shared library execute an Azure REST API. // Script execution: Custom script to perform a specific action or collect data
The input is $azureSuffix and output is info_table"
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get All ResourceGroups"
comment = "Using this Azure API URL to get list of resource groups using the specifics subscription ID." // Script execution: Custom script to perform a specific action or collect data
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://management.azure.com/subscriptions/" // Script execution: Custom script to perform a specific action or collect data
get_attr {"service_account[1].account_id"}
"/resourcegroups?api-version=2015-01-01"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
}
sys_id_op = "ce1305cec33322003e76741e81d3aefe"
to_var_names = table {
name = "resourcegroups_table"
col_names = "resourcegroup_name"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "resourcegroup_name"
xpath = "/root/value/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get location name to display name"
comment = "Using this Azure API URL to get a list of locations using the specifics subscription ID." // Script execution: Custom script to perform a specific action or collect data
custom_operation {
attributes { // Attribute collection: Collects specific attributes from the discovered CI
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "url"
value = concat {
"https://management.azure.com/subscriptions/" // Script execution: Custom script to perform a specific action or collect data
get_attr {"service_account[1].account_id"}
"/locations?api-version=2014-04-01"
}
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "method"
value = "GET"
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "body"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "headers"
value = ""
}
attribute { // Attribute collection: Collects specific attributes from the discovered CI
name = "formatted"
value = "true"
}
}
sys_id_op = "ce1305cec33322003e76741e81d3aefe"
to_var_names = table {
name = "ldc_table"
col_names = "display_name","ldc_name"
}
parsing_strategy = custom_parsing_strategy {
sys_id = "512a3d5a9f3312003cb191aec32e708a" // Unique identifier for the pattern
rootXpath = "/root"
fields {
field {
col_name = "display_name"
xpath = "/root/value/displayName/text()"
delimiters = ""
position = 1
}
field {
col_name = "ldc_name"
xpath = "/root/value/name/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter locations to current location"
comment = "Filter out logical data centers according to LDC table."
filter {
src_table_name = "ldc_table"
target_table_name = "ldc_table"
condition = contains {
get_attr {"ldc_table[].ldc_name"}
get_attr {"ldc[1].region"}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get Azure query results"
comment = "Using the loop functionality of the \"Transform Table\" operation to get WebSites list."
transform {
src_table_name = "resourcegroups_table"
target_table_name = "info_table"
operation {set_field {
field_name = "payload_info"
value = eval {"javascript: // Script execution: Custom script to perform a specific action or collect data
try{
var result = CTX.getCommandManager().cloudApi('https://management.azure.com/subscriptions/'+${service_account[1].account_id}+'/resourcegroups/'+${resourcegroups_table[].resourcegroup_name}+'/providers'+${azureSuffix},'cloud_context', ${service_account[1].discovery_credentials}, null, 'GET', null, true, CTX); // Script execution: Custom script to perform a specific action or collect data
result;
}
catch(e) { e.getMessage();
}"}
}}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove empty resource groups"
filter {
src_table_name = "info_table"
target_table_name = "info_table"
condition = all {
not_contains {
get_attr {"info_table[].payload_info"}
"[ ]"
}
not_contains {
get_attr {"info_table[].payload_info"}
"[]"
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Reference to library \"Azure JSON to XML\""
comment = "The functionality of this shared library is to convert Json payload format to XML format, remove empty lines and add \\\"xml\\\" tags in the beginning and the end of the payload."
ref {refid = "56ba953353c13200859ca638cec587c4"} // Unique identifier for the pattern
}
}
|
AWS Organizational Units Tags | I would like for you to help me build a Pattern that helps achieve Discovery of AWS Organizational Units Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "AWS Organizational Units Tags"
id = "e375ad481bb635102f24dc61ab4bcb64"
description = "null"
step {
name = "Parse only the OU IDs"
parse_var_to_var {
from_var_name = "cmdb_ci_aws_org_unit[*].aws_org_id"
to_var_names = table {
name = "OU_table"
col_names = "id"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step {
name = "Get all OU tags"
if {
condition = is_not_empty {get_attr {"OU_table"}}
on_true = transform {
src_table_name = "OU_table"
target_table_name = "OU_table"
operation {set_field {
field_name = "response"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"AWS Service Account Tags Extension\");
var cloudcall = new CloudRestAPIClient();
var tagResult = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var tag_table = new Packages.java.util.ArrayList();
var urlAwsTags = \"https://organizations.\"+${region};
var rtrn = \"none\";
headersMap.put(\"X-Amz-Target\", \"AWSOrganizationsV20161128.ListTagsForResource\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
headersMap.put(\"Accept\", \"application/json\");
var tagBody = '{\\\"ResourceId\\\": \\\"'+${OU_table[].id}+'\\\"}';
try{
tagResult = cloudcall.arrayListExecute(${service_account},null, urlAwsTags, headersMap, \"POST\", tagBody, \"true\", CTX );
}
catch (e){
logger.error(\"Sub Accunt Tags REST request failed. exception=\" + e);
}
for (var j = 0; j < tagResult.size(); j++){
tag_table.add(tagResult.get(j));
}
rtrn = tag_table;"}
}}
}
on_false = nop {}
}
}
step {
name = "Filter out OUs without Tags"
filter {
src_table_name = "OU_table"
target_table_name = "OU_table"
condition = all {
contains {
get_attr {"OU_table[].response"}
"\"Key\""
}
contains {
get_attr {"OU_table[].response"}
"\"Value\""
}
}
}
}
step {
name = "Parse the Tags"
set_attr {
"tmp"
eval {"javascript: var resultList = new Packages.java.util.ArrayList();
var resources = ${OU_table[*].id};
var tags_response = ${OU_table[*].response};
for(var i=0; i<tags_response.size(); i++) {
var jsonObj = JSON.parse(tags_response.get(i));
// assuming any OU has less Tags than the API page limit. If this is not the case the index 0 should be replaced with variable.
for(var key_index =0; key_index<jsonObj[0].Tags.length;key_index++){
var row = new Packages.java.util.HashMap();
row.put(\"resource_id\",resources.get(i));
row.put(\"key\",jsonObj[0].Tags[key_index].Key);
row.put(\"value\",jsonObj[0].Tags[key_index].Value);
resultList.add(row);
}
}
CTX.setAttribute('cmdb_key_value', resultList);
"}
}
}
step {
name = "Remove duplicate name value"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"resource_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
}
step {
name = "create reference to OUs"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "resource_id"
table2_name = "cmdb_ci_aws_org_unit"
key2_name = "aws_org_id"
result_table_name = "key_value_to_OU"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "AWS Organizational Units Tags"
id = "e375ad481bb635102f24dc61ab4bcb64" // Unique identifier for the pattern
description = "null" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse only the OU IDs"
parse_var_to_var {
from_var_name = "cmdb_ci_aws_org_unit[*].aws_org_id"
to_var_names = table {
name = "OU_table"
col_names = "id"
}
parsing_strategy = delimited_parsing {
selected_positions = 1
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Get all OU tags"
if {
condition = is_not_empty {get_attr {"OU_table"}}
on_true = transform {
src_table_name = "OU_table"
target_table_name = "OU_table"
operation {set_field {
field_name = "response"
value = eval {"javascript: var logger=Packages.com.snc.sw.log.DiscoLog.getLogger(\"AWS Service Account Tags Extension\"); // Script execution: Custom script to perform a specific action or collect data
var cloudcall = new CloudRestAPIClient();
var tagResult = new Packages.java.util.ArrayList();
var headersMap = new Packages.java.util.HashMap();
var tag_table = new Packages.java.util.ArrayList();
var urlAwsTags = \"https://organizations.\"+${region};
var rtrn = \"none\";
headersMap.put(\"X-Amz-Target\", \"AWSOrganizationsV20161128.ListTagsForResource\");
headersMap.put(\"Content-Type\", \"application/x-amz-json-1.1\");
headersMap.put(\"Accept\", \"application/json\");
var tagBody = '{\\\"ResourceId\\\": \\\"'+${OU_table[].id}+'\\\"}';
try{
tagResult = cloudcall.arrayListExecute(${service_account},null, urlAwsTags, headersMap, \"POST\", tagBody, \"true\", CTX );
}
catch (e){
logger.error(\"Sub Accunt Tags REST request failed. exception=\" + e);
}
for (var j = 0; j < tagResult.size(); j++){
tag_table.add(tagResult.get(j));
}
rtrn = tag_table;"}
}}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Filter out OUs without Tags"
filter {
src_table_name = "OU_table"
target_table_name = "OU_table"
condition = all {
contains {
get_attr {"OU_table[].response"}
"\"Key\""
}
contains {
get_attr {"OU_table[].response"}
"\"Value\""
}
}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse the Tags"
set_attr {
"tmp"
eval {"javascript: var resultList = new Packages.java.util.ArrayList(); // Script execution: Custom script to perform a specific action or collect data
var resources = ${OU_table[*].id};
var tags_response = ${OU_table[*].response};
for(var i=0; i<tags_response.size(); i++) {
var jsonObj = JSON.parse(tags_response.get(i));
// assuming any OU has less Tags than the API page limit. If this is not the case the index 0 should be replaced with variable.
for(var key_index =0; key_index<jsonObj[0].Tags.length;key_index++){
var row = new Packages.java.util.HashMap();
row.put(\"resource_id\",resources.get(i));
row.put(\"key\",jsonObj[0].Tags[key_index].Key);
row.put(\"value\",jsonObj[0].Tags[key_index].Value);
resultList.add(row);
}
}
CTX.setAttribute('cmdb_key_value', resultList);
"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
set_attr {
"tmp"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"resource_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "create reference to OUs"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "resource_id"
table2_name = "cmdb_ci_aws_org_unit"
key2_name = "aws_org_id"
result_table_name = "key_value_to_OU"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|
Security Group Tags | I would like for you to help me build a Pattern that helps achieve Discovery of Security Group Tags. \n CI Type: cmdb_ci_appl_generic\nPattern Type: 2 - Shared library | cmdb_ci_appl_generic | 2 - Shared library | library {
name = "Security Group Tags"
id = "e37b7c6173a733008c51d6dcb7f6a7dd"
description = "Security Group Tags"
step {
name = "Parse Security Group Tags"
parse_var_to_var {
from_var_name = "securitygroup_rest"
to_var_names = table {
name = "cmdb_key_value"
col_names = "object_id","key","value"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeSecurityGroupsResponse"
fields {
field {
col_name = "object_id"
xpath = "/DescribeSecurityGroupsResponse/securityGroupInfo/item/groupId/text()"
delimiters = ""
position = 1
}
field {
col_name = "key"
xpath = "/DescribeSecurityGroupsResponse/securityGroupInfo/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeSecurityGroupsResponse/securityGroupInfo/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step {
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = '';
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step {
name = "Create reference between Security Group and Tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_compute_security_group"
key2_name = "object_id"
result_table_name = "key_to_sec_group"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
| library {
name = "Security Group Tags"
id = "e37b7c6173a733008c51d6dcb7f6a7dd" // Unique identifier for the pattern
description = "Security Group Tags" // Script execution: Custom script to perform a specific action or collect data
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Parse Security Group Tags"
parse_var_to_var {
from_var_name = "securitygroup_rest"
to_var_names = table {
name = "cmdb_key_value"
col_names = "object_id","key","value"
}
parsing_strategy = xml_parsing_strategy {
rootXpath = "/DescribeSecurityGroupsResponse"
fields {
field {
col_name = "object_id"
xpath = "/DescribeSecurityGroupsResponse/securityGroupInfo/item/groupId/text()"
delimiters = ""
position = 1
}
field {
col_name = "key"
xpath = "/DescribeSecurityGroupsResponse/securityGroupInfo/item/tagSet/item/key/text()"
delimiters = ""
position = 1
}
field {
col_name = "value"
xpath = "/DescribeSecurityGroupsResponse/securityGroupInfo/item/tagSet/item/value/text()"
delimiters = ""
position = 1
}
field {
col_name = "forEach"
for_each = "forEach"
delimiters = ""
position = 1
}
}
}
if_not_found_do = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Remove duplicate name value"
if {
condition = is_not_empty {get_attr {"cmdb_key_value"}}
on_true = set_attr {
"dump_var"
eval {"javascript: var tableWithoutDuplicates = ''; // Script execution: Custom script to perform a specific action or collect data
tableWithoutDuplicates = DuplicateRemover.removeDuplicates(${cmdb_key_value},[\"key\", \"value\",\"object_id\"]);
CTX.setAttribute(\"cmdb_key_value\", tableWithoutDuplicates);"}
}
on_false = nop {}
}
}
step { // Step definition: Represents a single action or set of actions in the pattern
name = "Create reference between Security Group and Tags"
relation_reference {
table1_name = "cmdb_key_value"
key1_name = "object_id"
table2_name = "cmdb_ci_compute_security_group"
key2_name = "object_id"
result_table_name = "key_to_sec_group"
unmatched_lines = remove
ref_direction = parentToChild
ref_field_name = "configuration_item"
}
}
}
|