Skip to content

Commit b56bc2c

Browse files
committed
add statuses for other components for iib10;
use bip codes for all components depending on iib version
1 parent c394d0d commit b56bc2c

12 files changed

+226
-87
lines changed

iib_metrics_client.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def put_metric_to_gateway(metric_data, job, pushgateway_host, pushgateway_port):
7979
raise PrometheusBadResponse("{0} is not available!".format(dest_url))
8080

8181

82-
def get_iib_metrics(pushgateway_host, pushgateway_port, mqsilist_command, bip_codes_brokers):
82+
def get_iib_metrics(pushgateway_host, pushgateway_port, mqsilist_command, bip_codes_brokers, bip_codes_components):
8383
start_time = time.time()
8484
logger.info("Starting metrics collecting for Integration Bus!")
8585
try:
@@ -95,10 +95,20 @@ def get_iib_metrics(pushgateway_host, pushgateway_port, mqsilist_command, bip_co
9595
broker_row_data = run_iib_command(
9696
task='get_broker_objects',
9797
broker_name=broker_name)
98-
exec_groups, applications, message_flows = get_broker_items(broker_row_data=broker_row_data)
99-
exec_groups_data = format_exec_groups(exec_groups=exec_groups)
100-
applications_data = format_applications(applications=applications, broker_name=broker_name)
101-
message_flows_data = format_message_flows(message_flows=message_flows, broker_name=broker_name)
98+
exec_groups, applications, message_flows = get_broker_items(
99+
broker_row_data=broker_row_data,
100+
bip_codes=bip_codes_components)
101+
exec_groups_data = format_exec_groups(
102+
exec_groups=exec_groups,
103+
bip_codes=bip_codes_components)
104+
applications_data = format_applications(
105+
applications=applications,
106+
broker_name=broker_name,
107+
bip_codes=bip_codes_components)
108+
message_flows_data = format_message_flows(
109+
message_flows=message_flows,
110+
broker_name=broker_name,
111+
bip_codes=bip_codes_components)
102112
metric_data = "{0}{1}{2}{3}".format(
103113
broker_data,
104114
exec_groups_data,
@@ -130,11 +140,12 @@ def get_iib_metrics(pushgateway_host, pushgateway_port, mqsilist_command, bip_co
130140
logger.info("Run {0}".format(static_content()))
131141
pushgateway_host, pushgateway_port, iib_ver = parse_commandline_args()
132142
logger.info("Integration Bus version: {0}".format(iib_ver))
133-
mqsilist_command, bip_codes_brokers = get_platform_params_for_commands (iib_ver=iib_ver)
143+
mqsilist_command, bip_codes_brokers, bip_codes_components = get_platform_params_for_commands(iib_ver=iib_ver)
134144
while True:
135145
get_iib_metrics(
136146
pushgateway_host=pushgateway_host,
137147
pushgateway_port=pushgateway_port,
138148
mqsilist_command=mqsilist_command,
139-
bip_codes_brokers=bip_codes_brokers)
149+
bip_codes_brokers=bip_codes_brokers,
150+
bip_codes_components=bip_codes_components)
140151
time.sleep(60)

modules/iib_api.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def get_platform_params_for_commands(iib_ver):
4747
"""Returns parameters for internal functions depending on Integration Bus version."""
4848
mqsilist_brokers = "get_brokers_status"
4949
mqsilist_integration_nodes = "get_integration_nodes_status"
50+
# See IBM diagnostic messages:
5051
# https://www.ibm.com/support/knowledgecenter/en/SSMKHH_9.0.0/com.ibm.etools.mft.bipmsgs.doc/ay_bip1.htm
52+
# Also you can use command: mqsiexplain <bip_code>
5153
bip_codes_broker = {
5254
# BIPCode: [broker_name_position, qm_name_position, status_position, trim_last_dot_in_qm_name]
5355
'BIP1284I': [2, 6, 8, 'false'],
@@ -75,7 +77,24 @@ def get_platform_params_for_commands(iib_ver):
7577
'BIP1376I': [3, 19, 15, 'true'],
7678
'BIP1377I': [3, 24, 5, 'true']
7779
}
80+
bip_codes_broker_components = {
81+
# BIPCode: [component_type, positions: broker_name, egname, status]
82+
'BIP1286I': ['exec_groups', 6, 3, 8],
83+
'BIP1287I': ['exec_groups', 6, 3, 8],
84+
# BIPCode: [component_type, positions: egname, appname, status]
85+
'BIP1275I': ['applications', 6, 2, 8],
86+
'BIP1276I': ['applications', 6, 2, 8],
87+
# BIPCode: [component_type, positions: egname, appname, msgflowname, status]
88+
'BIP1277I': ['message_flows', 7, 11, 3, 9],
89+
'BIP1278I': ['message_flows', 7, 11, 3, 9]}
90+
bip_codes_integration_nodes_components = {
91+
'BIP1286I': ['exec_groups', 7, 3, 9],
92+
'BIP1287I': ['exec_groups', 7, 3, 9],
93+
'BIP1275I': ['applications', 6, 2, 8],
94+
'BIP1276I': ['applications', 6, 2, 8],
95+
'BIP1277I': ['message_flows', 7, 11, 3, 9],
96+
'BIP1278I': ['message_flows', 7, 11, 3, 9]}
7897
if iib_ver == "9":
79-
return mqsilist_brokers, bip_codes_broker
98+
return mqsilist_brokers, bip_codes_broker, bip_codes_broker_components
8099
if iib_ver == "10":
81-
return mqsilist_integration_nodes, bip_codes_integration_nodes
100+
return mqsilist_integration_nodes, bip_codes_integration_nodes, bip_codes_integration_nodes_components

modules/iib_applications.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,28 @@ def get_metric_annotation():
1616
return annotations
1717

1818

19-
def format_applications(applications, broker_name):
19+
def format_applications(applications, broker_name, bip_codes):
2020
"""Returns string with all metrics for all applications which ready to push to pushgateway."""
2121
metrics_annotation = get_metric_annotation()
2222
app_metric_data = str()
2323
for app in applications:
2424
app_list = app.split()
25-
egname, app_name, status = app_list[6], app_list[2], app_list[8].replace(".", "")
26-
template_string = 'egname="{0}", brokername="{1}", appname="{2}"'.format(
27-
egname.replace("'", ""),
28-
broker_name,
29-
app_name.replace("'", ""))
30-
app_metric = '{0}{{{1}}} {2}\n'.format(
31-
get_metric_name(metric_label='status'),
32-
template_string,
33-
get_status(status=status))
34-
app_metric_data += app_metric
35-
app_metric_data = '{0}{1}'.format(
36-
metrics_annotation['status'],
37-
app_metric_data)
25+
bip_code = app_list[0].replace(':', '')
26+
if bip_code in bip_codes.keys():
27+
egname = app_list[bip_codes[bip_code][1]]
28+
app_name = app_list[bip_codes[bip_code][2]]
29+
status = app_list[bip_codes[bip_code][3]].replace(".", "")
30+
template_string = 'egname="{0}", brokername="{1}", appname="{2}"'.format(
31+
egname.replace("'", ""),
32+
broker_name,
33+
app_name.replace("'", ""))
34+
app_metric = '{0}{{{1}}} {2}\n'.format(
35+
get_metric_name(metric_label='status'),
36+
template_string,
37+
get_status(status=status))
38+
app_metric_data += app_metric
39+
if app_metric_data:
40+
app_metric_data = '{0}{1}'.format(
41+
metrics_annotation['status'],
42+
app_metric_data)
3843
return app_metric_data

modules/iib_brokers.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,22 @@ def get_brokers_status(brokers_data, bip_codes):
3636
return brokers
3737

3838

39-
def get_broker_items(broker_row_data):
39+
def get_broker_items(broker_row_data, bip_codes):
4040
"""Returns lists with data for broker items: execution groups, applications, message flows."""
4141
output_list = broker_row_data.split('\n')
4242
exec_groups = list()
4343
applications = list()
4444
message_flows = list()
45-
# See IBM diagnostic messages:
46-
# https://www.ibm.com/support/knowledgecenter/en/SSMKHH_9.0.0/com.ibm.etools.mft.bipmsgs.doc/ay_bip1.htm
47-
# Also you can use command: mqsiexplain <bip_code>
48-
bip_codes = {
49-
'BIP1286I': exec_groups,
50-
'BIP1287I': exec_groups,
51-
'BIP1275I': applications,
52-
'BIP1276I': applications,
53-
'BIP1277I': message_flows,
54-
'BIP1278I': message_flows}
5545
for record in output_list:
5646
if record:
5747
bip_code = record.split()[0].replace(':', '')
5848
if bip_code in bip_codes.keys():
59-
bip_codes[bip_code].append(record)
49+
if bip_codes[bip_code][0] == 'exec_groups':
50+
exec_groups.append(record)
51+
if bip_codes[bip_code][0] == 'applications':
52+
applications.append(record)
53+
if bip_codes[bip_code][0] == 'message_flows':
54+
message_flows.append(record)
6055
return exec_groups, applications, message_flows
6156

6257

modules/iib_exec_groups.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@ def get_metric_annotation():
1616
return annotations
1717

1818

19-
def format_exec_groups(exec_groups):
19+
def format_exec_groups(exec_groups, bip_codes):
2020
"""Returns string with all metrics for all execution groups which ready to push to pushgateway."""
2121
metrics_annotation = get_metric_annotation()
2222
eg_metric_data = str()
2323
for eg in exec_groups:
2424
eg_list = eg.split()
25-
broker_name, egname, status = eg_list[6], eg_list[3], eg_list[8].replace(".", "")
26-
template_string = 'brokername="{0}", egname="{1}"'.format(
27-
broker_name.replace("'", ""),
28-
egname.replace("'", ""))
29-
eg_metric = '{0}{{{1}}} {2}\n'.format(
30-
get_metric_name(metric_label='status'),
31-
template_string,
32-
get_status(status=status))
33-
eg_metric_data += eg_metric
34-
eg_metric_data = '{0}{1}'.format(
35-
metrics_annotation['status'],
36-
eg_metric_data)
25+
bip_code = eg_list[0].replace(':', '')
26+
if bip_code in bip_codes.keys():
27+
broker_name = eg_list[bip_codes[bip_code][1]]
28+
egname = eg_list[bip_codes[bip_code][2]]
29+
status = eg_list[bip_codes[bip_code][3]].replace(".", "")
30+
template_string = 'brokername="{0}", egname="{1}"'.format(
31+
broker_name.replace("'", ""),
32+
egname.replace("'", ""))
33+
eg_metric = '{0}{{{1}}} {2}\n'.format(
34+
get_metric_name(metric_label='status'),
35+
template_string,
36+
get_status(status=status))
37+
eg_metric_data += eg_metric
38+
if eg_metric_data:
39+
eg_metric_data = '{0}{1}'.format(
40+
metrics_annotation['status'],
41+
eg_metric_data)
3742
return eg_metric_data

modules/iib_message_flows.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,30 @@ def get_metric_annotation():
1616
return annotations
1717

1818

19-
def format_message_flows(message_flows, broker_name):
19+
def format_message_flows(message_flows, broker_name, bip_codes):
2020
"""Returns string with all metrics for all message flows which ready to push to pushgateway."""
2121
metrics_annotation = get_metric_annotation()
2222
msg_flow_metric_data = str()
2323
for msg_flow in message_flows:
2424
msg_flow_list = msg_flow.split()
25-
egname, app_name, message_flow_name, status = msg_flow_list[7], msg_flow_list[11], msg_flow_list[3], msg_flow_list[9].replace(".", "")
26-
template_string = 'egname="{0}", brokername="{1}", appname="{2}", messageflowname="{3}"'.format(
27-
egname.replace("'", ""),
28-
broker_name,
29-
app_name.replace("'", "").replace(",", ""),
30-
message_flow_name.replace("'", ""))
31-
msg_flow_metric = '{0}{{{1}}} {2}\n'.format(
32-
get_metric_name(metric_label='status'),
33-
template_string,
34-
get_status(status=status))
35-
msg_flow_metric_data += msg_flow_metric
36-
msg_flow_metric_data = '{0}{1}'.format(
37-
metrics_annotation['status'],
38-
msg_flow_metric_data)
25+
bip_code = msg_flow_list[0].replace(':', '')
26+
if bip_code in bip_codes.keys():
27+
egname = msg_flow_list[bip_codes[bip_code][1]]
28+
app_name = msg_flow_list[bip_codes[bip_code][2]]
29+
message_flow_name = msg_flow_list[bip_codes[bip_code][3]]
30+
status = msg_flow_list[bip_codes[bip_code][4]].replace(".", "")
31+
template_string = 'egname="{0}", brokername="{1}", appname="{2}", messageflowname="{3}"'.format(
32+
egname.replace("'", ""),
33+
broker_name,
34+
app_name.replace("'", "").replace(",", ""),
35+
message_flow_name.replace("'", ""))
36+
msg_flow_metric = '{0}{{{1}}} {2}\n'.format(
37+
get_metric_name(metric_label='status'),
38+
template_string,
39+
get_status(status=status))
40+
msg_flow_metric_data += msg_flow_metric
41+
if msg_flow_metric_data:
42+
msg_flow_metric_data = '{0}{1}'.format(
43+
metrics_annotation['status'],
44+
msg_flow_metric_data)
3945
return msg_flow_metric_data

tests/test_iib_api.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ def test_get_status(self):
4444
class TestGetPlatformParamsForCommands(unittest.TestCase):
4545
def test_get_platform_params_for_commands(self):
4646
"""Test for `get_platform_params_for_commands` dunction."""
47-
command, bip_codes = get_platform_params_for_commands(iib_ver='9')
47+
command, bip_codes_brokers, bip_codes_components = get_platform_params_for_commands(iib_ver='9')
4848
self.assertEqual("get_brokers_status", command)
49-
self.assertEqual(8, len(bip_codes))
50-
command, bip_codes = get_platform_params_for_commands(iib_ver='10')
49+
self.assertEqual(8, len(bip_codes_brokers))
50+
self.assertEqual(6, len(bip_codes_components))
51+
command, bip_codes_brokers, bip_codes_components = get_platform_params_for_commands(iib_ver='10')
5152
self.assertEqual("get_integration_nodes_status", command)
52-
self.assertEqual(12, len(bip_codes))
53+
self.assertEqual(12, len(bip_codes_brokers))
54+
self.assertEqual(6, len(bip_codes_components))

tests/test_iib_applications.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
format_applications,
88
get_metric_name,
99
get_metric_annotation)
10+
from modules.iib_api import get_platform_params_for_commands
1011
sys.path.append(os.getcwd())
1112

1213

@@ -23,20 +24,39 @@ def test_format_applications_good_status(self):
2324
# TYPE ib_application_status gauge
2425
ib_application_status{egname="TEST", brokername="TEST", appname="TEST.RUNNING"} 1
2526
ib_application_status{egname="TEST", brokername="TEST", appname="TEST.STOPPED"} 0\n'''
27+
bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2]
2628
self.assertEqual(
2729
check_data,
2830
format_applications(
2931
applications=input_data_app,
30-
broker_name=self.input_data_broker))
32+
broker_name=self.input_data_broker,
33+
bip_codes=bip_codes_components))
34+
bip_codes_components = get_platform_params_for_commands(iib_ver='10')[2]
35+
self.assertEqual(
36+
check_data,
37+
format_applications(
38+
applications=input_data_app,
39+
broker_name=self.input_data_broker,
40+
bip_codes=bip_codes_components))
3141

3242
def test_format_applications_bad_status(self):
3343
"""Test for `format_applications` function for bad case."""
3444
input_data_app = ["BIP1111I: Execution group 'TEST.INVALID' on execution group 'TEST' is invalid."]
35-
self.assertRaises(
36-
KeyError,
37-
format_applications,
38-
applications=input_data_app,
39-
broker_name=self.input_data_broker)
45+
check_data = ''
46+
bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2]
47+
self.assertEqual(
48+
check_data,
49+
format_applications(
50+
applications=input_data_app,
51+
broker_name=self.input_data_broker,
52+
bip_codes=bip_codes_components))
53+
bip_codes_components = get_platform_params_for_commands(iib_ver='10')[2]
54+
self.assertEqual(
55+
check_data,
56+
format_applications(
57+
applications=input_data_app,
58+
broker_name=self.input_data_broker,
59+
bip_codes=bip_codes_components))
4060

4161

4262
class GetMetricAnnotation(unittest.TestCase):

tests/test_iib_brokers.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,37 @@ def test_get_broker_items(self):
8787
"BIP1276I: Application 'Adapter2' on execution group 'IB' is stopped."],
8888
["BIP1277I: Message flow 'esb.adapter.RequestForESB' on execution group 'IB' is running. (Application 'Adapter', Library '')",
8989
"BIP1278I: Message flow 'esb.adapter.RequestForESB2' on execution group 'IB' is stopped. (Application 'Adapter', Library '')"])
90-
self.assertEqual(check_data, get_broker_items(broker_row_data=input_data))
90+
bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2]
91+
self.assertEqual(
92+
check_data,
93+
get_broker_items(
94+
broker_row_data=input_data,
95+
bip_codes=bip_codes_components))
96+
97+
input_data = '''"-----------------------------------
98+
BIP1286I: Integration server 'IB' on integration node 'TEST' is running.
99+
BIP1287I: Integration server 'IB' on integration node 'TEST2' is stopped.
100+
BIP1275I: Application 'Adapter' on execution group 'IB' is running.
101+
BIP1276I: Application 'Adapter2' on execution group 'IB' is stopped.
102+
BIP1277I: Message flow 'esb.adapter.RequestForESB' on execution group 'IB' is running. (Application 'Adapter', Library '')
103+
BIP1278I: Message flow 'esb.adapter.RequestForESB2' on execution group 'IB' is stopped. (Application 'Adapter', Library '')
104+
BIP1274I: Library 'Utils' is deployed to execution group 'IB'. (Application 'Adapter')
105+
BIP1299I: File 'esb.util.subflow' is deployed to execution group 'IB'. (Application 'Adapter', Library 'Utils')
106+
BIP8071I: Successful command completion.\n"'''
107+
check_data = (["BIP1286I: Integration server 'IB' on integration node 'TEST' is running.",
108+
"BIP1287I: Integration server 'IB' on integration node 'TEST2' is stopped."],
109+
["BIP1275I: Application 'Adapter' on execution group 'IB' is running.",
110+
"BIP1276I: Application 'Adapter2' on execution group 'IB' is stopped."],
111+
["BIP1277I: Message flow 'esb.adapter.RequestForESB' on execution group 'IB' is running. (Application 'Adapter', Library '')",
112+
"BIP1278I: Message flow 'esb.adapter.RequestForESB2' on execution group 'IB' is stopped. (Application 'Adapter', Library '')"])
113+
bip_codes_components = get_platform_params_for_commands(iib_ver='10')[2]
114+
self.assertEqual(
115+
check_data,
116+
get_broker_items(
117+
broker_row_data=input_data,
118+
bip_codes=bip_codes_components))
119+
120+
91121

92122

93123
class TestFormatBroker(unittest.TestCase):

0 commit comments

Comments
 (0)