pattern { metadata { id = "6188bc6ebc974120b90947a80e74a76f" name = "RabbitMQ Windows" description = "erl.exe pattern" citype = "cmdb_ci_appl_rabbitmq" apply_to_os_families = "cmdb_ci_win_server" } identification { name = "Identification section of RabbitMQ" entry_point {type = "cmdb_ci_endpoint_fromcluster_t,cmdb_ci_endpoint_rabbitmq"} find_process_strategy {strategy = LISTENING_PORT} step { name = "match process name" match { all { eq { get_attr {"process.executable"} "erl.exe" } contains { get_attr {"process.commandLine"} "rabbit" } } terminate_op = terminate } } step { name = "Get Service name" run_wmi_query_to_var { namespace = "\\root\\CIMV2" query = concat { "SELECT Name FROM Win32_Service WHERE ProcessId =" get_attr {"process.parentProcessId"} } var_names = table { name = "ServiceName" } if_not_found_do = nop {} cache_flag = 0 } } step { name = "Check RabbitMQ" match { contains { get_attr {"ServiceName[*].Name"} "RabbitMQ" } terminate_op = terminate } } step { name = "Set Service name" set_attr { "service_name" get_attr {"ServiceName[1].Name"} } } step { name = "get node name" parse_var_to_var { from_var_name = "process.commandLine" to_var_names = "node_name" parsing_strategy = regex_parsing {regex = "-sname\\s([\\w|@]*)\\s.*"} if_not_found_do = nop {} } } step { name = "get install_directory" parse_var_to_var { from_var_name = "process.commandLine" to_var_names = "install_directory" parsing_strategy = regex_parsing {regex = "-pa \"(.*)\\\\\\\\ebin"} if_not_found_do = nop {} } } step { name = "if install_directory is EMPTY" if { condition = is_empty {get_attr {"install_directory"}} on_true = runcmd_to_var { cmd = "where rabbitmq-server.bat" execution_mode = "DEFAULT" var_names = "install_directory" parsing_strategy = regex_parsing {regex = "(.*)\\\\sbin\\\\rabbitmq-server\\.bat"} if_not_found_do = nop {} cache_flag = 0 } on_false = nop {} } } step { name = "if install_directory is still EMPTY" if { condition = is_empty {get_attr {"install_directory"}} on_true = parse_var_to_var { from_var_name = "process.environmentVariables.ERL_LIBS.value" to_var_names = "install_directory" parsing_strategy = delimited_parsing { delimiters = "\\plugins" selected_positions = 1 } if_not_found_do = nop {} } on_false = nop {} } } step { name = "get node name if empty" if { condition = is_empty {get_attr {"node_name"}} on_true = parse_var_to_var { from_var_name = "process.commandLine" to_var_names = table {col_names = "node_name","install_directory"} parsing_strategy = regex_parsing {regex = "-sname\\s(.*)\\s.*-pa \"(.*)\\\\\\\\ebin"} if_not_found_do = nop {} } on_false = nop {} } } step { name = "Set label" set_attr { "name" get_attr {"node_name"} } } step { name = "Set vname" set_attr { "vhost" get_attr {"entry_point.vhost"} } } step { name = "get version" runcmd_to_var { cmd = concat { "\"" get_attr {"install_directory"} "\\\\sbin\\\\rabbitmqctl.bat\" " "status" } var_names = "version" parsing_strategy = regex_parsing {regex = "\"RabbitMQ\",\"(.*)\""} if_not_found_do = nop {} cache_flag = 0 } } step { name = "if version is EMPTY - get version" if { condition = is_empty {get_attr {"version"}} on_true = runcmd_to_var { cmd = concat { "\"" get_attr {"install_directory"} "\\\\sbin\\\\rabbitmqctl.bat\" " "status" } var_names = "version" parsing_strategy = regex_parsing {regex = "RabbitMQ version: (.*)"} if_not_found_do = nop {} cache_flag = 0 } on_false = nop {} } } step { name = "Check Mandatory Attributes" match { all { is_not_empty {get_attr {"service_name"}} is_not_empty {get_attr {"install_directory"}} is_not_empty {get_attr {"node_name"}} is_not_empty {get_attr {"vhost"}} } terminate_op = terminate } } } connection { name = "queue connectivity no queue name" step { name = "GetQueues" if { condition = is_empty {get_attr {"entry_point.queue_name"}} on_true = runcmd_to_var { cmd = concat { "\"" get_attr {"install_directory"} "\\\\sbin\\\\rabbitmqctl.bat\" " " -p " get_attr {"vhost"} " list_queues name pid slave_pids | findstr " get_attr {"node_name"} } var_names = table { name = "QueueTable" col_names = "QueueName" } parsing_strategy = regex_parsing {regex = "(\\S*)\\s.*"} if_not_found_do = nop {} cache_flag = 0 } on_false = nop {} } } step { name = "create connection" if { condition = is_not_empty {get_attr {"QueueTable"}} on_true = create_connection { connection_type = INCLUSION entry_point_type = "cmdb_ci_endpoint_inclusion_rabbitmq_queue" attributes { attribute { name = "host" value = get_attr {"entry_point.host"} } attribute { name = "name" value = get_attr {"QueueTable[*].QueueName"} } attribute { name = "vhost" value = get_attr {"vhost"} } } is_artificial = "false" traffic_based = "false" } on_false = nop {} } } } connection { name = "queue connectivity with queue name" step { name = "set default vhost" if { condition = all { is_not_empty {get_attr {"entry_point.queue_name"}} is_empty {get_attr {"vhost"}} } on_true = set_attr { "vhost" "/" } on_false = nop {} } } step { name = "Create connection" if { condition = is_not_empty {get_attr {"entry_point.queue_name"}} on_true = create_connection { connection_type = INCLUSION entry_point_type = "cmdb_ci_endpoint_inclusion_rabbitmq_queue" attributes { attribute { name = "host" value = get_attr {"entry_point.host"} } attribute { name = "name" value = get_attr {"entry_point.queue_name"} } attribute { name = "vhost" value = get_attr {"vhost"} } } is_artificial = "false" traffic_based = "false" } on_false = nop {} } } } connection { name = "queue connectivity no queue no vhost" step { name = "get vhosts" if { condition = all { is_empty {get_attr {"entry_point.queue_name"}} is_empty {get_attr {"vhost"}} } on_true = runcmd_to_var { cmd = concat { "\"" get_attr {"install_directory"} "\\\\sbin\\\\rabbitmqctl.bat\" " " -q list_vhosts" } var_names = table { name = "OutputTable" col_names = "vhost" } parsing_strategy = delimited_parsing { selected_positions = 1 } if_not_found_do = nop {} cache_flag = 0 } on_false = nop {} } } step { name = "get queues" transform { src_table_name = "OutputTable" target_table_name = "OutputTable" operation {set_field { field_name = "queues" value = concat {eval {"return com.snc.sw.commands.wmi.WmiCommand.getWmiProvider (ctx).executeCommand (\"\\\"\"+${install_directory}+\"\\\\sbin\\\\rabbitmqctl.bat\\\" -q -p \"+${OutputTable[].vhost} + \" list_queues name\")"}} }} } } step { name = "parse queues" parse_var_to_var { from_var_name = "OutputTable[*].queues" to_var_names = table { name = "QueueTable" col_names = "Queue" } parsing_strategy = delimited_parsing { selected_positions = 1 } if_not_found_do = nop {} } } step { name = "add vhost to queue" merge { table1_name = "QueueTable" table2_name = "OutputTable" result_table_name = "OutputTable" unmatched_lines = remove condition = contains { get_attr {"OutputTable[].queues"} get_attr {"QueueTable[].Queue"} } } } step { name = "Create connection" create_connection { connection_type = INCLUSION entry_point_type = "cmdb_ci_endpoint_inclusion_rabbitmq_queue" attributes { attribute { name = "host" value = get_attr {"entry_point.host"} } attribute { name = "name" value = get_attr {"OutputTable[*].Queue"} } attribute { name = "vhost" value = get_attr {"OutputTable[*].vhost"} } } is_artificial = "false" traffic_based = "false" } } } }