0% found this document useful (0 votes)
11 views10 pages

REXX Programming for Automation & JSON

Uploaded by

saimou352
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views10 pages

REXX Programming for Automation & JSON

Uploaded by

saimou352
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

REXX Programming: Automation, JSON, and AI

Integration – Real Scenarios Addendum (Sections 1–40)


Added: practical scenarios, who codes, and hands-on examples for each section.

1. Introduction to REXX and Its Ecosystem


Who codes: Mainframe automation engineer; Platform SRE; IT Ops generalist.
Scenario: REXX as a glue layer unifying classic mainframe workflows with modern CLI tools across
Linux/Windows.
/* Warm-up script that verifies runtime and prints platform */
SAY 'Welcome to REXX Automation Guide'
ADDRESS SYSTEM 'uname -a > .platform 2>&1'
IF STREAM('.platform','c','query exists') <> '' THEN DO
DO WHILE LINES('.platform') > 0
CALL LINEIN '.platform', line
SAY 'Platform:' line
END
END

Tip: Run lightweight probes and print useful environment details before larger orchestrations.

2. REXX Syntax Refresher and Best Practices


Who codes: REXX developer; junior ops learning mainframe scripting.
Scenario: Keep scripts readable and testable; prefer clear PARSE patterns and small PROCEDUREs.
/* Rotate through hosts and print status */
hosts = 'db01 web01 cache01'
i = 1
DO WHILE WORD(hosts, i) <> ''
host = WORD(hosts, i)
SAY 'Checking:' host
IF LENGTH(host) < 3 THEN SIGNAL badInput
i = i + 1
END
EXIT 0
badInput:
SAY 'Invalid host'; EXIT 1

Tip: Structure with labels and PROCEDUREs; reserve SIGNAL for exceptional flow only.

3. Environment Setup and Interpreters


Who codes: DevOps engineer; desktop support automator.
Scenario: Cross-platform team needs the same script to run under Regina (Linux) and ooRexx (Windows).
/* Portable shebang and version check */
SAY 'Interpreter sanity check'
ADDRESS SYSTEM 'rexx -v 2>&1 | head -1 > .iv'
CALL LINEIN '.iv', v
SAY 'Interpreter:' v

Tip: Document versions in logs to simplify incident root-cause analysis.

4. File Manipulation and I/O


Who codes: Data ops engineer; batch integrator.
Scenario: Nightly job ingests CSVs from an SFTP drop and emits a cleaned file.
/* Stream-clean CSV */
in = '[Link]'; out = '[Link]'
DO WHILE LINES(in) > 0
CALL LINEIN in, row
row = STRIP(row)
IF row = '' THEN ITERATE
CALL LINEOUT out, TRANSLATE(row, '', '"') /* remove quotes */
END
CALL LINEOUT out

Tip: Always stream; avoid loading entire files in memory. Log counts.

5. String Handling and Parsing Techniques


Who codes: Observability engineer; on-call responder.
Scenario: Parse app logs like 'ERROR 404 /login user=jane ip=[Link]' into fields for metrics.
line = 'ERROR 404 /login user=jane ip=[Link]'
PARSE VAR line level code path . 'user=' user ' ip=' ip
SAY 'level='level 'code='code 'path='path 'user='user 'ip='ip

Tip: Design PARSE patterns to be tolerant to minor log format drift.

6. Using Pipes and External Commands


Who codes: Platform engineer; site admin.
Scenario: Wrap platform CLIs to capture inventory and normalize output.
/* List processes then filter with grep/awk */
ADDRESS SYSTEM 'ps aux | grep -v grep | awk "{print $1"||"","||"$2"||"","||"$11}" > [Link]'
/* Bring back into REXX for post-processing */
DO WHILE LINES('[Link]') > 0
CALL LINEIN '[Link]', row
SAY 'PROC:' row
END

Tip: Prefer stable CLI flags; redirect stderr to files and keep for post-mortem.

7. Automating System Administration Tasks


Who codes: Sysadmin; production support.
Scenario: Auto-restart a crashed service after basic health checks; write structured log lines.
service = 'nginx'
rc = SYSTEM('systemctl is-active ' service ' >/dev/null 2>&1')
IF rc <> 0 THEN DO
r2 = SYSTEM('sudo systemctl restart ' service)
CALL LINEOUT '[Link]', '{"event":"restart","service":"'service'","rc":' r2 '}'
END
ELSE SAY service 'healthy'

Tip: Always emit machine-friendly logs (JSON Lines) for later search.

8. Job Control and Scheduling Examples


Who codes: Mainframe scheduler; Linux cron maintainer.
Scenario: Run hourly ETL, capturing exit codes and rotating logs.
/* Cron: 0 * * * * /usr/bin/rexx /etl/[Link] >> /var/log/[Link] 2>&1 */
SAY 'ETL tick:' DATE() TIME()
rc = SYSTEM('/etl/[Link]'); IF rc <> 0 THEN SAY 'Step1 failed:' rc
rc = SYSTEM('/etl/[Link]'); IF rc <> 0 THEN SAY 'Step2 failed:' rc

Tip: Keep each step idempotent; fail fast with helpful context.

9. Network Automation Basics with REXX


Who codes: NetOps engineer.
Scenario: Ping, check ports, and fetch a status page to confirm dependencies.
host='app01'; port=5432
ADDRESS SYSTEM 'ping -c1 ' host ' >/dev/null 2>&1'; prc=RC
ADDRESS SYSTEM 'nc -z ' host ' ' port ' >/dev/null 2>&1'; src=RC
ADDRESS SYSTEM 'curl -s [Link] > .h 2>/dev/null'; hrc=RC
SAY '{"||"ping":'prc', "||"port":'src', "||"http":'hrc'}'

Tip: Use multiple simple checks to avoid false positives.

10. JSON Overview and Interplay with REXX


Who codes: SRE; telemetry integrator.
Scenario: Emit JSON summaries to feed Grafana/Loki or Splunk pipelines.
host='server01'; cpu=42; mem=73
json='{"||"host":"||host||"","||"cpu":'||cpu||',"||"mem":'||mem||'}'
CALL LINEOUT '[Link]', json

Tip: Prefer JSON Lines for streaming ingestion.


11. Parsing JSON in REXX
Who codes: Ops engineer on a hotfix call.
Scenario: Quick-and-dirty parse of a tiny, predictable JSON payload.
json='{"||"status":"||"ok"||"","||"version":"||"1.2.3"||""}'
PARSE VAR json '{"status":"' status '","version":"' version '"}'
SAY 'status='status 'version='version

Tip: For anything complex, offload to Python/Node to avoid brittle parsing.

12. Generating JSON from REXX


Who codes: Integration engineer.
Scenario: Prepare payloads for a webhook receiver or REST ingestion service.
services='["||"nginx"||"","||"sshd"||""]'
json='{"||"host":"||"server01"||"","||"services":'||services||'}'
CALL LINEOUT '[Link]', json

Tip: Escape quotes carefully; test with jq before sending.

13. Calling REST APIs from REXX


Who codes: Incident commander; chatops maintainer.
Scenario: Post incident events to a chatops webhook with auth token.
msg='Disk usage high on db01'
token = GETENV('CHAT_TOKEN')
ADDRESS SYSTEM 'curl -s -H "Authorization: Bearer 'token'" -H "Content-Type: application/json" '||,
'-d ''{"text":"'msg'"}'' [Link] > .resp'
CALL LINEIN '.resp', r; SAY 'resp:' r

Tip: Store tokens in env vars or a vault; never hardcode secrets.

14. Error Handling and Logging Patterns


Who codes: Ops platform engineer.
Scenario: Standardize failure records with timestamps and correlation IDs.
:generateCid
cid = LEFT(TRANSLATE(STEM('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'),, ), 8)
ts = DATE('S')||'T'||TIME('L')
rc = SYSTEM('false'); IF rc <> 0 THEN DO
CALL LINEOUT '[Link]', '{"||"ts":"||ts||"","||"cid":"||cid||"","||"rc":'||rc||'}'
END

Tip: Make logs greppable and JSON-parseable; include a correlation id.

15. Case Study: Batch File Processor


Who codes: Back-office batch owner.
Scenario: Convert N input files to uppercase and archive originals.
indir='in'; out='[Link]'
DO i=1 TO 10
file = indir||'/file'||i||'.txt'
IF STREAM(file,'c','query exists') = '' THEN ITERATE
DO WHILE LINES(file) > 0
CALL LINEIN file, line
CALL LINEOUT out, TRANSLATE(line)
END
ADDRESS SYSTEM 'mv ' file ' ' indir||'/archive/'
END

Tip: Keep operations idempotent; skip missing files gracefully.

16. Case Study: Log Analyzer


Who codes: Observability analyst.
Scenario: Summarize ERROR counts by code and write a compact JSON report.
in='[Link]'
errors=0
DO WHILE LINES(in) > 0
CALL LINEIN in, line
IF POS('ERROR', line) > 0 THEN DO
PARSE VAR line . code .
errors = errors + 1
END
END
CALL LINEOUT 'log_summary.json', '{"||"errors":'||errors||'}'

Tip: Output minimal metrics that downstream tools can chart.

17. Case Study: Inventory Collector


Who codes: IT asset manager.
Scenario: Collect hostname, uptime, and IP, then send to CMDB.
ADDRESS SYSTEM 'hostname > .hn && uptime -s > .up && hostname -I | awk "{print $1}" > .ip'
CALL LINEIN '.hn', hn; CALL LINEIN '.up', up; CALL LINEIN '.ip', ip
json='{"||"host":"||STRIP(hn)||"","||"uptime":"||STRIP(up)||"","||"ip":"||STRIP(ip)||""}'
CALL LINEOUT '[Link]', json

Tip: Favor simple shell helpers for facts, then normalize in REXX.

18. Integration: REXX with Python Middleware


Who codes: Hybrid stack engineer.
Scenario: Use Python to parse large JSON and return just what REXX needs.
ADDRESS SYSTEM 'python3 parse_large.py --pick [Link] > [Link]'
CALL LINEIN '[Link]', out
SAY 'Selected:' out

Tip: REXX orchestrates; Python handles heavy JSON/regex/DB work.

19. Integration: REXX with [Link] Middleware


Who codes: Integration developer.
Scenario: Delegate async API fan-out to Node, then merge results in REXX.
ADDRESS SYSTEM 'node fetch_many.js [Link] [Link]'
CALL LINEIN '[Link]', j
SAY 'Combined:' j

Tip: Node excels at concurrent I/O; REXX coordinates inputs/outputs.


20. AI Intro: Using ML/AI via REST from REXX
Who codes: Support engineer triaging tickets.
Scenario: Score a text with sentiment API and log results.
text='Service slow for premium users'
ADDRESS SYSTEM 'curl -s -X POST [Link] -H "Content-Type: application/json" '||
'-d ''{"text":"'||text||'"}'' > [Link]'
CALL LINEIN '[Link]', s
SAY 'AI:' s

Tip: Treat AI like any other flaky network dependency: retries, timeouts.
21. AI Case: Text Summarization
Who codes: Post-incident reviewer.
Scenario: Chunk oversized incident timelines and store summaries.
ADDRESS SYSTEM 'split -l 2000 [Link] chunk_'
ADDRESS SYSTEM 'for f in chunk_*; do curl -s -X POST [Link] -d @"$f"; done > s
SAY 'Summaries written to [Link]'

Tip: Choose chunk boundaries at logical separators (timestamps, blank lines).

22. AI Case: Extract Entities from Logs


Who codes: Security analyst; fraud detection engineer.
Scenario: Pull IPs and error codes with AI, verify with regex, then emit CSV.
ADDRESS SYSTEM 'curl -s -X POST [Link] -d @[Link] > [Link]'
/* Fallback regex pass */
ADDRESS SYSTEM 'grep -Eo "([0-9]{1,3}\.){3}[0-9]{1,3}" [Link] | sort -u > [Link]'

Tip: Never trust AI fully for parsing; add deterministic checks.

23. AI Case: Automating Ticket Triage


Who codes: Service desk lead.
Scenario: Classify tickets and route high priority to paging channel.
ADDRESS SYSTEM 'curl -s -X POST [Link] -d @[Link] > [Link]'
/* Example downstream: send high-pri to webhook */
ADDRESS SYSTEM 'jq -c ".[] | select(.priority==\"P1\")" [Link] | while read -r l; do echo "$l"

Tip: Keep a manual override path; never auto-close without human review.

24. Security Considerations


Who codes: Security-conscious SRE.
Scenario: Load secrets from env vars and fail closed when missing.
api = GETENV('API_KEY'); IF api = '' THEN DO
SAY 'API key missing'; EXIT 1
END

Tip: Avoid printing secrets; scrub logs; prefer least privilege.

25. JSON Examples and Schema Design


Who codes: Data contract owner.
Scenario: Version schemas and validate required fields before sending.
payload='{"||"host":"||"server01"||"","||"schema_version":1}'
/* quick shape test with jq (exit code signals validity) */
ADDRESS SYSTEM 'echo ''"||payload||"'' | jq . >/dev/null 2>&1'

Tip: Include schema_version and reserved fields for future extensions.

26. Best Practices for Maintainability


Who codes: Team lead; code reviewer.
Scenario: Refactor big scripts into small PROCEDUREs with clear inputs/outputs.
PROCESS_FILE: PROCEDURE
PARSE ARG path
IF STREAM(path,'c','query exists') = '' THEN RETURN 1
/* ... processing ... */
RETURN 0
/* main */
rc = PROCESS_FILE('[Link]'); IF rc <> 0 THEN SAY 'failed'

Tip: Document assumptions at the top; keep functions short.

27. Unit Testing REXX Scripts


Who codes: QA engineer; maintainer.
Scenario: Golden-file test: compare actual vs expected outputs.
expected = 'Hello'
actual = 'Hello'
IF expected <> actual THEN DO
CALL LINEOUT '[Link]', 'Mismatch: ' actual
EXIT 1
END
SAY 'OK'

Tip: Automate these checks in CI; keep failure diffs small and clear.

28. Packaging and Distribution


Who codes: Release engineer.
Scenario: Ship scripts with a tiny wrapper and dependency notes.
#!/usr/bin/env rexx
CALL PROCESS '--help'
EXIT 0

Tip: Package a README and example config; prefer portable dependencies.

29. Performance Tuning


Who codes: Performance-minded SRE.
Scenario: Move expensive grep out of inner loops; batch where possible.
/* BAD: calling external grep per line. Prefer batching: */
ADDRESS SYSTEM 'grep ERROR [Link] > [Link]'
/* then iterate [Link] in REXX */

Tip: Profile first; count external process spawns; stream everything.

30. Working with Large JSON Files


Who codes: Data engineer.
Scenario: Use jq streaming to avoid memory blowups.
ADDRESS SYSTEM 'jq -c . [Link] > big_lines.json'
/* Process line-by-line */
DO WHILE LINES('big_lines.json') > 0
CALL LINEIN 'big_lines.json', j
SAY LEFT(j, 60)||'...'
END

Tip: Prefer -c (compact) and chunked processing; avoid full loads.


31. Hybrid Workflows (REXX + Modern Tools)
Who codes: Pipeline orchestrator.
Scenario: Three-step pipeline: Python -> Node -> jq -> [Link].
ADDRESS SYSTEM 'python3 [Link] > [Link]'
ADDRESS SYSTEM 'node [Link] [Link] > [Link]'
ADDRESS SYSTEM 'jq -s add [Link] > [Link]'

Tip: Keep artifacts on disk for auditability; log timings between steps.

32. Troubleshooting Guide


Who codes: On-call engineer.
Scenario: Capture stderr separately and store with timestamps.
ADDRESS SYSTEM 'curl -sS [Link] 2> curl_errors.log'
SAY 'If failure, see curl_errors.log'

Tip: Normalize error paths; include repro commands in tickets.

33. Migration Strategies to Modern Stacks


Who codes: Modernization architect.
Scenario: Peel off heavy logic into a microservice while REXX continues orchestrating.
SAY 'Adapting interface v1 -> v2'
/* Call new service while keeping legacy input format */
ADDRESS SYSTEM 'curl -s [Link] -d @[Link] > [Link]'

Tip: Run v1 and v2 in parallel temporarily; compare outputs.

34. Reference: Common REXX Built-ins


Who codes: New REXX learner.
Scenario: Quick demo to uppercase an input safely.
text = 'rexx'
SAY TRANSLATE(text, 'REXX')

Tip: Keep a cheatsheet of PARSE, WORD, POS, SUBSTR, STRIP, TRANSLATE.

35. Reference: Useful External Tools


Who codes: Linux-savvy operator.
Scenario: Combine grep/awk/sort/uniq for quick top talkers.
ADDRESS SYSTEM 'grep ERROR [Link] | awk "{print $2}" | sort | uniq -c > [Link]'
DO WHILE LINES('[Link]') > 0
CALL LINEIN '[Link]', line
SAY 'Top:' line
END

Tip: Stick to widely available flags for portability.

36. Appendix A: REXX Examples (Quick)


Who codes: CLI user; script invoker.
Scenario: Echo arguments and count them.
SAY 'Args:'
DO i = 1 TO ARG(0)
SAY ARG(i)
END
SAY 'Total:' ARG(0)

Tip: Handle no-arg case gracefully; print usage if required.

37. Appendix B: JSON Snippets


Who codes: Data integrator.
Scenario: Template for inventory payload with optional tags.
json='{"||"host":"||"[Link]"||"","||"services":["||"nginx"||"","||"sshd"||""],
"||"tags":["||"prod"||"","||"eu-west"||""],"||"schema_version":1}'
CALL LINEOUT '[Link]', json

Tip: Keep optional arrays present but possibly empty to simplify consumers.

38. Appendix C: AI Integration Patterns


Who codes: AI platform integrator.
Scenario: Pick the right pattern: direct call vs helper script vs queue.
/* Direct */
ADDRESS SYSTEM 'curl -s -X POST [Link] -d ''{"text":"Sample"}'''
/* Helper */
ADDRESS SYSTEM 'python3 ai_helper.py [Link] > [Link]'

Tip: Queues decouple spikes; helpers centralize retries/backoff.

39. Further Reading & Resources


Who codes: Knowledge curator.
Scenario: Point engineers to official docs and stable guides; bake links into runbooks.
SAY 'See official docs for latest details'
SAY 'Regina REXX, ooRexx, jq, curl, Node, Python'

Tip: Prefer vendor docs for flags/behaviors that change frequently.

40. Index and Acknowledgements


Who codes: Doc maintainer.
Scenario: Provide a quick index of key terms and thank contributors.
SAY 'End of guide'

Tip: Keep a [Link] with roles and review dates.

Common questions

Powered by AI

A hybrid workflow involving REXX, Python, and Node.js balances strengths across languages: REXX's script orchestration and file processing, Python's ability to handle complex JSON and data aggregation tasks, and Node.js's efficient I/O for async operations. This setup benefits from leveraging the best tool for each task, leading to efficient and maintainable workflows. However, the drawback lies in the increased complexity due to managing multiple environments, dependencies, and potential integration issues. Consistent documentation and standardized interfaces are crucial to minimizing these drawbacks .

REXX can integrate with AI services via REST APIs by constructing HTTP requests using system commands to communicate with AI endpoints. For example, a support engineer might use REXX to send text data to an AI sentiment analysis service by using curl to make a POST request to the API endpoint, then receive and process the sentiment score or analysis in JSON format. This enables the automation of AI evaluation tasks within REXX scripts without extensive modification of existing code .

Using the JSON Lines format is advantageous when ingesting data into tools like Grafana or Splunk because it allows for the efficient streaming of large volumes of data entries. JSON Lines supports incremental processing, which means data can be processed as it arrives without having to load entire files into memory. This format is ideal for real-time analysis and visualization, where performance and scalability are critical .

Outputting structured logs like JSON Lines is critical as it ensures uniformity and ease of parsing by automation tools and scripts, which is especially useful for system administration tasks that may involve large-scale operations or distributed systems. By standardizing logs, administrators can utilize automated processes for searching, filtering, and analyzing logs, which facilitates quick issue resolution and enhances system monitoring and management capabilities .

REXX handles cross-platform operability by allowing scripts to be executed under different interpreters like Regina on Linux and ooRexx on Windows through the use of portable features and the inclusion of version checks. By abstracting system-specific details, REXX scripts can perform consistently in various environments. Developers may include sanity checks to ensure interpreter compatibility, logging relevant details for debugging, and adapting required commands to maintain functionality across platforms .

A correlation ID is significant in logging patterns as it allows for tracking and correlating logs across distributed systems and processes. Each log entry with a correlation ID can be uniquely identified and linked, enabling traceability of transactions or processes across various system components. This aids in efficient troubleshooting and operational auditing, reducing the time needed for problem resolution as engineers can quickly gather logs related to a specific operation or incident .

To ensure that each ETL process step remains idempotent and fails fast with REXX, developers should design each script to handle repeated executions gracefully, without causing unintended data modifications. This might involve maintaining state checks or flags that denote completed operations. Incorporating immediate error handling, with clear logging on failure, ensures that any non-zero exit codes trigger appropriate responses, enabling the job to fail fast with context to facilitate troubleshooting .

To ensure readability and testability in REXX scripts, it is advised to use clear PARSE patterns, structure scripts with labels and PROCEDUREs, and reserve the use of SIGNALs for managing exceptional flow only. These practices help in organizing code logically, making maintenance easier and testing more straightforward. Additionally, keeping scripts modular with small, focused procedures further enhances their manageability and reduces the risk of introducing errors .

REXX serves as a 'glue layer' by using its scripting capabilities to automate and unify tasks across different platforms, such as Windows and Linux, while interacting seamlessly with modern CLI tools. This approach enables a mainframe automation engineer or an IT operations generalist to execute cross-platform workflows by running shell commands, parsing outputs, and chaining operations that involve both legacy systems and new technologies, thus bridging the gap between them .

Running lightweight probes before larger orchestrations in REXX helps ensure that the environment is appropriately configured and identifies any fundamental issues early. This practice can save time and resources by avoiding the execution of complex scripts in an incompatible or misconfigured environment. By verifying runtime conditions and printing essential environment details first, developers can proceed confidently with more complex automation tasks .

You might also like