﻿--  category:  IBM i Services for BRMS
--  description:  Application - BRMS Enterprise Initial Setup
--  minvrm: V7R3M0
--  Requires BRMS PTFs - 7.5 SI80273, 7.4 SI80272, 7.3 SI80271
--  last updated: 3/14/2023

--  
-- Step 1: Initialize BRMS SQL services
--  
-- Ensures the BRMS SQL services are enabled and available to use 
--  
CL: INZBRM OPTION(*SQLSRVINZ);

--
-- Step 2: Add contact names
--
-- CALL QUSRBRM.ADD_ENTERPRISE_CONTACT(
-- CONTACT_USER_NAME=> contact-user-name,     Required
-- EMAIL_ADDRESS=> email-address,             Optional
-- FIRST_NAME=> first-name,                   Optional
-- LAST_NAME=> last-name,                     Optional
-- PRIMARY_PHONE=> primary-phone,             Optional
-- SECONDARY_PHONE=> secondary-phone,         Optional
-- DESCRIPTION=> description);                Optional
--
-- Add contact name example:
--
CALL QUSRBRM.ADD_ENTERPRISE_CONTACT(
    CONTACT_USER_NAME => 'CONTACT',
    EMAIL_ADDRESS => 'CONTACT.USERID@COMPANY.COM',
    first_name => 'FIRST',
    last_name => 'LAST',
    PRIMARY_PHONE => '111-222-3333',
    SECONDARY_PHONE => '444-555-6666',
    DESCRIPTION => 'BRMS ENTERPRISE CONTACT'
);

--  
-- Step 3: Verify system communication (Recommended guidance)
--  
-- Communication needs to be established outside of BRMS for the remote system to connect and be available for use.
-- BRMS Enterprise uses relational database (RDB) entries for all of its network operations. 
--  
-- Considerations to help set up communications
-- Check TCP/IP: Use the following command to verify TCP/IP is running on the Node:
-- replace 'node-tcpip-name' with your remote system tcpip name 
CL: PING RMTSYS(node-tcpip-name);
-- If TCP/IP is not running, then you will need to configure and/or start TCP/IP on the Node.
-- SET TCP/IP DDM Connection for secure connections
-- Use ONE of the following commands to change the TCP/IP DDM attributes for secured operations:
CL: CHGDDMTCPA PWDRQD(*YES);
CL: CHGDDMTCPA PWDRQD(*USRIDPWD);
-- Change the QRETSVRSEC system value so that passwords used for authentication can be stored
CL: CHGSYSVAL QRETSVRSEC VALUE('1');
-- Use Server Authentication support
-- Add server authentication entries for each user who will be authorized to perform secured TCP/IP operations to the Nodes
-- NOTE: "QDDMDRDASERVER" must be uppercase
-- replace 'user-profile' , node-user-profile and 'node-user-profile-password' with your desired individual information
CL: ADDSVRAUTE USRPRF(user-profile) SERVER(QDDMDRDASERVER) USRID(node-user-profile) PASSWORD(node-user-profile-password);
CL: ADDSVRAUTE USRPRF(QBRMS) SERVER(QDDMDRDASERVER) USRID(node-user-profile) PASSWORD(node-user-profile-password);
-- INZBRM *VFYSYS example to verify expected communications are enabled for BRMS remote system being added
-- replace 'APPN.BRMS1' with your remote system name in the format netId.sysName
CL: INZBRM OPTION(*VFYSYS) SYSNAME('APPN.BRMS1');
-- To verify SMTP is working correctly for email functions
-- Ensure the SMTP server is running
CL: STRTCPSVR SERVER(*SMTP);
-- run the following command on the Hub and ensure the recipient receives the email.
-- replace 'userid@my.company.com' with your contact email address
CL: SNDSMTPEMM RCP((userid.mycompany.com)) SUBJECT('SMTP test') NOTE('SMTP test');

--
-- Step 4: Add system(s) into the BRMS Enterprise network
--
-- CALL QUSRBRM.ADD_ENTERPRISE_NODE(
-- SYSTEM_NAME=> system-name,                                       Required
-- RELATIONAL_DATABASE_NAME=> relational-database-name,             Required
-- ADD_NETWORK_SYSTEMS => add-network-systems,                      Optional
-- PRIMARY_CONTACT=> primary-contact,                               Optional
-- SECONDARY_CONTACT=> secondary-contact,                           Optional
-- HUB_OUTPUT_QUEUE_LIBRARY=> hub-output-queue-library,             Optional
-- HUB_OUTPUT_QUEUE=> hub-output-queue,                             Optional
-- NODE_OUTPUT_QUEUE_LIBRARY=> node-output-queue-library,           Optional
-- NODE_OUTPUT_QUEUE=> node-output-queue,                           Optional
-- DESCRIPTION=> description)                                       Optional
--
-- Add node example 1 adding a single system
--
CALL QUSRBRM.ADD_ENTERPRISE_NODE(
    SYSTEM_NAME => 'APPN.BRMS1',
    RELATIONAL_DATABASE_NAME => 'BRMS1',
    ADD_NETWORK_SYSTEMS => 'NO',
    PRIMARY_CONTACT => 'CONTACT'
);

--
-- Add node example 2
--
-- adding the system AND including all systems that are part of its BRMS network
--
CALL QUSRBRM.ADD_ENTERPRISE_NODE(
    SYSTEM_NAME => 'APPN.BRMS1',
    RELATIONAL_DATABASE_NAME => 'BRMS1',
    ADD_NETWORK_SYSTEMS => 'YES',
    PRIMARY_CONTACT => 'CONTACT'
);

--
-- Step 5: Add a report definition
--
-- CALL QUSRBRM.ADD_ENTERPRISE_REPORT_DEFINITION(
-- REPORT_DEFINITION=> report-definition,                  Required
-- SYSTEM_NAME=> system-name,                              Required
-- GENERATION_TIME=> generation-time,                      Required
-- COMMAND=> command,                                      Required
-- NUMBER_REPORTS=> number-reports,                        Optional
-- SEND_ERROR_EMAIL=> send-error-email,                    Optional
-- SEND_REPORT_EMAIL=> send-report-email,                  Optional
-- FREQUENCY_INTERVAL=> frequency-interval,                Optional
-- WEEK_DAYS=> week-days,                                  Optional
-- WAIT_DAYS=> wait-days,                                  Optional
-- DESCRIPTION=> description);                             Optional
--
-- Add report definition example 1
-- run STRMNTBRM daily
--
CALL QUSRBRM.ADD_ENTERPRISE_REPORT_DEFINITION(
    REPORT_DEFINITION => 'BRMSMNT',
    SYSTEM_NAME => 'APPN.BRMS1',
    GENERATION_TIME => '100000',
    COMMAND => 'STRMNTBRM PRTEXPMED(*YES) PRTBKUACT(*YES) PRTRCYRPT(*ALL)',
    FREQUENCY_INTERVAL => 'DAYS',
    WAIT_DAYS => '1',
    SEND_ERROR_EMAIL => 'YES',
    NUMBER_REPORTS => '7',
    SEND_REPORT_EMAIL => 'YES',
    DESCRIPTION => 'RUN EVERY DAY'
);

--
-- Add report definition example 2
--
-- run DSPLOGBRM every Monday and Friday
--
CALL QUSRBRM.ADD_ENTERPRISE_REPORT_DEFINITION(
    REPORT_DEFINITION => 'BRMSLOG',
    SYSTEM_NAME => 'APPN.BRMS1',
    GENERATION_TIME => '060000',
    COMMAND => 'DSPLOGBRM',
    FREQUENCY_INTERVAL => 'WEEKLY',
    WEEK_DAYS => 'MON FRI',
    SEND_ERROR_EMAIL => 'YES',
    NUMBER_REPORTS => '10',
    SEND_REPORT_EMAIL => 'YES',
    DESCRIPTION => 'RUNS EVERY MONDAY AND FRIDAY'
);

--
-- Step 6: Verify the report definition runs manually (Optional)
--
-- CALL QUSRBRM.RUN_ENTERPRISE_REPORT_DEFINITION(
-- REPORT_DEFINITION=> report-definition,                     Required
-- SYSTEM_NAME=> system-name);                                Required
--
-- Run report definition example
--
CALL QUSRBRM.RUN_ENTERPRISE_REPORT_DEFINITION(
    REPORT_DEFINITION => 'BRMSMNT',
    SYSTEM_NAME => 'APPN.BRMS1'
);