def test_get_broker_items(self): """Test for `get_broker_items` function.""" input_data = '''"----------------------------------- BIP1286I: Execution group 'IB' on broker 'TEST' is running. BIP1287I: Execution group 'IB' on broker 'TEST2' is stopped. BIP1275I: Application 'Adapter' on execution group 'IB' is running. BIP1276I: Application 'Adapter2' on execution group 'IB' is stopped. BIP1277I: Message flow 'esb.adapter.RequestForESB' on execution group 'IB' is running. (Application 'Adapter', Library '') BIP1278I: Message flow 'esb.adapter.RequestForESB2' on execution group 'IB' is stopped. (Application 'Adapter', Library '') BIP1274I: Library 'Utils' is deployed to execution group 'IB'. (Application 'Adapter') BIP1299I: File 'esb.util.subflow' is deployed to execution group 'IB'. (Application 'Adapter', Library 'Utils') BIP8071I: Successful command completion.\n"''' check_data = ([ "BIP1286I: Execution group 'IB' on broker 'TEST' is running.", "BIP1287I: Execution group 'IB' on broker 'TEST2' is stopped." ], [ "BIP1275I: Application 'Adapter' on execution group 'IB' is running.", "BIP1276I: Application 'Adapter2' on execution group 'IB' is stopped." ], [ "BIP1277I: Message flow 'esb.adapter.RequestForESB' on execution group 'IB' is running. (Application 'Adapter', Library '')", "BIP1278I: Message flow 'esb.adapter.RequestForESB2' on execution group 'IB' is stopped. (Application 'Adapter', Library '')" ]) bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2] self.assertEqual( check_data, get_broker_items(broker_row_data=input_data, bip_codes=bip_codes_components)) input_data = '''"----------------------------------- BIP1286I: Integration server 'IB' on integration node 'TEST' is running. BIP1287I: Integration server 'IB' on integration node 'TEST2' is stopped. BIP1275I: Application 'Adapter' on execution group 'IB' is running. BIP1276I: Application 'Adapter2' on execution group 'IB' is stopped. BIP1277I: Message flow 'esb.adapter.RequestForESB' on execution group 'IB' is running. (Application 'Adapter', Library '') BIP1278I: Message flow 'esb.adapter.RequestForESB2' on execution group 'IB' is stopped. (Application 'Adapter', Library '') BIP1274I: Library 'Utils' is deployed to execution group 'IB'. (Application 'Adapter') BIP1299I: File 'esb.util.subflow' is deployed to execution group 'IB'. (Application 'Adapter', Library 'Utils') BIP8071I: Successful command completion.\n"''' check_data = ([ "BIP1286I: Integration server 'IB' on integration node 'TEST' is running.", "BIP1287I: Integration server 'IB' on integration node 'TEST2' is stopped." ], [ "BIP1275I: Application 'Adapter' on execution group 'IB' is running.", "BIP1276I: Application 'Adapter2' on execution group 'IB' is stopped." ], [ "BIP1277I: Message flow 'esb.adapter.RequestForESB' on execution group 'IB' is running. (Application 'Adapter', Library '')", "BIP1278I: Message flow 'esb.adapter.RequestForESB2' on execution group 'IB' is stopped. (Application 'Adapter', Library '')" ]) bip_codes_components = get_platform_params_for_commands( iib_ver='10')[2] self.assertEqual( check_data, get_broker_items(broker_row_data=input_data, bip_codes=bip_codes_components))
def test_get_platform_params_for_commands(self): """Test for `get_platform_params_for_commands` dunction.""" command, bip_codes_brokers, bip_codes_components = get_platform_params_for_commands( iib_ver='9') self.assertEqual("get_brokers_status", command) self.assertEqual(8, len(bip_codes_brokers)) self.assertEqual(6, len(bip_codes_components)) command, bip_codes_brokers, bip_codes_components = get_platform_params_for_commands( iib_ver='10') self.assertEqual("get_integration_nodes_status", command) self.assertEqual(12, len(bip_codes_brokers)) self.assertEqual(6, len(bip_codes_components))
def test_get_integration_nodes_status(self): """Test for `get_brokers_status` function for Integration Bus v10.""" input_data = """\ BIP1284I: Integration node 'TEST' with default queue manager 'QM1 and administration URI 'http://testhost:4415' is running. BIP1285I: Integration node 'TEST' on queue manager 'QM1' is stopped. BIP1295I: Integration node 'TEST' is an active multi-instance or High Availability integration node that is running on queue manager 'QM1'. 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'. BIP1298I: Integration node 'TEST' is stopped. It will be started as a WebSphere MQ service by queue manager 'QM1'. BIP1325I: Integration node 'TEST' with administration URI 'http://testhost:4415' is running. BIP1326I: Integration node 'TEST' is stopped. BIP1340I: Integration node 'TEST' is running. BIP1353I: Integration node 'TEST' with default queue manager 'QM1' is running. 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' 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' 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\ """ check_data = [['TEST', 'running', 'QM1'], ['TEST', 'stopped', 'QM1'], ['TEST', 'running', 'QM1'], ['TEST', 'stopped', 'QM1'], ['TEST', 'stopped', 'QM1'], ['TEST', 'running', ''], ['TEST', 'stopped', ''], ['TEST', 'running', ''], ['TEST', 'running', 'QM1'], ['TEST', 'running', 'QM1'], ['TEST', 'running', 'QM1'], ['TEST', 'stopped', 'QM1']] bip_codes_integration_nodes = get_platform_params_for_commands( iib_ver='10')[1] self.assertEqual( check_data, get_brokers_status(brokers_data=input_data, bip_codes=bip_codes_integration_nodes))
def test_format_exec_group_bad_status(self): """Test for `format_exec_groups` function for good case.""" check_data = '' input_data_eg = ["BIP1111I: Execution group 'TEST.INVALID' on broker 'TEST' is invalid."] bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2] self.assertEqual( check_data, format_exec_groups( exec_groups=input_data_eg, bip_codes=bip_codes_components)) input_data_eg = ["BIP1111I: Integration server 'TEST.INVALID' on integration node 'TEST' is invalid."] bip_codes_components = get_platform_params_for_commands(iib_ver='10')[2] self.assertEqual( check_data, format_exec_groups( exec_groups=input_data_eg, bip_codes=bip_codes_components))
def test_format_message_flows_bad_status(self): """Test for `format_message_flows` function for bad case.""" input_data_msgflow = [ "BIP1111I: Message flow 'TETS.INVALID' on execution group 'TEST' is invalid. (Application 'TEST', Library '')" ] check_data = '' bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2] self.assertEqual( check_data, format_message_flows(message_flows=input_data_msgflow, broker_name=self.input_data_broker, bip_codes=bip_codes_components)) bip_codes_components = get_platform_params_for_commands( iib_ver='10')[2] self.assertEqual( check_data, format_message_flows(message_flows=input_data_msgflow, broker_name=self.input_data_broker, bip_codes=bip_codes_components))
def test_format_applications_bad_status(self): """Test for `format_applications` function for bad case.""" input_data_app = [ "BIP1111I: Execution group 'TEST.INVALID' on execution group 'TEST' is invalid." ] check_data = '' bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2] self.assertEqual( check_data, format_applications(applications=input_data_app, broker_name=self.input_data_broker, bip_codes=bip_codes_components)) bip_codes_components = get_platform_params_for_commands( iib_ver='10')[2] self.assertEqual( check_data, format_applications(applications=input_data_app, broker_name=self.input_data_broker, bip_codes=bip_codes_components))
def test_format_exec_group_good_status(self): """Test for `format_exec_groups` function for good case.""" input_data_eg = ["BIP1286I: Execution group 'TEST.RUNNING' on broker 'TEST' is running.", "BIP1287I: Execution group 'TEST.STOPPED' on broker 'TEST' is stopped."] check_data = '''\ # HELP ib_exec_group_status Current status of IB execution group. # TYPE ib_exec_group_status gauge ib_exec_group_status{brokername="TEST", egname="TEST.RUNNING"} 1 ib_exec_group_status{brokername="TEST", egname="TEST.STOPPED"} 0\n''' bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2] self.assertEqual( check_data, format_exec_groups( exec_groups=input_data_eg, bip_codes=bip_codes_components)) bip_codes_components = get_platform_params_for_commands(iib_ver='10')[2] input_data_eg = ["BIP1286I: Integration server 'TEST.RUNNING' on integration node 'TEST' is running.", "BIP1287I: Integration server 'TEST.STOPPED' on integration node 'TEST' is stopped."] self.assertEqual( check_data, format_exec_groups( exec_groups=input_data_eg, bip_codes=bip_codes_components))
def test_fformat_message_flows_good_status(self): """Test for `format_message_flows` function for good case.""" input_data_msgflow = [ "BIP1277I: Message flow 'TEST.RUNNING' on execution group 'TEST' is running. (Application 'TEST', Library '')", "BIP1278I: Message flow 'TEST.STOPPED' on execution group 'TEST' is stopped. (Application 'TEST', Library '')" ] check_data = '''\ # HELP ib_message_flow_status Current status of IB message flow. # TYPE ib_message_flow_status gauge ib_message_flow_status{egname="TEST", brokername="TEST", appname="TEST", messageflowname="TEST.RUNNING"} 1 ib_message_flow_status{egname="TEST", brokername="TEST", appname="TEST", messageflowname="TEST.STOPPED"} 0\n''' bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2] self.assertEqual( check_data, format_message_flows(message_flows=input_data_msgflow, broker_name=self.input_data_broker, bip_codes=bip_codes_components)) bip_codes_components = get_platform_params_for_commands( iib_ver='10')[2] self.assertEqual( check_data, format_message_flows(message_flows=input_data_msgflow, broker_name=self.input_data_broker, bip_codes=bip_codes_components))
def test_format_applications_good_status(self): """Test for `format_applications` function for good case.""" input_data_app = [ "BIP1275I: Application 'TEST.RUNNING' on execution group 'TEST' is running.", "BIP1276I: Application 'TEST.STOPPED' on execution group 'TEST' is stopped." ] check_data = '''\ # HELP ib_application_status Current status of IB application. # TYPE ib_application_status gauge ib_application_status{egname="TEST", brokername="TEST", appname="TEST.RUNNING"} 1 ib_application_status{egname="TEST", brokername="TEST", appname="TEST.STOPPED"} 0\n''' bip_codes_components = get_platform_params_for_commands(iib_ver='9')[2] self.assertEqual( check_data, format_applications(applications=input_data_app, broker_name=self.input_data_broker, bip_codes=bip_codes_components)) bip_codes_components = get_platform_params_for_commands( iib_ver='10')[2] self.assertEqual( check_data, format_applications(applications=input_data_app, broker_name=self.input_data_broker, bip_codes=bip_codes_components))
def test_get_brokers_status(self): """Test for `get_brokers_status` function.""" input_data = """\ BIP1284I: Broker 'TEST' on queue manager 'QM1' is running. BIP1285I: Broker 'TEST' on queue manager 'QM1' is stopped. BIP1293I: Broker 'TEST' is a multi-instance broker running in standby mode on queue manager 'QM1'. 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. BIP1295I: Broker 'TEST' is an active multi-instance or High Availability broker that is running on queue manager 'QM1'. BIP1296I: Broker 'TEST' is stopped. It is a multi-instance broker and will be started as a WebSphere MQ service by queue manager 'QM1'. BIP1297I: Broker 'TEST' is a multi-instance broker running in standby mode on queue manager 'QM1'. BIP1298I: Broker 'TEST' is stopped. It will be started as a WebSphere MQ service by queue manager 'QM1'. """ check_data = [['TEST', 'running', 'QM1'], ['TEST', 'stopped', 'QM1'], ['TEST', 'running', 'QM1'], ['TEST', 'running', 'QM1'], ['TEST', 'running', 'QM1'], ['TEST', 'stopped', 'QM1'], ['TEST', 'running', 'QM1'], ['TEST', 'stopped', 'QM1']] bip_codes_brokers = get_platform_params_for_commands(iib_ver='9')[1] self.assertEqual( check_data, get_brokers_status(brokers_data=input_data, bip_codes=bip_codes_brokers))
pushgateway_port=pushgateway_port) logger.warning( "The status of broker is {0}\nOther metrics will not be collected!" .format(status)) logger.info("Script finished in - {0} seconds -".format(time.time() - start_time)) except PrometheusBadResponse as error: logger.error(error) except Exception as e: tb = sys.exc_info()[-1] stk = traceback.extract_tb(tb, 1)[0] logger.error("Function: {0}\n{1}".format(stk, e)) if __name__ == "__main__": logger.info("Run {0}".format(static_content())) pushgateway_host, pushgateway_port, iib_ver, sleep_interval = parse_commandline_args( ) logger.info("Integration Bus version: {0}".format(iib_ver)) logger.info( "Metrics will be collected every {0} seconds".format(sleep_interval)) mqsilist_command, bip_codes_brokers, bip_codes_components = get_platform_params_for_commands( iib_ver=iib_ver) while True: get_iib_metrics(pushgateway_host=pushgateway_host, pushgateway_port=pushgateway_port, mqsilist_command=mqsilist_command, bip_codes_brokers=bip_codes_brokers, bip_codes_components=bip_codes_components) time.sleep(sleep_interval)