Skip to content

Commit c394d0d

Browse files
committed
style change: use bip codes for brokers;
add brokers status for iib10; add multi-instance broker status for iib9
1 parent ee03249 commit c394d0d

File tree

6 files changed

+141
-20
lines changed

6 files changed

+141
-20
lines changed

iib_metrics_client.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from modules.iib_applications import format_applications
1818
from modules.iib_message_flows import format_message_flows
1919
from log.logger_client import set_logger
20-
from modules.iib_api import run_iib_command
20+
from modules.iib_api import (
21+
run_iib_command,
22+
get_platform_params_for_commands)
2123

2224

2325
logger = set_logger()
@@ -53,7 +55,7 @@ def parse_commandline_args():
5355
parser.add_argument('--iibver', metavar='iibVersion', nargs='?', default=None, dest='iib_cmd_ver', help='IIB version: 9 or 10')
5456
args = parser.parse_args()
5557
if (args.iib_cmd_ver is None) or ((args.iib_cmd_ver != '9') and (args.iib_cmd_ver != '10')):
56-
logger.info("Trying to determine ntegration Bus version from environment variable MQSI_VERSION_V.")
58+
logger.info("Trying to determine Integration Bus version from environment variable MQSI_VERSION_V.")
5759
iib_cmd_ver = get_version_from_env()
5860
else:
5961
iib_cmd_ver = args.iib_cmd_ver
@@ -77,12 +79,12 @@ def put_metric_to_gateway(metric_data, job, pushgateway_host, pushgateway_port):
7779
raise PrometheusBadResponse("{0} is not available!".format(dest_url))
7880

7981

80-
def get_iib_metrics(pushgateway_host, pushgateway_port, iib_ver):
82+
def get_iib_metrics(pushgateway_host, pushgateway_port, mqsilist_command, bip_codes_brokers):
8183
start_time = time.time()
8284
logger.info("Starting metrics collecting for Integration Bus!")
8385
try:
84-
brokers_data = run_iib_command(task='get_brokers_status')
85-
brokers = get_brokers_status(brokers_data=brokers_data)
86+
brokers_data = run_iib_command(task=mqsilist_command)
87+
brokers = get_brokers_status(brokers_data=brokers_data, bip_codes=bip_codes_brokers)
8688
for broker in brokers:
8789
broker_name, status, qm_name = broker
8890
broker_data = format_broker(
@@ -128,9 +130,11 @@ def get_iib_metrics(pushgateway_host, pushgateway_port, iib_ver):
128130
logger.info("Run {0}".format(static_content()))
129131
pushgateway_host, pushgateway_port, iib_ver = parse_commandline_args()
130132
logger.info("Integration Bus version: {0}".format(iib_ver))
133+
mqsilist_command, bip_codes_brokers = get_platform_params_for_commands (iib_ver=iib_ver)
131134
while True:
132135
get_iib_metrics(
133136
pushgateway_host=pushgateway_host,
134137
pushgateway_port=pushgateway_port,
135-
iib_ver=iib_ver)
138+
mqsilist_command=mqsilist_command,
139+
bip_codes_brokers=bip_codes_brokers)
136140
time.sleep(60)

modules/iib_api.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def run_iib_command(**kwargs):
77
"""Calls predefined commands and returns their result."""
88
command_mapping = {
99
'get_brokers_status': 'mqsilist | grep Broker',
10+
'get_integration_nodes_status': 'mqsilist | grep "Integration node"',
1011
'get_broker_objects': 'mqsilist {0} -r',
1112
}
1213
broker = str()
@@ -40,3 +41,41 @@ def get_status(status):
4041
'running': 1,
4142
'stopped': 0}
4243
return status_map[status]
44+
45+
46+
def get_platform_params_for_commands(iib_ver):
47+
"""Returns parameters for internal functions depending on Integration Bus version."""
48+
mqsilist_brokers = "get_brokers_status"
49+
mqsilist_integration_nodes = "get_integration_nodes_status"
50+
# https://www.ibm.com/support/knowledgecenter/en/SSMKHH_9.0.0/com.ibm.etools.mft.bipmsgs.doc/ay_bip1.htm
51+
bip_codes_broker = {
52+
# BIPCode: [broker_name_position, qm_name_position, status_position, trim_last_dot_in_qm_name]
53+
'BIP1284I': [2, 6, 8, 'false'],
54+
'BIP1285I': [2, 6, 8, 'false'],
55+
'BIP1293I': [2, 14 ,7, 'true'],
56+
'BIP1294I': [2, 14 ,7, 'true'],
57+
'BIP1295I': [2, 17, 13, 'true'],
58+
'BIP1296I': [2, 22, 4, 'true'],
59+
'BIP1297I': [2, 14, 7, 'true'],
60+
'BIP1298I': [2, 17, 4, 'true']
61+
}
62+
# https://www.ibm.com/support/knowledgecenter/en/SSMKHH_10.0.0/com.ibm.etools.mft.bipmsgs.doc/ay_bip1.htm
63+
bip_codes_integration_nodes = {
64+
# BIPCode: [broker_name_position, qm_name_position, status_position, trim_last_dot_in_qm_name]
65+
'BIP1284I': [3, 8, 14, 'false'],
66+
'BIP1285I': [3, 7, 9, 'false'],
67+
'BIP1295I': [3, 19, 15, 'true'],
68+
'BIP1296I': [3, 24 ,5, 'true'],
69+
'BIP1298I': [3, 18, 5, 'true'],
70+
'BIP1325I': [3, None, 9, 'false'],
71+
'BIP1326I': [3, None, 5, 'false'],
72+
'BIP1340I': [3, None, 5, 'false'],
73+
'BIP1353I': [3, 8, 10, 'false'],
74+
'BIP1366I': [3, 19, 15, 'true'],
75+
'BIP1376I': [3, 19, 15, 'true'],
76+
'BIP1377I': [3, 24, 5, 'true']
77+
}
78+
if iib_ver == "9":
79+
return mqsilist_brokers, bip_codes_broker
80+
if iib_ver == "10":
81+
return mqsilist_integration_nodes, bip_codes_integration_nodes

modules/iib_brokers.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,23 @@ def get_metric_annotation():
1616
return annotations
1717

1818

19-
def get_brokers_status(brokers_data):
19+
def get_brokers_status(brokers_data, bip_codes):
2020
"""Returns list with statuses for brokers."""
2121
output_list = brokers_data.split('\n')
2222
brokers = list()
2323
for record in filter(None, output_list):
2424
record_list = record.split()
25-
broker_name = record_list[2].replace("'", "")
26-
qm_name = record_list[6].replace("'", "")
27-
status = record_list[8].replace("'", "").replace(".", "")
28-
brokers.append([broker_name, status, qm_name])
25+
bip_code = record_list[0].replace(':', '')
26+
if bip_code in bip_codes.keys():
27+
qm_name = str()
28+
broker_name = record_list[bip_codes[bip_code][0]].replace("'", "")
29+
trim_last_dot = bip_codes[bip_code][3]
30+
if bip_codes[bip_code][1] is not None:
31+
qm_name = record_list[bip_codes[bip_code][1]].replace("'", "")
32+
if trim_last_dot == 'true':
33+
qm_name = qm_name[:-1]
34+
status = record_list[bip_codes[bip_code][2]].replace("'", "").replace(".", "")
35+
brokers.append([broker_name, status, qm_name])
2936
return brokers
3037

3138

tests/test_iib_api.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from mock import patch
1010
from modules.iib_api import (
1111
run_iib_command,
12-
get_status)
12+
get_status,
13+
get_platform_params_for_commands)
1314
sys.path.append(os.getcwd())
1415

1516

@@ -25,6 +26,9 @@ def test_run_iib_command(self, execute_command):
2526
self.assertEqual(
2627
run_iib_command(task='get_brokers_status'),
2728
'mqsilist | grep Broker')
29+
self.assertEqual(
30+
run_iib_command(task='get_integration_nodes_status', broker_name='TEST'),
31+
'mqsilist | grep "Integration node"')
2832
self.assertEqual(
2933
run_iib_command(task='get_broker_objects', broker_name='TEST'),
3034
'mqsilist TEST -r')
@@ -35,3 +39,14 @@ def test_get_status(self):
3539
"""Test for `get_status` function."""
3640
self.assertEqual(0, get_status(status='stopped'))
3741
self.assertEqual(1, get_status(status='running'))
42+
43+
44+
class TestGetPlatformParamsForCommands(unittest.TestCase):
45+
def test_get_platform_params_for_commands(self):
46+
"""Test for `get_platform_params_for_commands` dunction."""
47+
command, bip_codes = get_platform_params_for_commands(iib_ver='9')
48+
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')
51+
self.assertEqual("get_integration_nodes_status", command)
52+
self.assertEqual(12, len(bip_codes))

tests/test_iib_brokers.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,65 @@
77
format_broker,
88
get_metric_name,
99
get_metric_annotation)
10+
from modules.iib_api import get_platform_params_for_commands
1011

1112

1213
class TestGetBrokersStatus(unittest.TestCase):
1314
def test_get_brokers_status(self):
1415
"""Test for `get_brokers_status` function."""
15-
input_data = "BIP1284I: Broker 'TEST' on queue manager 'TEST' is running.\n"
16-
check_data = [['TEST', 'running', 'TEST']]
17-
self.assertEqual(check_data, get_brokers_status(brokers_data=input_data))
16+
input_data = """\
17+
BIP1284I: Broker 'TEST' on queue manager 'QM1' is running.
18+
BIP1285I: Broker 'TEST' on queue manager 'QM1' is stopped.
19+
BIP1293I: Broker 'TEST' is a multi-instance broker running in standby mode on queue manager 'QM1'.
20+
BIP1294I: Broker 'TEST' is a multi-instance broker running in standby mode on queue manager 'QM1'.\nMore information will be available when the broker instance is active.
21+
BIP1295I: Broker 'TEST' is an active multi-instance or High Availability broker that is running on queue manager 'QM1'.
22+
BIP1296I: Broker 'TEST' is stopped. It is a multi-instance broker and will be started as a WebSphere MQ service by queue manager 'QM1'.
23+
BIP1297I: Broker 'TEST' is a multi-instance broker running in standby mode on queue manager 'QM1'.
24+
BIP1298I: Broker 'TEST' is stopped. It will be started as a WebSphere MQ service by queue manager 'QM1'.
25+
"""
26+
check_data = [
27+
['TEST', 'running', 'QM1'],
28+
['TEST', 'stopped', 'QM1'],
29+
['TEST', 'running', 'QM1'],
30+
['TEST', 'running', 'QM1'],
31+
['TEST', 'running', 'QM1'],
32+
['TEST', 'stopped', 'QM1'],
33+
['TEST', 'running', 'QM1'],
34+
['TEST', 'stopped', 'QM1']]
35+
bip_codes_brokers = get_platform_params_for_commands (iib_ver='9')[1]
36+
self.assertEqual(check_data, get_brokers_status(brokers_data=input_data, bip_codes=bip_codes_brokers))
37+
38+
def test_get_integration_nodes_status(self):
39+
"""Test for `get_brokers_status` function for Integration Bus v10."""
40+
input_data = """\
41+
BIP1284I: Integration node 'TEST' with default queue manager 'QM1 and administration URI 'http://testhost:4415' is running.
42+
BIP1285I: Integration node 'TEST' on queue manager 'QM1' is stopped.
43+
BIP1295I: Integration node 'TEST' is an active multi-instance or High Availability integration node that is running on queue manager 'QM1'.
44+
BIP1296I: Integration node 'TEST' is stopped. It is a multi-instance integration node and will be started as a WebSphere MQ service by queue manager 'QM1'.
45+
BIP1298I: Integration node 'TEST' is stopped. It will be started as a WebSphere MQ service by queue manager 'QM1'.
46+
BIP1325I: Integration node 'TEST' with administration URI 'http://testhost:4415' is running.
47+
BIP1326I: Integration node 'TEST' is stopped.
48+
BIP1340I: Integration node 'TEST' is running.
49+
BIP1353I: Integration node 'TEST' with default queue manager 'QM1' is running.
50+
BIP1366I: Integration node 'TEST' is an active multi-instance or High Availability integration node that is running on queue manager 'QM1'. The administration URI is 'http://testhost:4415'
51+
BIP1376I: Integration node 'TEST' is an active multi-instance or High Availability integration node that is running on queue manager 'QM1'. The administration URI is 'http://testhost:4415'
52+
BIP1377I: Integration node 'TEST' is stopped. It is a multi-instance integration node and will be started as a WebSphere MQ service by queue manager 'QM1'. Web administration will be enabled when the node is active.\n\
53+
"""
54+
check_data = [
55+
['TEST', 'running', 'QM1'],
56+
['TEST', 'stopped', 'QM1'],
57+
['TEST', 'running', 'QM1'],
58+
['TEST', 'stopped', 'QM1'],
59+
['TEST', 'stopped', 'QM1'],
60+
['TEST', 'running', ''],
61+
['TEST', 'stopped', ''],
62+
['TEST', 'running', ''],
63+
['TEST', 'running', 'QM1'],
64+
['TEST', 'running', 'QM1'],
65+
['TEST', 'running', 'QM1'],
66+
['TEST', 'stopped', 'QM1']]
67+
bip_codes_integration_nodes = get_platform_params_for_commands (iib_ver='10')[1]
68+
self.assertEqual(check_data, get_brokers_status(brokers_data=input_data, bip_codes=bip_codes_integration_nodes))
1869

1970

2071
class TestGetBrokerItems(unittest.TestCase):

tests/test_iib_metrics_client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def mock_put_metric_to_gateway(metric_data, job):
3838
class TestGetIIBMetrics(unittest.TestCase):
3939
pushgateway_host = 'testhost'
4040
pushgateway_port = '9091'
41-
iib_ver = '9'
41+
mqsilist_command = str()
42+
bip_codes_brokers = dict()
4243

4344
Mocked = MockFunction()
4445
@patch('iib_metrics_client.logger.info', side_effect=Mocked.mock_logging_info)
@@ -56,14 +57,16 @@ def test_get_iib_metrics(
5657
get_iib_metrics(
5758
pushgateway_host=self.pushgateway_host,
5859
pushgateway_port=self.pushgateway_port,
59-
iib_ver=self.iib_ver),
60+
mqsilist_command=self.mqsilist_command,
61+
bip_codes_brokers=self.bip_codes_brokers),
6062
None)
6163
mock_get_brokers_status.return_value = [['TEST', 'stopped', 'TEST']]
6264
self.assertEqual(
6365
get_iib_metrics(
6466
pushgateway_host=self.pushgateway_host,
6567
pushgateway_port=self.pushgateway_port,
66-
iib_ver=self.iib_ver),
68+
mqsilist_command=self.mqsilist_command,
69+
bip_codes_brokers=self.bip_codes_brokers),
6770
None)
6871

6972
@patch('iib_metrics_client.logger.info', side_effect=Mocked.mock_logging_info)
@@ -77,14 +80,16 @@ def test_get_iib_metrics_exception(self, mock_logging_info, mock_logging_error):
7780
get_iib_metrics,
7881
pushgateway_host=self.pushgateway_host,
7982
pushgateway_port=self.pushgateway_port,
80-
iib_ver=self.iib_ver)
83+
mqsilist_command=self.mqsilist_command,
84+
bip_codes_brokers=self.bip_codes_brokers)
8185
mock_iib_command.side_effect = Exception()
8286
self.assertRaises(
8387
Exception,
8488
get_iib_metrics,
8589
pushgateway_host=self.pushgateway_host,
8690
pushgateway_port=self.pushgateway_port,
87-
iib_ver=self.iib_ver)
91+
mqsilist_command=self.mqsilist_command,
92+
bip_codes_brokers=self.bip_codes_brokers)
8893

8994

9095
class TestPutMetricToGateway(unittest.TestCase):

0 commit comments

Comments
 (0)